-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syscall, os: Chmod doesn't support long paths on Windows #20829
Comments
I've found this issue while investigating golang/dep#774. I've found multiple other file related functions implemented outside
Here is a list of possible occurrences of this issue (where these functions were called without running the path through
It could possibly occur in |
I think we previously decided that we aren't adding magic UNC path mangling to the low-level syscall package. If users are using syscall, they can read MSDN docs. Let's keep this bug specifically about Chmod. |
I'm can work on a fix. But I've some questions:
edit: Actually, there is a difference. |
@bradfitz Edit: my mistake. I was reading the wrong file. Only |
Remove was already done in 231aa9d. I see: // Remove removes the named file or directory.
// If there is an error, it will be of type *PathError.
func Remove(name string) error {
p, e := syscall.UTF16PtrFromString(fixLongPath(name))
if e != nil {
return &PathError{"remove", name, e}
}
... And Chmod should be just: diff --git a/src/os/file_posix.go b/src/os/file_posix.go
index 6ee7eeb..5ac0acd 100644
--- a/src/os/file_posix.go
+++ b/src/os/file_posix.go
@@ -48,7 +48,7 @@ func syscallMode(i FileMode) (o uint32) {
// If the file is a symbolic link, it changes the mode of the link's target.
// If there is an error, it will be of type *PathError.
func Chmod(name string, mode FileMode) error {
- if e := syscall.Chmod(name, syscallMode(mode)); e != nil {
+ if e := syscall.Chmod(fixLongPath(name), syscallMode(mode)); e != nil {
return &PathError{"chmod", name, e}
}
return nil |
CL https://golang.org/cl/47010 mentions this issue. |
What version of Go are you using (
go version
)?go version go1.8.3 windows/amd64
What operating system and processor architecture are you using (
go env
)?GOOS=windows
GOARCH=amd64
What did you do?
os.Chmod
returns an unexpected error when passed a path that is longer thanMAX_PATH
(260) characters.What did you expect to see?
Similar behavior to other file functions in
os
. Callingos.fixLongPath
on the path before passing the pointer toGetFileAttributesW
andSetFileAttributesW
.231aa9d fixed the issue with long paths (>=260 chars) by introducing a new function,
os.fixLongPath
, which converts the path to an extended-length path on Windows.What did you see instead?
chmod C:\Users\ibrahim\go\src\github.com\ibrasho\deptest\vendor\github.com\prometheus\procfs\sysfs\fixtures.src\devices\pci0000_@colon@_00\0000_@colon@_00_@colon@_0d.0\ata4\host3\target3_@colon@_0_@colon@_0\3_@colon@_0_@colon@_0_@colon@_0\block\sdb\bcache\dirty_data: The system cannot find the path specified.
Applying the same logic from
os.fixLongPath
before passing the path toos.Chmod
resolves this issue.The text was updated successfully, but these errors were encountered: