vfs: [bugfix] Update dir modification time

A subtle bug where dir modification time is not updated when the dir already exists
in the cache. It is only noticeable when some clients use dir modification time to
invalidate cache.
This commit is contained in:
Saleh Dindar 2023-09-24 14:51:08 -07:00 committed by Nick Craig-Wood
parent 23f8dea182
commit 7801b160f2

View File

@ -694,9 +694,10 @@ func (d *Dir) _readDirFromEntries(entries fs.DirEntries, dirTree dirtree.DirTree
if node == nil || !node.IsDir() { if node == nil || !node.IsDir() {
node = newDir(d.vfs, d.f, d, item) node = newDir(d.vfs, d.f, d, item)
} }
dir := node.(*Dir)
dir.mu.Lock()
dir.modTime = item.ModTime(context.TODO())
if dirTree != nil { if dirTree != nil {
dir := node.(*Dir)
dir.mu.Lock()
err = dir._readDirFromDirTree(dirTree, when) err = dir._readDirFromDirTree(dirTree, when)
if err != nil { if err != nil {
dir.read = time.Time{} dir.read = time.Time{}
@ -704,10 +705,10 @@ func (d *Dir) _readDirFromEntries(entries fs.DirEntries, dirTree dirtree.DirTree
dir.read = when dir.read = when
dir.cleanupTimer.Reset(d.vfs.Opt.DirCacheTime * 2) dir.cleanupTimer.Reset(d.vfs.Opt.DirCacheTime * 2)
} }
dir.mu.Unlock() }
if err != nil { dir.mu.Unlock()
return err if err != nil {
} return err
} }
default: default:
err = fmt.Errorf("unknown type %T", item) err = fmt.Errorf("unknown type %T", item)