diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-07-07 18:22:32 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2024-07-07 18:22:32 -0500 |
| commit | a18bb0366ef70670f91a881e55ef10a73f968337 (patch) | |
| tree | 4dcf3948266ce03b450ac7959f74e0aabbd33ad5 /src/slskd/Files | |
| parent | 02444a36017bc094d9f28fa71a782dabb320190d (diff) | |
| parent | 19030c1879c16c3bf132bd65a30c67cb48916394 (diff) | |
| download | slskd-a18bb0366ef70670f91a881e55ef10a73f968337.tar.gz | |
Merge branch 'symlinks' of github.com:slskd/slskd into symlinks
Diffstat (limited to 'src/slskd/Files')
| -rw-r--r-- | src/slskd/Files/FileExtensions.cs | 21 |
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 |
