mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
vfs, cmount: make truncate work properly in the presence or otherwise of open files
This commit is contained in:
@@ -52,6 +52,12 @@ func newRWFileHandle(d *Dir, f *File, remote string, flags int) (fh *RWFileHandl
|
||||
flags: flags,
|
||||
osPath: osPath,
|
||||
}
|
||||
|
||||
rdwrMode := fh.flags & accessModeMask
|
||||
if rdwrMode != os.O_RDONLY {
|
||||
fh.file.addWriter(fh)
|
||||
}
|
||||
|
||||
return fh, nil
|
||||
}
|
||||
|
||||
@@ -63,8 +69,6 @@ func (fh *RWFileHandle) openPending(truncate bool) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
rdwrMode := fh.flags & accessModeMask
|
||||
|
||||
// if not truncating the file, need to read it first
|
||||
if fh.flags&os.O_TRUNC == 0 && !truncate {
|
||||
// Fetch the file if it hasn't changed
|
||||
@@ -92,9 +96,6 @@ func (fh *RWFileHandle) openPending(truncate bool) (err error) {
|
||||
fh.file.setSize(0)
|
||||
}
|
||||
|
||||
if rdwrMode != os.O_RDONLY {
|
||||
fh.file.addWriters(1)
|
||||
}
|
||||
fs.Debugf(fh.remote, "Opening cached copy with flags=%s", decodeOpenFlags(fh.flags))
|
||||
fd, err := os.OpenFile(fh.osPath, fh.flags|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
@@ -140,6 +141,9 @@ func (fh *RWFileHandle) close() (err error) {
|
||||
}
|
||||
fh.closed = true
|
||||
rdwrMode := fh.flags & accessModeMask
|
||||
if rdwrMode != os.O_RDONLY {
|
||||
fh.file.delWriter(fh)
|
||||
}
|
||||
if !fh.opened {
|
||||
// If read only then return
|
||||
if rdwrMode == os.O_RDONLY {
|
||||
@@ -157,7 +161,6 @@ func (fh *RWFileHandle) close() (err error) {
|
||||
}
|
||||
}
|
||||
if rdwrMode != os.O_RDONLY {
|
||||
fh.file.addWriters(-1)
|
||||
fi, err := fh.File.Stat()
|
||||
if err != nil {
|
||||
fs.Errorf(fh.remote, "Failed to stat cache file: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user