Explorar o código

cross device rename: remove the source if copy suceeded

Nicola Murino %!s(int64=4) %!d(string=hai) anos
pai
achega
fc7066a25c
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      vfs/osfs.go

+ 7 - 2
vfs/osfs.go

@@ -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
 }