mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
Compare commits
2 Commits
v1.56.1
...
fix-4293-v
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f36afac89 | ||
|
|
6277b8bf03 |
29
vfs/dir.go
29
vfs/dir.go
@@ -781,6 +781,9 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
|
||||
return err
|
||||
}
|
||||
// Check to see if destination exists
|
||||
newNode, _ := destDir.stat(newName)
|
||||
destinationExists := newNode != nil
|
||||
switch x := oldNode.DirEntry().(type) {
|
||||
case nil:
|
||||
if oldFile, ok := oldNode.(*File); ok {
|
||||
@@ -793,6 +796,19 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||
return EPERM
|
||||
}
|
||||
case fs.Object:
|
||||
if destinationExists {
|
||||
// Can't overwrite dir with file
|
||||
if newNode.IsDir() {
|
||||
return EEXIST // EISDIR is POSIX
|
||||
}
|
||||
// Try to delete the file
|
||||
fs.Debugf(newPath, "Dir.Rename removing existing file")
|
||||
err = newNode.Remove()
|
||||
if err != nil {
|
||||
fs.Errorf(newPath, "Dir.Rename error: couldn't delete existing file: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if oldFile, ok := oldNode.(*File); ok {
|
||||
if err = oldFile.rename(context.TODO(), destDir, newName); err != nil {
|
||||
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
|
||||
@@ -804,6 +820,19 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
||||
return err
|
||||
}
|
||||
case fs.Directory:
|
||||
if destinationExists {
|
||||
// Can't overwrite file with dir
|
||||
if newNode.IsFile() {
|
||||
return EEXIST // ENOTDIR is POSIX
|
||||
}
|
||||
// Try to delete the existing directory - will succeed only if empty
|
||||
fs.Debugf(newPath, "Dir.Rename removing existing dir")
|
||||
err = newNode.Remove()
|
||||
if err != nil {
|
||||
fs.Errorf(newPath, "Dir.Rename error: couldn't rmdir existing dir: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
features := d.f.Features()
|
||||
if features.DirMove == nil && features.Move == nil && features.Copy == nil {
|
||||
err := errors.Errorf("Fs %q can't rename directories (no DirMove, Move or Copy)", d.f)
|
||||
|
||||
@@ -283,11 +283,9 @@ func (fh *WriteFileHandle) Stat() (os.FileInfo, error) {
|
||||
|
||||
// Truncate file to given size
|
||||
func (fh *WriteFileHandle) Truncate(size int64) (err error) {
|
||||
// defer log.Trace(fh.remote, "size=%d", size)("err=%v", &err)
|
||||
fh.mu.Lock()
|
||||
defer fh.mu.Unlock()
|
||||
if fh.closed {
|
||||
return ECLOSED
|
||||
}
|
||||
if size != fh.offset {
|
||||
fs.Errorf(fh.remote, "WriteFileHandle: Truncate: Can't change size without --vfs-cache-mode >= writes")
|
||||
return EPERM
|
||||
|
||||
Reference in New Issue
Block a user