]> Cypherpunks repositories - gostls13.git/commitdiff
os: handle long path in RemoveAll for windows
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Sat, 11 Jan 2020 18:53:20 +0000 (19:53 +0100)
committerIan Lance Taylor <iant@golang.org>
Mon, 13 Jan 2020 20:42:57 +0000 (20:42 +0000)
Fixes #36375

Change-Id: I407a1db23868880b83e73bc136d274659483fb69
Reviewed-on: https://go-review.googlesource.com/c/go/+/214437
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/os/removeall_noat.go
src/os/removeall_test.go

index c1b43e380753e6ea748ade2803fb346688d0f2f8..6474d2d54e4dfed005bb21b3bb5f3bbaa78d6915 100644 (file)
@@ -27,6 +27,7 @@ func removeAll(path string) error {
        }
 
        // Simple case: if Remove works, we're done.
+       path = fixLongPath(path)
        err := Remove(path)
        if err == nil || IsNotExist(err) {
                return nil
index 8a71f687ed0d7ccfe30885c33fe2eb97e81d2d02..6fb31c2d8f1ef77c0ff36b7bcbde49f8c941cb5c 100644 (file)
@@ -206,6 +206,26 @@ func TestRemoveAllLongPath(t *testing.T) {
        }
 }
 
+func TestRemoveAllLongPathWindows(t *testing.T) {
+       startPath, err := ioutil.TempDir("", "TestRemoveAllLongPath-")
+       if err != nil {
+               t.Fatalf("Could not create TempDir: %s", err)
+       }
+       defer RemoveAll(startPath)
+
+       // Make a long path
+       err = MkdirAll(filepath.Join(startPath, "foo", "bar", strings.Repeat("a", 150),
+               strings.Repeat("b", 150)), ModePerm)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       err = RemoveAll("foo")
+       if err != nil {
+               t.Fatal(err)
+       }
+}
+
 func TestRemoveAllDot(t *testing.T) {
        prevDir, err := Getwd()
        if err != nil {