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.
This commit is contained in:
Nick Craig-Wood 2020-08-20 16:01:55 +01:00
parent 9d3d397f50
commit 94a0991584
3 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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)