mirror of
https://github.com/Radarr/Radarr
synced 2025-01-04 06:23:32 +00:00
Fixed: NET Core doing copy/delete instead of rename
This commit is contained in:
parent
38b6bb3952
commit
10fc0b071f
3 changed files with 31 additions and 5 deletions
|
@ -80,6 +80,23 @@ public void MoveFile_should_overwrite_existing_file()
|
||||||
File.Exists(destination).Should().BeTrue();
|
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]
|
[Test]
|
||||||
public void MoveFile_should_not_move_overwrite_itself()
|
public void MoveFile_should_not_move_overwrite_itself()
|
||||||
{
|
{
|
||||||
|
|
|
@ -218,13 +218,18 @@ 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));
|
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);
|
DeleteFile(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveReadOnly(source);
|
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)
|
public void MoveFolder(string source, string destination, bool overwrite = false)
|
||||||
|
@ -246,9 +251,13 @@ public void MoveFolder(string source, string destination, bool overwrite = false
|
||||||
Directory.Move(source, destination);
|
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);
|
File.Move(source, destination);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract bool TryCreateHardLink(string source, string destination);
|
public abstract bool TryCreateHardLink(string source, string destination);
|
||||||
|
|
|
@ -151,7 +151,7 @@ protected override void CopyFileInternal(string source, string destination, bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void MoveFileInternal(string source, string destination)
|
protected override void MoveFileInternal(string source, string destination, bool overwrite)
|
||||||
{
|
{
|
||||||
var sourceInfo = UnixFileSystemInfo.GetFileSystemEntry(source);
|
var sourceInfo = UnixFileSystemInfo.GetFileSystemEntry(source);
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ protected override void MoveFileInternal(string source, string destination)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
base.MoveFileInternal(source, destination);
|
base.MoveFileInternal(source, destination, overwrite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue