Closed
Description
On Go 1.13.5 on Windows 2008 R2, running os.RemoveAll on a directory that contains a path longer than 260 characters hangs.
In the following repro, the directory is created, and then the program hangs on os.RemoveAll.
package main
import (
"log"
"os"
"path/filepath"
)
func main() {
// make a long path
a := ""
b := ""
for i := 0; i < 150; i++ {
a += "a"
b += "b"
}
wd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
err = os.MkdirAll(filepath.Join(wd, "foo", "bar", a, b), 0755)
if err != nil {
log.Fatal(err)
}
// remove the root of the long path
err = os.RemoveAll("foo")
if err != nil {
log.Fatal(err)
}
}
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
ALTree commentedon Jan 3, 2020
Previously: #3358
[-]os.RemoveAll hangs on a path longer than 260 characters on Windows[/-][+]os: RemoveAll hangs on a path longer than 260 characters on Windows[/+]networkimprov commentedon Jan 4, 2020
cc @zx2c4 @alexbrainman @mattn
alexbrainman commentedon Jan 4, 2020
@bsamek I can reproduce it here, thank you very much.
The problem is that
calls
which calls
which fails, because syscalls don't allow for relative path to be longer than 256 chars. But syscall.RemoveDirectory should succeeds, because directory exists and can be deleted.
Path is converted with os.fixLongPath in os.Remove, but os.fixLongPath does not handle relative path, and returns them as is.
Alex
networkimprov commentedon Jan 4, 2020
Could os.RemoveAll() construct an absolute path and pass that to os.Remove() ?
gopherbot commentedon Jan 12, 2020
Change https://golang.org/cl/214437 mentions this issue:
os: handle long path in RemoveAll for windows
networkimprov commentedon Jan 13, 2020
I don't think that fix is correct...
gopherbot commentedon Jan 13, 2020
Change https://golang.org/cl/214598 mentions this issue:
os: actually remove long path in TestRemoveAll
gopherbot commentedon Jan 13, 2020
Change https://golang.org/cl/214601 mentions this issue:
Revert "os: handle long path in RemoveAll for windows"
ianlancetaylor commentedon Jan 13, 2020
Patch was reverted, so reopening issue.
63 remaining items