From 257af8b914fb75406bd876c01b3ed90c7ac5bdf4 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 28 Oct 2017 23:00:09 -0400 Subject: [PATCH] Fixed: Try to set last write time on files moved to recycle bin --- .../MediaFiles/RecycleBinProvider.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index 06b9aa598..fabb4d3fd 100644 --- a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs +++ b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -62,11 +62,7 @@ namespace NzbDrone.Core.MediaFiles _diskProvider.FolderSetLastWriteTime(destination, DateTime.UtcNow); foreach (var file in _diskProvider.GetFiles(destination, SearchOption.AllDirectories)) { - if (OsInfo.IsWindows) - { - //TODO: Better fix than this for non-Windows? - _diskProvider.FileSetLastWriteTime(file, DateTime.UtcNow); - } + SetLastWriteTime(file, DateTime.UtcNow); } _logger.Debug("Folder has been moved to the recycling bin: {0}", destination); @@ -123,12 +119,8 @@ namespace NzbDrone.Core.MediaFiles _logger.Error(e, "Unable to move '{0}' to the recycling bin: '{1}'", path, destination); throw; } - - //TODO: Better fix than this for non-Windows? - if (OsInfo.IsWindows) - { - _diskProvider.FileSetLastWriteTime(destination, DateTime.UtcNow); - } + + SetLastWriteTime(destination, DateTime.UtcNow); _logger.Debug("File has been moved to the recycling bin: {0}", destination); } @@ -192,6 +184,18 @@ namespace NzbDrone.Core.MediaFiles _logger.Debug("Recycling Bin has been cleaned up."); } + private void SetLastWriteTime(string file, DateTime dateTime) + { + // Swallow any IOException that may be thrown due to "Invalid parameter" + try + { + _diskProvider.FileSetLastWriteTime(file, dateTime); + } + catch (IOException) + { + } + } + public void Execute(CleanUpRecycleBinCommand message) { Cleanup();