]> Cypherpunks repositories - gostls13.git/commitdiff
os: fix passing long paths to Chmod on Windows
authorIbrahim AshShohail <ibra.sho@gmail.com>
Wed, 28 Jun 2017 17:09:15 +0000 (20:09 +0300)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 28 Jun 2017 18:49:21 +0000 (18:49 +0000)
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 <bradfitz@golang.org>
src/os/file_posix.go
src/os/os_test.go

index 6ee7eeb2dad5f924c8ce6a79cb4d537f43bf007b..5ac0acdd3631a7ad0feeb4a873c6ac3c5c656d32 100644 (file)
@@ -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
index 91c6be6148d37f5b7297f03a4a995169444b0ac5..dbe4ff8830e305bca08944b5001b1c4355e1ec6e 100644 (file)
@@ -1990,6 +1990,10 @@ func TestLongPath(t *testing.T) {
                                        if dir.Size() != filesize || filesize != wantSize {
                                                t.Errorf("Size(%q) is %d, len(ReadFile()) is %d, want %d", path, dir.Size(), filesize, wantSize)
                                        }
+                                       err = Chmod(path, dir.Mode())
+                                       if err != nil {
+                                               t.Fatalf("Chmod(%q) failed: %v", path, err)
+                                       }
                                }
                                if err := Truncate(sizedTempDir+"/bar.txt", 0); err != nil {
                                        t.Fatalf("Truncate failed: %v", err)