From ecbf1273210e19e2ea70b533db222e4873887a51 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 13 Nov 2011 20:05:33 -0800 Subject: [PATCH] Fixed a bug in DiskProvider where it wouldn't copy subfolders properly. --- NzbDrone.Common.Test/DiskProviderTests.cs | 20 ++++++++++++-------- NzbDrone.Common/DiskProvider.cs | 7 ++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/NzbDrone.Common.Test/DiskProviderTests.cs b/NzbDrone.Common.Test/DiskProviderTests.cs index 8729ae4b4..d2c2a950a 100644 --- a/NzbDrone.Common.Test/DiskProviderTests.cs +++ b/NzbDrone.Common.Test/DiskProviderTests.cs @@ -35,11 +35,7 @@ namespace NzbDrone.Common.Test diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); //Assert - BinFolder.Refresh(); - BinFolderCopy.Refresh(); - - BinFolder.GetFiles("*.*", SearchOption.AllDirectories) - .Should().HaveSameCount(BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories)); + VerifyCopy(); } [Test] @@ -51,16 +47,24 @@ namespace NzbDrone.Common.Test diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); //Delete Random File - BinFolderCopy.GetFiles().First().Delete(); + BinFolderCopy.Refresh(); + BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete(); diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); //Assert + VerifyCopy(); + } + + private void VerifyCopy() + { BinFolder.Refresh(); BinFolderCopy.Refresh(); - BinFolder.GetFiles("*.*", SearchOption.AllDirectories) - .Should().HaveSameCount(BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories)); + BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories) + .Should().HaveSameCount(BinFolder.GetFiles("*.*", SearchOption.AllDirectories)); + + BinFolderCopy.GetDirectories().Should().HaveSameCount(BinFolder.GetDirectories()); } } } diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index a3f49be2f..340ad3ff7 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -67,7 +67,12 @@ namespace NzbDrone.Common targetFolder.Create(); } - foreach (var file in sourceFolder.GetFiles("*.*", SearchOption.AllDirectories)) + foreach (var subDir in sourceFolder.GetDirectories()) + { + CopyDirectory(subDir.FullName, Path.Combine(target, subDir.Name)); + } + + foreach (var file in sourceFolder.GetFiles("*.*", SearchOption.TopDirectoryOnly)) { var destFile = Path.Combine(target, file.Name); file.CopyTo(destFile, true);