trying to fix Unix stat

This commit is contained in:
Flaminel
2025-02-21 14:24:31 +02:00
parent 017e25fb06
commit 2d6f16692c
3 changed files with 22 additions and 17 deletions
@@ -327,7 +327,16 @@ public class QBitService : DownloadService, IQBitService
return; 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; hasHardlinks = true;
}; };
@@ -13,7 +13,7 @@ public class HardlinkFileService : IHardlinkFileService
_logger = logger; _logger = logger;
} }
public uint GetHardLinkCount(string filePath) public ulong GetHardLinkCount(string filePath)
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
@@ -63,11 +63,11 @@ public class HardlinkFileService : IHardlinkFileService
public uint FileIndexLow; public uint FileIndexLow;
} }
private uint GetUnixHardLinkCount(string filePath) private ulong GetUnixHardLinkCount(string filePath)
{ {
try try
{ {
if (stat64(filePath, out Stat stat) == 0) if (HardlinkFileService.stat(filePath, out StatStruct stat) == 0)
{ {
return stat.st_nlink; return stat.st_nlink;
} }
@@ -81,19 +81,15 @@ public class HardlinkFileService : IHardlinkFileService
return 0; return 0;
} }
[DllImport("libc", SetLastError = true)]
private static extern int stat64(string path, out Stat stat);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
private struct Stat private struct StatStruct
{ {
public uint st_dev; public ulong st_dev; // Device ID
public ulong st_ino; public ulong st_ino; // Inode number
public uint st_mode; public ulong st_nlink; // Number of hard links
public uint st_nlink; // Hard link count // Additional fields are omitted for brevity
public uint st_uid;
public uint st_gid;
public uint st_rdev;
public long st_size;
} }
[DllImport("libc", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int stat(string path, out StatStruct stat);
} }
@@ -2,5 +2,5 @@
public interface IHardlinkFileService public interface IHardlinkFileService
{ {
uint GetHardLinkCount(string filePath); ulong GetHardLinkCount(string filePath);
} }