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.
This commit is contained in:
dny238 2023-01-20 18:32:11 -07:00
parent 8eebce5171
commit fbcb0b511a

View file

@ -144,6 +144,25 @@ public void Scan(List<string> 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<string>());
continue;
}
@ -314,6 +333,24 @@ public List<string> FilterPaths(string basePath, IEnumerable<string> 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<IFileInfo> FilterFiles(string basePath, IEnumerable<IFileInfo> files)
{
return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file.FullName)))