diff --git a/internal/gps/strip_vendor.go b/internal/gps/strip_vendor.go index 7a95457e..aaaf9bcd 100644 --- a/internal/gps/strip_vendor.go +++ b/internal/gps/strip_vendor.go @@ -21,8 +21,8 @@ func stripVendor(path string, info os.FileInfo, err error) error { return nil } - // If the file is a symlink to a directory, delete the symlink. - if (info.Mode() & os.ModeSymlink) != 0 { + // If the file is a symlink to a directory, delete the symlink. + if (info.Mode() & os.ModeSymlink) != 0 { if realInfo, err := os.Stat(path); err == nil && realInfo.IsDir() { return os.Remove(path) } diff --git a/internal/gps/strip_vendor_windows.go b/internal/gps/strip_vendor_windows.go index ab659cbe..c6b0a133 100644 --- a/internal/gps/strip_vendor_windows.go +++ b/internal/gps/strip_vendor_windows.go @@ -14,34 +14,37 @@ func stripVendor(path string, info os.FileInfo, err error) error { return err } - if info.Name() != "vendor" { + if info.Name() != "vendor" { return nil } - if _, err := os.Lstat(path); err == nil { - symlink := (info.Mode() & os.ModeSymlink) != 0 - dir := info.IsDir() + if _, err := os.Lstat(path); err != nil { + return nil + } - 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 + symlink := (info.Mode() & os.ModeSymlink) != 0 + dir := info.IsDir() - case symlink: - if realInfo, err := os.Stat(path); err == nil && realInfo.IsDir() { - return os.Remove(path) - } + 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 dir: - if err := os.RemoveAll(path); err != nil { - return err - } + case symlink: + if realInfo, err := os.Stat(path); err == nil && realInfo.IsDir() { + return os.Remove(path) + } + + case dir: + if err := os.RemoveAll(path); err != nil { + return err + } return filepath.SkipDir }