From 1692c6bd0aa6bd407bf5b3494eee28d575811a9b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 4 Mar 2019 17:25:04 +0000 Subject: [PATCH] vfs: shorten the locking window for vfs/refresh Before this change we locked the root directory, recursively fetched the listing, applied it then unlocked the root directory. After this change we recursively fetch the listing then apply it with the root directory locked which shortens the time that the root directory is locked greatly. With the original method and the new method the subdirectories are left unlocked and so potentially could be changed leading to inconsistencies. This change makes the potential for inconsistencies slightly worse by leaving the root directory unlocked at a gain of a much more responsive system while runing vfs/refresh. See: https://forum.rclone.org/t/rclone-rc-vfs-refresh-locking-directory-being-refreshed/9004 --- vfs/dir.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vfs/dir.go b/vfs/dir.go index aa7567cc8..5aa450c4f 100644 --- a/vfs/dir.go +++ b/vfs/dir.go @@ -290,14 +290,17 @@ func (d *Dir) _readDirFromEntries(entries fs.DirEntries, dirTree walk.DirTree, w // readDirTree forces a refresh of the complete directory tree func (d *Dir) readDirTree() error { d.mu.Lock() - defer d.mu.Unlock() + f, path := d.f, d.path + d.mu.Unlock() when := time.Now() - d.read = time.Time{} - fs.Debugf(d.path, "Reading directory tree") - dt, err := walk.NewDirTree(d.f, d.path, false, -1) + fs.Debugf(path, "Reading directory tree") + dt, err := walk.NewDirTree(f, path, false, -1) if err != nil { return err } + d.mu.Lock() + defer d.mu.Unlock() + d.read = time.Time{} err = d._readDirFromDirTree(dt, when) if err != nil { return err