Skip to content

Commit 5c44cc4

Browse files
iwdgoianlancetaylor
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 5d8a61a commit 5c44cc4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/os/removeall_noat.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func removeAll(path string) error {
2727
}
2828

2929
// Simple case: if Remove works, we're done.
30+
path = fixLongPath(path)
3031
err := Remove(path)
3132
if err == nil || IsNotExist(err) {
3233
return nil

src/os/removeall_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ func TestRemoveAllLongPath(t *testing.T) {
206206
}
207207
}
208208

209+
func TestRemoveAllLongPathWindows(t *testing.T) {
210+
startPath, err := ioutil.TempDir("", "TestRemoveAllLongPath-")
211+
if err != nil {
212+
t.Fatalf("Could not create TempDir: %s", err)
213+
}
214+
defer RemoveAll(startPath)
215+
216+
// Make a long path
217+
err = MkdirAll(filepath.Join(startPath, "foo", "bar", strings.Repeat("a", 150),
218+
strings.Repeat("b", 150)), ModePerm)
219+
if err != nil {
220+
t.Fatal(err)
221+
}
222+
223+
err = RemoveAll("foo")
224+
if err != nil {
225+
t.Fatal(err)
226+
}
227+
}
228+
209229
func TestRemoveAllDot(t *testing.T) {
210230
prevDir, err := Getwd()
211231
if err != nil {

0 commit comments

Comments
 (0)