From fbcb0b511aab13b67113153ce82302c1f4bc2808 Mon Sep 17 00:00:00 2001 From: dny238 Date: Fri, 20 Jan 2023 18:32:11 -0700 Subject: [PATCH] Fix: Creates Empty Author Folders if the user has turned that on in the UI Readarr was missing the CreateEmptyAuthorFolders function which is similar to CreateEmptySeriesFolders from Sonarr. All these changes were in the DiskScanService.cs file alone. Updated the "public void Scan()" function to make it match Sonarr's mechanism for creating empty folders for authors/series. Brought the Sonarr code over and changed "Series" references to "Author", also added the SetPermissions function that was a part of Sonarr's implementation. This is part 2 of a set of changes to improve scan function to scan author folders and create them if they are missing. --- .../MediaFiles/DiskScanService.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs index 5cb9ccfae..1204e14fc 100644 --- a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -144,6 +144,25 @@ public void Scan(List folders = null, FilterFilesType filter = FilterFil { _logger.Debug("Specified scan folder ({0}) doesn't exist.", folder); + if (_configService.CreateEmptyAuthorFolders) + { + if (_configService.DeleteEmptyFolders) + { + _logger.Debug("Not creating missing author folder: {0} because delete empty series folders is enabled", folder); + } + else + { + _logger.Debug("Creating missing author folder: {0}", folder); + + _diskProvider.CreateFolder(folder); + SetPermissions(folder); + } + } + else + { + _logger.Debug("Author folder doesn't exist: {0}", rootFolder.Path); + } + CleanMediaFiles(folder, new List()); continue; } @@ -314,6 +333,24 @@ public List FilterPaths(string basePath, IEnumerable paths) .ToList(); } + 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 FilterFiles(string basePath, IEnumerable files) { return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file.FullName)))