]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: make subdirectories unwritable too
authorRuss Cox <rsc@golang.org>
Tue, 17 Jul 2018 01:29:39 +0000 (21:29 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 18 Jul 2018 02:09:00 +0000 (02:09 +0000)
The top-level directory in a module was marked unwritable
but not the subdirectories. Fix that.

Change-Id: Ia57e5343624753851d9fe1ddfe496b870b67f924
Reviewed-on: https://go-review.googlesource.com/124381
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modfetch/unzip.go
src/cmd/go/mod_test.go

index 724976176109dce214fee8dd58fc4c31fe5cde42..a50431fd8629de18f4cd9b2f1f5ee1b790852bf9 100644 (file)
@@ -146,7 +146,7 @@ func Unzip(dir, zipfile, prefix string, maxSize int64) error {
 
        // Run over list backward to chmod children before parents.
        for i := len(dirlist) - 1; i >= 0; i-- {
-               os.Chmod(dir, 0555)
+               os.Chmod(dirlist[i], 0555)
        }
 
        return nil
index 946a7fb1909a5a81d0d6a25996f91b4cc0df0ab7..a15832faca5996f27d39d1fffd4c09e39206966c 100644 (file)
@@ -1037,8 +1037,7 @@ func TestModList(t *testing.T) {
        `), 0666))
        tg.must(ioutil.WriteFile(tg.path("x/go.mod"), []byte(`
                module x
-               require rsc.io/quote v1.5.1
-               replace rsc.io/sampler v1.3.0 => rsc.io/sampler v1.3.1
+               require rsc.io/quote v1.5.2
        `), 0666))
        tg.cd(tg.path("x"))
 
@@ -1051,7 +1050,7 @@ func TestModList(t *testing.T) {
        tg.grepStdoutNot(`quote@`, "should not have local copy of code")
 
        tg.run("list", "-f={{.Dir}}", "rsc.io/quote") // downloads code to load package
-       tg.grepStdout(`mod[\\/]rsc.io[\\/]quote@v1.5.1`, "expected cached copy of code")
+       tg.grepStdout(`mod[\\/]rsc.io[\\/]quote@v1.5.2`, "expected cached copy of code")
        dir := strings.TrimSpace(tg.getStdout())
        info, err := os.Stat(dir)
        if err != nil {
@@ -1060,7 +1059,21 @@ func TestModList(t *testing.T) {
        if info.Mode()&0222 != 0 {
                t.Fatalf("%s should be unwritable", dir)
        }
+       info, err = os.Stat(filepath.Join(dir, "buggy"))
+       if err != nil {
+               t.Fatal(err)
+       }
+       if info.Mode()&0222 != 0 {
+               t.Fatalf("%s should be unwritable", filepath.Join(dir, "buggy"))
+       }
 
+       tg.must(ioutil.WriteFile(tg.path("x/go.mod"), []byte(`
+               module x
+               require rsc.io/quote v1.5.1
+               replace rsc.io/sampler v1.3.0 => rsc.io/sampler v1.3.1
+       `), 0666))
+
+       tg.run("list", "-f={{.Dir}}", "rsc.io/quote") // downloads code to load package
        tg.run("list", "-m", "-f={{.Path}} {{.Version}} {{.Dir}}{{with .Replace}} => {{.Version}} {{.Dir}}{{end}}", "all")
        tg.grepStdout(`mod[\\/]rsc.io[\\/]quote@v1.5.1`, "expected cached copy of code")
        tg.grepStdout(`v1.3.0 .*mod[\\/]rsc.io[\\/]sampler@v1.3.1 => v1.3.1 .*@v1.3.1`, "expected v1.3.1 replacement")