mirror of
https://github.com/Lidarr/Lidarr
synced 2026-05-07 12:02:14 +02:00
Fixed: set permissions on created artist folders when SetPermissionsLinux is enabled
This commit is contained in:
parent
f6a3e73705
commit
7c48b78783
2 changed files with 98 additions and 0 deletions
|
|
@ -10,6 +10,7 @@
|
|||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
|
|
@ -560,5 +561,83 @@ public void should_update_fields_for_updated_files()
|
|||
l[0].MediaInfo.AudioFormat == localTrack.FileTrackInfo.MediaInfo.AudioFormat)),
|
||||
Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_create_missing_artist_folder_with_correct_permissions()
|
||||
{
|
||||
GivenRootFolder();
|
||||
|
||||
// Setup root folder to exist and NOT be empty
|
||||
GivenRootFolder(_otherArtistFolder);
|
||||
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.CreateEmptyArtistFolders)
|
||||
.Returns(true);
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DeleteEmptyFolders)
|
||||
.Returns(false);
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.SetPermissionsLinux)
|
||||
.Returns(true);
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.ChmodFolder)
|
||||
.Returns("755");
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.ChownGroup)
|
||||
.Returns("users");
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Setup(s => s.GetArtists(It.IsAny<List<int>>()))
|
||||
.Returns(new List<Artist> { _artist });
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(_artist.Path))
|
||||
.Returns(false);
|
||||
|
||||
Subject.Scan(new List<string> { _artist.Path }, FilterFilesType.Known, false, new List<int> { _artist.Id });
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.CreateFolder(_artist.Path), Times.Once());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.SetPermissions(_artist.Path, "755", "users"), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_change_folder_permissions_when_setpermissionslinux_false()
|
||||
{
|
||||
GivenRootFolder();
|
||||
|
||||
// Setup root folder to exist and NOT be empty
|
||||
GivenRootFolder(_otherArtistFolder);
|
||||
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.CreateEmptyArtistFolders)
|
||||
.Returns(true);
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DeleteEmptyFolders)
|
||||
.Returns(false);
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.SetPermissionsLinux)
|
||||
.Returns(false);
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.ChmodFolder)
|
||||
.Returns("755");
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.ChownGroup)
|
||||
.Returns("users");
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Setup(s => s.GetArtists(It.IsAny<List<int>>()))
|
||||
.Returns(new List<Artist> { _artist });
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.FolderExists(_artist.Path))
|
||||
.Returns(false);
|
||||
|
||||
Subject.Scan(new List<string> { _artist.Path }, FilterFilesType.Known, false, new List<int> { _artist.Id });
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.CreateFolder(_artist.Path), Times.Once());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.SetPermissions(_artist.Path, It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ public void Scan(List<string> folders = null, FilterFilesType filter = FilterFil
|
|||
{
|
||||
_logger.Debug("Creating missing artist folder: {0}", artist.Path);
|
||||
_diskProvider.CreateFolder(artist.Path);
|
||||
SetPermissions(artist.Path);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -291,6 +292,24 @@ public string[] GetNonAudioFiles(string path, bool allDirectories = true)
|
|||
return mediaFileList.ToArray();
|
||||
}
|
||||
|
||||
private void SetPermissions(string path)
|
||||
{
|
||||
if (!_configService.SetPermissionsLinux)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_diskProvider.SetPermissions(path, _configService.ChmodFolder, _configService.ChownGroup);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Unable to apply permissions to: " + path);
|
||||
_logger.Debug(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> FilterPaths(string basePath, IEnumerable<string> paths)
|
||||
{
|
||||
return paths.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue