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

Commit 6a9bc1e

Browse files
committed
internal/gps: update stripVendor functions
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 99f36e9 commit 6a9bc1e

File tree

3 files changed

+49
-59
lines changed

3 files changed

+49
-59
lines changed

internal/gps/prune.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ func pruneNonGoFiles(baseDir string, logger *log.Logger) error {
214214
return errors.Wrap(err, "could not prune non-Go files")
215215
}
216216

217-
if err := deleteFiles(files); err != nil {
218-
return err
219-
}
220-
221-
return nil
217+
return deleteFiles(files)
222218
}
223219

224220
// calculateNonGoFiles returns a list of all non-Go files within baseDir.
@@ -279,11 +275,7 @@ func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
279275
return errors.Wrap(err, "could not prune Go test files")
280276
}
281277

282-
if err := deleteFiles(files); err != nil {
283-
return err
284-
}
285-
286-
return nil
278+
return deleteFiles(files)
287279
}
288280

289281
// calculateGoTestFiles walks over baseDir and returns a list of all

internal/gps/strip_vendor.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,27 @@ func stripVendor(path string, info os.FileInfo, err error) error {
1616
return err
1717
}
1818

19-
if info.Name() == "vendor" {
20-
if _, err := os.Lstat(path); err != nil {
19+
// Skip anything not named vendor
20+
if info.Name() != "vendor" {
21+
return nil
22+
}
23+
24+
// If the file is a symlink to a directory, delete the symlink.
25+
if (info.Mode() & os.ModeSymlink) != 0 {
26+
realInfo, err := os.Stat(path)
27+
if err != nil {
2128
return err
2229
}
23-
24-
if (info.Mode() & os.ModeSymlink) != 0 {
25-
realInfo, err := os.Stat(path)
26-
if err != nil {
27-
return err
28-
}
29-
if realInfo.IsDir() {
30-
return os.Remove(path)
31-
}
30+
if realInfo.IsDir() {
31+
return os.Remove(path)
3232
}
33+
}
3334

34-
if info.IsDir() {
35-
if err := removeAll(path); err != nil {
36-
return err
37-
}
38-
return filepath.SkipDir
35+
if info.IsDir() {
36+
if err := removeAll(path); err != nil {
37+
return err
3938
}
40-
41-
return nil
39+
return filepath.SkipDir
4240
}
4341

4442
return nil

internal/gps/strip_vendor_windows.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@ func stripVendor(path string, info os.FileInfo, err error) error {
1414
return err
1515
}
1616

17-
if info.Name() == "vendor" {
18-
if _, err := os.Lstat(path); err == nil {
19-
symlink := (info.Mode() & os.ModeSymlink) != 0
20-
dir := info.IsDir()
21-
22-
switch {
23-
case symlink && dir:
24-
// This could be a windows junction directory. Support for these in the
25-
// standard library is spotty, and we could easily delete an important
26-
// folder if we called os.Remove or os.RemoveAll. Just skip these.
27-
//
28-
// TODO: If we could distinguish between junctions and Windows symlinks,
29-
// we might be able to safely delete symlinks, even though junctions are
30-
// dangerous.
31-
return filepath.SkipDir
32-
33-
case symlink:
34-
realInfo, err := os.Stat(path)
35-
if err != nil {
36-
return err
37-
}
38-
if realInfo.IsDir() {
39-
return os.Remove(path)
40-
}
41-
42-
case dir:
43-
if err := removeAll(path); err != nil {
44-
return err
45-
}
46-
return filepath.SkipDir
47-
}
17+
if info.Name() != "vendor" {
18+
return nil
19+
}
20+
21+
symlink := (info.Mode() & os.ModeSymlink) != 0
22+
dir := info.IsDir()
23+
24+
switch {
25+
case symlink && dir:
26+
// This could be a windows junction directory. Support for these in the
27+
// standard library is spotty, and we could easily delete an important
28+
// folder if we called os.Remove or os.RemoveAll. Just skip these.
29+
//
30+
// TODO: If we could distinguish between junctions and Windows symlinks,
31+
// we might be able to safely delete symlinks, even though junctions are
32+
// dangerous.
33+
return filepath.SkipDir
34+
35+
case symlink:
36+
realInfo, err := os.Stat(path)
37+
if err != nil {
38+
return err
39+
}
40+
if realInfo.IsDir() {
41+
return os.Remove(path)
42+
}
43+
44+
case dir:
45+
if err := removeAll(path); err != nil {
46+
return err
4847
}
48+
return filepath.SkipDir
4949
}
5050

5151
return nil

0 commit comments

Comments
 (0)