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

Commit

Permalink
Merge pull request #1191 from wolkykim/skip_broken_vendor_symlink
Browse files Browse the repository at this point in the history
Skip broken vendor symlink rather than returning an error.
  • Loading branch information
sdboyer authored Oct 6, 2017
2 parents 23a470c + 82b5519 commit 97d2cd0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
6 changes: 1 addition & 5 deletions internal/gps/strip_vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ func stripVendor(path string, info os.FileInfo, err error) error {

// 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 realInfo.IsDir() {
if realInfo, err := os.Stat(path); err == nil && realInfo.IsDir() {
return os.Remove(path)
}
}
Expand Down
25 changes: 25 additions & 0 deletions internal/gps/strip_vendor_nonwindows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ func TestStripVendorSymlinks(t *testing.T) {
},
}))

t.Run("broken vendor symlink", stripVendorTestCase(fsTestCase{
before: filesystemState{
dirs: []fsPath{
{"package"},
},
links: []fsLink{
{
path: fsPath{"package", "vendor"},
to: "nonexistence",
},
},
},
after: filesystemState{
dirs: []fsPath{
{"package"},
},
links: []fsLink{
{
path: fsPath{"package", "vendor"},
to: "nonexistence",
},
},
},
}))

t.Run("chained symlinks", stripVendorTestCase(fsTestCase{
before: filesystemState{
dirs: []fsPath{
Expand Down
6 changes: 1 addition & 5 deletions internal/gps/strip_vendor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ func stripVendor(path string, info os.FileInfo, err error) error {
return filepath.SkipDir

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

Expand Down
25 changes: 25 additions & 0 deletions internal/gps/strip_vendor_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ func TestStripVendorSymlinks(t *testing.T) {
},
}))

t.Run("broken vendor symlink", stripVendorTestCase(fsTestCase{
before: filesystemState{
dirs: []fsPath{
{"package"},
},
links: []fsLink{
{
path: fsPath{"package", "vendor"},
to: "nonexistence",
},
},
},
after: filesystemState{
dirs: []fsPath{
{"package"},
},
links: []fsLink{
{
path: fsPath{"package", "vendor"},
to: "nonexistence",
},
},
},
}))

t.Run("chained symlinks", stripVendorTestCase(fsTestCase{
// Curiously, if a symlink on windows points to *another* symlink which
// eventually points at a directory, we'll correctly remove that first
Expand Down

0 comments on commit 97d2cd0

Please sign in to comment.