aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2012-02-07 00:38:15 -0200
committerGustavo Niemeyer <gustavo@niemeyer.net>2012-02-07 00:38:15 -0200
commitc2fe6634db08902f078093f3ad9c7fa9cf7bb330 (patch)
tree1189926ec572c4b8b2f2224ea614b4948c29c486
parent4151183e94a9268b639485a35cc15c86377da81e (diff)
downloadgo-c2fe6634db08902f078093f3ad9c7fa9cf7bb330.tar.gz
go-c2fe6634db08902f078093f3ad9c7fa9cf7bb330.zip
cmd/dist: prevent race on VERSION creation
Commands such as "dist version > VERSION" will cause the shell to create an empty VERSION file and set dist's stdout to its fd. dist in turn looks at VERSION and uses its content if available, which is empty at this point. Fix that by ignoring VERSION if it's empty. Also prevent cmdversion from running findgoversion a second time. It was already loaded by init. R=adg, gustavo, rsc CC=golang-dev https://golang.org/cl/5639044
-rw-r--r--src/cmd/dist/build.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c
index 54510db1da..d5cf17dcd3 100644
--- a/src/cmd/dist/build.c
+++ b/src/cmd/dist/build.c
@@ -179,7 +179,12 @@ findgoversion(void)
if(isfile(bstr(&path))) {
readfile(&b, bstr(&path));
chomp(&b);
- goto done;
+ // Commands such as "dist version > VERSION" will cause
+ // the shell to create an empty VERSION file and set dist's
+ // stdout to its fd. dist in turn looks at VERSION and uses
+ // its content if available, which is empty at this point.
+ if(b.len > 0)
+ goto done;
}
// The $GOROOT/VERSION.cache file is a cache to avoid invoking
@@ -1370,5 +1375,5 @@ cmdversion(int argc, char **argv)
if(argc > 0)
usage();
- xprintf("%s\n", findgoversion());
+ xprintf("%s\n", goversion);
}