Fixed: Set permissions on new metadata files (mono)

pull/6/head
Mark McDowall 10 years ago
parent 044d5ad0a5
commit 96c1ceaa29

@ -7,7 +7,6 @@ using NzbDrone.Common;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.EnsureThat; using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Exceptions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;

@ -7,6 +7,7 @@ using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
@ -29,6 +30,7 @@ namespace NzbDrone.Core.Metadata
private readonly IEpisodeService _episodeService; private readonly IEpisodeService _episodeService;
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly IHttpProvider _httpProvider; private readonly IHttpProvider _httpProvider;
private readonly IConfigService _configService;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger; private readonly Logger _logger;
@ -39,6 +41,7 @@ namespace NzbDrone.Core.Metadata
IEpisodeService episodeService, IEpisodeService episodeService,
IDiskProvider diskProvider, IDiskProvider diskProvider,
IHttpProvider httpProvider, IHttpProvider httpProvider,
IConfigService configService,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
Logger logger) Logger logger)
{ {
@ -49,6 +52,7 @@ namespace NzbDrone.Core.Metadata
_episodeService = episodeService; _episodeService = episodeService;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_httpProvider = httpProvider; _httpProvider = httpProvider;
_configService = configService;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_logger = logger; _logger = logger;
} }
@ -156,11 +160,13 @@ namespace NzbDrone.Core.Metadata
return null; return null;
} }
_logger.Debug("Writing Series Metadata to: {0}", seriesMetadata.RelativePath); var fullPath = Path.Combine(series.Path, seriesMetadata.RelativePath);
_diskProvider.WriteAllText(seriesMetadata.RelativePath, seriesMetadata.Contents);
_logger.Debug("Writing Series Metadata to: {0}", fullPath);
SaveMetadataFile(fullPath, seriesMetadata.Contents);
metadata.Hash = hash; metadata.Hash = hash;
metadata.RelativePath = series.Path.GetRelativePath(seriesMetadata.RelativePath); metadata.RelativePath = seriesMetadata.RelativePath;
return metadata; return metadata;
} }
@ -207,7 +213,7 @@ namespace NzbDrone.Core.Metadata
} }
_logger.Debug("Writing Episode Metadata to: {0}", fullPath); _logger.Debug("Writing Episode Metadata to: {0}", fullPath);
_diskProvider.WriteAllText(fullPath, episodeMetadata.Contents); SaveMetadataFile(fullPath, episodeMetadata.Contents);
metadata.Hash = hash; metadata.Hash = hash;
@ -326,11 +332,12 @@ namespace NzbDrone.Core.Metadata
return result; return result;
} }
private void DownloadImage(Series series, string url, string path) private void DownloadImage(Series series, String url, String path)
{ {
try try
{ {
_httpProvider.DownloadFile(url, path); _httpProvider.DownloadFile(url, path);
SetFilePermissions(path);
} }
catch (WebException e) catch (WebException e)
{ {
@ -341,5 +348,31 @@ namespace NzbDrone.Core.Metadata
_logger.ErrorException("Couldn't download image " + url + " for " + series, e); _logger.ErrorException("Couldn't download image " + url + " for " + series, e);
} }
} }
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);
}
}
} }
} }

Loading…
Cancel
Save