Fixed: NET Core not deleting source when moving across drives

This reverts commit 10fc0b071fae9807fa456144b0708d95574d17ff.  Use the
mono fix from 43a35c84477fd194eaa816f1b3e4ade6cb4af42a in NET Core also
pull/1689/head
ta264 4 years ago committed by Qstick
parent 8771e715ae
commit d6e47fde7e

@ -78,23 +78,6 @@ namespace NzbDrone.Common.Test.DiskTests
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()
{

@ -234,18 +234,13 @@ namespace NzbDrone.Common.Disk
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)
@ -256,15 +251,9 @@ namespace NzbDrone.Common.Disk
Directory.Move(source, destination);
}
protected virtual void MoveFileInternal(string source, string destination, bool overwrite)
protected virtual void MoveFileInternal(string source, string destination)
{
#if NETCOREAPP
// This is a hack but the netcore specific overwrite parameter
// isn't availaboe via system.io.abstractions
File.Move(source, destination, overwrite);
#else
_fileSystem.File.Move(source, destination);
#endif
}
public abstract bool TryCreateHardLink(string source, string destination);

@ -192,7 +192,7 @@ namespace NzbDrone.Mono.Disk
}
}
protected override void MoveFileInternal(string source, string destination, bool overwrite)
protected override void MoveFileInternal(string source, string destination)
{
var sourceInfo = UnixFileSystemInfo.GetFileSystemEntry(source);
@ -230,11 +230,11 @@ namespace NzbDrone.Mono.Disk
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);
}
}
@ -246,7 +246,9 @@ namespace NzbDrone.Mono.Disk
// 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 &&
@ -261,11 +263,11 @@ namespace NzbDrone.Mono.Disk
{
if (move)
{
base.MoveFileInternal(source, destination, overwrite);
base.MoveFileInternal(source, destination);
}
else
{
base.CopyFileInternal(source, destination, overwrite);
base.CopyFileInternal(source, destination);
}
}
catch (UnauthorizedAccessException)

Loading…
Cancel
Save