diff --git a/src/NzbDrone.Core/Datastore/TableMapping.cs b/src/NzbDrone.Core/Datastore/TableMapping.cs index 38787b074..d62ba991a 100644 --- a/src/NzbDrone.Core/Datastore/TableMapping.cs +++ b/src/NzbDrone.Core/Datastore/TableMapping.cs @@ -15,7 +15,6 @@ using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Jobs; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Profiles.Delay; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Notifications; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; @@ -105,8 +104,7 @@ namespace NzbDrone.Core.Datastore Mapper.Entity().RegisterModel("PendingReleases") .Ignore(e => e.RemoteEpisode); - - Mapper.Entity().RegisterModel("RemotePathMappings"); + Mapper.Entity().RegisterModel("Tags"); Mapper.Entity().RegisterModel("Restrictions"); diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs index eb8034fa0..687ec9dcc 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/TorrentBlackhole.cs @@ -11,7 +11,6 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Download.Clients.Blackhole @@ -29,9 +28,8 @@ namespace NzbDrone.Core.Download.Clients.Blackhole IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _scanWatchFolder = scanWatchFolder; @@ -99,7 +97,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole TotalSize = item.TotalSize, RemainingTime = item.RemainingTime, - OutputPath = item.OutputPath, + OutputPath = new DownloadClientPath(Definition.Id, item.OutputPath), Status = item.Status, @@ -124,7 +122,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole return new DownloadClientInfo { IsLocalhost = true, - OutputRootFolders = new List { new OsPath(Settings.WatchFolder) } + OutputRootFolders = new List { new DownloadClientPath(Definition.Id, new OsPath(Settings.WatchFolder)) } }; } diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs index 561b4901b..b55d0cf9d 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs @@ -9,7 +9,6 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.Blackhole { @@ -23,10 +22,9 @@ namespace NzbDrone.Core.Download.Clients.Blackhole IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, IValidateNzbs nzbValidationService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, nzbValidationService, logger) + : base(httpClient, configService, diskProvider, nzbValidationService, logger) { _scanWatchFolder = scanWatchFolder; @@ -67,7 +65,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole TotalSize = item.TotalSize, RemainingTime = item.RemainingTime, - OutputPath = item.OutputPath, + OutputPath = new DownloadClientPath(Definition.Id, item.OutputPath), Status = item.Status, @@ -92,7 +90,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole return new DownloadClientInfo { IsLocalhost = true, - OutputRootFolders = new List { new OsPath(Settings.WatchFolder) } + OutputRootFolders = new List { new DownloadClientPath(Definition.Id, new OsPath(Settings.WatchFolder)) } }; } diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs index 8e6ae9543..8bf73274c 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/Deluge.cs @@ -11,7 +11,6 @@ using NzbDrone.Core.Validation; using NLog; using FluentValidation.Results; using System.Net; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.Deluge { @@ -24,9 +23,8 @@ namespace NzbDrone.Core.Download.Clients.Deluge IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _proxy = proxy; } @@ -106,8 +104,8 @@ namespace NzbDrone.Core.Download.Clients.Deluge item.DownloadClient = Definition.Name; - var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.DownloadPath)); - item.OutputPath = outputPath + torrent.Name; + var outputPath = new OsPath(torrent.DownloadPath) + torrent.Name; + item.OutputPath = new DownloadClientPath(Definition.Id, outputPath); item.RemainingSize = torrent.Size - torrent.BytesDownloaded; try @@ -176,7 +174,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge if (!destDir.IsEmpty) { - status.OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }; + status.OutputRootFolders = new List { new DownloadClientPath(Definition.Id, destDir) }; } return status; diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 79c177b3f..1fc52fa9e 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -12,7 +12,6 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.DownloadStation.Proxies; using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.DownloadStation @@ -34,9 +33,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _dsInfoProxy = dsInfoProxy; _dsTaskProxy = dsTaskProxy; @@ -96,7 +94,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation if (item.Status == DownloadItemStatus.Completed || item.Status == DownloadItemStatus.Failed) { - item.OutputPath = GetOutputPath(outputPath, torrent, serialNumber); + item.OutputPath = new DownloadClientPath(Definition.Id, GetOutputPath(outputPath, torrent, serialNumber)); } items.Add(item); @@ -114,7 +112,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation return new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", - OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) } + OutputRootFolders = new List { new DownloadClientPath(Definition.Id, new OsPath(path)) } }; } catch (DownloadClientException e) @@ -140,9 +138,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation { var fullPath = _sharedFolderResolver.RemapToFullPath(outputPath, Settings, serialNumber); - var remotePath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, fullPath); - - var finalPath = remotePath + torrent.Title; + var finalPath = fullPath + torrent.Title; return finalPath; } diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs index aed5d8362..0b3cbcf70 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs @@ -10,7 +10,6 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.DownloadStation.Proxies; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.DownloadStation @@ -31,11 +30,10 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, IValidateNzbs nzbValidationService, Logger logger ) - : base(httpClient, configService, diskProvider, remotePathMappingService, nzbValidationService, logger) + : base(httpClient, configService, diskProvider, nzbValidationService, logger) { _dsInfoProxy = dsInfoProxy; _dsTaskProxy = dsTaskProxy; @@ -111,7 +109,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation if (item.Status == DownloadItemStatus.Completed || item.Status == DownloadItemStatus.Failed) { - item.OutputPath = GetOutputPath(outputPath, nzb, serialNumber); + item.OutputPath = new DownloadClientPath(Definition.Id, GetOutputPath(outputPath, nzb, serialNumber)); } items.Add(item); @@ -124,7 +122,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation { var fullPath = _sharedFolderResolver.RemapToFullPath(outputPath, Settings, serialNumber); - var remotePath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, fullPath); + var remotePath = fullPath; var finalPath = remotePath + task.Title; @@ -140,7 +138,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation return new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", - OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) } + OutputRootFolders = new List { new DownloadClientPath(Definition.Id, new OsPath(path)) } }; } catch (DownloadClientException e) diff --git a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs index e652cd9e9..0fbe0ea56 100644 --- a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs +++ b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs @@ -10,7 +10,6 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.Hadouken.Models; using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.Hadouken @@ -24,9 +23,8 @@ namespace NzbDrone.Core.Download.Clients.Hadouken IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _proxy = proxy; } @@ -46,7 +44,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken continue; } - var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath)); + var outputPath = new OsPath(torrent.SavePath); var eta = TimeSpan.FromSeconds(0); if (torrent.DownloadRate > 0 && torrent.TotalSize > 0) @@ -58,7 +56,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken { DownloadClient = Definition.Name, DownloadId = torrent.InfoHash.ToUpper(), - OutputPath = outputPath + torrent.Name, + OutputPath = new DownloadClientPath(Definition.Id, outputPath + torrent.Name), RemainingSize = torrent.TotalSize - torrent.DownloadedBytes, RemainingTime = eta, Title = torrent.Name, @@ -119,7 +117,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken if (!destDir.IsEmpty) { - status.OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }; + status.OutputRootFolders = new List { new DownloadClientPath(Definition.Id, destDir) }; } return status; diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs index 0d38a29a0..3b64eb4bf 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortex.cs @@ -10,7 +10,6 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.NzbVortex { @@ -22,10 +21,9 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, IValidateNzbs nzbValidationService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, nzbValidationService, logger) + : base(httpClient, configService, diskProvider, nzbValidationService, logger) { _proxy = proxy; } @@ -88,7 +86,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex break; } - queueItem.OutputPath = GetOutputPath(vortexQueueItem, queueItem); + queueItem.OutputPath = new DownloadClientPath(Definition.Id, GetOutputPath(vortexQueueItem, queueItem)); if (vortexQueueItem.State == NzbVortexStateType.PasswordRequest) { @@ -221,7 +219,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex private OsPath GetOutputPath(NzbVortexQueueItem vortexQueueItem, DownloadClientItem queueItem) { - var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(vortexQueueItem.DestinationPath)); + var outputPath = new OsPath(vortexQueueItem.DestinationPath); if (outputPath.FileName == vortexQueueItem.UiTitle) { diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index ab4b29783..51266d22f 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -10,7 +10,6 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.Nzbget @@ -25,10 +24,9 @@ namespace NzbDrone.Core.Download.Clients.Nzbget IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, IValidateNzbs nzbValidationService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, nzbValidationService, logger) + : base(httpClient, configService, diskProvider, nzbValidationService, logger) { _proxy = proxy; } @@ -123,7 +121,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget historyItem.DownloadId = droneParameter == null ? item.Id.ToString() : droneParameter.Value.ToString(); historyItem.Title = item.Name; historyItem.TotalSize = MakeInt64(item.FileSizeHi, item.FileSizeLo); - historyItem.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(item.DestDir)); + historyItem.OutputPath = new DownloadClientPath(Definition.Id, new OsPath(item.DestDir)); historyItem.Category = item.Category; historyItem.Message = $"PAR Status: {item.ParStatus} - Unpack Status: {item.UnpackStatus} - Move Status: {item.MoveStatus} - Script Status: {item.ScriptStatus} - Delete Status: {item.DeleteStatus} - Mark Status: {item.MarkStatus}"; historyItem.Status = DownloadItemStatus.Completed; @@ -208,7 +206,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget if (category != null) { - status.OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(category.DestDir)) }; + status.OutputRootFolders = new List { new DownloadClientPath(Definition.Id, new OsPath(category.DestDir)) }; } return status; diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index c2ca17a63..3704b3a70 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -8,7 +8,6 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; @@ -21,9 +20,8 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic public Pneumatic(IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(configService, diskProvider, remotePathMappingService, logger) + : base(configService, diskProvider, logger) { _httpClient = httpClient; } @@ -82,7 +80,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic TotalSize = _diskProvider.GetFileSize(file), - OutputPath = new OsPath(file) + OutputPath = new DownloadClientPath(Definition.Id, new OsPath(file)) }; if (_diskProvider.IsFileLocked(file)) diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index 56ff9f315..66d630fc1 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -11,7 +11,6 @@ using NzbDrone.Core.Validation; using FluentValidation.Results; using System.Net; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.QBittorrent { @@ -24,9 +23,8 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _proxy = proxy; } @@ -109,16 +107,17 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent item.RemainingSize = (long)(torrent.Size * (1.0 - torrent.Progress)); item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta); - item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath)); + var outputPath = new OsPath(torrent.SavePath); + if (!outputPath.IsEmpty && outputPath.FileName != torrent.Name) + { + outputPath += torrent.Name; + } + item.OutputPath = new DownloadClientPath(Definition.Id, outputPath); // Avoid removing torrents that haven't reached the global max ratio. // Removal also requires the torrent to be paused, in case a higher max ratio was set on the torrent itself (which is not exposed by the api). item.CanMoveFiles = item.CanBeRemoved = (!config.MaxRatioEnabled || config.MaxRatio <= torrent.Ratio) && torrent.State == "pausedUP"; - if (!item.OutputPath.IsEmpty && item.OutputPath.FileName != torrent.Name) - { - item.OutputPath += torrent.Name; - } switch (torrent.State) { @@ -176,7 +175,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent return new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", - OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) } + OutputRootFolders = new List { new DownloadClientPath(Definition.Id, destDir) } }; } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 1e4840df8..2ba0af462 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -10,7 +10,6 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.Sabnzbd { @@ -22,10 +21,9 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, IValidateNzbs nzbValidationService, Logger logger) - : base(httpClient, configService, diskProvider, remotePathMappingService, nzbValidationService, logger) + : base(httpClient, configService, diskProvider, nzbValidationService, logger) { _proxy = proxy; } @@ -163,23 +161,22 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd historyItem.Status = DownloadItemStatus.Downloading; } - var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(sabHistoryItem.Storage)); + var outputPath = new OsPath(sabHistoryItem.Storage); if (!outputPath.IsEmpty) { - historyItem.OutputPath = outputPath; - var parent = outputPath.Directory; while (!parent.IsEmpty) { if (parent.FileName == sabHistoryItem.Title) { - historyItem.OutputPath = parent; + outputPath = parent; } parent = parent.Directory; } - } + historyItem.OutputPath = new DownloadClientPath(Definition.Id, outputPath); + } historyItems.Add(historyItem); } @@ -261,7 +258,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd if (category != null) { - status.OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, category.FullPath) }; + status.OutputRootFolders = new List { new DownloadClientPath(Definition.Id, category.FullPath) }; } return status; diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs index 058023d0c..8009f1a17 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs @@ -6,7 +6,6 @@ using NzbDrone.Core.Configuration; using NLog; using FluentValidation.Results; using NzbDrone.Core.MediaFiles.TorrentInfo; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.Transmission { @@ -17,9 +16,8 @@ namespace NzbDrone.Core.Download.Clients.Transmission IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(proxy, torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(proxy, torrentFileInfoReader, httpClient, configService, diskProvider, logger) { } diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs index 8533f71dc..cdc7c7216 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs @@ -10,7 +10,6 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles.TorrentInfo; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.Transmission @@ -24,9 +23,8 @@ namespace NzbDrone.Core.Download.Clients.Transmission IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _proxy = proxy; } @@ -54,8 +52,6 @@ namespace NzbDrone.Core.Download.Clients.Transmission if (!directories.Contains(Settings.TvCategory)) continue; } - outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath); - var item = new DownloadClientItem(); item.DownloadId = torrent.HashString.ToUpper(); item.Category = Settings.TvCategory; @@ -63,7 +59,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission item.DownloadClient = Definition.Name; - item.OutputPath = GetOutputPath(outputPath, torrent); + item.OutputPath = new DownloadClientPath(Definition.Id, GetOutputPath(outputPath, torrent)); item.TotalSize = torrent.TotalSize; item.RemainingSize = torrent.LeftUntilDone; if (torrent.Eta >= 0) @@ -122,7 +118,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission return new DownloadClientInfo { IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", - OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(destDir)) } + OutputRootFolders = new List { new DownloadClientPath(Definition.Id, new OsPath(destDir)) } }; } diff --git a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs index dc3bb712e..5d6c47051 100644 --- a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs +++ b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs @@ -5,7 +5,6 @@ using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients.Transmission; using NzbDrone.Core.MediaFiles.TorrentInfo; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download.Clients.Vuze { @@ -18,9 +17,8 @@ namespace NzbDrone.Core.Download.Clients.Vuze IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(proxy, torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(proxy, torrentFileInfoReader, httpClient, configService, diskProvider, logger) { } diff --git a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs index 95fb2db19..2de1dbea3 100644 --- a/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/rTorrent/RTorrent.cs @@ -13,7 +13,6 @@ using FluentValidation.Results; using NzbDrone.Core.Download.Clients.rTorrent; using NzbDrone.Core.Exceptions; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Download.Clients.RTorrent @@ -28,10 +27,9 @@ namespace NzbDrone.Core.Download.Clients.RTorrent IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, IRTorrentDirectoryValidator rTorrentDirectoryValidator, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _proxy = proxy; _rTorrentDirectoryValidator = rTorrentDirectoryValidator; @@ -100,7 +98,7 @@ namespace NzbDrone.Core.Download.Clients.RTorrent item.DownloadClient = Definition.Name; item.Title = torrent.Name; item.DownloadId = torrent.Hash; - item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.Path)); + item.OutputPath = new DownloadClientPath(Definition.Id, new OsPath(torrent.Path)); item.TotalSize = torrent.TotalSize; item.RemainingSize = torrent.RemainingSize; item.Category = torrent.Category; diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs index e02bf646c..f80103dde 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrent.cs @@ -11,7 +11,6 @@ using NzbDrone.Core.Validation; using FluentValidation.Results; using System.Net; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Common.Cache; namespace NzbDrone.Core.Download.Clients.UTorrent @@ -27,9 +26,8 @@ namespace NzbDrone.Core.Download.Clients.UTorrent IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger) + : base(torrentFileInfoReader, httpClient, configService, diskProvider, logger) { _proxy = proxy; @@ -99,16 +97,13 @@ namespace NzbDrone.Core.Download.Clients.UTorrent item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta); } - var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.RootDownloadPath)); + var outputPath = new OsPath(torrent.RootDownloadPath); - if (outputPath == null || outputPath.FileName == torrent.Name) + if (outputPath != null && outputPath.FileName != torrent.Name) { - item.OutputPath = outputPath; - } - else - { - item.OutputPath = outputPath + torrent.Name; + outputPath += torrent.Name; } + item.OutputPath = new DownloadClientPath(Definition.Id, outputPath); if (torrent.Status.HasFlag(UTorrentTorrentStatus.Error)) { @@ -209,7 +204,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent if (!destDir.IsEmpty) { - status.OutputRootFolders = new List { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }; + status.OutputRootFolders = new List { new DownloadClientPath(Definition.Id, destDir) }; } return status; diff --git a/src/NzbDrone.Core/Download/DownloadClientBase.cs b/src/NzbDrone.Core/Download/DownloadClientBase.cs index 713935a4c..3950865cf 100644 --- a/src/NzbDrone.Core/Download/DownloadClientBase.cs +++ b/src/NzbDrone.Core/Download/DownloadClientBase.cs @@ -8,7 +8,6 @@ using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -19,7 +18,6 @@ namespace NzbDrone.Core.Download { protected readonly IConfigService _configService; protected readonly IDiskProvider _diskProvider; - protected readonly IRemotePathMappingService _remotePathMappingService; protected readonly Logger _logger; public abstract string Name { get; } @@ -36,14 +34,12 @@ namespace NzbDrone.Core.Download protected TSettings Settings => (TSettings)Definition.Settings; - protected DownloadClientBase(IConfigService configService, - IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, + protected DownloadClientBase(IConfigService configService, + IDiskProvider diskProvider, Logger logger) { _configService = configService; _diskProvider = diskProvider; - _remotePathMappingService = remotePathMappingService; _logger = logger; } @@ -76,6 +72,9 @@ namespace NzbDrone.Core.Download return; } + // FIXME: Doesn't work if remote. + throw new NotSupportedException(); + /* if (item.OutputPath.IsEmpty) { _logger.Trace("[{0}] Doesn't have an outputPath, skipping delete data.", item.Title); @@ -104,7 +103,7 @@ namespace NzbDrone.Core.Download catch (Exception ex) { _logger.Warn(ex, string.Format("[{0}] Error occurred while trying to delete data from '{1}'.", item.Title, item.OutputPath)); - } + }*/ } public ValidationResult Test() diff --git a/src/NzbDrone.Core/Download/DownloadClientInfo.cs b/src/NzbDrone.Core/Download/DownloadClientInfo.cs index cf586ab64..f0dec7857 100644 --- a/src/NzbDrone.Core/Download/DownloadClientInfo.cs +++ b/src/NzbDrone.Core/Download/DownloadClientInfo.cs @@ -6,6 +6,6 @@ namespace NzbDrone.Core.Download public class DownloadClientInfo { public bool IsLocalhost { get; set; } - public List OutputRootFolders { get; set; } + public List OutputRootFolders { get; set; } } } diff --git a/src/NzbDrone.Core/Download/DownloadClientItem.cs b/src/NzbDrone.Core/Download/DownloadClientItem.cs index acd0b0579..e2c7e617c 100644 --- a/src/NzbDrone.Core/Download/DownloadClientItem.cs +++ b/src/NzbDrone.Core/Download/DownloadClientItem.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Download public long RemainingSize { get; set; } public TimeSpan? RemainingTime { get; set; } - public OsPath OutputPath { get; set; } + public DownloadClientPath OutputPath { get; set; } public string Message { get; set; } public DownloadItemStatus Status { get; set; } diff --git a/src/NzbDrone.Core/Download/DownloadClientPath.cs b/src/NzbDrone.Core/Download/DownloadClientPath.cs index e3891e4a6..849c46385 100644 --- a/src/NzbDrone.Core/Download/DownloadClientPath.cs +++ b/src/NzbDrone.Core/Download/DownloadClientPath.cs @@ -1,8 +1,16 @@ -namespace NzbDrone.Core.Download +using NzbDrone.Common.Disk; + +namespace NzbDrone.Core.Download { public class DownloadClientPath { public int DownloadClientId { get; set; } - public string Path { get; set; } + public OsPath Path { get; set; } + + public DownloadClientPath(int downloadClientId, OsPath path) + { + DownloadClientId = downloadClientId; + Path = path; + } } } diff --git a/src/NzbDrone.Core/Download/TorrentClientBase.cs b/src/NzbDrone.Core/Download/TorrentClientBase.cs index 07f0bd42c..9601f322f 100644 --- a/src/NzbDrone.Core/Download/TorrentClientBase.cs +++ b/src/NzbDrone.Core/Download/TorrentClientBase.cs @@ -12,7 +12,6 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Configuration; using NLog; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download { @@ -26,9 +25,8 @@ namespace NzbDrone.Core.Download IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, Logger logger) - : base(configService, diskProvider, remotePathMappingService, logger) + : base(configService, diskProvider, logger) { _httpClient = httpClient; _torrentFileInfoReader = torrentFileInfoReader; diff --git a/src/NzbDrone.Core/Download/UsenetClientBase.cs b/src/NzbDrone.Core/Download/UsenetClientBase.cs index c6be7ab45..4b8b9a1d5 100644 --- a/src/NzbDrone.Core/Download/UsenetClientBase.cs +++ b/src/NzbDrone.Core/Download/UsenetClientBase.cs @@ -8,7 +8,6 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Configuration; using NLog; -using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.Download { @@ -21,10 +20,9 @@ namespace NzbDrone.Core.Download protected UsenetClientBase(IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, - IRemotePathMappingService remotePathMappingService, IValidateNzbs nzbValidationService, Logger logger) - : base(configService, diskProvider, remotePathMappingService, logger) + : base(configService, diskProvider, logger) { _httpClient = httpClient; _nzbValidationService = nzbValidationService; diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index b88d16322..5a3e222e1 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -949,7 +949,6 @@ - @@ -958,9 +957,6 @@ - - - diff --git a/src/NzbDrone.Core/TransferProviders/Providers/DefaultTransfer.cs b/src/NzbDrone.Core/TransferProviders/Providers/DefaultTransfer.cs index 98e652cd9..3d933f56d 100644 --- a/src/NzbDrone.Core/TransferProviders/Providers/DefaultTransfer.cs +++ b/src/NzbDrone.Core/TransferProviders/Providers/DefaultTransfer.cs @@ -73,7 +73,7 @@ namespace NzbDrone.Core.TransferProviders.Providers protected string ResolvePath(DownloadClientPath path) { - return path.Path; + return path.Path.FullPath; } } } diff --git a/src/NzbDrone.Core/TransferProviders/Providers/EmptyVirtualDiskProvider.cs b/src/NzbDrone.Core/TransferProviders/Providers/EmptyVirtualDiskProvider.cs index 40c32e5b5..30f05d976 100644 --- a/src/NzbDrone.Core/TransferProviders/Providers/EmptyVirtualDiskProvider.cs +++ b/src/NzbDrone.Core/TransferProviders/Providers/EmptyVirtualDiskProvider.cs @@ -8,7 +8,6 @@ namespace NzbDrone.Core.TransferProviders.Providers { public bool SupportStreaming => true; - public string[] GetFiles() { return new string[0]; diff --git a/src/NzbDrone.Core/TransferProviders/Providers/MountTransfer.cs b/src/NzbDrone.Core/TransferProviders/Providers/MountTransfer.cs index d2b1880aa..b6f8bfebc 100644 --- a/src/NzbDrone.Core/TransferProviders/Providers/MountTransfer.cs +++ b/src/NzbDrone.Core/TransferProviders/Providers/MountTransfer.cs @@ -11,7 +11,6 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.TransferProviders.Providers { // Indicates that the remote path is mounted locally, and thus should honor the DownloadItem isReadonly flag and may transfer slowly. - public class MountSettings : IProviderConfig { public string DownloadClientPath { get; set; } @@ -48,6 +47,10 @@ namespace NzbDrone.Core.TransferProviders.Providers if (item == null) return false; var path = ResolvePath(item); + if (path == null) + { + return false; + } return _diskProvider.FolderExists(path) || _diskProvider.FileExists(path); } @@ -69,8 +72,15 @@ namespace NzbDrone.Core.TransferProviders.Providers protected string ResolvePath(DownloadClientPath path) { - // Same logic as RemotePathMapping service. - throw new NotImplementedException(); + var remotePath = path.Path; + if (new OsPath(Settings.DownloadClientPath).Contains(remotePath)) + { + var localPath = new OsPath(Settings.MountPath) + (remotePath - new OsPath(Settings.DownloadClientPath)); + + return localPath.FullPath; + } + + return null; } } } diff --git a/src/NzbDrone.Core/TransferProviders/TransferProviderBase.cs b/src/NzbDrone.Core/TransferProviders/TransferProviderBase.cs index fea5b8900..87904115e 100644 --- a/src/NzbDrone.Core/TransferProviders/TransferProviderBase.cs +++ b/src/NzbDrone.Core/TransferProviders/TransferProviderBase.cs @@ -10,20 +10,16 @@ namespace NzbDrone.Core.TransferProviders public abstract class TransferProviderBase : ITransferProvider where TSettings : IProviderConfig, new() { public abstract string Name { get; } - public Type ConfigContract => typeof(TSettings); - public virtual ProviderMessage Message => null; - public virtual IEnumerable DefaultDefinitions => new List(); - public ProviderDefinition Definition { get; set; } public abstract ValidationResult Test(); - public virtual object RequestAction(string action, IDictionary query) { return null; } - public abstract bool IsAvailable(DownloadClientPath item); + protected TSettings Settings => (TSettings)Definition.Settings; + public abstract bool IsAvailable(DownloadClientPath item); public abstract IVirtualDiskProvider GetFileSystemWrapper(DownloadClientPath item, string tempPath = null); } } diff --git a/src/NzbDrone.Core/TransferProviders/old/RemotePathMapping.cs b/src/NzbDrone.Core/TransferProviders/old/RemotePathMapping.cs deleted file mode 100644 index 2a1322b5b..000000000 --- a/src/NzbDrone.Core/TransferProviders/old/RemotePathMapping.cs +++ /dev/null @@ -1,12 +0,0 @@ -using NzbDrone.Core.Datastore; - - -namespace NzbDrone.Core.RemotePathMappings -{ - public class RemotePathMapping : ModelBase - { - public string Host { get; set; } - public string RemotePath { get; set; } - public string LocalPath { get; set; } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Core/TransferProviders/old/RemotePathMappingRepository.cs b/src/NzbDrone.Core/TransferProviders/old/RemotePathMappingRepository.cs deleted file mode 100644 index bfdfc0000..000000000 --- a/src/NzbDrone.Core/TransferProviders/old/RemotePathMappingRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using NzbDrone.Core.Datastore; -using NzbDrone.Core.Messaging.Events; - -namespace NzbDrone.Core.RemotePathMappings -{ - public interface IRemotePathMappingRepository : IBasicRepository - { - - } - - public class RemotePathMappingRepository : BasicRepository, IRemotePathMappingRepository - { - - public RemotePathMappingRepository(IMainDatabase database, IEventAggregator eventAggregator) - : base(database, eventAggregator) - { - } - - protected override bool PublishModelEvents => true; - } -} diff --git a/src/NzbDrone.Core/TransferProviders/old/RemotePathMappingService.cs b/src/NzbDrone.Core/TransferProviders/old/RemotePathMappingService.cs deleted file mode 100644 index 4210ef0cb..000000000 --- a/src/NzbDrone.Core/TransferProviders/old/RemotePathMappingService.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System.Linq; -using System; -using System.Collections.Generic; -using System.IO; -using NLog; -using NzbDrone.Common.Disk; -using NzbDrone.Common.Extensions; -using NzbDrone.Common.Cache; -using NzbDrone.Core.Download; - -namespace NzbDrone.Core.RemotePathMappings -{ - public interface IRemotePathMappingService - { - List All(); - RemotePathMapping Add(RemotePathMapping mapping); - void Remove(int id); - RemotePathMapping Get(int id); - RemotePathMapping Update(RemotePathMapping mapping); - - OsPath RemapRemoteToLocal(string host, OsPath remotePath); - OsPath RemapLocalToRemote(string host, OsPath localPath); - } - - public class RemotePathMappingService : IRemotePathMappingService - { - private readonly IRemotePathMappingRepository _remotePathMappingRepository; - private readonly IDiskProvider _diskProvider; - private readonly Logger _logger; - - private readonly ICached> _cache; - - public RemotePathMappingService(IDownloadClientRepository downloadClientRepository, - IRemotePathMappingRepository remotePathMappingRepository, - IDiskProvider diskProvider, - ICacheManager cacheManager, - Logger logger) - { - _remotePathMappingRepository = remotePathMappingRepository; - _diskProvider = diskProvider; - _logger = logger; - - _cache = cacheManager.GetCache>(GetType()); - } - - public List All() - { - return _cache.Get("all", () => _remotePathMappingRepository.All().ToList(), TimeSpan.FromSeconds(10)); - } - - public RemotePathMapping Add(RemotePathMapping mapping) - { - mapping.LocalPath = new OsPath(mapping.LocalPath).AsDirectory().FullPath; - mapping.RemotePath = new OsPath(mapping.RemotePath).AsDirectory().FullPath; - - var all = All(); - - ValidateMapping(all, mapping); - - var result = _remotePathMappingRepository.Insert(mapping); - - _cache.Clear(); - - return result; - } - - public void Remove(int id) - { - _remotePathMappingRepository.Delete(id); - - _cache.Clear(); - } - - public RemotePathMapping Get(int id) - { - return _remotePathMappingRepository.Get(id); - } - - public RemotePathMapping Update(RemotePathMapping mapping) - { - var existing = All().Where(v => v.Id != mapping.Id).ToList(); - - ValidateMapping(existing, mapping); - - var result = _remotePathMappingRepository.Update(mapping); - - _cache.Clear(); - - return result; - } - - private void ValidateMapping(List existing, RemotePathMapping mapping) - { - if (mapping.Host.IsNullOrWhiteSpace()) - { - throw new ArgumentException("Invalid Host"); - } - - var remotePath = new OsPath(mapping.RemotePath); - var localPath = new OsPath(mapping.LocalPath); - - if (remotePath.IsEmpty) - { - throw new ArgumentException("Invalid RemotePath"); - } - - if (localPath.IsEmpty || !localPath.IsRooted) - { - throw new ArgumentException("Invalid LocalPath"); - } - - if (!_diskProvider.FolderExists(localPath.FullPath)) - { - throw new DirectoryNotFoundException("Can't add mount point directory that doesn't exist."); - } - - if (existing.Exists(r => r.Host == mapping.Host && r.RemotePath == mapping.RemotePath)) - { - throw new InvalidOperationException("RemotePath already mounted."); - } - } - - public OsPath RemapRemoteToLocal(string host, OsPath remotePath) - { - if (remotePath.IsEmpty) - { - return remotePath; - } - - foreach (var mapping in All()) - { - if (host == mapping.Host && new OsPath(mapping.RemotePath).Contains(remotePath)) - { - var localPath = new OsPath(mapping.LocalPath) + (remotePath - new OsPath(mapping.RemotePath)); - - return localPath; - } - } - - return remotePath; - } - - public OsPath RemapLocalToRemote(string host, OsPath localPath) - { - if (localPath.IsEmpty) - { - return localPath; - } - - foreach (var mapping in All()) - { - if (host == mapping.Host && new OsPath(mapping.LocalPath).Contains(localPath)) - { - var remotePath = new OsPath(mapping.RemotePath) + (localPath - new OsPath(mapping.LocalPath)); - - return remotePath; - } - } - - return localPath; - } - } -}