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

Skip broken vendor symlink rather than returning an error. #1191

Merged
merged 3 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions internal/gps/strip_vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ func stripVendor(path string, info os.FileInfo, err error) error {
}

if (info.Mode() & os.ModeSymlink) != 0 {
realInfo, err := os.Stat(path)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than simply ignoring errors here, let's verify that it's an error indicating that the target file does not exist.

(I'm still thinking about this change overall, but if we do go this direction, then we absolutely need this check.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess adding err != nil { do_nothing } is not necessary. it ignores when lstat() succeed but stat() is either returns null or non-directory. What checks would you like to add specifically?
This is a case our whole team had to rollback.

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 @@ -31,11 +31,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