Commit a27bbb7f authored by Rahul Chaudhry's avatar Rahul Chaudhry Committed by Brad Fitzpatrick

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 6094dad0
......@@ -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))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment