Old code cleanup. Removing functionality no longer needed.
diff --git a/action/config_wizard.go b/action/config_wizard.go index e941399..ae2b317 100644 --- a/action/config_wizard.go +++ b/action/config_wizard.go
@@ -18,6 +18,7 @@ // ConfigWizard reads configuration from a glide.yaml file and attempts to suggest // improvements. The wizard is interactive. func ConfigWizard(base string) { + cache.SystemLock() _, err := gpath.Glide() glidefile := gpath.GlideFile if err != nil {
diff --git a/action/get.go b/action/get.go index aab0e4a..0d5e004 100644 --- a/action/get.go +++ b/action/get.go
@@ -19,9 +19,7 @@ // // This includes resolving dependency resolution and re-generating the lock file. func Get(names []string, installer *repo.Installer, insecure, skipRecursive, stripVendor, nonInteract, testDeps bool) { - if installer.UseCache { - cache.SystemLock() - } + cache.SystemLock() base := gpath.Basepath() EnsureGopath()
diff --git a/action/install.go b/action/install.go index b3f5052..2247e1f 100644 --- a/action/install.go +++ b/action/install.go
@@ -13,9 +13,7 @@ // Install installs a vendor directory based on an existing Glide configuration. func Install(installer *repo.Installer, stripVendor bool) { - if installer.UseCache { - cache.SystemLock() - } + cache.SystemLock() base := "." // Ensure GOPATH
diff --git a/action/list.go b/action/list.go index f4b3379..29d815f 100644 --- a/action/list.go +++ b/action/list.go
@@ -25,7 +25,7 @@ if err != nil { msg.Die("Could not create a resolver: %s", err) } - h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}} + h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "vendor"} r.Handler = h localPkgs, _, err := r.ResolveLocal(deep)
diff --git a/action/remove.go b/action/remove.go index bdf96a1..63a6a58 100644 --- a/action/remove.go +++ b/action/remove.go
@@ -1,6 +1,7 @@ package action import ( + "github.com/Masterminds/glide/cache" "github.com/Masterminds/glide/cfg" "github.com/Masterminds/glide/msg" gpath "github.com/Masterminds/glide/path" @@ -9,6 +10,7 @@ // Remove removes a dependncy from the configuration. func Remove(packages []string, inst *repo.Installer) { + cache.SystemLock() base := gpath.Basepath() EnsureGopath() EnsureVendorDir()
diff --git a/action/update.go b/action/update.go index 219c98e..91891f4 100644 --- a/action/update.go +++ b/action/update.go
@@ -13,9 +13,7 @@ // Update updates repos and the lock file from the main glide yaml. func Update(installer *repo.Installer, skipRecursive, stripVendor bool) { - if installer.UseCache { - cache.SystemLock() - } + cache.SystemLock() base := "." EnsureGopath()
diff --git a/cfg/config.go b/cfg/config.go index 60d385b..06ba9b9 100644 --- a/cfg/config.go +++ b/cfg/config.go
@@ -368,15 +368,14 @@ // Dependency describes a package that the present package depends upon. type Dependency struct { - Name string `yaml:"package"` - Reference string `yaml:"version,omitempty"` - Pin string `yaml:"-"` - Repository string `yaml:"repo,omitempty"` - VcsType string `yaml:"vcs,omitempty"` - Subpackages []string `yaml:"subpackages,omitempty"` - Arch []string `yaml:"arch,omitempty"` - Os []string `yaml:"os,omitempty"` - UpdateAsVendored bool `yaml:"-"` + Name string `yaml:"package"` + Reference string `yaml:"version,omitempty"` + Pin string `yaml:"-"` + Repository string `yaml:"repo,omitempty"` + VcsType string `yaml:"vcs,omitempty"` + Subpackages []string `yaml:"subpackages,omitempty"` + Arch []string `yaml:"arch,omitempty"` + Os []string `yaml:"os,omitempty"` } // A transitive representation of a dependency for importing and exploting to yaml. @@ -506,15 +505,14 @@ // Clone creates a clone of a Dependency func (d *Dependency) Clone() *Dependency { return &Dependency{ - Name: d.Name, - Reference: d.Reference, - Pin: d.Pin, - Repository: d.Repository, - VcsType: d.VcsType, - Subpackages: d.Subpackages, - Arch: d.Arch, - Os: d.Os, - UpdateAsVendored: d.UpdateAsVendored, + Name: d.Name, + Reference: d.Reference, + Pin: d.Pin, + Repository: d.Repository, + VcsType: d.VcsType, + Subpackages: d.Subpackages, + Arch: d.Arch, + Os: d.Os, } }
diff --git a/dependency/delete.go b/dependency/delete.go deleted file mode 100644 index 6456370..0000000 --- a/dependency/delete.go +++ /dev/null
@@ -1,106 +0,0 @@ -package dependency - -import ( - "errors" - "os" - "path/filepath" - "strings" - - "github.com/Masterminds/glide/cfg" - "github.com/Masterminds/glide/msg" - gpath "github.com/Masterminds/glide/path" -) - -// DeleteUnused removes packages from vendor/ that are no longer used. -// -// TODO: This should work off of a Lock file, not glide.yaml. -func DeleteUnused(conf *cfg.Config) error { - vpath, err := gpath.Vendor() - if err != nil { - return err - } - if vpath == "" { - return errors.New("Vendor not set") - } - - // Build directory tree of what to keep. - var pkgList []string - for _, dep := range conf.Imports { - pkgList = append(pkgList, dep.Name) - } - for _, dep := range conf.DevImports { - pkgList = append(pkgList, dep.Name) - } - - var searchPath string - var markForDelete []string - // Callback function for filepath.Walk to delete packages not in yaml file. - fn := func(path string, info os.FileInfo, err error) error { - // Bubble up the error - if err != nil { - return err - } - - if info.IsDir() == false || path == searchPath || path == vpath { - return nil - } - - localPath := strings.TrimPrefix(path, searchPath) - keep := false - - // First check if the path has a prefix that's a specific package. If - // so we keep it to keep the package. - for _, name := range pkgList { - if strings.HasPrefix(localPath, name) { - keep = true - } - } - - // If a package is, for example, github.com/Masterminds/glide the - // previous look will not mark the directories github.com or - // github.com/Masterminds to keep. Here we see if these names prefix - // and packages we know about to mark as keepers. - if keep == false { - for _, name := range pkgList { - if strings.HasPrefix(name, localPath) { - keep = true - } - } - } - - // If the parent directory has already been marked for delete this - // directory doesn't need to be marked. - for _, markedDirectory := range markForDelete { - if strings.HasPrefix(path, markedDirectory) { - return nil - } - } - - // Remove the directory if we are not keeping it. - if keep == false { - // Mark for deletion - markForDelete = append(markForDelete, path) - } - - return nil - } - - // Walk vendor directory - searchPath = vpath + string(os.PathSeparator) - err = filepath.Walk(searchPath, fn) - if err != nil { - return err - } - - // Perform the actual delete. - for _, path := range markForDelete { - localPath := strings.TrimPrefix(path, searchPath) - msg.Info("Removing unused package: %s\n", localPath) - rerr := os.RemoveAll(path) - if rerr != nil { - return rerr - } - } - - return nil -}
diff --git a/dependency/resolver.go b/dependency/resolver.go index 5a31ae2..b3000ee 100644 --- a/dependency/resolver.go +++ b/dependency/resolver.go
@@ -64,6 +64,7 @@ type DefaultMissingPackageHandler struct { Missing []string Gopath []string + Prefix string } // NotFound prints a warning and then stores the package name in Missing. @@ -88,7 +89,11 @@ return nil } +// PkgPath returns the path to the package func (d *DefaultMissingPackageHandler) PkgPath(pkg string) string { + if d.Prefix != "" { + return filepath.Join(d.Prefix, pkg) + } return pkg } @@ -486,9 +491,9 @@ // try to brute force the packages with a slower scan. msg.Debug("Using Iterative Scanning for %s", dep) if testDeps { - _, imps, err = IterativeScan(vdep) + _, imps, err = IterativeScan(r.Handler.PkgPath(dep)) } else { - imps, _, err = IterativeScan(vdep) + imps, _, err = IterativeScan(r.Handler.PkgPath(dep)) } if err != nil { @@ -496,7 +501,7 @@ continue } } else if err != nil { - msg.Debug("ImportDir error on %s: %s", vdep, err) + msg.Debug("ImportDir error on %s: %s", r.Handler.PkgPath(dep), err) if strings.HasPrefix(err.Error(), "no buildable Go source") { msg.Debug("No subpackages declared. Skipping %s.", dep) continue @@ -782,9 +787,9 @@ // or main but +build ignore as a build tag. In that case we // try to brute force the packages with a slower scan. if testDeps { - _, imps, err = IterativeScan(pkg) + _, imps, err = IterativeScan(r.Handler.PkgPath(pkg)) } else { - imps, _, err = IterativeScan(pkg) + imps, _, err = IterativeScan(r.Handler.PkgPath(pkg)) } if err != nil {
diff --git a/glide.lock b/glide.lock index 06b0f01..2d3fc9c 100644 --- a/glide.lock +++ b/glide.lock
@@ -1,5 +1,5 @@ hash: 67c5571c33bfcb663d32d2b40b9ce1f2a05a3fa2e9f442077277c2782195729c -updated: 2016-08-11T14:07:30.163990133-04:00 +updated: 2016-08-11T14:22:17.773372627-04:00 imports: - name: github.com/codegangsta/cli version: 1efa31f08b9333f1bd4882d61f9d668a70cd902e
diff --git a/path/strip.go b/path/strip.go index be00be9..62c5fd8 100644 --- a/path/strip.go +++ b/path/strip.go
@@ -8,35 +8,6 @@ "github.com/Masterminds/glide/msg" ) -// StripVcs removes VCS metadata (.git, .hg, .bzr, .svn) from the vendor/ -// directory. -func StripVcs() error { - searchPath, _ := Vendor() - if _, err := os.Stat(searchPath); err != nil { - if os.IsNotExist(err) { - msg.Debug("Vendor directory does not exist.") - } - - return err - } - - return filepath.Walk(searchPath, func(path string, info os.FileInfo, err error) error { - name := info.Name() - if name == ".git" || name == ".bzr" || name == ".svn" || name == ".hg" { - if _, err := os.Stat(path); err == nil { - if info.IsDir() { - msg.Info("Removing: %s", path) - return os.RemoveAll(path) - } - - msg.Debug("%s is not a directory. Skipping removal", path) - return nil - } - } - return nil - }) -} - // StripVendor removes nested vendor and Godeps/_workspace/ directories. func StripVendor() error { searchPath, _ := Vendor()
diff --git a/path/strip_test.go b/path/strip_test.go deleted file mode 100644 index 23e9d94..0000000 --- a/path/strip_test.go +++ /dev/null
@@ -1,75 +0,0 @@ -package path - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestStripVcs(t *testing.T) { - tempDir, err := ioutil.TempDir("", "strip-vcs") - if err != nil { - t.Error(err) - } - - defer func() { - err = os.RemoveAll(tempDir) - if err != nil { - t.Error(err) - } - }() - - // Make VCS directories. - v := filepath.Join(tempDir, VendorDir) - err = os.Mkdir(v, 0755) - if err != nil { - t.Error(err) - } - - gp := filepath.Join(tempDir, VendorDir, ".git") - err = os.Mkdir(gp, 0755) - if err != nil { - t.Error(err) - } - - bp := filepath.Join(tempDir, VendorDir, ".bzr") - err = os.Mkdir(bp, 0755) - if err != nil { - t.Error(err) - } - - hp := filepath.Join(tempDir, VendorDir, ".hg") - err = os.Mkdir(hp, 0755) - if err != nil { - t.Error(err) - } - - sp := filepath.Join(tempDir, VendorDir, ".svn") - err = os.Mkdir(sp, 0755) - if err != nil { - t.Error(err) - } - - wd, _ := os.Getwd() - os.Chdir(tempDir) - - if err := StripVcs(); err != nil { - t.Errorf("Failed to strip vcs: %s", err) - } - - os.Chdir(wd) - - if _, err := os.Stat(gp); !os.IsNotExist(err) { - t.Error(".git directory not deleted") - } - if _, err := os.Stat(hp); !os.IsNotExist(err) { - t.Error(".hg directory not deleted") - } - if _, err := os.Stat(bp); !os.IsNotExist(err) { - t.Error(".bzr directory not deleted") - } - if _, err := os.Stat(sp); !os.IsNotExist(err) { - t.Error(".svn directory not deleted") - } -}
diff --git a/repo/installer.go b/repo/installer.go index 99a6452..bb46db2 100644 --- a/repo/installer.go +++ b/repo/installer.go
@@ -32,20 +32,6 @@ // Vendor contains the path to put the vendor packages Vendor string - // Use a cache - UseCache bool - // Use Gopath to cache - UseCacheGopath bool - // Use Gopath as a source to read from - UseGopath bool - - // UpdateVendored instructs the environment to update in a way that is friendly - // to packages that have been "vendored in" (e.g. are copies of source, not repos) - UpdateVendored bool - - // DeleteUnused deletes packages that are unused, but found in the vendor dir. - DeleteUnused bool - // ResolveAllFiles enables a resolver that will examine the dependencies // of every file of every package, rather than only following imported // packages. @@ -145,16 +131,11 @@ m := &MissingPackageHandler{ destination: vpath, - - cache: i.UseCache, - cacheGopath: i.UseCacheGopath, - useGopath: i.UseGopath, - home: i.Home, - force: i.Force, - updateVendored: i.UpdateVendored, - Config: conf, - Use: ic, - updated: i.Updated, + home: i.Home, + force: i.Force, + Config: conf, + Use: ic, + updated: i.Updated, } v := &VersionHandler{ @@ -502,12 +483,12 @@ // // When a package is found on the GOPATH, this notifies the user. type MissingPackageHandler struct { - destination string - home string - cache, cacheGopath, useGopath, force, updateVendored bool - Config *cfg.Config - Use *importCache - updated *UpdateTracker + destination string + home string + force bool + Config *cfg.Config + Use *importCache + updated *UpdateTracker } // NotFound attempts to retrieve a package when not found in the local vendor/ @@ -573,11 +554,6 @@ // vendor/ directory or download it from the internet. This is dependent if // useGopath on the installer is set to true to copy from the GOPATH. func (m *MissingPackageHandler) OnGopath(pkg string, addTest bool) (bool, error) { - // If useGopath is false, we fall back to the strategy of fetching from - // remote. - if !m.useGopath { - return m.NotFound(pkg, addTest) - } root := util.GetRootFromPackage(pkg)
diff --git a/repo/vendored_cleanup.go b/repo/vendored_cleanup.go deleted file mode 100644 index acbab91..0000000 --- a/repo/vendored_cleanup.go +++ /dev/null
@@ -1,43 +0,0 @@ -package repo - -import ( - "os" - "path/filepath" - - "github.com/Masterminds/glide/cfg" - "github.com/Masterminds/glide/msg" - gpath "github.com/Masterminds/glide/path" -) - -// VendoredCleanup cleans up vendored codebases after an update. -// -// This should _only_ be run for installations that do not want VCS repos inside -// of the vendor/ directory. -func VendoredCleanup(conf *cfg.Config) error { - vend, err := gpath.Vendor() - if err != nil { - return err - } - - for _, dep := range conf.Imports { - if dep.UpdateAsVendored == true { - msg.Info("Cleaning up vendored package %s\n", dep.Name) - - // Remove the VCS directory - cwd := filepath.Join(vend, dep.Name) - repo, err := dep.GetRepo(cwd) - if err != nil { - msg.Err("Error cleaning up %s:%s", dep.Name, err) - continue - } - t := repo.Vcs() - err = os.RemoveAll(cwd + string(os.PathSeparator) + "." + string(t)) - if err != nil { - msg.Err("Error cleaning up VCS dir for %s:%s", dep.Name, err) - } - } - - } - - return nil -}