mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-24 16:40:26 +00:00
cross device rename: remove the source if copy suceeded
This commit is contained in:
parent
e1bf46c6a5
commit
fc7066a25c
1 changed files with 7 additions and 2 deletions
|
@ -102,9 +102,14 @@ func (*OsFs) Create(name string, flag int) (File, *PipeWriter, func(), error) {
|
|||
func (fs *OsFs) Rename(source, target string) error {
|
||||
err := os.Rename(source, target)
|
||||
if err != nil && isCrossDeviceError(err) {
|
||||
fsLog(fs, logger.LevelWarn, "cross device error detected while renaming %#v -> %#v. Trying a copy, this could take a long time",
|
||||
fsLog(fs, logger.LevelWarn, "cross device error detected while renaming %#v -> %#v. Trying a copy and remove, this could take a long time",
|
||||
source, target)
|
||||
return fscopy.Copy(source, target)
|
||||
err = fscopy.Copy(source, target)
|
||||
if err != nil {
|
||||
fsLog(fs, logger.LevelDebug, "cross device copy error: %v", err)
|
||||
return err
|
||||
}
|
||||
return os.RemoveAll(source)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue