Commit 1e5729e0 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fs: use syscall.Rename rather than os.Rename

This provides more fidelity for reproducing file system behavior. Case
in point, it lets us rename a directory on top of an existing
directory

Fixes #55.

Change-Id: I82572aae32ee225b1629303c448a09f1066eb4ed
parent 4367657f
......@@ -155,9 +155,9 @@ func (n *loopbackNode) Rename(ctx context.Context, name string, newParent InodeE
}
p1 := filepath.Join(n.path(), name)
p2 := filepath.Join(newParentLoopback.path(), newName)
err := os.Rename(p1, p2)
err := syscall.Rename(p1, p2)
return ToErrno(err)
}
......
......@@ -33,6 +33,7 @@ var All = map[string]func(*testing.T, string){
"LinkUnlinkRename": LinkUnlinkRename,
"RenameOverwriteDestNoExist": RenameOverwriteDestNoExist,
"RenameOverwriteDestExist": RenameOverwriteDestExist,
"RenameOpenDir": RenameOpenDir,
"ReadDir": ReadDir,
"ReadDirPicksUpCreate": ReadDirPicksUpCreate,
"DirectIO": DirectIO,
......@@ -354,6 +355,41 @@ func RenameOverwrite(t *testing.T, mnt string, destExists bool) {
}
}
func RenameOpenDir(t *testing.T, mnt string) {
if err := os.Mkdir(mnt+"/dir1", 0755); err != nil {
t.Fatalf("Mkdir: %v", err)
}
if err := os.Mkdir(mnt+"/dir2", 0755); err != nil {
t.Fatalf("Mkdir: %v", err)
}
var st1 syscall.Stat_t
if err := syscall.Stat(mnt+"/dir2", &st1); err != nil {
t.Fatalf("Stat: %v", err)
}
fd, err := syscall.Open(mnt+"/dir2", syscall.O_RDONLY, 0)
if err != nil {
t.Fatalf("Open: %v", err)
}
defer syscall.Close(fd)
if err := syscall.Rename(mnt+"/dir1", mnt+"/dir2"); err != nil {
t.Fatalf("Rename: %v", err)
}
var st2 syscall.Stat_t
if err := syscall.Fstat(fd, &st2); err != nil {
t.Fatalf("Fstat: %v", err)
}
if st2.Mode&syscall.S_IFMT != syscall.S_IFDIR {
t.Errorf("got mode %o, want %o", st2.Mode, syscall.S_IFDIR)
}
if st2.Ino != st1.Ino {
t.Errorf("got ino %d, want %d", st2.Ino, st1.Ino)
}
}
// ReadDir creates 110 files one by one, checking that we get the expected
// entries after each file creation.
func ReadDir(t *testing.T, mnt string) {
......
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