1
0
mirror of https://github.com/golang/go synced 2024-11-18 00:54:45 -07:00

os: make TestLchown actually test Lchown.

TestLchown was creating a hard-link instead of a symlink. It would
have passed if you replaced all Lchown() calls in it with Chown().

Change-Id: I3a108948ec25fcbac8ea890a6eaf5bac094f0800
Reviewed-on: https://go-review.googlesource.com/17397
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Rahul Chaudhry 2015-12-03 13:19:48 -08:00 committed by Brad Fitzpatrick
parent 6094dad084
commit a27bbb7f74

View File

@ -18,16 +18,16 @@ func init() {
}
func checkUidGid(t *testing.T, path string, uid, gid int) {
dir, err := Stat(path)
dir, err := Lstat(path)
if err != nil {
t.Fatalf("Stat %q (looking for uid/gid %d/%d): %s", path, uid, gid, err)
t.Fatalf("Lstat %q (looking for uid/gid %d/%d): %s", path, uid, gid, err)
}
sys := dir.Sys().(*syscall.Stat_t)
if int(sys.Uid) != uid {
t.Errorf("Stat %q: uid %d want %d", path, sys.Uid, uid)
t.Errorf("Lstat %q: uid %d want %d", path, sys.Uid, uid)
}
if int(sys.Gid) != gid {
t.Errorf("Stat %q: gid %d want %d", path, sys.Gid, gid)
t.Errorf("Lstat %q: gid %d want %d", path, sys.Gid, gid)
}
}
@ -144,17 +144,11 @@ func TestLchown(t *testing.T) {
}
linkname := f.Name() + "2"
if err := Link(f.Name(), linkname); err != nil {
if err := Symlink(f.Name(), linkname); err != nil {
t.Fatalf("link %s -> %s: %v", f.Name(), linkname, err)
}
defer Remove(linkname)
f2, err := Open(linkname)
if err != nil {
t.Fatalf("open %s: %v", linkname, err)
}
defer f2.Close()
// Can't change uid unless root, but can try
// changing the group id. First try our current group.
gid := Getgid()
@ -177,10 +171,7 @@ func TestLchown(t *testing.T) {
}
checkUidGid(t, linkname, int(sys.Uid), g)
// change back to gid to test fd.Chown
if err = f2.Chown(-1, gid); err != nil {
t.Fatalf("fchown %s -1 %d: %s", linkname, gid, err)
}
checkUidGid(t, linkname, int(sys.Uid), gid)
// Check that link target's gid is unchanged.
checkUidGid(t, f.Name(), int(sys.Uid), int(sys.Gid))
}
}