mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
New: Setting file permissions on import (Linux)
This commit is contained in:
parent
37231d1ef0
commit
5459b5fed4
@ -27,6 +27,9 @@ Function Build()
|
|||||||
|
|
||||||
AddJsonNet
|
AddJsonNet
|
||||||
|
|
||||||
|
Write-Host "Removing Mono.Posix.dll"
|
||||||
|
Remove-Item "$outputFolder\Mono.Posix.dll"
|
||||||
|
|
||||||
Write-Host "##teamcity[progressFinish 'Build']"
|
Write-Host "##teamcity[progressFinish 'Build']"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.EnsureThat;
|
using NzbDrone.Common.EnsureThat;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
|
||||||
namespace NzbDrone.Common.Disk
|
namespace NzbDrone.Common.Disk
|
||||||
@ -23,7 +21,7 @@ enum TransferAction
|
|||||||
|
|
||||||
public abstract long? GetAvailableSpace(string path);
|
public abstract long? GetAvailableSpace(string path);
|
||||||
public abstract void InheritFolderPermissions(string filename);
|
public abstract void InheritFolderPermissions(string filename);
|
||||||
public abstract void SetFilePermissions(string path, string mask);
|
public abstract void SetPermissions(string path, string mask);
|
||||||
public abstract long? GetTotalSize(string path);
|
public abstract long? GetTotalSize(string path);
|
||||||
|
|
||||||
public DateTime GetLastFolderWrite(string path)
|
public DateTime GetLastFolderWrite(string path)
|
||||||
|
@ -13,6 +13,11 @@ namespace NzbDrone.Common.Disk
|
|||||||
{
|
{
|
||||||
public interface IDiskProvider
|
public interface IDiskProvider
|
||||||
{
|
{
|
||||||
|
long? GetAvailableSpace(string path);
|
||||||
|
void InheritFolderPermissions(string filename);
|
||||||
|
void SetPermissions(string path, string mask);
|
||||||
|
long? GetTotalSize(string path);
|
||||||
|
|
||||||
DateTime GetLastFolderWrite(string path);
|
DateTime GetLastFolderWrite(string path);
|
||||||
DateTime GetLastFileWrite(string path);
|
DateTime GetLastFileWrite(string path);
|
||||||
void EnsureFolder(string path);
|
void EnsureFolder(string path);
|
||||||
@ -29,8 +34,6 @@ public interface IDiskProvider
|
|||||||
void DeleteFile(string path);
|
void DeleteFile(string path);
|
||||||
void MoveFile(string source, string destination);
|
void MoveFile(string source, string destination);
|
||||||
void DeleteFolder(string path, bool recursive);
|
void DeleteFolder(string path, bool recursive);
|
||||||
void InheritFolderPermissions(string filename);
|
|
||||||
long? GetAvailableSpace(string path);
|
|
||||||
string ReadAllText(string filePath);
|
string ReadAllText(string filePath);
|
||||||
void WriteAllText(string filename, string contents);
|
void WriteAllText(string filename, string contents);
|
||||||
void FileSetLastWriteTimeUtc(string path, DateTime dateTime);
|
void FileSetLastWriteTimeUtc(string path, DateTime dateTime);
|
||||||
@ -44,7 +47,6 @@ public interface IDiskProvider
|
|||||||
FileAttributes GetFileAttributes(string path);
|
FileAttributes GetFileAttributes(string path);
|
||||||
void EmptyFolder(string path);
|
void EmptyFolder(string path);
|
||||||
string[] GetFixedDrives();
|
string[] GetFixedDrives();
|
||||||
long? GetTotalSize(string path);
|
|
||||||
string GetVolumeLabel(string path);
|
string GetVolumeLabel(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -278,12 +278,26 @@ public Boolean CreateEmptySeriesFolders
|
|||||||
set { SetValue("CreateEmptySeriesFolders", value); }
|
set { SetValue("CreateEmptySeriesFolders", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DownloadClientWorkingFolders
|
public String DownloadClientWorkingFolders
|
||||||
{
|
{
|
||||||
get { return GetValue("DownloadClientWorkingFolders", "_UNPACK_|_FAILED_"); }
|
get { return GetValue("DownloadClientWorkingFolders", "_UNPACK_|_FAILED_"); }
|
||||||
set { SetValue("DownloadClientWorkingFolders", value); }
|
set { SetValue("DownloadClientWorkingFolders", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String FileChmod
|
||||||
|
{
|
||||||
|
get { return GetValue("FileChmod", "0755"); }
|
||||||
|
|
||||||
|
set { SetValue("FileChmod", value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public String FolderChmod
|
||||||
|
{
|
||||||
|
get { return GetValue("FolderChmod", "0755"); }
|
||||||
|
|
||||||
|
set { SetValue("FolderChmod", value); }
|
||||||
|
}
|
||||||
|
|
||||||
private string GetValue(string key)
|
private string GetValue(string key)
|
||||||
{
|
{
|
||||||
return GetValue(key, String.Empty);
|
return GetValue(key, String.Empty);
|
||||||
|
@ -42,5 +42,7 @@ public interface IConfigService
|
|||||||
Boolean EnableFailedDownloadHandling { get; set; }
|
Boolean EnableFailedDownloadHandling { get; set; }
|
||||||
Boolean CreateEmptySeriesFolders { get; set; }
|
Boolean CreateEmptySeriesFolders { get; set; }
|
||||||
void SaveValues(Dictionary<string, object> configValues);
|
void SaveValues(Dictionary<string, object> configValues);
|
||||||
|
String FileChmod { get; set; }
|
||||||
|
String FolderChmod { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
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.Core.Messaging.Events;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Organizer;
|
using NzbDrone.Core.Organizer;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
@ -24,16 +24,19 @@ public class EpisodeFileMovingService : IMoveEpisodeFiles
|
|||||||
private readonly IEpisodeService _episodeService;
|
private readonly IEpisodeService _episodeService;
|
||||||
private readonly IBuildFileNames _buildFileNames;
|
private readonly IBuildFileNames _buildFileNames;
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
private readonly IConfigService _configService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public EpisodeFileMovingService(IEpisodeService episodeService,
|
public EpisodeFileMovingService(IEpisodeService episodeService,
|
||||||
IBuildFileNames buildFileNames,
|
IBuildFileNames buildFileNames,
|
||||||
IDiskProvider diskProvider,
|
IDiskProvider diskProvider,
|
||||||
|
IConfigService configService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_episodeService = episodeService;
|
_episodeService = episodeService;
|
||||||
_buildFileNames = buildFileNames;
|
_buildFileNames = buildFileNames;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
|
_configService = configService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +88,7 @@ private void MoveFile(EpisodeFile episodeFile, Series series, string destination
|
|||||||
{
|
{
|
||||||
_logger.Trace("Setting last write time on series folder: {0}", series.Path);
|
_logger.Trace("Setting last write time on series folder: {0}", series.Path);
|
||||||
_diskProvider.SetFolderWriteTime(series.Path, episodeFile.DateAdded);
|
_diskProvider.SetFolderWriteTime(series.Path, episodeFile.DateAdded);
|
||||||
|
SetFolderPermissions(series.Path);
|
||||||
|
|
||||||
if (series.SeasonFolder)
|
if (series.SeasonFolder)
|
||||||
{
|
{
|
||||||
@ -92,6 +96,7 @@ private void MoveFile(EpisodeFile episodeFile, Series series, string destination
|
|||||||
|
|
||||||
_logger.Trace("Setting last write time on season folder: {0}", seasonFolder);
|
_logger.Trace("Setting last write time on season folder: {0}", seasonFolder);
|
||||||
_diskProvider.SetFolderWriteTime(seasonFolder, episodeFile.DateAdded);
|
_diskProvider.SetFolderWriteTime(seasonFolder, episodeFile.DateAdded);
|
||||||
|
SetFolderPermissions(seasonFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +127,33 @@ private void MoveFile(EpisodeFile episodeFile, Series series, string destination
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetPermissions(destinationFilename, _configService.FileChmod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetPermissions(string path, string permissions)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_diskProvider.SetPermissions(path, permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex is UnauthorizedAccessException || ex is InvalidOperationException)
|
||||||
|
{
|
||||||
|
_logger.Debug("Unable to apply permissions to: ", path);
|
||||||
|
_logger.TraceException(ex.Message, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetFolderPermissions(string path)
|
||||||
|
{
|
||||||
|
SetPermissions(path, _configService.FolderChmod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
60
src/NzbDrone.Core/MediaFiles/SetMediaFilePermissions.cs
Normal file
60
src/NzbDrone.Core/MediaFiles/SetMediaFilePermissions.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.MediaFiles
|
||||||
|
{
|
||||||
|
public interface ISetMediaFilePermissions
|
||||||
|
{
|
||||||
|
void SetPermissions(string filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SetMediaFilePermissions : ISetMediaFilePermissions
|
||||||
|
{
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
private readonly IConfigService _configService;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public SetMediaFilePermissions(IDiskProvider diskProvider, IConfigService configService, Logger logger)
|
||||||
|
{
|
||||||
|
_diskProvider = diskProvider;
|
||||||
|
_configService = configService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPermissions(string filename)
|
||||||
|
{
|
||||||
|
if (OsInfo.IsWindows)
|
||||||
|
{
|
||||||
|
//Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_diskProvider.InheritFolderPermissions(filename);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex is UnauthorizedAccessException || ex is InvalidOperationException)
|
||||||
|
{
|
||||||
|
_logger.Debug("Unable to apply folder permissions to: ", filename);
|
||||||
|
_logger.TraceException(ex.Message, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_diskProvider.SetPermissions(filename, _configService.FileChmod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -290,6 +290,7 @@
|
|||||||
<Compile Include="MediaFiles\MediaFileExtensions.cs" />
|
<Compile Include="MediaFiles\MediaFileExtensions.cs" />
|
||||||
<Compile Include="MediaFiles\MediaInfo\VideoFileInfoReader.cs" />
|
<Compile Include="MediaFiles\MediaInfo\VideoFileInfoReader.cs" />
|
||||||
<Compile Include="MediaFiles\RenameEpisodeFilePreview.cs" />
|
<Compile Include="MediaFiles\RenameEpisodeFilePreview.cs" />
|
||||||
|
<Compile Include="MediaFiles\SetMediaFilePermissions.cs" />
|
||||||
<Compile Include="Messaging\Commands\CommandExecutor.cs" />
|
<Compile Include="Messaging\Commands\CommandExecutor.cs" />
|
||||||
<Compile Include="Messaging\Commands\ICommandExecutor.cs" />
|
<Compile Include="Messaging\Commands\ICommandExecutor.cs" />
|
||||||
<Compile Include="Messaging\Commands\IExecute.cs" />
|
<Compile Include="Messaging\Commands\IExecute.cs" />
|
||||||
|
@ -49,8 +49,10 @@ public override void InheritFolderPermissions(string filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFilePermissions(string path, string mask)
|
public override void SetPermissions(string path, string mask)
|
||||||
{
|
{
|
||||||
|
Logger.Trace("Setting permissions: {0} on {1}", mask, path);
|
||||||
|
|
||||||
var filePermissions = NativeConvert.FromOctalPermissionString(mask);
|
var filePermissions = NativeConvert.FromOctalPermissionString(mask);
|
||||||
|
|
||||||
if (Syscall.chmod(path, filePermissions) < 0)
|
if (Syscall.chmod(path, filePermissions) < 0)
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnsureThat;
|
using NzbDrone.Common.EnsureThat;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
|
||||||
namespace NzbDrone.Windows
|
namespace NzbDrone.Windows
|
||||||
@ -41,9 +40,9 @@ public override void InheritFolderPermissions(string filename)
|
|||||||
File.SetAccessControl(filename, fs);
|
File.SetAccessControl(filename, fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFilePermissions(string path, string mask)
|
public override void SetPermissions(string path, string mask)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override long? GetTotalSize(string path)
|
public override long? GetTotalSize(string path)
|
||||||
|
Loading…
Reference in New Issue
Block a user