Skip to content

Commit 6926a5e

Browse files
committed
update a dir's mtime when we know that it's changed
fixes #219
1 parent 4a0551a commit 6926a5e

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

internal/dir.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (dh *DirHandle) listObjectsSlurp(prefix string) (resp *s3.ListObjectsOutput
180180

181181
if sealed || !*resp.IsTruncated {
182182
d.dir.DirTime = time.Now()
183+
d.Attributes.Mtime = d.findChildMaxTime()
183184
}
184185
}
185186

internal/goofys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ func (fs *Goofys) ReadDir(
797797
// from S3 then update the cache time
798798
if readFromS3 {
799799
inode.dir.DirTime = time.Now()
800+
inode.Attributes.Mtime = inode.findChildMaxTime()
800801
}
801802
break
802803
}

internal/goofys_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,3 +1864,40 @@ func (s *GoofysTest) TestWriteSeekWriteFuse(t *C) {
18641864

18651865
s.writeSeekWriteFuse(t, file, fh, "", "never", "minding")
18661866
}
1867+
1868+
func (s *GoofysTest) TestDirMtimeCreate(t *C) {
1869+
root := s.getRoot(t)
1870+
1871+
attr, _ := root.GetAttributes()
1872+
m1 := attr.Mtime
1873+
time.Sleep(time.Second)
1874+
1875+
_, _ = root.Create("foo")
1876+
attr2, _ := root.GetAttributes()
1877+
m2 := attr2.Mtime
1878+
1879+
t.Assert(m1.Before(m2), Equals, true)
1880+
}
1881+
1882+
func (s *GoofysTest) TestDirMtimeLs(t *C) {
1883+
root := s.getRoot(t)
1884+
1885+
attr, _ := root.GetAttributes()
1886+
m1 := attr.Mtime
1887+
time.Sleep(time.Second)
1888+
1889+
params := &s3.PutObjectInput{
1890+
Bucket: &s.fs.bucket,
1891+
Key: aws.String("newfile"),
1892+
Body: bytes.NewReader([]byte("foo")),
1893+
}
1894+
_, err := s.s3.PutObject(params)
1895+
t.Assert(err, IsNil)
1896+
1897+
s.readDirIntoCache(t, fuseops.RootInodeID)
1898+
1899+
attr2, _ := root.GetAttributes()
1900+
m2 := attr2.Mtime
1901+
1902+
t.Assert(m1.Before(m2), Equals, true)
1903+
}

internal/handles.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func (inode *Inode) FullName() *string {
8686
}
8787
}
8888

89+
func (inode *Inode) touch() {
90+
inode.Attributes.Mtime = time.Now()
91+
}
92+
8993
func (inode *Inode) InflateAttributes() (attr fuseops.InodeAttributes) {
9094
attr = fuseops.InodeAttributes{
9195
Size: inode.Attributes.Size,
@@ -316,6 +320,8 @@ func (parent *Inode) Create(
316320
fh.dirty = true
317321
inode.fileHandles = 1
318322

323+
parent.touch()
324+
319325
return
320326
}
321327

@@ -961,6 +967,18 @@ func (parent *Inode) insertSubTree(path string, obj *s3.Object, dirs map[*Inode]
961967
}
962968
}
963969

970+
func (parent *Inode) findChildMaxTime() time.Time {
971+
maxTime := parent.Attributes.Mtime
972+
973+
for _, c := range parent.dir.Children {
974+
if c.Attributes.Mtime.After(maxTime) {
975+
maxTime = c.Attributes.Mtime
976+
}
977+
}
978+
979+
return maxTime
980+
}
981+
964982
func (parent *Inode) readDirFromCache(offset fuseops.DirOffset) (en *DirHandleEntry, ok bool) {
965983
parent.mu.Lock()
966984
defer parent.mu.Unlock()

0 commit comments

Comments
 (0)