Commit dfd827ce authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Fixes for weekly 2012.02.07: stop using os.FileInfo.

parent 76c6deb5
......@@ -134,12 +134,6 @@ func (a *Attr) FromStat(s *syscall.Stat_t) {
a.Blksize = uint32(s.Blksize)
}
func (a *Attr) FromFileInfo(fi os.FileInfo) {
stat := fi.(*os.FileStat)
sys := stat.Sys.(*syscall.Stat_t)
a.FromStat(sys)
}
func (a *Attr) ChangeTime() time.Time {
return time.Unix(int64(a.Ctime), int64(a.Ctimensec))
}
......@@ -153,9 +147,9 @@ func (a *Attr) ModTime() time.Time {
}
func ToStatT(f os.FileInfo) *syscall.Stat_t {
s := f.(*os.FileStat).Sys
s, _ := f.Sys().(*syscall.Stat_t)
if s != nil {
return s.(*syscall.Stat_t)
return s
}
return nil
}
......
......@@ -126,11 +126,12 @@ func TestTouch(t *testing.T) {
CheckSuccess(err)
err = os.Chtimes(ts.mountFile, time.Unix(42, 0), time.Unix(43, 0))
CheckSuccess(err)
fi, err := os.Lstat(ts.mountFile)
var stat syscall.Stat_t
err = syscall.Lstat(ts.mountFile, &stat)
CheckSuccess(err)
stat := fi.(*os.FileStat).Sys.(*syscall.Stat_t)
if stat.Atim.Sec != 42 || stat.Mtim.Sec != 43 {
t.Errorf("Got wrong timestamps %v", fi)
t.Errorf("Got wrong timestamps %v", stat)
}
}
......@@ -242,18 +243,17 @@ func TestLinkCreate(t *testing.T) {
err = os.Link(me.mountFile, mountSubfile)
CheckSuccess(err)
subStat, err := os.Lstat(mountSubfile)
var subStat, stat syscall.Stat_t
err = syscall.Lstat(mountSubfile, &subStat)
CheckSuccess(err)
stat, err := os.Lstat(me.mountFile)
err = syscall.Lstat(me.mountFile, &stat)
CheckSuccess(err)
subfi := ToStatT(subStat)
fi := ToStatT(stat)
if fi.Nlink != 2 {
t.Errorf("Expect 2 links: %v", fi)
if stat.Nlink != 2 {
t.Errorf("Expect 2 links: %v", stat)
}
if fi.Ino != subfi.Ino {
t.Errorf("Link succeeded, but inode numbers different: %v %v", fi.Ino, subfi.Ino)
if stat.Ino != subStat.Ino {
t.Errorf("Link succeeded, but inode numbers different: %v %v", stat.Ino, subStat.Ino)
}
readback, err := ioutil.ReadFile(mountSubfile)
CheckSuccess(err)
......@@ -282,13 +282,12 @@ func TestLinkExisting(t *testing.T) {
err = os.Link(me.orig+"/file1", me.orig+"/file2")
CheckSuccess(err)
f1, err := os.Lstat(me.mnt + "/file1")
var s1, s2 syscall.Stat_t
err = syscall.Lstat(me.mnt + "/file1", &s1)
CheckSuccess(err)
f2, err := os.Lstat(me.mnt + "/file2")
err = syscall.Lstat(me.mnt + "/file2", &s2)
CheckSuccess(err)
s1 := ToStatT(f1)
s2 := ToStatT(f2)
if s1.Ino != s2.Ino {
t.Errorf("linked files should have identical inodes %v %v", s1.Ino, s2.Ino)
}
......@@ -313,16 +312,14 @@ func TestLinkForget(t *testing.T) {
err = os.Link(me.orig+"/file1", me.orig+"/file2")
CheckSuccess(err)
f1, err := os.Lstat(me.mnt + "/file1")
var s1, s2 syscall.Stat_t
err = syscall.Lstat(me.mnt + "/file1", &s1)
CheckSuccess(err)
me.pathFs.ForgetClientInodes()
f2, err := os.Lstat(me.mnt + "/file2")
err = syscall.Lstat(me.mnt + "/file2", &s2)
CheckSuccess(err)
s1 := ToStatT(f1)
s2 := ToStatT(f2)
if s1.Ino == s2.Ino {
t.Error("After forget, we should not export links")
}
......
......@@ -35,17 +35,16 @@ func TestLinkAt(t *testing.T) {
t.Fatalf("Linkat %d", e)
}
f1, err := os.Lstat(dir + "/a")
var s1, s2 syscall.Stat_t
err := syscall.Lstat(dir + "/a", &s1)
if err != nil {
t.Fatalf("Lstat a: %v", err)
}
f2, err := os.Lstat(dir + "/b")
err = syscall.Lstat(dir + "/b", &s2)
if err != nil {
t.Fatalf("Lstat b: %v", err)
}
s1 := ToStatT(f1)
s2 := ToStatT(f2)
if s1.Ino != s2.Ino {
t.Fatal("Ino mismatch", s1, s2)
}
......
......@@ -3,6 +3,7 @@ package fuse
import (
"io/ioutil"
"os"
"syscall"
"testing"
)
......@@ -43,10 +44,12 @@ func setupOwnerTest(opts *FileSystemOptions) (workdir string, cleanup func()) {
func TestOwnerDefault(t *testing.T) {
wd, cleanup := setupOwnerTest(NewFileSystemOptions())
defer cleanup()
fi, err := os.Lstat(wd + "/foo")
var stat syscall.Stat_t
err := syscall.Lstat(wd + "/foo", &stat)
CheckSuccess(err)
if int(ToStatT(fi).Uid) != os.Getuid() || int(ToStatT(fi).Gid) != os.Getgid() {
if int(stat.Uid) != os.Getuid() || int(stat.Gid) != os.Getgid() {
t.Fatal("Should use current uid for mount")
}
}
......@@ -54,10 +57,12 @@ func TestOwnerDefault(t *testing.T) {
func TestOwnerRoot(t *testing.T) {
wd, cleanup := setupOwnerTest(&FileSystemOptions{})
defer cleanup()
fi, err := os.Lstat(wd + "/foo")
var st syscall.Stat_t
err := syscall.Lstat(wd + "/foo", &st)
CheckSuccess(err)
if ToStatT(fi).Uid != _RANDOM_OWNER || ToStatT(fi).Gid != _RANDOM_OWNER {
if st.Uid != _RANDOM_OWNER || st.Gid != _RANDOM_OWNER {
t.Fatal("Should use FS owner uid")
}
}
......@@ -65,10 +70,12 @@ func TestOwnerRoot(t *testing.T) {
func TestOwnerOverride(t *testing.T) {
wd, cleanup := setupOwnerTest(&FileSystemOptions{Owner: &Owner{42, 43}})
defer cleanup()
fi, err := os.Lstat(wd + "/foo")
var stat syscall.Stat_t
err := syscall.Lstat(wd + "/foo", &stat)
CheckSuccess(err)
if ToStatT(fi).Uid != 42 || ToStatT(fi).Gid != 43 {
if stat.Uid != 42 || stat.Gid != 43 {
t.Fatal("Should use current uid for mount")
}
}
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