1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: NET Core not deleting source when moving across drives

This reverts commit 10fc0b071f.  Use the
mono fix from 43a35c8447 in NET Core also
This commit is contained in:
ta264 2020-05-14 21:01:23 +01:00 committed by Qstick
parent 5c9b85972d
commit d03a6486d3
3 changed files with 11 additions and 35 deletions

View File

@ -81,23 +81,6 @@ public void MoveFile_should_overwrite_existing_file()
File.Exists(destination).Should().BeTrue();
}
[Test]
[Retry(5)]
public void MoveFile_should_not_overwrite_existing_file()
{
var source1 = GetTempFilePath();
var source2 = GetTempFilePath();
var destination = GetTempFilePath();
File.WriteAllText(source1, "SourceFile1");
File.WriteAllText(source2, "SourceFile2");
Subject.MoveFile(source1, destination);
Assert.Throws<IOException>(() => Subject.MoveFile(source2, destination, false));
File.ReadAllText(destination).Should().Be("SourceFile1");
}
[Test]
public void MoveFile_should_not_move_overwrite_itself()
{

View File

@ -227,18 +227,13 @@ public void MoveFile(string source, string destination, bool overwrite = false)
throw new IOException(string.Format("Source and destination can't be the same {0}", source));
}
var destExists = FileExists(destination);
if (destExists && overwrite)
if (FileExists(destination) && overwrite)
{
DeleteFile(destination);
}
RemoveReadOnly(source);
// 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);
MoveFileInternal(source, destination);
}
public void MoveFolder(string source, string destination, bool overwrite = false)
@ -260,13 +255,9 @@ public void MoveFolder(string source, string destination, bool overwrite = false
Directory.Move(source, destination);
}
protected virtual void MoveFileInternal(string source, string destination, bool overwrite)
protected virtual void MoveFileInternal(string source, string destination)
{
#if NETCOREAPP
File.Move(source, destination, overwrite);
#else
File.Move(source, destination);
#endif
}
public abstract bool TryCreateHardLink(string source, string destination);

View File

@ -179,7 +179,7 @@ protected override void CopyFileInternal(string source, string destination, bool
}
}
protected override void MoveFileInternal(string source, string destination, bool overwrite)
protected override void MoveFileInternal(string source, string destination)
{
var sourceInfo = UnixFileSystemInfo.GetFileSystemEntry(source);
@ -217,11 +217,11 @@ protected override void MoveFileInternal(string source, string destination, bool
else if ((PlatformInfo.Platform == PlatformType.Mono && PlatformInfo.GetVersion() >= new Version(6, 0)) ||
PlatformInfo.Platform == PlatformType.NetCore)
{
TransferFilePatched(source, destination, overwrite, true);
TransferFilePatched(source, destination, false, true);
}
else
{
base.MoveFileInternal(source, destination, overwrite);
base.MoveFileInternal(source, destination);
}
}
@ -233,7 +233,9 @@ private void TransferFilePatched(string source, string destination, bool overwri
// Catch the exception and attempt to handle these edgecases
// Mono 6.x till 6.10 doesn't properly try use rename first.
if (move && PlatformInfo.Platform == PlatformType.Mono && PlatformInfo.GetVersion() < new Version(6, 10))
if (move &&
((PlatformInfo.Platform == PlatformType.Mono && PlatformInfo.GetVersion() < new Version(6, 10)) ||
(PlatformInfo.Platform == PlatformType.NetCore)))
{
if (Syscall.lstat(source, out var sourcestat) == 0 &&
Syscall.lstat(destination, out var deststat) != 0 &&
@ -248,11 +250,11 @@ private void TransferFilePatched(string source, string destination, bool overwri
{
if (move)
{
base.MoveFileInternal(source, destination, overwrite);
base.MoveFileInternal(source, destination);
}
else
{
base.CopyFileInternal(source, destination, overwrite);
base.CopyFileInternal(source, destination);
}
}
catch (UnauthorizedAccessException)