From 264b3f0c900a3023e4f391c32971ca4b3201af3f Mon Sep 17 00:00:00 2001 From: Saleh Dindar Date: Sun, 24 Sep 2023 14:51:08 -0700 Subject: [PATCH] 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. --- vfs/dir.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vfs/dir.go b/vfs/dir.go index 511d8db4a..5044ee855 100644 --- a/vfs/dir.go +++ b/vfs/dir.go @@ -694,9 +694,10 @@ func (d *Dir) _readDirFromEntries(entries fs.DirEntries, dirTree dirtree.DirTree if node == nil || !node.IsDir() { node = newDir(d.vfs, d.f, d, item) } + dir := node.(*Dir) + dir.mu.Lock() + dir.modTime = item.ModTime(context.TODO()) if dirTree != nil { - dir := node.(*Dir) - dir.mu.Lock() err = dir._readDirFromDirTree(dirTree, when) if err != nil { dir.read = time.Time{} @@ -704,10 +705,10 @@ func (d *Dir) _readDirFromEntries(entries fs.DirEntries, dirTree dirtree.DirTree dir.read = when dir.cleanupTimer.Reset(d.vfs.Opt.DirCacheTime * 2) } - dir.mu.Unlock() - if err != nil { - return err - } + } + dir.mu.Unlock() + if err != nil { + return err } default: err = fmt.Errorf("unknown type %T", item)