This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
vendor directory writes: add counts to verbose logging, limits writers, abort on error #1043
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import ( | |
"log" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
@@ -65,37 +64,59 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool, logger *log | |
return err | ||
} | ||
|
||
var wg sync.WaitGroup | ||
errCh := make(chan error, len(l.Projects())) | ||
lps := l.Projects() | ||
|
||
type resp struct { | ||
i int | ||
err error | ||
} | ||
respCh := make(chan resp, len(lps)) | ||
|
||
for i := range lps { | ||
go func(i int) { | ||
p := lps[i] | ||
|
||
var err error | ||
defer func() { | ||
if r := recover(); r != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen one, but I wanted to be careful not to return a false positive if one occurs. |
||
err = errors.Errorf("recovered from panic exporting %s: %s", p.Ident().ProjectRoot, r) | ||
} | ||
respCh <- resp{i, err} | ||
}() | ||
|
||
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) | ||
if err = sm.ExportProject(p.Ident(), p.Version(), to); err != nil { | ||
err = errors.Wrapf(err, "failed to export %s", p.Ident().ProjectRoot) | ||
return | ||
} | ||
|
||
if sv { | ||
err := 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) | ||
err = errors.Wrapf(err, "failed to strip vendor from %s", p.Ident().ProjectRoot) | ||
} | ||
} | ||
}(p) | ||
}(i) | ||
} | ||
|
||
wg.Wait() | ||
close(errCh) | ||
var errs []error | ||
for i := 0; i < len(lps); i++ { | ||
resp := <-respCh | ||
msg := "Wrote" | ||
if resp.err != nil { | ||
errs = append(errs, resp.err) | ||
msg = "Failed to write" | ||
} | ||
p := lps[resp.i] | ||
logger.Printf("(%d/%d) %s %s@%s\n", i+1, len(lps), msg, p.Ident(), p.Version()) | ||
} | ||
close(respCh) | ||
|
||
if len(errCh) > 0 { | ||
if len(errs) > 0 { | ||
logger.Println("Failed to write dep tree. The following errors occurred:") | ||
for err := range errCh { | ||
logger.Println(" * ", err) | ||
for i, err := range errs { | ||
logger.Printf("(%d/%d) %s\n", i+1, len(errs), err) | ||
} | ||
|
||
removeAll(basedir) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any objections to this
errString
format becoming the canonical exported String method format?fmt.Sprintf("%s (from %s)", i.ProjectRoot, i.Source)
errString()
has 36 usages, all of which are passed to formatting functions with%s
, so I'd like to do a follow up PR to just absorb that method into this one and let them all implicitly call this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm yes, i like this. the individual properties are accessible already - callers can easily construct their own output if they so choose. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(separate PR, though)