diff --git a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs index 7090f1b..c48daa9 100644 --- a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs +++ b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs @@ -327,7 +327,16 @@ public class QBitService : DownloadService, IQBitService return; } - if (_hardlinkFileService.GetHardLinkCount(file.Name) > 1) + ulong hardlinkCount = _hardlinkFileService.GetHardLinkCount(file.Name); + + if (hardlinkCount is 0) + { + _logger.LogDebug("skip | could not get file properties | {name}", download.Name); + hasHardlinks = true; + break; + } + + if (hardlinkCount > 1) { hasHardlinks = true; }; diff --git a/code/Infrastructure/Verticals/Files/HardlinkFileService.cs b/code/Infrastructure/Verticals/Files/HardlinkFileService.cs index 5e3e4b3..39dcb06 100644 --- a/code/Infrastructure/Verticals/Files/HardlinkFileService.cs +++ b/code/Infrastructure/Verticals/Files/HardlinkFileService.cs @@ -13,7 +13,7 @@ public class HardlinkFileService : IHardlinkFileService _logger = logger; } - public uint GetHardLinkCount(string filePath) + public ulong GetHardLinkCount(string filePath) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -63,11 +63,11 @@ public class HardlinkFileService : IHardlinkFileService public uint FileIndexLow; } - private uint GetUnixHardLinkCount(string filePath) + private ulong GetUnixHardLinkCount(string filePath) { try { - if (stat64(filePath, out Stat stat) == 0) + if (HardlinkFileService.stat(filePath, out StatStruct stat) == 0) { return stat.st_nlink; } @@ -81,19 +81,15 @@ public class HardlinkFileService : IHardlinkFileService return 0; } - [DllImport("libc", SetLastError = true)] - private static extern int stat64(string path, out Stat stat); - [StructLayout(LayoutKind.Sequential)] - private struct Stat + private struct StatStruct { - public uint st_dev; - public ulong st_ino; - public uint st_mode; - public uint st_nlink; // Hard link count - public uint st_uid; - public uint st_gid; - public uint st_rdev; - public long st_size; + public ulong st_dev; // Device ID + public ulong st_ino; // Inode number + public ulong st_nlink; // Number of hard links + // Additional fields are omitted for brevity } + + [DllImport("libc", SetLastError = true, CharSet = CharSet.Auto)] + private static extern int stat(string path, out StatStruct stat); } \ No newline at end of file diff --git a/code/Infrastructure/Verticals/Files/IHardlinkFileService.cs b/code/Infrastructure/Verticals/Files/IHardlinkFileService.cs index 26bc80c..34ac2e5 100644 --- a/code/Infrastructure/Verticals/Files/IHardlinkFileService.cs +++ b/code/Infrastructure/Verticals/Files/IHardlinkFileService.cs @@ -2,5 +2,5 @@ public interface IHardlinkFileService { - uint GetHardLinkCount(string filePath); + ulong GetHardLinkCount(string filePath); } \ No newline at end of file