Skip to content

Commit

Permalink
Do not delete destination file when renaming another file over it
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed May 6, 2024
1 parent 51972d0 commit d28fbfb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -1618,12 +1618,18 @@ func (parent *Inode) Rename(from string, newParent *Inode, to string) (err error
toFullName := appendChildName(toPath, to)

if toInode != nil {
// this file's been overwritten, it's
// been detached but we can't delete
// it just yet, because the kernel
// will still send forget ops to us
// this file's been overwritten, it's been detached but we can't delete
// it just yet, because the kernel will still send forget ops to us
toInode.mu.Lock()
toInode.doUnlink()
if toInode.isDir() {
toInode.doUnlink()
} else {
// Do not unlink target file if it's a file to make situation where the old
// file is already deleted, but the new one is not uploaded yet, impossible
newParent.removeChildUnlocked(toInode)
toInode.resetCache()
toInode.SetCacheState(ST_DEAD)
}
toInode.mu.Unlock()
}

Expand Down

0 comments on commit d28fbfb

Please sign in to comment.