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;
}
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;
};
@@ -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);
}
@@ -2,5 +2,5 @@
public interface IHardlinkFileService
{
uint GetHardLinkCount(string filePath);
ulong GetHardLinkCount(string filePath);
}