Skip to content

Commit

Permalink
Merge pull request #286 from Masterminds/fix-empty-directory
Browse files Browse the repository at this point in the history
Fixed #275, #285: Empty package location causes errors
  • Loading branch information
mattfarina committed Feb 24, 2016
2 parents e2c79cf + bcf56da commit b0616a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dependency/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (r *Resolver) resolveImports(queue *list.List) ([]string, error) {
msg.Debug("Using Iterative Scanning for %s", dep)
imps, err = IterativeScan(vdep)
if err != nil {
msg.Err("Error scanning %s: %s", dep, err)
msg.Err("Iterative scanning error %s: %s", dep, err)
continue
}
} else if err != nil {
Expand Down
19 changes: 17 additions & 2 deletions repo/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,23 @@ func (m *MissingPackageHandler) NotFound(pkg string) (bool, error) {
// 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 {
msg.Debug("Found %s", dest)
return true, 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)
Expand Down
11 changes: 11 additions & 0 deletions repo/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ func VcsUpdate(dep *cfg.Dependency, dest, home string, cache, cacheGopath, useGo
_, err = v.DetectVcsFromFS(dest)
if updateVendored == false && empty == false && err == v.ErrCannotDetectVCS {
msg.Warn("%s appears to be a vendored package. Unable to update. Consider the '--update-vendored' flag.\n", dep.Name)
} else if updateVendored == false && empty == true && err == v.ErrCannotDetectVCS {
msg.Warn("%s is an empty directory. Fetching a new copy of the dependency.", dep.Name)
msg.Debug("Removing empty directory %s", dest)
err := os.RemoveAll(dest)
if err != nil {
return err
}
if err = VcsGet(dep, dest, home, cache, cacheGopath, useGopath); err != nil {
msg.Warn("Unable to checkout %s\n", dep.Name)
return err
}
} else {

if updateVendored == true && empty == false && err == v.ErrCannotDetectVCS {
Expand Down

0 comments on commit b0616a2

Please sign in to comment.