]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: prevent race on VERSION creation
authorGustavo Niemeyer <gustavo@niemeyer.net>
Tue, 7 Feb 2012 02:38:15 +0000 (00:38 -0200)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Tue, 7 Feb 2012 02:38:15 +0000 (00:38 -0200)
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

src/cmd/dist/build.c

index 54510db1daaaca5c5883c1e3e22727207e18dd87..d5cf17dcd31f50651397124a2553157f4b5f56c1 100644 (file)
@@ -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);
 }