vfs: fix directory cache serving stale data

The VFS directory cache layer didn't update directory properties like
the last modified time at all, as the new objects were not used.
The same problem is already solved for files, implement the same
solution for directories.

Fixes #6335
This commit is contained in:
Lorenz Brun 2022-09-20 00:31:56 +02:00
parent 2f461f13e3
commit 7630e72674

View File

@ -632,7 +632,9 @@ func (d *Dir) _readDirFromEntries(entries fs.DirEntries, dirTree dirtree.DirTree
}
case fs.Directory:
// Reuse old dir value if it exists
if node == nil || !node.IsDir() {
if dir, ok := node.(*Dir); node != nil && ok {
dir.setObjectNoUpdate(item)
} else {
node = newDir(d.vfs, d.f, d, item)
}
if dirTree != nil {
@ -788,6 +790,17 @@ func (d *Dir) cachedNode(relativePath string) Node {
return node
}
// Update the object but don't update the directory cache - for use by
// the directory cache
func (d *Dir) setObjectNoUpdate(newDir fs.Directory) {
d.modTimeMu.Lock()
d.modTime = newDir.ModTime(context.TODO())
d.modTimeMu.Unlock()
d.mu.Lock()
d.entry = newDir
d.mu.Unlock()
}
// Stat looks up a specific entry in the receiver.
//
// Stat should return a Node corresponding to the entry. If the