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 all commits
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 @@ -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