fixed using root directory instead of root path
This commit is contained in:
@@ -14,13 +14,13 @@ public sealed record DownloadCleanerConfig : IJobConfig
|
|||||||
[ConfigurationKeyName("DELETE_PRIVATE")]
|
[ConfigurationKeyName("DELETE_PRIVATE")]
|
||||||
public bool DeletePrivate { get; init; }
|
public bool DeletePrivate { get; init; }
|
||||||
|
|
||||||
[ConfigurationKeyName("NO_HARDLINKS_CATEGORY")]
|
[ConfigurationKeyName("NO_HL_CATEGORY")]
|
||||||
public string NoHardlinksCategory { get; init; } = "";
|
public string NoHardlinksCategory { get; init; } = "";
|
||||||
|
|
||||||
[ConfigurationKeyName("IGNORE_ROOT_DIR")]
|
[ConfigurationKeyName("NO_HL_IGNORE_ROOT_DIR")]
|
||||||
public bool IgnoreRootDir { get; init; }
|
public bool IgnoreRootDir { get; init; }
|
||||||
|
|
||||||
[ConfigurationKeyName("HARDLINK_CATEGORIES")]
|
[ConfigurationKeyName("NO_HL_CATEGORIES")]
|
||||||
public List<string>? HardlinkCategories { get; init; }
|
public List<string>? HardlinkCategories { get; init; }
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
|
|||||||
@@ -45,8 +45,9 @@
|
|||||||
"MAX_SEED_TIME": -1
|
"MAX_SEED_TIME": -1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"NO_HARDLINKS_CATEGORY": "nohardlinks",
|
"NO_HL_CATEGORY": "nohardlinks",
|
||||||
"HARDLINK_CATEGORIES": [
|
"NO_HL_IGNORE_ROOT_DIR": false,
|
||||||
|
"NO_HL_CATEGORIES": [
|
||||||
"tv-sonarr",
|
"tv-sonarr",
|
||||||
"radarr"
|
"radarr"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Common.Configuration.ContentBlocker;
|
using Common.Configuration.ContentBlocker;
|
||||||
using Common.Configuration.DownloadCleaner;
|
using Common.Configuration.DownloadCleaner;
|
||||||
@@ -145,6 +146,26 @@ public abstract class DownloadService : IDownloadService
|
|||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected string? GetRootWithFirstDirectory(string path)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? root = Path.GetPathRoot(path);
|
||||||
|
|
||||||
|
if (root is null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string relativePath = path[root.Length..].TrimStart(Path.DirectorySeparatorChar);
|
||||||
|
string[] parts = relativePath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
return parts.Length > 0 ? Path.Combine(root, parts[0]) : root;
|
||||||
|
}
|
||||||
|
|
||||||
private bool DownloadReachedRatio(double ratio, TimeSpan seedingTime, CleanCategory category)
|
private bool DownloadReachedRatio(double ratio, TimeSpan seedingTime, CleanCategory category)
|
||||||
{
|
{
|
||||||
if (category.MaxRatio < 0)
|
if (category.MaxRatio < 0)
|
||||||
|
|||||||
@@ -317,8 +317,24 @@ public class QBitService : DownloadService, IQBitService
|
|||||||
{
|
{
|
||||||
downloads
|
downloads
|
||||||
.Cast<TorrentInfo>()
|
.Cast<TorrentInfo>()
|
||||||
.GroupBy(x => Path.GetPathRoot(x.SavePath))
|
.Select(x =>
|
||||||
.Select(x => x.Key)
|
{
|
||||||
|
string? firstDir = GetRootWithFirstDirectory(x.SavePath);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(firstDir))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstDir == Path.GetPathRoot(x.SavePath))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return firstDir;
|
||||||
|
})
|
||||||
|
.Where(x => !string.IsNullOrEmpty(x))
|
||||||
|
.Distinct()
|
||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(x =>
|
.ForEach(x =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user