Commit 589723ca authored by Aaron Jacobs's avatar Aaron Jacobs

Tightened up symlink tests, in particular around removing.

parents 2f23b2ca 32c4d03a
...@@ -436,15 +436,16 @@ func (o *RmDirOp) toBazilfuseResponse() (bfResp interface{}) { ...@@ -436,15 +436,16 @@ func (o *RmDirOp) toBazilfuseResponse() (bfResp interface{}) {
return return
} }
// Unlink a file from its parent. If this brings the inode's link count to // Unlink a file or symlink from its parent. If this brings the inode's link
// zero, the inode should be deleted once the kernel sends ForgetInodeOp. It // count to zero, the inode should be deleted once the kernel sends
// may still be referenced before then if a user still has the file open. // ForgetInodeOp. It may still be referenced before then if a user still has
// the file open.
// //
// Sample implementation in ext2: ext2_unlink (http://goo.gl/hY6r6C) // Sample implementation in ext2: ext2_unlink (http://goo.gl/hY6r6C)
type UnlinkOp struct { type UnlinkOp struct {
commonOp commonOp
// The ID of parent directory inode, and the name of the file being removed // The ID of parent directory inode, and the name of the entry being removed
// within it. // within it.
Parent InodeID Parent InodeID
Name string Name string
......
...@@ -1136,19 +1136,36 @@ func (t *MemFSTest) HardLinks() { ...@@ -1136,19 +1136,36 @@ func (t *MemFSTest) HardLinks() {
} }
func (t *MemFSTest) CreateSymlink() { func (t *MemFSTest) CreateSymlink() {
var fi os.FileInfo
var err error var err error
symlinkName := path.Join(t.Dir, "foo") symlinkName := path.Join(t.Dir, "foo")
target := "taco/burrito" target := "taco/burrito"
// Create. // Create the link.
err = os.Symlink(target, symlinkName) err = os.Symlink(target, symlinkName)
AssertEq(nil, err) AssertEq(nil, err)
// Read // Stat the link.
fi, err = os.Lstat(symlinkName)
AssertEq(nil, err)
ExpectEq("foo", fi.Name())
ExpectEq(0444|os.ModeSymlink, fi.Mode())
// Read the link.
actual, err := os.Readlink(symlinkName) actual, err := os.Readlink(symlinkName)
AssertEq(nil, err) AssertEq(nil, err)
ExpectEq(target, actual) ExpectEq(target, actual)
// Read the parent directory.
entries, err := fusetesting.ReadDirPicky(t.Dir)
AssertEq(nil, err)
AssertEq(1, len(entries))
fi = entries[0]
ExpectEq("foo", fi.Name())
ExpectEq(0444|os.ModeSymlink, fi.Mode())
} }
func (t *MemFSTest) CreateSymlink_AlreadyExists() { func (t *MemFSTest) CreateSymlink_AlreadyExists() {
...@@ -1209,3 +1226,28 @@ func (t *MemFSTest) ReadLink_NotASymlink() { ...@@ -1209,3 +1226,28 @@ func (t *MemFSTest) ReadLink_NotASymlink() {
ExpectThat(err, Error(HasSubstr("invalid argument"))) ExpectThat(err, Error(HasSubstr("invalid argument")))
} }
} }
func (t *MemFSTest) DeleteSymlink() {
var err error
symlinkName := path.Join(t.Dir, "foo")
target := "taco/burrito"
// Create the link.
err = os.Symlink(target, symlinkName)
AssertEq(nil, err)
// Remove it.
err = os.Remove(symlinkName)
AssertEq(nil, err)
// Statting should now fail.
_, err = os.Lstat(symlinkName)
ExpectTrue(os.IsNotExist(err), "err: %v", err)
// Read the parent directory.
entries, err := fusetesting.ReadDirPicky(t.Dir)
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
}
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