From 650467fedb2d6d8a3357049392c6dadc74dbdb22 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 6 Mar 2015 05:33:17 +1100 Subject: [PATCH] Update mtime for mkdir and rmdir. --- samples/memfs/inode.go | 6 ++++++ samples/memfs/memfs_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index edbe983..9090db1 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -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 { diff --git a/samples/memfs/memfs_test.go b/samples/memfs/memfs_test.go index 7bad96e..c27a4ef 100644 --- a/samples/memfs/memfs_test.go +++ b/samples/memfs/memfs_test.go @@ -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)