From 5795bd7db6d76da5e75d1e4c54297896a54b3f65 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 2 Mar 2018 16:01:13 +0000 Subject: [PATCH] vfs: update cached copy if we know it has changed even if pending opens This fixes a problem with Caddy serving corrupted files out of the VFS cache when the file on the remote changed. --- vfs/read_write.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vfs/read_write.go b/vfs/read_write.go index 2b8e9525b..b612fdf1d 100644 --- a/vfs/read_write.go +++ b/vfs/read_write.go @@ -112,8 +112,8 @@ func (fh *RWFileHandle) openPending(truncate bool) (err error) { // if not truncating the file, need to read it first if fh.flags&os.O_TRUNC == 0 && !truncate { // If the remote object exists AND its cached file exists locally AND there are no - // other handles with it open writers, then attempt to update it. - if o != nil && fh.d.vfs.cache.opens(fh.remote) <= 1 { + // other RW handles with it open, then attempt to update it. + if o != nil && fh.file.rwOpens() == 0 { cacheObj, err := fh.d.vfs.cache.f.NewObject(fh.remote) if err == nil && cacheObj != nil { cacheObj, err = copyObj(fh.d.vfs.cache.f, cacheObj, fh.remote, o)