This commit is contained in:
mainLink0435 2026-06-05 20:18:11 -06:00 committed by GitHub
commit 699d9a6c02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 37 deletions

View file

@ -1,4 +1,4 @@
using RdtClient.Data.Enums; using RdtClient.Data.Enums;
using RdtClient.Service.Helpers; using RdtClient.Service.Helpers;
using Serilog; using Serilog;
@ -6,8 +6,6 @@ namespace RdtClient.Service.Services.Downloaders;
public class SymlinkDownloader(String uri, String destinationPath, String path, Provider? clientKind) : IDownloader public class SymlinkDownloader(String uri, String destinationPath, String path, Provider? clientKind) : IDownloader
{ {
private const Int32 MaxRetries = 10;
private readonly CancellationTokenSource _cancellationToken = new(); private readonly CancellationTokenSource _cancellationToken = new();
private readonly ILogger _logger = Log.ForContext<SymlinkDownloader>(); private readonly ILogger _logger = Log.ForContext<SymlinkDownloader>();
@ -108,44 +106,32 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
potentialFilePaths = potentialFilePaths.Distinct().ToList(); potentialFilePaths = potentialFilePaths.Distinct().ToList();
for (var retryCount = 0; retryCount < MaxRetries; retryCount++) _logger.Debug($"Searching {rcloneMountPath} for {fileName}...");
file = FindFile(rcloneMountPath, potentialFilePaths, fileName);
if (file == null && searchSubDirectories)
{ {
DownloadProgress?.Invoke(this, var subDirectories = Directory.GetDirectories(rcloneMountPath, "*.*", SearchOption.TopDirectoryOnly);
new()
{
BytesDone = retryCount,
BytesTotal = 10,
Speed = 1
});
_logger.Debug($"Searching {rcloneMountPath} for {fileName} (attempt #{retryCount})..."); foreach (var subDirectory in subDirectories)
file = FindFile(rcloneMountPath, potentialFilePaths, fileName);
if (file == null && searchSubDirectories)
{ {
var subDirectories = Directory.GetDirectories(rcloneMountPath, "*.*", SearchOption.TopDirectoryOnly); file = FindFile(Path.Combine(rcloneMountPath, subDirectory), potentialFilePaths, fileName);
foreach (var subDirectory in subDirectories) if (file != null)
{ {
file = FindFile(Path.Combine(rcloneMountPath, subDirectory), potentialFilePaths, fileName); break;
if (file != null)
{
break;
}
} }
} }
if (file == null)
{
await Task.Delay(1000 * retryCount);
}
else
{
break;
}
} }
DownloadProgress?.Invoke(this,
new()
{
BytesDone = 1,
BytesTotal = 1,
Speed = 0
});
} }
if (file == null) if (file == null)
@ -172,7 +158,7 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
if (!result) if (!result)
{ {
throw new("Could not find file from rclone mount!"); throw new("Could not create symbolic link!");
} }
DownloadComplete?.Invoke(this, new()); DownloadComplete?.Invoke(this, new());
@ -229,6 +215,12 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
{ {
try try
{ {
if (File.Exists(symlinkPath)) // Symlink already exists from a prior run.
{
_logger.Information($"Symbolic link already exists at {symlinkPath}");
return true;
}
File.CreateSymbolicLink(symlinkPath, sourcePath); File.CreateSymbolicLink(symlinkPath, sourcePath);
if (File.Exists(symlinkPath)) // Double-check that the link was created if (File.Exists(symlinkPath)) // Double-check that the link was created

View file

@ -1,4 +1,4 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Diagnostics; using System.Diagnostics;
using System.Text.Json; using System.Text.Json;
using Aria2NET; using Aria2NET;
@ -216,9 +216,15 @@ public class TorrentRunner(
if (download.RetryCount < download.Torrent.DownloadRetryAttempts) if (download.RetryCount < download.Torrent.DownloadRetryAttempts)
{ {
Log($"Retrying download", download, download.Torrent); var retryDelay = download.Torrent.DownloadClient == Data.Enums.DownloadClient.Symlink
? TimeSpan.FromMinutes(1)
: TimeSpan.Zero;
await downloads.Reset(downloadId); var retryAt = DateTimeOffset.UtcNow.Add(retryDelay);
Log($"Retrying download at {retryAt:u}", download, download.Torrent);
await downloads.Reset(downloadId, retryAt);
await downloads.UpdateRetryCount(downloadId, download.RetryCount + 1); await downloads.UpdateRetryCount(downloadId, download.RetryCount + 1);
} }
else else