|
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
@ -32,6 +33,8 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
private readonly INamingConfigService _namingConfigService;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly ICached<string> _cache;
|
|
|
|
|
|
|
|
|
|
private static readonly HashSet<string> SpecialFolders = new HashSet<string>
|
|
|
|
|
{
|
|
|
|
|
"$recycle.bin",
|
|
|
|
@ -50,6 +53,7 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
IMovieRepository movieRepository,
|
|
|
|
|
IConfigService configService,
|
|
|
|
|
INamingConfigService namingConfigService,
|
|
|
|
|
ICacheManager cacheManager,
|
|
|
|
|
Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_rootFolderRepository = rootFolderRepository;
|
|
|
|
@ -58,6 +62,8 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
_configService = configService;
|
|
|
|
|
_namingConfigService = namingConfigService;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
|
|
_cache = cacheManager.GetCache<string>(GetType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<RootFolder> All()
|
|
|
|
@ -115,7 +121,7 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
|
|
|
|
|
if (!_diskProvider.FolderWritable(rootFolder.Path))
|
|
|
|
|
{
|
|
|
|
|
throw new UnauthorizedAccessException(string.Format("Root folder path '{0}' is not writable by user '{1}'", rootFolder.Path, Environment.UserName));
|
|
|
|
|
throw new UnauthorizedAccessException($"Root folder path '{rootFolder.Path}' is not writable by user '{Environment.UserName}'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_rootFolderRepository.Insert(rootFolder);
|
|
|
|
@ -123,6 +129,7 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
var moviePaths = _movieRepository.AllMoviePaths();
|
|
|
|
|
|
|
|
|
|
GetDetails(rootFolder, moviePaths, true);
|
|
|
|
|
_cache.Clear();
|
|
|
|
|
|
|
|
|
|
return rootFolder;
|
|
|
|
|
}
|
|
|
|
@ -130,6 +137,7 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
public void Remove(int id)
|
|
|
|
|
{
|
|
|
|
|
_rootFolderRepository.Delete(id);
|
|
|
|
|
_cache.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<UnmappedFolder> GetUnmappedFolders(string path, Dictionary<int, string> moviePaths)
|
|
|
|
@ -201,18 +209,7 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
|
|
|
|
|
public string GetBestRootFolderPath(string path, List<RootFolder> rootFolders = null)
|
|
|
|
|
{
|
|
|
|
|
var allRootFoldersToConsider = rootFolders ?? All();
|
|
|
|
|
|
|
|
|
|
var possibleRootFolder = allRootFoldersToConsider.Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length);
|
|
|
|
|
|
|
|
|
|
if (possibleRootFolder == null)
|
|
|
|
|
{
|
|
|
|
|
var osPath = new OsPath(path);
|
|
|
|
|
|
|
|
|
|
return osPath.Directory.ToString().TrimEnd(osPath.IsUnixPath ? '/' : '\\');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return possibleRootFolder?.Path;
|
|
|
|
|
return _cache.Get(path, () => GetBestRootFolderPathInternal(path, rootFolders), TimeSpan.FromDays(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetDetails(RootFolder rootFolder, Dictionary<int, string> moviePaths, bool timeout)
|
|
|
|
@ -228,5 +225,21 @@ namespace NzbDrone.Core.RootFolders
|
|
|
|
|
}
|
|
|
|
|
}).Wait(timeout ? 5000 : -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetBestRootFolderPathInternal(string path, List<RootFolder> rootFolders = null)
|
|
|
|
|
{
|
|
|
|
|
var allRootFoldersToConsider = rootFolders ?? All();
|
|
|
|
|
|
|
|
|
|
var possibleRootFolder = allRootFoldersToConsider.Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length);
|
|
|
|
|
|
|
|
|
|
if (possibleRootFolder == null)
|
|
|
|
|
{
|
|
|
|
|
var osPath = new OsPath(path);
|
|
|
|
|
|
|
|
|
|
return osPath.Directory.ToString().TrimEnd(osPath.IsUnixPath ? '/' : '\\');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return possibleRootFolder.Path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|