From 00bf533696c187aad899b22493e40f56798dd685 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 8 Sep 2013 10:13:46 -0700 Subject: [PATCH] Empty folder before update instead of deleting it --- NzbDrone.Common/DiskProvider.cs | 17 ++++++++++++++++- .../UpdateEngine/InstallUpdateService.cs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index 592a7d12c..db49896fe 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -42,6 +42,7 @@ public interface IDiskProvider void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType); bool IsParent(string parentPath, string childPath); FileAttributes GetFileAttributes(string path); + void EmptyFolder(string path); } public class DiskProvider : IDiskProvider @@ -352,7 +353,6 @@ public void WriteAllText(string filename, string contents) File.WriteAllText(filename, contents); } - public void FileSetLastWriteTimeUtc(string path, DateTime dateTime) { Ensure.That(() => path).IsValidPath(); @@ -446,5 +446,20 @@ public FileAttributes GetFileAttributes(string path) { return File.GetAttributes(path); } + + public void EmptyFolder(string path) + { + Ensure.That(() => path).IsValidPath(); + + foreach (var file in GetFiles(path, SearchOption.TopDirectoryOnly)) + { + DeleteFile(file); + } + + foreach (var directory in GetDirectories(path)) + { + DeleteFolder(directory, true); + } + } } } \ No newline at end of file diff --git a/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs b/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs index 13626a3c7..0323360cc 100644 --- a/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs +++ b/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs @@ -64,7 +64,7 @@ public void Start(string installationFolder) try { - _diskProvider.DeleteFolder(installationFolder, true); + _diskProvider.EmptyFolder(installationFolder); _diskProvider.CopyFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder); } catch (Exception e)