mirror of https://github.com/golang/go.git
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 <alex.brainman@gmail.com>
This commit is contained in:
parent
d0ed87d15c
commit
3b7841b3af
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue