Skip to content

Commit cfb8404

Browse files
ibrashobradfitz
authored andcommitted
os: fix passing long paths to Chmod on Windows
os.Chmod returns an error when passed a long path (>=260) characters on Windows. CL 32451 fixed most file functions in os. This change applies the same fix to os.Chmod. Fixes #20829 Change-Id: I3270db8317ce6e06e6d77070a32a5df6ab2491e0 Reviewed-on: https://go-review.googlesource.com/47010 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent e1ced32 commit cfb8404

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/os/file_posix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func syscallMode(i FileMode) (o uint32) {
4848
// If the file is a symbolic link, it changes the mode of the link's target.
4949
// If there is an error, it will be of type *PathError.
5050
func Chmod(name string, mode FileMode) error {
51-
if e := syscall.Chmod(name, syscallMode(mode)); e != nil {
51+
if e := syscall.Chmod(fixLongPath(name), syscallMode(mode)); e != nil {
5252
return &PathError{"chmod", name, e}
5353
}
5454
return nil

src/os/os_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,10 @@ func TestLongPath(t *testing.T) {
19901990
if dir.Size() != filesize || filesize != wantSize {
19911991
t.Errorf("Size(%q) is %d, len(ReadFile()) is %d, want %d", path, dir.Size(), filesize, wantSize)
19921992
}
1993+
err = Chmod(path, dir.Mode())
1994+
if err != nil {
1995+
t.Fatalf("Chmod(%q) failed: %v", path, err)
1996+
}
19931997
}
19941998
if err := Truncate(sizedTempDir+"/bar.txt", 0); err != nil {
19951999
t.Fatalf("Truncate failed: %v", err)

0 commit comments

Comments
 (0)