From b4373a78aedb3620baafa65e31e943e9bf1de2cf Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 17 Aug 2017 10:02:32 -0400 Subject: [PATCH 1/5] Guard against errs in stripVendor WalkFunc --- internal/gps/result.go | 5 ++++- internal/gps/strip_vendor.go | 9 ++++++++- internal/gps/strip_vendor_windows.go | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/gps/result.go b/internal/gps/result.go index d3ec22a5d4..e29ed91c9b 100644 --- a/internal/gps/result.go +++ b/internal/gps/result.go @@ -79,7 +79,10 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool, logger *log } if sv { - filepath.Walk(to, stripVendor) + err := filepath.Walk(to, stripVendor) + if err != nil { + errCh <- errors.Wrapf(err, "failed to strip vendor from %s", p.Ident().ProjectRoot) + } } wg.Done() }(p) diff --git a/internal/gps/strip_vendor.go b/internal/gps/strip_vendor.go index fec4ee13fb..1b822b4178 100644 --- a/internal/gps/strip_vendor.go +++ b/internal/gps/strip_vendor.go @@ -6,9 +6,16 @@ package gps -import "os" +import ( + "os" + "path/filepath" +) func stripVendor(path string, info os.FileInfo, err error) error { + if err != nil && err != filepath.SkipDir { + return err + } + if info.Name() == "vendor" { if _, err := os.Lstat(path); err == nil { if (info.Mode() & os.ModeSymlink) != 0 { diff --git a/internal/gps/strip_vendor_windows.go b/internal/gps/strip_vendor_windows.go index 7286934cf3..f14cf105c2 100644 --- a/internal/gps/strip_vendor_windows.go +++ b/internal/gps/strip_vendor_windows.go @@ -10,6 +10,10 @@ import ( ) func stripVendor(path string, info os.FileInfo, err error) error { + if err != nil && err != filepath.SkipDir { + return err + } + if info.Name() == "vendor" { if _, err := os.Lstat(path); err == nil { symlink := (info.Mode() & os.ModeSymlink) != 0 From 8f928b1ca310625b5c0f3ec42c50ec8f5ee747f3 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 17 Aug 2017 10:30:05 -0400 Subject: [PATCH 2/5] Accommodate error channel size properly --- internal/gps/result.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/gps/result.go b/internal/gps/result.go index e29ed91c9b..b374c6815b 100644 --- a/internal/gps/result.go +++ b/internal/gps/result.go @@ -71,11 +71,13 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool, logger *log for _, p := range l.Projects() { wg.Add(1) go func(p LockedProject) { + defer wg.Done() to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot))) logger.Printf("Writing out %s@%s", p.Ident().errString(), p.Version()) if err := sm.ExportProject(p.Ident(), p.Version(), to); err != nil { errCh <- errors.Wrapf(err, "failed to export %s", p.Ident().ProjectRoot) + return } if sv { @@ -84,7 +86,7 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool, logger *log errCh <- errors.Wrapf(err, "failed to strip vendor from %s", p.Ident().ProjectRoot) } } - wg.Done() + return }(p) } From b4ff96f9035d7c93b8570d456db438030e699a84 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 17 Aug 2017 11:54:18 -0400 Subject: [PATCH 3/5] Fix remove-before-visit bug --- internal/gps/result.go | 1 - internal/gps/strip_vendor.go | 30 +++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/internal/gps/result.go b/internal/gps/result.go index b374c6815b..16e4f05268 100644 --- a/internal/gps/result.go +++ b/internal/gps/result.go @@ -86,7 +86,6 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool, logger *log errCh <- errors.Wrapf(err, "failed to strip vendor from %s", p.Ident().ProjectRoot) } } - return }(p) } diff --git a/internal/gps/strip_vendor.go b/internal/gps/strip_vendor.go index 1b822b4178..04753ad731 100644 --- a/internal/gps/strip_vendor.go +++ b/internal/gps/strip_vendor.go @@ -17,20 +17,28 @@ func stripVendor(path string, info os.FileInfo, err error) error { } if info.Name() == "vendor" { - if _, err := os.Lstat(path); err == nil { - if (info.Mode() & os.ModeSymlink) != 0 { - realInfo, err := os.Stat(path) - if err != nil { - return err - } - if realInfo.IsDir() { - return os.Remove(path) - } + if _, err := os.Lstat(path); err != nil { + return err + } + + if (info.Mode() & os.ModeSymlink) != 0 { + realInfo, err := os.Stat(path) + if err != nil { + return err + } + if realInfo.IsDir() { + return os.Remove(path) } - if info.IsDir() { - return removeAll(path) + } + + if info.IsDir() { + if err := removeAll(path); err != nil { + return err } + return filepath.SkipDir } + + return nil } return nil From 151b3c82b548994c9061da2b05acbd8eab78cead Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 17 Aug 2017 13:04:41 -0400 Subject: [PATCH 4/5] Fix remove-before-visit for Windows, too --- internal/gps/strip_vendor_windows.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/gps/strip_vendor_windows.go b/internal/gps/strip_vendor_windows.go index f14cf105c2..0c268ff36e 100644 --- a/internal/gps/strip_vendor_windows.go +++ b/internal/gps/strip_vendor_windows.go @@ -40,7 +40,10 @@ func stripVendor(path string, info os.FileInfo, err error) error { } case dir: - return removeAll(path) + if err := removeAll(path); err != nil { + return err + } + return filepath.SkipDir } } } From 8c851799f1540446ced32cf0ec009ac77f1d21a2 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 17 Aug 2017 16:16:21 -0400 Subject: [PATCH 5/5] Drop unnecessary err check at start of walker --- internal/gps/strip_vendor.go | 2 +- internal/gps/strip_vendor_windows.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/gps/strip_vendor.go b/internal/gps/strip_vendor.go index 04753ad731..324a07df80 100644 --- a/internal/gps/strip_vendor.go +++ b/internal/gps/strip_vendor.go @@ -12,7 +12,7 @@ import ( ) func stripVendor(path string, info os.FileInfo, err error) error { - if err != nil && err != filepath.SkipDir { + if err != nil { return err } diff --git a/internal/gps/strip_vendor_windows.go b/internal/gps/strip_vendor_windows.go index 0c268ff36e..bb07da84c9 100644 --- a/internal/gps/strip_vendor_windows.go +++ b/internal/gps/strip_vendor_windows.go @@ -10,7 +10,7 @@ import ( ) func stripVendor(path string, info os.FileInfo, err error) error { - if err != nil && err != filepath.SkipDir { + if err != nil { return err }