From: Constantin Konstantinidis Date: Sat, 11 Jan 2020 18:53:20 +0000 (+0100) Subject: os: handle long path in RemoveAll for windows X-Git-Tag: go1.14rc1~120 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5c44cc47c6e868c3b6c800b24e64182bcc213fe6;p=gostls13.git os: handle long path in RemoveAll for windows Fixes #36375 Change-Id: I407a1db23868880b83e73bc136d274659483fb69 Reviewed-on: https://go-review.googlesource.com/c/go/+/214437 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/os/removeall_noat.go b/src/os/removeall_noat.go index c1b43e3807..6474d2d54e 100644 --- a/src/os/removeall_noat.go +++ b/src/os/removeall_noat.go @@ -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 diff --git a/src/os/removeall_test.go b/src/os/removeall_test.go index 8a71f687ed..6fb31c2d8f 100644 --- a/src/os/removeall_test.go +++ b/src/os/removeall_test.go @@ -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 {