Changing format
This commit is contained in:
parent
b8c009a3e0
commit
86ff7e4d45
42
link.go
42
link.go
@ -29,11 +29,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type link struct {
|
|
||||||
Dst string
|
|
||||||
Src string
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanPath(loc string, flags int) error {
|
func cleanPath(loc string, flags int) error {
|
||||||
verbose := flags&optVerbose == optVerbose
|
verbose := flags&optVerbose == optVerbose
|
||||||
|
|
||||||
@ -74,13 +69,34 @@ func prepInstallPath(loc string, flags int) error {
|
|||||||
return cleanPath(loc, flags)
|
return cleanPath(loc, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this link) install(srcDir, dstDir string, flags int) error {
|
func (this *link) source() string {
|
||||||
if len(this.Dst) == 0 {
|
if len(*this) > 0 {
|
||||||
this.Dst = this.Src
|
return (*this)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
srcPath := path.Join(srcDir, this.Src)
|
return ""
|
||||||
dstPath := path.Join(dstDir, this.Dst)
|
}
|
||||||
|
|
||||||
|
func (this *link) destination() string {
|
||||||
|
if len(*this) > 1 {
|
||||||
|
return (*this)[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.source()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *link) valid() bool {
|
||||||
|
length := len(*this)
|
||||||
|
return length >= 1 && length <= 2
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *link) install(srcDir, dstDir string, flags int) error {
|
||||||
|
if !this.valid() {
|
||||||
|
return fmt.Errorf("Link element is invalid")
|
||||||
|
}
|
||||||
|
|
||||||
|
srcPath := path.Join(srcDir, this.source())
|
||||||
|
dstPath := path.Join(dstDir, this.destination())
|
||||||
|
|
||||||
if _, err := os.Stat(srcPath); os.IsNotExist(err) {
|
if _, err := os.Stat(srcPath); os.IsNotExist(err) {
|
||||||
return fmt.Errorf("Source path does not exist in filesystem: '%s'", srcPath)
|
return fmt.Errorf("Source path does not exist in filesystem: '%s'", srcPath)
|
||||||
@ -98,9 +114,9 @@ func (this link) install(srcDir, dstDir string, flags int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *link) uninstall(dstDir string, flags int) error {
|
func (this *link) uninstall(dstDir string, flags int) error {
|
||||||
if len(this.Dst) == 0 {
|
if !this.valid() {
|
||||||
this.Dst = this.Src
|
return fmt.Errorf("Link element is invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
return cleanPath(path.Join(dstDir, this.Dst), flags)
|
return cleanPath(path.Join(dstDir, this.destination()), flags)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user