MemFSTest.UnlinkFile_StillOpen

geesefs-0-30-9
Aaron Jacobs 2015-03-06 22:31:44 -06:00
parent e8c884f82b
commit c9cd78eef2
1 changed files with 41 additions and 1 deletions

View File

@ -571,7 +571,47 @@ func (t *MemFSTest) UnlinkFile_NonExistent() {
}
func (t *MemFSTest) UnlinkFile_StillOpen() {
AssertTrue(false, "TODO")
fileName := path.Join(t.mfs.Dir(), "foo")
// Create and open a file.
f, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0600)
t.toClose = append(t.toClose, f)
AssertEq(nil, err)
// Write some data into it.
n, err := f.Write([]byte("taco"))
AssertEq(nil, err)
AssertEq(4, n)
// Unlink it.
err = os.Remove(fileName)
AssertEq(nil, err)
// The directory should no longer contain it.
entries, err := ioutil.ReadDir(t.mfs.Dir())
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
// We should be able to stat the file. It should still show as having
// contents, but with no links.
fi, err := f.Stat()
AssertEq(nil, err)
ExpectEq(4, fi.Size())
ExpectEq(0, fi.Sys().(*syscall.Stat_t).Nlink)
// The contents should still be available.
buf := make([]byte, 1024)
n, err = f.ReadAt(buf, 0)
AssertEq(nil, err)
AssertEq(4, n)
ExpectEq("taco", buf[:4])
// Writing should still work, too.
n, err = f.Write([]byte("burrito"))
AssertEq(nil, err)
AssertEq(4, n)
}
func (t *MemFSTest) Rmdir_NonEmpty() {