diff --git a/vfs/file.go b/vfs/file.go index 967adae60..c556fb5d8 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -29,8 +29,7 @@ type File struct { modified bool // has the cache file be modified by a RWFileHandle? pendingModTime time.Time // will be applied once o becomes available, i.e. after file was written - muClose sync.Mutex // synchonize RWFileHandle.close() - muOpen sync.Mutex // synchonize RWFileHandle.openPending() + muRW sync.Mutex // synchonize RWFileHandle.openPending(), RWFileHandle.close() and File.Remove } // newFile creates a new File @@ -385,6 +384,8 @@ func (f *File) Sync() error { // Remove the file func (f *File) Remove() error { + f.muRW.Lock() + defer f.muRW.Unlock() if f.d.vfs.Opt.ReadOnly { return EROFS } diff --git a/vfs/read_write.go b/vfs/read_write.go index b612fdf1d..9817027f4 100644 --- a/vfs/read_write.go +++ b/vfs/read_write.go @@ -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