From 9c20c0b8890d5e7ff59d1bf95e5ea59ef533305d Mon Sep 17 00:00:00 2001 From: Marcelo Castagna Date: Thu, 16 Feb 2017 10:22:02 -0300 Subject: [PATCH] Check to see if output path is right when DownloadClient.Test is invoked (#768) changed to string interpolation a few lines --- .../DownloadStation/TorrentDownloadStation.cs | 126 +++++++++++------- 1 file changed, 75 insertions(+), 51 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 410576d16..474bec9ef 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -23,6 +23,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected readonly IDownloadStationProxy _proxy; protected readonly ISharedFolderResolver _sharedFolderResolver; protected readonly ISerialNumberProvider _serialNumberProvider; + protected readonly IFileStationProxy _fileStationProxy; public TorrentDownloadStation(IDownloadStationProxy proxy, ITorrentFileInfoReader torrentFileInfoReader, @@ -33,12 +34,14 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation Logger logger, ICacheManager cacheManager, ISharedFolderResolver sharedFolderResolver, - ISerialNumberProvider serialNumberProvider) + ISerialNumberProvider serialNumberProvider, + IFileStationProxy fileStationProxy) : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) { _proxy = proxy; _sharedFolderResolver = sharedFolderResolver; _serialNumberProvider = serialNumberProvider; + _fileStationProxy = fileStationProxy; } public override string Name => "Download Station"; @@ -191,56 +194,10 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation { failures.AddIfNotNull(TestConnection()); if (failures.Any()) return; + failures.AddIfNotNull(TestOutputPath()); + if (failures.Any()) return; failures.AddIfNotNull(TestGetTorrents()); - } - - protected ValidationFailure TestConnection() - { - try - { - return ValidateVersion(); - } - catch (DownloadClientAuthenticationException ex) - { - _logger.Error(ex, ex.Message); - return new NzbDroneValidationFailure("Username", "Authentication failure") - { - DetailedDescription = $"Please verify your username and password. Also verify if the host running Sonarr isn't blocked from accessing {Name} by WhiteList limitations in the {Name} configuration." - }; - } - catch (WebException ex) - { - _logger.Error(ex); - - if (ex.Status == WebExceptionStatus.ConnectFailure) - { - return new NzbDroneValidationFailure("Host", "Unable to connect") - { - DetailedDescription = "Please verify the hostname and port." - }; - } - return new NzbDroneValidationFailure(string.Empty, "Unknown exception: " + ex.Message); - } - catch (Exception ex) - { - _logger.Error(ex); - return new NzbDroneValidationFailure(string.Empty, "Unknown exception: " + ex.Message); - } - } - - protected ValidationFailure ValidateVersion() - { - var versionRange = _proxy.GetApiVersion(Settings); - - _logger.Debug("Download Station api version information: Min {0} - Max {1}", versionRange.Min(), versionRange.Max()); - - if (!versionRange.Contains(2)) - { - return new ValidationFailure(string.Empty, $"Download Station API version not supported, should be at least 2. It supports from {versionRange.Min()} to {versionRange.Max()}"); - } - - return null; - } + } protected bool IsFinished(DownloadStationTorrent torrent) { @@ -318,6 +275,73 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation return TimeSpan.FromSeconds(remainingSize / downloadSpeed); } + protected ValidationFailure TestOutputPath() + { + try + { + var folderInfo = _fileStationProxy.GetInfoFileOrDirectory($"/{GetDownloadDirectory()}", Settings); + + if (!folderInfo.IsDir || folderInfo.Additional == null) + { + throw new Exception($"{folderInfo.Path} is not a shared folder or it doesn't exist"); + } + + return null; + } + catch (Exception ex) + { + return new NzbDroneValidationFailure(string.Empty, $"Failed to get output path: {ex.Message}"); + } + } + + protected ValidationFailure TestConnection() + { + try + { + return ValidateVersion(); + } + catch (DownloadClientAuthenticationException ex) + { + _logger.Error(ex, ex.Message); + return new NzbDroneValidationFailure("Username", "Authentication failure") + { + DetailedDescription = $"Please verify your username and password. Also verify if the host running Sonarr isn't blocked from accessing {Name} by WhiteList limitations in the {Name} configuration." + }; + } + catch (WebException ex) + { + _logger.Error(ex); + + if (ex.Status == WebExceptionStatus.ConnectFailure) + { + return new NzbDroneValidationFailure("Host", "Unable to connect") + { + DetailedDescription = "Please verify the hostname and port." + }; + } + return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}"); + } + catch (Exception ex) + { + _logger.Error(ex); + return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}"); + } + } + + protected ValidationFailure ValidateVersion() + { + var versionRange = _proxy.GetApiVersion(Settings); + + _logger.Debug("Download Station api version information: Min {0} - Max {1}", versionRange.Min(), versionRange.Max()); + + if (!versionRange.Contains(2)) + { + return new ValidationFailure(string.Empty, $"Download Station API version not supported, should be at least 2. It supports from {versionRange.Min()} to {versionRange.Max()}"); + } + + return null; + } + protected ValidationFailure TestGetTorrents() { try @@ -327,7 +351,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation } catch (Exception ex) { - return new NzbDroneValidationFailure(string.Empty, "Failed to get the list of torrents: " + ex.Message); + return new NzbDroneValidationFailure(string.Empty, $"Failed to get the list of torrents: {ex.Message}"); } }