From e1022c29c33363bd3c2471b7cef2d37dbd704dca Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Fri, 5 May 2017 19:56:30 +0200 Subject: implement rtree import --- pkg/rtree/repo.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'pkg/rtree/repo.go') 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 +} -- cgit v1.3.1