]> Cypherpunks repositories - gostls13.git/commitdiff
os: document that Chown with -1 means to leave values unchanged, like POSIX
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 11 Apr 2018 22:51:17 +0000 (22:51 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 11 Apr 2018 23:06:44 +0000 (23:06 +0000)
And fix the nacl implementation.

Fixes #24710

Change-Id: I31ffeea03a72dac5021ffb183fde31e9ffd060ad
Reviewed-on: https://go-review.googlesource.com/106464
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/file_plan9.go
src/os/file_posix.go
src/syscall/fs_nacl.go

index 7e281789642879315ed36d6e9b32c6a1597ecb22..feca8630beaf907d5b7d8d1bf3087330e3a35d32 100644 (file)
@@ -451,7 +451,11 @@ func Readlink(name string) (string, error) {
 
 // Chown changes the numeric uid and gid of the named file.
 // If the file is a symbolic link, it changes the uid and gid of the link's target.
+// A uid or gid of -1 means to not change that value.
 // If there is an error, it will be of type *PathError.
+//
+// On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or
+// EPLAN9 error, wrapped in *PathError.
 func Chown(name string, uid, gid int) error {
        return &PathError{"chown", name, syscall.EPLAN9}
 }
index 36f7b90e806622c1ff85de75c956ac153f2503e2..b8835a70b8e331ff38b5f6bd25f56ac87993da09 100644 (file)
@@ -65,10 +65,11 @@ func (f *File) chmod(mode FileMode) error {
 
 // Chown changes the numeric uid and gid of the named file.
 // If the file is a symbolic link, it changes the uid and gid of the link's target.
+// A uid or gid of -1 means to not change that value.
 // If there is an error, it will be of type *PathError.
 //
-// On Windows, it always returns the syscall.EWINDOWS error, wrapped
-// in *PathError.
+// On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or
+// EPLAN9 error, wrapped in *PathError.
 func Chown(name string, uid, gid int) error {
        if e := syscall.Chown(name, uid, gid); e != nil {
                return &PathError{"chown", name, e}
index 33334dc24b694bed7fc836c24996f5bac121892d..dfe13d92a1321066d687069d18710d9b7455f20e 100644 (file)
@@ -582,8 +582,12 @@ func Chown(path string, uid, gid int) error {
        if err != nil {
                return err
        }
-       ip.Uid = uint32(uid)
-       ip.Gid = uint32(gid)
+       if uid != -1 {
+               ip.Uid = uint32(uid)
+       }
+       if gid != -1 {
+               ip.Gid = uint32(gid)
+       }
        return nil
 }