1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-12 14:03:16 +01:00

DiskProvider.MoveFile now overwrites existing file.

This commit is contained in:
kay.one 2011-11-17 23:16:05 -08:00
parent d97a1d068c
commit 950b2f0965
2 changed files with 24 additions and 8 deletions

View File

@ -34,6 +34,20 @@ public void Setup()
}
}
[Test]
public void moveFile_should_overwrite_existing_file()
{
var diskProvider = new DiskProvider();
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
var targetPath = Path.Combine(BinFolderCopy.FullName, "file.move");
diskProvider.MoveFile(BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath);
diskProvider.MoveFile(BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath);
File.Exists(targetPath).Should().BeTrue();
}
[Test]
public void CopyFolder_should_copy_folder()
{
@ -45,6 +59,7 @@ public void CopyFolder_should_copy_folder()
VerifyCopy();
}
[Test]
public void CopyFolder_should_overright_existing_folder()
{

View File

@ -98,24 +98,20 @@ private void TransferDirectory(string source, string target, TransferAction tran
TransferDirectory(subDir.FullName, Path.Combine(target, subDir.Name), transferAction);
}
foreach (var file in sourceFolder.GetFiles("*.*", SearchOption.TopDirectoryOnly))
foreach (var sourceFile in sourceFolder.GetFiles("*.*", SearchOption.TopDirectoryOnly))
{
var destFile = Path.Combine(target, file.Name);
var destFile = Path.Combine(target, sourceFile.Name);
switch (transferAction)
{
case TransferAction.Copy:
{
file.CopyTo(destFile, true);
sourceFile.CopyTo(destFile, true);
break;
}
case TransferAction.Move:
{
if (FileExists(destFile))
{
File.Delete(destFile);
}
file.MoveTo(destFile);
MoveFile(sourceFile.FullName, destFile);
break;
}
}
@ -130,6 +126,11 @@ public virtual void DeleteFile(string path)
public virtual void MoveFile(string sourcePath, string destinationPath)
{
if (FileExists(destinationPath))
{
DeleteFile(destinationPath);
}
File.Move(sourcePath, destinationPath);
}