Update mtime for mkdir and rmdir.

geesefs-0-30-9
Aaron Jacobs 2015-03-06 05:33:17 +11:00
parent ea53ba8488
commit 650467fedb
2 changed files with 35 additions and 0 deletions

View File

@ -236,6 +236,9 @@ func (inode *inode) AddChild(
dt fuseutil.DirentType) {
var index int
// Update the modification time.
inode.attributes.Mtime = inode.clock.Now()
// No matter where we place the entry, make sure it has the correct Offset
// field.
defer func() {
@ -268,6 +271,9 @@ func (inode *inode) AddChild(
// REQUIRES: An entry for the given name exists.
// EXCLUSIVE_LOCKS_REQUIRED(inode.mu)
func (inode *inode) RemoveChild(name string) {
// Update the modification time.
inode.attributes.Mtime = inode.clock.Now()
// Find the entry.
i, ok := inode.findChild(name)
if !ok {

View File

@ -168,6 +168,9 @@ func (t *MemFSTest) Mkdir_OneLevel() {
dirName := path.Join(t.mfs.Dir(), "dir")
// Simulate time advancing.
t.clock.AdvanceTime(time.Second)
// Create a directory within the root.
createTime := t.clock.Now()
err = os.Mkdir(dirName, 0754)
@ -196,6 +199,12 @@ func (t *MemFSTest) Mkdir_OneLevel() {
ExpectEq(0, timespecToTime(stat.Ctimespec).Sub(createTime))
ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime))
// Check the root's mtime.
fi, err = os.Stat(t.mfs.Dir())
AssertEq(nil, err)
ExpectEq(0, fi.ModTime().Sub(createTime))
// Read the directory.
entries, err = ioutil.ReadDir(dirName)
@ -223,6 +232,9 @@ func (t *MemFSTest) Mkdir_TwoLevels() {
err = os.Mkdir(path.Join(t.mfs.Dir(), "parent"), 0700)
AssertEq(nil, err)
// Simulate time advancing.
t.clock.AdvanceTime(time.Second)
// Create a child of that directory.
createTime := t.clock.Now()
err = os.Mkdir(path.Join(t.mfs.Dir(), "parent/dir"), 0754)
@ -251,6 +263,11 @@ func (t *MemFSTest) Mkdir_TwoLevels() {
ExpectEq(0, timespecToTime(stat.Ctimespec).Sub(createTime))
ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime))
// Check the parent's mtime.
fi, err = os.Stat(path.Join(t.mfs.Dir(), "parent"))
AssertEq(nil, err)
ExpectEq(0, fi.ModTime().Sub(createTime))
// Read the directory.
entries, err = ioutil.ReadDir(path.Join(t.mfs.Dir(), "parent/dir"))
@ -510,16 +527,28 @@ func (t *MemFSTest) Rmdir_Empty() {
err = os.MkdirAll(path.Join(t.mfs.Dir(), "foo/bar"), 0754)
AssertEq(nil, err)
// Simulate time advancing.
t.clock.AdvanceTime(time.Second)
// Remove the leaf.
rmTime := t.clock.Now()
err = os.Remove(path.Join(t.mfs.Dir(), "foo/bar"))
AssertEq(nil, err)
// Simulate time advancing.
t.clock.AdvanceTime(time.Second)
// There should be nothing left in the parent.
entries, err = ioutil.ReadDir(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
// Check the parent's mtime.
fi, err := os.Stat(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)
ExpectEq(0, fi.ModTime().Sub(rmTime))
// Remove the parent.
err = os.Remove(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)