Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus

This commit is contained in:
Mark McDowall 2011-11-18 00:10:56 -08:00
commit b7e0499691
4 changed files with 30 additions and 14 deletions

View File

@ -34,6 +34,20 @@ namespace NzbDrone.Common.Test
} }
} }
[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] [Test]
public void CopyFolder_should_copy_folder() public void CopyFolder_should_copy_folder()
{ {
@ -45,6 +59,7 @@ namespace NzbDrone.Common.Test
VerifyCopy(); VerifyCopy();
} }
[Test] [Test]
public void CopyFolder_should_overright_existing_folder() public void CopyFolder_should_overright_existing_folder()
{ {

View File

@ -98,24 +98,20 @@ namespace NzbDrone.Common
TransferDirectory(subDir.FullName, Path.Combine(target, subDir.Name), transferAction); 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) switch (transferAction)
{ {
case TransferAction.Copy: case TransferAction.Copy:
{ {
file.CopyTo(destFile, true); sourceFile.CopyTo(destFile, true);
break; break;
} }
case TransferAction.Move: case TransferAction.Move:
{ {
if (FileExists(destFile)) MoveFile(sourceFile.FullName, destFile);
{
File.Delete(destFile);
}
file.MoveTo(destFile);
break; break;
} }
} }
@ -130,6 +126,11 @@ namespace NzbDrone.Common
public virtual void MoveFile(string sourcePath, string destinationPath) public virtual void MoveFile(string sourcePath, string destinationPath)
{ {
if (FileExists(destinationPath))
{
DeleteFile(destinationPath);
}
File.Move(sourcePath, destinationPath); File.Move(sourcePath, destinationPath);
} }

View File

@ -130,7 +130,7 @@ namespace NzbDrone.Update.Test
public void should_copy_update_package_to_target() public void should_copy_update_package_to_target()
{ {
Mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)); .Setup(c => c.MoveDirectory(UPDATE_FOLDER, TARGET_FOLDER));
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER); Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
} }
@ -139,7 +139,7 @@ namespace NzbDrone.Update.Test
public void should_restore_if_update_fails() public void should_restore_if_update_fails()
{ {
Mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)) .Setup(c => c.MoveDirectory(UPDATE_FOLDER, TARGET_FOLDER))
.Throws(new IOException()); .Throws(new IOException());
//Act //Act
@ -184,7 +184,7 @@ namespace NzbDrone.Update.Test
WithServiceRunning(true); WithServiceRunning(true);
Mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)) .Setup(c => c.MoveDirectory(UPDATE_FOLDER, TARGET_FOLDER))
.Throws(new IOException()); .Throws(new IOException());
//Act //Act
@ -202,7 +202,7 @@ namespace NzbDrone.Update.Test
WithServiceRunning(false); WithServiceRunning(false);
Mocker.GetMock<DiskProvider>() Mocker.GetMock<DiskProvider>()
.Setup(c => c.CopyDirectory(UPDATE_FOLDER, TARGET_FOLDER)) .Setup(c => c.MoveDirectory(UPDATE_FOLDER, TARGET_FOLDER))
.Throws(new IOException()); .Throws(new IOException());
//Act //Act

View File

@ -68,11 +68,11 @@ namespace NzbDrone.Update.Providers
_diskProvider.CopyDirectory(targetFolder, _enviromentProvider.GetUpdateBackUpFolder()); _diskProvider.CopyDirectory(targetFolder, _enviromentProvider.GetUpdateBackUpFolder());
logger.Info("Copying update package to target"); logger.Info("Moving update package to target");
try try
{ {
_diskProvider.CopyDirectory(_enviromentProvider.GetUpdatePackageFolder(), targetFolder); _diskProvider.MoveDirectory(_enviromentProvider.GetUpdatePackageFolder(), targetFolder);
} }
catch (Exception e) catch (Exception e)
{ {