Fixed: NET Core doing copy/delete instead of rename

This commit is contained in:
ta264
2019-12-23 21:50:52 +00:00
parent 38b6bb3952
commit 10fc0b071f
3 changed files with 31 additions and 5 deletions
+12 -3
View File
@@ -218,13 +218,18 @@ namespace NzbDrone.Common.Disk
throw new IOException(string.Format("Source and destination can't be the same {0}", source));
}
if (FileExists(destination) && overwrite)
var destExists = FileExists(destination);
if (destExists && overwrite)
{
DeleteFile(destination);
}
RemoveReadOnly(source);
MoveFileInternal(source, destination);
// NET Core is too eager to copy/delete if overwrite is false
// Therefore we also set overwrite if we know destination doesn't exist
MoveFileInternal(source, destination, overwrite || !destExists);
}
public void MoveFolder(string source, string destination, bool overwrite = false)
@@ -246,9 +251,13 @@ namespace NzbDrone.Common.Disk
Directory.Move(source, destination);
}
protected virtual void MoveFileInternal(string source, string destination)
protected virtual void MoveFileInternal(string source, string destination, bool overwrite)
{
#if NETCOREAPP
File.Move(source, destination, overwrite);
#else
File.Move(source, destination);
#endif
}
public abstract bool TryCreateHardLink(string source, string destination);