diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 19:56:30 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 19:56:30 +0200 |
| commit | e1022c29c33363bd3c2471b7cef2d37dbd704dca (patch) | |
| tree | 0dcdb756d10d0e53c4c5589fa12e5f547123b589 /pkg/rtree/repo.go | |
| parent | cdf41693a87559dee892c042591a409200637b9a (diff) | |
| download | gofu-e1022c29c33363bd3c2471b7cef2d37dbd704dca.tar.gz | |
implement rtree import
Diffstat (limited to 'pkg/rtree/repo.go')
| -rw-r--r-- | pkg/rtree/repo.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/pkg/rtree/repo.go b/pkg/rtree/repo.go index 93ab9d2..12f087f 100644 --- a/pkg/rtree/repo.go +++ b/pkg/rtree/repo.go @@ -226,3 +226,39 @@ func (r Repo) InteractiveExec(command string, args ...string) (ok bool) { } return true } + +//Move sets the CheckoutPath to the given value and moves the existing repo +//from the old to the new checkoutPath. If makeSymlink is given, a symlink will +//be created from the old to the new location. +func (r *Repo) Move(checkoutPath string, makeSymlink bool) error { + sourcePath := filepath.Join(RootPath, r.CheckoutPath) + targetPath := filepath.Join(RootPath, checkoutPath) + + //ensure that target does not exist + _, err := os.Lstat(targetPath) + if err == nil { + return fmt.Errorf("cannot move %s to %s: target exists in filesystem", sourcePath, targetPath) + } + if !os.IsNotExist(err) { + return err + } + + //prepare directory to move repo into + err = os.MkdirAll(filepath.Dir(targetPath), 0755) + if err != nil { + return err + } + + //move directory + err = os.Rename(sourcePath, targetPath) + if err != nil { + return err + } + r.CheckoutPath = checkoutPath + + //if requested, make compatibility symlink + if makeSymlink { + return os.Symlink(targetPath, sourcePath) + } + return nil +} |
