mirror of
https://github.com/golang/go
synced 2024-11-22 03:24:41 -07:00
gofmt: race condition in error reporting and setting exit code
How to reproduce: $ mkdir /tmp/foo $ cp /dev/null /tmp/foo/bar.go $ chmod -r /tmp/foo/bar.go $ gofmt /tmp/foo open /tmp/foo/bar.go: permission denied $ echo $? # should echo 2 0 $ Maybe you need to put a call to time.Sleep at the beginning of report(). R=gri CC=golang-dev https://golang.org/cl/164073
This commit is contained in:
parent
d8bc797ed5
commit
0aa13c999b
@ -150,6 +150,7 @@ func (v fileVisitor) VisitFile(path string, d *os.Dir) {
|
|||||||
|
|
||||||
func walkDir(path string) {
|
func walkDir(path string) {
|
||||||
// start an error handler
|
// start an error handler
|
||||||
|
done := make(chan bool);
|
||||||
v := make(fileVisitor);
|
v := make(fileVisitor);
|
||||||
go func() {
|
go func() {
|
||||||
for err := range v {
|
for err := range v {
|
||||||
@ -157,10 +158,12 @@ func walkDir(path string) {
|
|||||||
report(err)
|
report(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
done <- true;
|
||||||
}();
|
}();
|
||||||
// walk the tree
|
// walk the tree
|
||||||
pathutil.Walk(path, v, v);
|
pathutil.Walk(path, v, v);
|
||||||
close(v);
|
close(v); // terminate error handler loop
|
||||||
|
<-done; // wait for all errors to be reported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user