Skip to content

Commit

Permalink
gps: Also remove symlinks when pruning non-go files
Browse files Browse the repository at this point in the history
This treats symlinks like files when considering whether to remove them
in the non-go pruning stage.

Fixes golang#1625.
  • Loading branch information
calmh authored and sigma committed Jun 7, 2018
1 parent e7e9f82 commit 5804ef6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gps/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ func collectUnusedPackagesFiles(fsState filesystemState, unusedPackages map[stri
func pruneNonGoFiles(fsState filesystemState) error {
toDelete := make([]string, 0, len(fsState.files)/4)

for _, path := range fsState.files {
paths := fsState.files
for _, link := range fsState.links {
paths = append(paths, link.path)
}

for _, path := range paths {
ext := fileExt(path)

// Refer to: https://github.com/golang/go/blob/release-branch.go1.9/src/go/build/build.go#L750
Expand Down
26 changes: 26 additions & 0 deletions gps/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,32 @@ func TestPruneNonGoFiles(t *testing.T) {
},
false,
},
{
"symlinks",
fsTestCase{
before: filesystemState{
files: []string{
"target.md",
},
links: []fsLink{
{path: "remove-1.md", to: "target.md"},
{path: "remove-2.md", to: "nonexistent", broken: true},
{path: "remove-3.md", to: "remove-3.md", circular: true},
{path: "retain-1.go", to: "target.md"},
{path: "retain-2.go", to: "nonexistent", broken: true},
{path: "retain-3.go", to: "retain-3.go", circular: true},
},
},
after: filesystemState{
links: []fsLink{
{path: "retain-1.go", to: "target.md"},
{path: "retain-2.go", to: "nonexistent", broken: true},
{path: "retain-3.go", to: "retain-3.go", circular: true},
},
},
},
false,
},
}

for _, tc := range testcases {
Expand Down

0 comments on commit 5804ef6

Please sign in to comment.