Clearning up some internal checks handling on the installer
diff --git a/repo/installer.go b/repo/installer.go index eb3cd66..112d7bb 100644 --- a/repo/installer.go +++ b/repo/installer.go
@@ -130,25 +130,22 @@ // In other words, all versions in the Lockfile will be empty. func (i *Installer) Update(conf *cfg.Config) error { base := "." - vpath := i.VendorPath() ic := newImportCache() m := &MissingPackageHandler{ - destination: vpath, - home: i.Home, - force: i.Force, - Config: conf, - Use: ic, - updated: i.Updated, + home: i.Home, + force: i.Force, + Config: conf, + Use: ic, + updated: i.Updated, } v := &VersionHandler{ - Destination: vpath, - Use: ic, - Imported: make(map[string]bool), - Conflicts: make(map[string]bool), - Config: conf, + Use: ic, + Imported: make(map[string]bool), + Conflicts: make(map[string]bool), + Config: conf, } // Update imports @@ -347,16 +344,14 @@ // List resolves the complete dependency tree and returns a list of dependencies. func (i *Installer) List(conf *cfg.Config) []*cfg.Dependency { base := "." - vpath := i.VendorPath() ic := newImportCache() v := &VersionHandler{ - Destination: vpath, - Use: ic, - Imported: make(map[string]bool), - Conflicts: make(map[string]bool), - Config: conf, + Use: ic, + Imported: make(map[string]bool), + Conflicts: make(map[string]bool), + Config: conf, } // Update imports @@ -516,71 +511,22 @@ // // When a package is found on the GOPATH, this notifies the user. type MissingPackageHandler struct { - destination string - home string - force bool - Config *cfg.Config - Use *importCache - updated *UpdateTracker + home string + force bool + Config *cfg.Config + Use *importCache + updated *UpdateTracker } -// NotFound attempts to retrieve a package when not found in the local vendor/ +// NotFound attempts to retrieve a package when not found in the local cache // folder. It will attempt to get it from the remote location info. func (m *MissingPackageHandler) NotFound(pkg string, addTest bool) (bool, error) { - root := util.GetRootFromPackage(pkg) - // Skip any references to the root package. - if root == m.Config.Name { - return false, nil - } - - dest := filepath.Join(m.destination, root) - - // This package may have been placed on the list to look for when it wasn't - // downloaded but it has since been downloaded before coming to this entry. - if _, err := os.Stat(dest); err == nil { - // Make sure the location contains files. It may be an empty directory. - empty, err := gpath.IsDirectoryEmpty(dest) - if err != nil { - return false, err - } - if empty { - msg.Warn("%s is an existing location with no files. Fetching a new copy of the dependency.", dest) - msg.Debug("Removing empty directory %s", dest) - err := os.RemoveAll(dest) - if err != nil { - msg.Debug("Installer error removing directory %s: %s", dest, err) - return false, err - } - } else { - msg.Debug("Found %s", dest) - return true, nil - } - } - - msg.Info("Fetching %s into %s", pkg, m.destination) - - d := m.Config.Imports.Get(root) - if d == nil && addTest { - d = m.Config.DevImports.Get(root) - } - - // If the dependency is nil it means the Config doesn't yet know about it. - if d == nil { - d, _ = m.Use.Get(root) - // We don't know about this dependency so we create a basic instance. - if d == nil { - d = &cfg.Dependency{Name: root} - } - if addTest { - m.Config.DevImports = append(m.Config.DevImports, d) - } else { - m.Config.Imports = append(m.Config.Imports, d) - } - } - if err := VcsGet(d); err != nil { + err := m.fetchToCache(pkg, addTest) + if err != nil { return false, err } - return true, nil + + return true, err } // OnGopath will either copy a package, already found in the GOPATH, to the @@ -588,68 +534,18 @@ // useGopath on the installer is set to true to copy from the GOPATH. func (m *MissingPackageHandler) OnGopath(pkg string, addTest bool) (bool, error) { - root := util.GetRootFromPackage(pkg) - - // Skip any references to the root package. - if root == m.Config.Name { - return false, nil + err := m.fetchToCache(pkg, addTest) + if err != nil { + return false, err } - msg.Info("Copying package %s from the GOPATH.", pkg) - dest := filepath.Join(m.destination, pkg) - // Find package on Gopath - for _, gp := range gpath.Gopaths() { - src := filepath.Join(gp, pkg) - // FIXME: Should probably check if src is a dir or symlink. - if _, err := os.Stat(src); err == nil { - if err := os.MkdirAll(dest, os.ModeDir|0755); err != nil { - return false, err - } - if err := gpath.CopyDir(src, dest); err != nil { - return false, err - } - return true, nil - } - } - - msg.Err("Could not locate %s on the GOPATH, though it was found before.", pkg) - return false, nil + return true, err } // InVendor updates a package in the vendor/ directory to make sure the latest // is available. func (m *MissingPackageHandler) InVendor(pkg string, addTest bool) error { - root := util.GetRootFromPackage(pkg) - // Skip any references to the root package. - if root == m.Config.Name { - return nil - } - - d := m.Config.Imports.Get(root) - if d == nil && addTest { - d = m.Config.DevImports.Get(root) - } - - // If the dependency is nil it means the Config doesn't yet know about it. - if d == nil { - d, _ = m.Use.Get(root) - // We don't know about this dependency so we create a basic instance. - if d == nil { - d = &cfg.Dependency{Name: root} - } - - if addTest { - m.Config.DevImports = append(m.Config.DevImports, d) - } else { - m.Config.Imports = append(m.Config.Imports, d) - } - } - - if err := VcsUpdate(d, m.force, m.updated); err != nil { - return err - } - - return nil + return m.fetchToCache(pkg, addTest) } // PkgPath resolves the location on the filesystem where the package should be. @@ -678,6 +574,36 @@ return filepath.Join(cache.Location(), "src", key, sub) } +func (m *MissingPackageHandler) fetchToCache(pkg string, addTest bool) error { + root := util.GetRootFromPackage(pkg) + // Skip any references to the root package. + if root == m.Config.Name { + return nil + } + + d := m.Config.Imports.Get(root) + if d == nil && addTest { + d = m.Config.DevImports.Get(root) + } + + // If the dependency is nil it means the Config doesn't yet know about it. + if d == nil { + d, _ = m.Use.Get(root) + // We don't know about this dependency so we create a basic instance. + if d == nil { + d = &cfg.Dependency{Name: root} + } + + if addTest { + m.Config.DevImports = append(m.Config.DevImports, d) + } else { + m.Config.Imports = append(m.Config.Imports, d) + } + } + + return VcsUpdate(d, m.force, m.updated) +} + // VersionHandler handles setting the proper version in the VCS. type VersionHandler struct { @@ -688,9 +614,6 @@ // Cache if importing scan has already occurred here. Imported map[string]bool - // Where the packages exist to set the version on. - Destination string - Config *cfg.Config // There's a problem where many sub-packages have been asked to set a version @@ -713,7 +636,7 @@ // Should we look in places other than the root of the project? if d.Imported[root] == false { d.Imported[root] = true - p := filepath.Join(d.Destination, root) + p := d.pkgPath(pkg) f, deps, err := importer.Import(p) if f && err == nil { for _, dep := range deps { @@ -770,7 +693,7 @@ v.Pin = "" dep = v } else if v.Reference != "" && dep.Reference != "" && v.Reference != dep.Reference { - dest := filepath.Join(d.Destination, filepath.FromSlash(v.Name)) + dest := d.pkgPath(pkg) dep = determineDependency(v, dep, dest, req) } else { dep = v @@ -811,6 +734,30 @@ return } +func (d *VersionHandler) pkgPath(pkg string) string { + root, sub := util.NormalizeName(pkg) + + dep := d.Config.Imports.Get(root) + if dep == nil { + dep = d.Config.DevImports.Get(root) + } + + if dep == nil { + dep, _ = d.Use.Get(root) + + if dep == nil { + dep = &cfg.Dependency{Name: root} + } + } + + key, err := cache.Key(dep.Remote()) + if err != nil { + msg.Die("Error generating cache key for %s", dep.Name) + } + + return filepath.Join(cache.Location(), "src", key, sub) +} + func determineDependency(v, dep *cfg.Dependency, dest, req string) *cfg.Dependency { repo, err := v.GetRepo(dest) if err != nil {
diff --git a/repo/vcs.go b/repo/vcs.go index 76349c9..508cf8b 100644 --- a/repo/vcs.go +++ b/repo/vcs.go
@@ -36,8 +36,6 @@ } updated.Add(dep.Name) - msg.Info("--> Fetching updates for %s.", dep.Name) - if filterArchOs(dep) { msg.Info("%s is not used for %s/%s.\n", dep.Name, runtime.GOOS, runtime.GOARCH) return nil @@ -52,12 +50,14 @@ // If destination doesn't exist we need to perform an initial checkout. if _, err := os.Stat(dest); os.IsNotExist(err) { + msg.Info("--> Fetching %s.", dep.Name) if err = VcsGet(dep); err != nil { msg.Warn("Unable to checkout %s\n", dep.Name) return err } } else { // At this point we have a directory for the package. + msg.Info("--> Fetching updates for %s.", dep.Name) // When the directory is not empty and has no VCS directory it's // a vendored files situation.