From 94a09915845757d41d2cc5a64845f3494233c21a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 20 Aug 2020 16:01:55 +0100 Subject: [PATCH] vfs: set the modtime of the cache file immediately Before this change we set the modtime of the cache file when all writers had finished. This has the unfortunate effect that the file is uploaded with the wrong modtime which means on backends which can't set modtimes except when uploading files it is wrong. This change sets the modtime of the cache file immediately in the cache and in turn sets the modtime in the file info. --- bin/test-repeat-vfs.sh | 7 +++++-- vfs/file.go | 10 +++++----- vfs/vfscache/item.go | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/test-repeat-vfs.sh b/bin/test-repeat-vfs.sh index c0eee3795..c9702a870 100755 --- a/bin/test-repeat-vfs.sh +++ b/bin/test-repeat-vfs.sh @@ -3,6 +3,9 @@ set -e +# Optionally set the iterations with the first parameter +iterations=${1:-100} + base=$(dirname $(dirname $(realpath "$0"))) echo ${base} run=${base}/bin/test-repeat.sh @@ -17,7 +20,7 @@ cmd/cmount " for testdir in ${testdirs}; do - echo "Testing ${testdir}" + echo "Testing ${testdir} with ${iterations} iterations" cd ${base}/${testdir} - ${run} -c=100 -race -tags=cmount + ${run} -i=${iterations} -race -tags=cmount done diff --git a/vfs/file.go b/vfs/file.go index db2bc8a27..eb1103cd3 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -351,6 +351,11 @@ func (f *File) SetModTime(modTime time.Time) error { f.pendingModTime = modTime + // set the time of the file in the cache + if f.d.vfs.cache != nil && f.d.vfs.cache.Exists(f._path()) { + f.d.vfs.cache.SetModTime(f._path(), f.pendingModTime) + } + // Only update the ModTime when there are no writers, setObject will do it if !f._writingInProgress() { return f._applyPendingModTime() @@ -384,11 +389,6 @@ func (f *File) _applyPendingModTime() error { return err } - // set the time of the file in the cache - if f.d.vfs.cache != nil && f.d.vfs.cache.Exists(f._path()) { - f.d.vfs.cache.SetModTime(f._path(), f.pendingModTime) - } - return nil } diff --git a/vfs/vfscache/item.go b/vfs/vfscache/item.go index 835151ef6..17317a34a 100644 --- a/vfs/vfscache/item.go +++ b/vfs/vfscache/item.go @@ -877,6 +877,7 @@ func (item *Item) setModTime(modTime time.Time) { item.mu.Lock() item._updateFingerprint() item._setModTime(modTime) + item.info.ModTime = modTime err := item._save() if err != nil { fs.Errorf(item.name, "vfs cache: setModTime: failed to save item info: %v", err)