Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
internal/gps: update stripVendor functions
Browse files Browse the repository at this point in the history
Signed-off-by: Ibrahim AshShohail <[email protected]>
  • Loading branch information
ibrasho committed Aug 18, 2017
1 parent 99f36e9 commit 6a9bc1e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 59 deletions.
12 changes: 2 additions & 10 deletions internal/gps/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ func pruneNonGoFiles(baseDir string, logger *log.Logger) error {
return errors.Wrap(err, "could not prune non-Go files")
}

if err := deleteFiles(files); err != nil {
return err
}

return nil
return deleteFiles(files)
}

// calculateNonGoFiles returns a list of all non-Go files within baseDir.
Expand Down Expand Up @@ -279,11 +275,7 @@ func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
return errors.Wrap(err, "could not prune Go test files")
}

if err := deleteFiles(files); err != nil {
return err
}

return nil
return deleteFiles(files)
}

// calculateGoTestFiles walks over baseDir and returns a list of all
Expand Down
34 changes: 16 additions & 18 deletions internal/gps/strip_vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,27 @@ func stripVendor(path string, info os.FileInfo, err error) error {
return err
}

if info.Name() == "vendor" {
if _, err := os.Lstat(path); err != nil {
// Skip anything not named vendor
if info.Name() != "vendor" {
return nil
}

// If the file is a symlink to a directory, delete the symlink.
if (info.Mode() & os.ModeSymlink) != 0 {
realInfo, err := os.Stat(path)
if err != nil {
return err
}

if (info.Mode() & os.ModeSymlink) != 0 {
realInfo, err := os.Stat(path)
if err != nil {
return err
}
if realInfo.IsDir() {
return os.Remove(path)
}
if realInfo.IsDir() {
return os.Remove(path)
}
}

if info.IsDir() {
if err := removeAll(path); err != nil {
return err
}
return filepath.SkipDir
if info.IsDir() {
if err := removeAll(path); err != nil {
return err
}

return nil
return filepath.SkipDir
}

return nil
Expand Down
62 changes: 31 additions & 31 deletions internal/gps/strip_vendor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ func stripVendor(path string, info os.FileInfo, err error) error {
return err
}

if info.Name() == "vendor" {
if _, err := os.Lstat(path); err == nil {
symlink := (info.Mode() & os.ModeSymlink) != 0
dir := info.IsDir()

switch {
case symlink && dir:
// This could be a windows junction directory. Support for these in the
// standard library is spotty, and we could easily delete an important
// folder if we called os.Remove or os.RemoveAll. Just skip these.
//
// TODO: If we could distinguish between junctions and Windows symlinks,
// we might be able to safely delete symlinks, even though junctions are
// dangerous.
return filepath.SkipDir

case symlink:
realInfo, err := os.Stat(path)
if err != nil {
return err
}
if realInfo.IsDir() {
return os.Remove(path)
}

case dir:
if err := removeAll(path); err != nil {
return err
}
return filepath.SkipDir
}
if info.Name() != "vendor" {
return nil
}

symlink := (info.Mode() & os.ModeSymlink) != 0
dir := info.IsDir()

switch {
case symlink && dir:
// This could be a windows junction directory. Support for these in the
// standard library is spotty, and we could easily delete an important
// folder if we called os.Remove or os.RemoveAll. Just skip these.
//
// TODO: If we could distinguish between junctions and Windows symlinks,
// we might be able to safely delete symlinks, even though junctions are
// dangerous.
return filepath.SkipDir

case symlink:
realInfo, err := os.Stat(path)
if err != nil {
return err
}
if realInfo.IsDir() {
return os.Remove(path)
}

case dir:
if err := removeAll(path); err != nil {
return err
}
return filepath.SkipDir
}

return nil
Expand Down

0 comments on commit 6a9bc1e

Please sign in to comment.