From fd71bd6969d9214eb630bbb60c2657043bf4f268 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 18 Nov 2014 07:38:31 -0800 Subject: [PATCH] Refactored setting attributes on media/metadata files to its own service --- .../MediaFiles/EpisodeFileMovingService.cs | 77 ++------------- .../MediaFiles/MediaFileAttributeService.cs | 98 +++++++++++++++++++ src/NzbDrone.Core/MetaData/MetadataService.cs | 38 ++----- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 116 insertions(+), 98 deletions(-) create mode 100644 src/NzbDrone.Core/MediaFiles/MediaFileAttributeService.cs diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index 59960292b..0f0d39d98 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -27,21 +27,21 @@ public class EpisodeFileMovingService : IMoveEpisodeFiles private readonly IUpdateEpisodeFileService _updateEpisodeFileService; private readonly IBuildFileNames _buildFileNames; private readonly IDiskProvider _diskProvider; - private readonly IConfigService _configService; + private readonly IMediaFileAttributeService _mediaFileAttributeService; private readonly Logger _logger; public EpisodeFileMovingService(IEpisodeService episodeService, IUpdateEpisodeFileService updateEpisodeFileService, IBuildFileNames buildFileNames, IDiskProvider diskProvider, - IConfigService configService, + IMediaFileAttributeService mediaFileAttributeService, Logger logger) { _episodeService = episodeService; _updateEpisodeFileService = updateEpisodeFileService; _buildFileNames = buildFileNames; _diskProvider = diskProvider; - _configService = configService; + _mediaFileAttributeService = mediaFileAttributeService; _logger = logger; } @@ -107,11 +107,11 @@ private EpisodeFile TransferFile(EpisodeFile episodeFile, Series series, List, - IHandle, - IHandle + public class MetadataService : IHandle, + IHandle, + IHandle { private readonly IMetadataFactory _metadataFactory; private readonly IMetadataFileService _metadataFileService; @@ -30,7 +28,7 @@ public class MetadataService private readonly IEpisodeService _episodeService; private readonly IDiskProvider _diskProvider; private readonly IHttpClient _httpClient; - private readonly IConfigService _configService; + private readonly IMediaFileAttributeService _mediaFileAttributeService; private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; @@ -41,7 +39,7 @@ public MetadataService(IMetadataFactory metadataFactory, IEpisodeService episodeService, IDiskProvider diskProvider, IHttpClient httpClient, - IConfigService configService, + IMediaFileAttributeService mediaFileAttributeService, IEventAggregator eventAggregator, Logger logger) { @@ -52,7 +50,7 @@ public MetadataService(IMetadataFactory metadataFactory, _episodeService = episodeService; _diskProvider = diskProvider; _httpClient = httpClient; - _configService = configService; + _mediaFileAttributeService = mediaFileAttributeService; _eventAggregator = eventAggregator; _logger = logger; } @@ -337,7 +335,7 @@ private void DownloadImage(Series series, String url, String path) try { _httpClient.DownloadFile(url, path); - SetFilePermissions(path); + _mediaFileAttributeService.SetFilePermissions(path); } catch (WebException e) { @@ -352,27 +350,7 @@ private void DownloadImage(Series series, String url, String path) private void SaveMetadataFile(String path, String contents) { _diskProvider.WriteAllText(path, contents); - SetFilePermissions(path); - } - - private void SetFilePermissions(String path) - { - if (!_configService.SetPermissionsLinux) - { - return; - } - - try - { - _diskProvider.SetPermissions(path, _configService.FileChmod, _configService.ChownUser, _configService.ChownGroup); - } - - catch (Exception ex) - { - - _logger.WarnException("Unable to apply permissions to: " + path, ex); - _logger.DebugException(ex.Message, ex); - } + _mediaFileAttributeService.SetFilePermissions(path); } } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index b9936358e..34b9a5c19 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -505,6 +505,7 @@ +