]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: reset read-only flag during TestIssue10952
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 29 Jun 2015 00:14:24 +0000 (10:14 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Mon, 29 Jun 2015 01:49:05 +0000 (01:49 +0000)
git sets read-only flag on all its repo files on Windows.
os.Remove cannot delete these files.

Fixes windows build

Change-Id: Icaf72470456b88a1c26295caecd4e0d3dc22a1b6
Reviewed-on: https://go-review.googlesource.com/11602
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/cmd/go/go_test.go

index 028ffd8a5967234fa7b14af51817e24230f6bb15..b3cb4e44f246e9956466a9b1bf62bfa159c4fe1c 100644 (file)
@@ -554,6 +554,32 @@ func (tg *testgoData) cleanup() {
        }
 }
 
+// resetReadOnlyFlagAll resets windows read-only flag
+// set on path and any children it contains.
+// The flag is set by git and has to be removed.
+// os.Remove refuses to remove files with read-only flag set.
+func (tg *testgoData) resetReadOnlyFlagAll(path string) {
+       fi, err := os.Stat(path)
+       if err != nil {
+               tg.t.Fatalf("resetReadOnlyFlagAll(%q) failed: %v", path, err)
+       }
+       if !fi.IsDir() {
+               err := os.Chmod(path, 0666)
+               if err != nil {
+                       tg.t.Fatalf("resetReadOnlyFlagAll(%q) failed: %v", path, err)
+               }
+       }
+       fd, err := os.Open(path)
+       if err != nil {
+               tg.t.Fatalf("resetReadOnlyFlagAll(%q) failed: %v", path, err)
+       }
+       defer fd.Close()
+       names, _ := fd.Readdirnames(-1)
+       for _, name := range names {
+               tg.resetReadOnlyFlagAll(path + string(filepath.Separator) + name)
+       }
+}
+
 // failSSH puts an ssh executable in the PATH that always fails.
 // This is to stub out uses of ssh by go get.
 func (tg *testgoData) failSSH() {
@@ -970,6 +996,7 @@ func TestIssue10952(t *testing.T) {
        const importPath = "github.com/zombiezen/go-get-issue-10952"
        tg.run("get", "-d", "-u", importPath)
        repoDir := tg.path("src/" + importPath)
+       defer tg.resetReadOnlyFlagAll(repoDir)
        tg.runGit(repoDir, "remote", "set-url", "origin", "https://"+importPath+".git")
        tg.run("get", "-d", "-u", importPath)
 }