aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Files
diff options
context:
space:
mode:
authormilleniumbug <milleniumbug@protonmail.com>2024-06-28 21:02:38 +0200
committermilleniumbug <milleniumbug@protonmail.com>2024-06-28 21:02:38 +0200
commitfd1620fe69244c9028b29be111ab3e888386d985 (patch)
tree6902ece2714b1a704030a6fe4ea6a3499b476983 /src/slskd/Files
parent1e33bcab3788bb93361bab0bba6a72277285591d (diff)
downloadslskd-fd1620fe69244c9028b29be111ab3e888386d985.tar.gz
Report file size (and therefore transfers) correctly if they happen to be symlinks to a file
Diffstat (limited to 'src/slskd/Files')
-rw-r--r--src/slskd/Files/FileExtensions.cs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/slskd/Files/FileExtensions.cs b/src/slskd/Files/FileExtensions.cs
index 4aa7a648..21395837 100644
--- a/src/slskd/Files/FileExtensions.cs
+++ b/src/slskd/Files/FileExtensions.cs
@@ -59,4 +59,25 @@ public static class FileExtensions
return (UnixFileMode)mode;
}
+
+#nullable enable
+ public static FileInfo? TryFollowSymlink(this FileInfo fileInfo)
+ {
+ try
+ {
+ return fileInfo.FollowSymlink();
+ }
+ catch (IOException)
+ {
+ return null;
+ }
+ }
+
+ public static FileInfo FollowSymlink(this FileInfo fileInfo)
+ {
+ FileSystemInfo fileSystemInfo = fileInfo;
+ fileSystemInfo = fileSystemInfo.ResolveLinkTarget(returnFinalTarget: true) ?? fileSystemInfo;
+ return (FileInfo)fileSystemInfo;
+ }
+#nullable restore
} \ No newline at end of file