CustomTransfer mimicking MountTransfer.cs
This commit is contained in:
parent
5c1491ca06
commit
2f02f0a92d
|
@ -1,6 +1,10 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
|
@ -25,19 +29,55 @@ namespace NzbDrone.Core.TransferProviders.Providers
|
|||
|
||||
public class CustomTransfer : TransferProviderBase<CustomTransferSettings>
|
||||
{
|
||||
public override string Link
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
private readonly Logger _logger;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IDiskTransferService _transferService;
|
||||
|
||||
public override string Name
|
||||
public override string Name => "Mount";
|
||||
|
||||
public CustomTransfer(IDiskTransferService transferService, IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
_logger = logger;
|
||||
_diskProvider = diskProvider;
|
||||
_transferService = transferService;
|
||||
}
|
||||
|
||||
public override ValidationResult Test()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool IsAvailable(DownloadClientPath item)
|
||||
{
|
||||
if (item == null) return false;
|
||||
|
||||
var path = ResolvePath(item);
|
||||
if (path == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _diskProvider.FolderExists(path) || _diskProvider.FileExists(path);
|
||||
}
|
||||
|
||||
// TODO: Give MountVirtualDiskProvider the tempPath.
|
||||
public override IVirtualDiskProvider GetFileSystemWrapper(DownloadClientPath item, string tempPath = null)
|
||||
{
|
||||
var path = ResolvePath(item);
|
||||
|
||||
if (_diskProvider.FolderExists(path) || _diskProvider.FileExists(path))
|
||||
{
|
||||
// Expose a virtual filesystem with only that directory/file in it.
|
||||
// This allows the caller to delete the directory if desired, but not it's siblings.
|
||||
return new MountVirtualDiskProvider(_diskProvider, _transferService, Path.GetDirectoryName(path), path);
|
||||
}
|
||||
|
||||
return new EmptyVirtualDiskProvider();
|
||||
}
|
||||
|
||||
protected string ResolvePath(DownloadClientPath path)
|
||||
{
|
||||
return ResolvePath(path.Path, Settings.DownloadClientPath, Settings.LocalPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,15 +72,7 @@ namespace NzbDrone.Core.TransferProviders.Providers
|
|||
|
||||
protected string ResolvePath(DownloadClientPath path)
|
||||
{
|
||||
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;
|
||||
return ResolvePath(path.Path, Settings.DownloadClientPath, Settings.MountPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation.Results;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
|
@ -21,5 +22,21 @@ namespace NzbDrone.Core.TransferProviders
|
|||
|
||||
public abstract bool IsAvailable(DownloadClientPath item);
|
||||
public abstract IVirtualDiskProvider GetFileSystemWrapper(DownloadClientPath item, string tempPath = null);
|
||||
|
||||
|
||||
|
||||
protected static string ResolvePath(OsPath path, string currentParent, string newParent)
|
||||
{
|
||||
var currentParentPath = new OsPath(currentParent);
|
||||
var newParentPath = new OsPath(newParent);
|
||||
if (!currentParentPath.Contains(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var newPath = newParentPath + (path - currentParentPath);
|
||||
|
||||
return newPath.FullPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue