From 3b7841b3aff9204f054ffabbe4dd39d3e3dd3e91 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 29 Jun 2015 10:14:24 +1000 Subject: [PATCH] cmd/go: reset read-only flag during TestIssue10952 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 --- src/cmd/go/go_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 028ffd8a59..b3cb4e44f2 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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) } -- 2.50.0