mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 13:10:13 -07:00
Refactored setting attributes on media/metadata files to its own service
This commit is contained in:
parent
f8c002db9f
commit
fd71bd6969
4 changed files with 116 additions and 98 deletions
98
src/NzbDrone.Core/MediaFiles/MediaFileAttributeService.cs
Normal file
98
src/NzbDrone.Core/MediaFiles/MediaFileAttributeService.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public interface IMediaFileAttributeService
|
||||
{
|
||||
void SetFilePermissions(string path);
|
||||
void SetFolderPermissions(string path);
|
||||
void SetFolderLastWriteTime(string path, DateTime time);
|
||||
}
|
||||
|
||||
public class MediaFileAttributeService : IMediaFileAttributeService
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MediaFileAttributeService(IConfigService configService,
|
||||
IDiskProvider diskProvider,
|
||||
Logger logger)
|
||||
{
|
||||
_configService = configService;
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void SetFilePermissions(string path)
|
||||
{
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
//Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes
|
||||
try
|
||||
{
|
||||
_diskProvider.InheritFolderPermissions(path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is UnauthorizedAccessException || ex is InvalidOperationException)
|
||||
{
|
||||
_logger.Debug("Unable to apply folder permissions to: ", path);
|
||||
_logger.DebugException(ex.Message, ex);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
SetMonoPermissions(path, _configService.FileChmod);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFolderPermissions(string path)
|
||||
{
|
||||
if (OsInfo.IsMono)
|
||||
{
|
||||
SetMonoPermissions(path, _configService.FolderChmod);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFolderLastWriteTime(string path, DateTime time)
|
||||
{
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
_logger.Debug("Setting last write time on series folder: {0}", path);
|
||||
_diskProvider.FolderSetLastWriteTime(path, time);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetMonoPermissions(string path, string permissions)
|
||||
{
|
||||
if (!_configService.SetPermissionsLinux)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_diskProvider.SetPermissions(path, permissions, _configService.ChownUser, _configService.ChownGroup);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
_logger.WarnException("Unable to apply permissions to: " + path, ex);
|
||||
_logger.DebugException(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue