vfs: unify locking for RWFileHandle.openPending,.close and File.Delete #2141

Without this fix the cached file can be removed as the file is being
uploaded or downloaded.  This can cause the directory listings to
become inconsistent (this issue) or data loss (if a retry was needed
in the Copy).

Remove file needs to be excluded from running at the same time as both
openPending and close so it makes sense to unify the locking between
all 3.
This commit is contained in:
Nick Craig-Wood
2018-03-15 20:36:48 +00:00
parent 34c45a7c04
commit c19e675ca6
2 changed files with 7 additions and 6 deletions

View File

@@ -102,8 +102,8 @@ func (fh *RWFileHandle) openPending(truncate bool) (err error) {
return nil
}
fh.file.muOpen.Lock()
defer fh.file.muOpen.Unlock()
fh.file.muRW.Lock()
defer fh.file.muRW.Unlock()
o := fh.file.getObject()
@@ -240,8 +240,8 @@ func (fh *RWFileHandle) modified() bool {
// to give the user a chance to recover it.
func (fh *RWFileHandle) close() (err error) {
defer log.Trace(fh.logPrefix(), "")("err=%v", &err)
fh.file.muClose.Lock()
defer fh.file.muClose.Unlock()
fh.file.muRW.Lock()
defer fh.file.muRW.Unlock()
if fh.closed {
return ECLOSED