public IFileInfo[] GetBookFiles(string path, bool allDirectories = true) { IEnumerable <IFileInfo> filesOnDisk; var rootFolder = _rootFolderService.GetBestRootFolder(path); _logger.Trace(rootFolder.ToJson()); if (rootFolder != null && rootFolder.IsCalibreLibrary && rootFolder.CalibreSettings != null) { _logger.Info($"Getting book list from calibre for {path}"); var paths = _calibre.GetAllBookFilePaths(rootFolder.CalibreSettings); var folderPaths = paths.Where(x => path.IsParentPath(x)); filesOnDisk = folderPaths.Select(x => _diskProvider.GetFileInfo(x)); } else { _logger.Debug("Scanning '{0}' for ebook files", path); var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; filesOnDisk = _diskProvider.GetFileInfos(path, searchOption); _logger.Trace("{0} files were found in {1}", filesOnDisk.Count(), path); } var mediaFileList = filesOnDisk.Where(file => MediaFileExtensions.AllExtensions.Contains(file.Extension)) .ToArray(); _logger.Debug("{0} book files were found in {1}", mediaFileList.Length, path); return(mediaFileList); }
public override HealthCheck Check() { var rootFolders = _rootFolderService.All().Where(x => x.IsCalibreLibrary); foreach (var folder in rootFolders) { try { var calibreIsLocal = folder.CalibreSettings.Host == "127.0.0.1" || folder.CalibreSettings.Host == "localhost"; var files = _calibreProxy.GetAllBookFilePaths(folder.CalibreSettings); if (files.Any()) { var file = files.First(); // This directory structure is forced by calibre var bookFolder = Path.GetDirectoryName(file); var authorFolder = Path.GetDirectoryName(bookFolder); var libraryFolder = Path.GetDirectoryName(authorFolder); var osPath = new OsPath(libraryFolder); if (!osPath.IsValid) { if (!calibreIsLocal) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Remote calibre for root folder {folder.Name} reports files in {libraryFolder} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and root folder settings.", "#bad_remote_path_mapping")); } else if (_osInfo.IsDocker) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; calibre for root folder {folder.Name} reports files in {libraryFolder} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and download client settings.", "#docker_bad_remote_path_mapping")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Local calibre server for root folder {folder.Name} reports files in {libraryFolder} but this is not a valid {_osInfo.Name} path. Review your download client settings.", "#bad_download_client_settings")); } } if (!_diskProvider.FolderExists(libraryFolder)) { if (_osInfo.IsDocker) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; calibre server for root folder {folder.Name} places downloads in {libraryFolder} but this directory does not appear to exist inside the container. Review your remote path mappings and container volume settings.", "#docker_bad_remote_path_mapping")); } else if (!calibreIsLocal) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Remote calibre server for root folder {folder.Name} places downloads in {libraryFolder} but this directory does not appear to exist. Likely missing or incorrect remote path mapping.", "#bad_remote_path_mapping")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Calibre server for root folder {folder.Name} places downloads in {libraryFolder} but Readarr cannot see this directory. You may need to adjust the folder's permissions or add a remote path mapping if calibre is running in docker", "#permissions_error")); } } if (!_diskProvider.FileExists(file)) { if (_osInfo.IsDocker) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; calibre server for root folder {folder.Name} listed file {file} but this file does not appear to exist inside the container. Review permissions for {libraryFolder} and PUID/PGID container settings", "#docker_bad_remote_path_mapping")); } else if (!calibreIsLocal) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Remote calibre server for root folder {folder.Name} listed file {file} but this file does not appear to exist. Review permissions for {libraryFolder}", "#permissions_error")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Calibre server for root folder {folder.Name} listed file {file} but Readarr cannot see this file. Review permissions for {libraryFolder}", "#permissions_error")); } } if (!libraryFolder.PathEquals(folder.Path)) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Calibre for root folder {folder.Name} reports files in {libraryFolder} but this is not the same as the root folder path {folder.Path} you chose. You may need to edit any remote path mapping or delete the root folder and re_create with the correct path", "#calibre_root_does_not_match")); } } } catch (DownloadClientException ex) { _logger.Debug(ex, "Unable to communicate with calibre server for root folder {0}", folder.Name); } catch (Exception ex) { _logger.Error(ex, "Unknown error occured in CalibreRootFolderCheck HealthCheck"); } } return(new HealthCheck(GetType())); }