Skip to content

Commit

Permalink
Merge the latest strip codes fromt the master
Browse files Browse the repository at this point in the history
  • Loading branch information
wolkykim committed Oct 4, 2017
1 parent 345fa0e commit 82b5519
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions internal/gps/strip_vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
53 changes: 28 additions & 25 deletions internal/gps/strip_vendor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

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:
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
}
if _, err := os.Lstat(path); err != nil {
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:
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
}

Expand Down

0 comments on commit 82b5519

Please sign in to comment.