aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2013-08-24 16:54:56 -0500
committerBrad Fitzpatrick <bradfitz@golang.org>2013-08-24 16:54:56 -0500
commite7b125fc65695e22e33da1f6bc5bec7efae2bf65 (patch)
tree0d611e6f371f24e3f20e7696f7f23521735a7988 /src
parentcb79c57dfa25b917c4ce1c08e2a9a6f9405a5998 (diff)
downloadgo-e7b125fc65695e22e33da1f6bc5bec7efae2bf65.tar.xz
cmd/api: be more robust against OS deleting temp files
OS X in particular deletes tmp files (but not directories) pretty reliably. Ask hg whether the go.tools directory in tmp is good before using it. Fixes issue Rob and others were reporting, which I just hit myself now. R=golang-dev, r CC=golang-dev https://golang.org/cl/13084049
Diffstat (limited to 'src')
-rw-r--r--src/cmd/api/run.go31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/cmd/api/run.go b/src/cmd/api/run.go
index a13d9a5496..067be4eb05 100644
--- a/src/cmd/api/run.go
+++ b/src/cmd/api/run.go
@@ -110,12 +110,13 @@ func prepGoPath() string {
tmpDir := filepath.Join(cloneDir, tempBase)
// finalDir is where the checkout will live once it's complete.
- // If this exists already, we're done.
finalDir := filepath.Join(cloneDir, "go.tools")
- if fi, err := os.Stat(finalDir); err == nil && fi.IsDir() {
+ if goToolsCheckoutGood(finalDir) {
return gopath
}
+ os.RemoveAll(finalDir) // in case it's there but corrupt
+ os.RemoveAll(tmpDir) // in case of aborted hg clone before
if err := os.MkdirAll(cloneDir, 0700); err != nil {
log.Fatal(err)
@@ -138,3 +139,29 @@ func prepGoPath() string {
}
return gopath
}
+
+func goToolsCheckoutGood(dir string) bool {
+ if _, err := os.Stat(dir); err != nil {
+ return false
+ }
+
+ cmd := exec.Command("hg", "id", "--id")
+ cmd.Dir = dir
+ out, err := cmd.Output()
+ if err != nil {
+ return false
+ }
+ id := strings.TrimSpace(string(out))
+ if id != goToolsVersion {
+ return false
+ }
+
+ cmd = exec.Command("hg", "status")
+ cmd.Dir = dir
+ out, err = cmd.Output()
+ if err != nil || len(out) > 0 {
+ return false
+ }
+
+ return true
+}