From 300036c85913b79bf9bbf13c81ea2241f1216f78 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 23 Mar 2026 17:08:15 -0400 Subject: [PATCH 1/7] Fix FolderStorageInfo to show parent filesystem A direct implementation using DriveInfo directly on a path does not work as expected. The method will return a DriveInfo object with the given path as both the Name and the RootDirectory, which is not helpful. Instead, add parsing logic to find the best possible match out of all filesystems on the system for the path, including handling edge cases involving symlinked paths in the chain. This ensures that the resulting DeviceId is a valid filesystem, allowing it to be used in the UI to show a better description. It also includes the new ResolvedPath which will show, if required, what the Path resolved to after all symlinks are interpolated. One possible issue here is that walking all drives as-is might become slow(er) on a system with many partitions, but even on my partition-heavy system with over a dozen ZVOLs and remote mounts, this takes under 0.4 seconds including runup time for `dotnet run`, so I imagine this should be fine. --- .../StorageHelpers/StorageHelper.cs | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs index ce628a04d0..0b8e2830d2 100644 --- a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs +++ b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs @@ -28,22 +28,41 @@ public static class StorageHelper } /// - /// Gets the free space of a specific directory. + /// Gets the free space of the parent filesystem of a specific directory. /// /// Path to a folder. - /// The number of bytes available space. + /// Various details about the parent filesystem containing the directory. public static FolderStorageInfo GetFreeSpaceOf(string path) { try { - var driveInfo = new DriveInfo(path); + // Fully resolve the given path to an actual filesystem target, in case it's a symlink or similar. + resolvedPath = ResolvePath(path); + // We iterate all filesystems reported by GetDrives() here, and attempt to find the best + // match that contains, as deep as possible, the given path. + // This is required because simply calling `DriveInfo` on a path returns that path as + // the Name and RootDevice, which is not at all how this should work. + DriveInfo[] allDrives = DriveInfo.GetDrives(); + DriveInfo bestMatch = null; + foreach (DriveInfo d in allDrives) + { + if (resolvedPath.StartsWith(d.RootDirectory.FullName) && + (bestMatch == null || d.RootDirectory.FullName.Length > bestMatch.RootDirectory.FullName.Length)) + { + bestMatch = d; + } + } + if (bestMatch is null) { + throw new InvalidOperationException($"The path `{path}` has no matching parent device. Space check invalid."); + } return new FolderStorageInfo() { Path = path, - FreeSpace = driveInfo.AvailableFreeSpace, - UsedSpace = driveInfo.TotalSize - driveInfo.AvailableFreeSpace, - StorageType = driveInfo.DriveType.ToString(), - DeviceId = driveInfo.Name, + ResolvedPath = resolvedPath, + FreeSpace = bestMatch.AvailableFreeSpace, + UsedSpace = bestMatch.TotalSize - bestMatch.AvailableFreeSpace, + StorageType = bestMatch.DriveType.ToString(), + DeviceId = bestMatch.Name, }; } catch @@ -59,6 +78,26 @@ public static class StorageHelper } } + /// + /// Walk a path and fully resolve any symlinks within it. + /// + private static string ResolvePath(string path) + { + var parts = path.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries); + var current = Path.DirectorySeparatorChar.ToString(); + foreach (var part in parts) + { + current = Path.Combine(current, part); + var resolved = new DirectoryInfo(current).ResolveLinkTarget(returnFinalTarget: true); + if (resolved is not null) + { + current = resolved.FullName; + } + } + + return current; + } + /// /// Gets the underlying drive data from a given path and checks if the available storage capacity matches the threshold. /// From 434ebc8b110a2736c9be08360c17cf74e27803d1 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 23 Mar 2026 17:11:29 -0400 Subject: [PATCH 2/7] Ensure ResolvedPath is sent on error too --- Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs index 0b8e2830d2..a36a51330d 100644 --- a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs +++ b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs @@ -70,6 +70,7 @@ public static class StorageHelper return new FolderStorageInfo() { Path = path, + ResolvedPath = path, FreeSpace = -1, UsedSpace = -1, StorageType = null, From 418beafebb49527974c5563907367e6b689352a3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 23 Mar 2026 17:15:49 -0400 Subject: [PATCH 3/7] Update FolderStorageInfo record --- MediaBrowser.Model/System/FolderStorageInfo.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Model/System/FolderStorageInfo.cs b/MediaBrowser.Model/System/FolderStorageInfo.cs index 7b10e4ea58..66356c6c48 100644 --- a/MediaBrowser.Model/System/FolderStorageInfo.cs +++ b/MediaBrowser.Model/System/FolderStorageInfo.cs @@ -11,17 +11,22 @@ public record FolderStorageInfo public required string Path { get; init; } /// - /// Gets the free space of the underlying storage device of the . + /// Gets the fully resolved path of the folder in question (interpolating any symlinks if present) + /// + public required string ResolvedPath { get; init; } + + /// + /// Gets the free space of the underlying storage device of the . /// public long FreeSpace { get; init; } /// - /// Gets the used space of the underlying storage device of the . + /// Gets the used space of the underlying storage device of the . /// public long UsedSpace { get; init; } /// - /// Gets the kind of storage device of the . + /// Gets the kind of storage device of the . /// public string? StorageType { get; init; } From 8142bbd50e4c2218e99c621900430b0189c267c3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 23 Mar 2026 17:22:35 -0400 Subject: [PATCH 4/7] Properly define variable type --- Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs index a36a51330d..b80d65ecbe 100644 --- a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs +++ b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs @@ -37,7 +37,7 @@ public static class StorageHelper try { // Fully resolve the given path to an actual filesystem target, in case it's a symlink or similar. - resolvedPath = ResolvePath(path); + string resolvedPath = ResolvePath(path); // We iterate all filesystems reported by GetDrives() here, and attempt to find the best // match that contains, as deep as possible, the given path. // This is required because simply calling `DriveInfo` on a path returns that path as From 965b602c6890623130d1d7e27de52e161c6d1069 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 23 Mar 2026 23:09:56 -0400 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: JPVenson --- .../StorageHelpers/StorageHelper.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs index b80d65ecbe..d3f94ad0bd 100644 --- a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs +++ b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs @@ -37,24 +37,26 @@ public static class StorageHelper try { // Fully resolve the given path to an actual filesystem target, in case it's a symlink or similar. - string resolvedPath = ResolvePath(path); + var resolvedPath = ResolvePath(path); // We iterate all filesystems reported by GetDrives() here, and attempt to find the best // match that contains, as deep as possible, the given path. // This is required because simply calling `DriveInfo` on a path returns that path as // the Name and RootDevice, which is not at all how this should work. - DriveInfo[] allDrives = DriveInfo.GetDrives(); - DriveInfo bestMatch = null; + var allDrives = DriveInfo.GetDrives(); + DriveInfo? bestMatch = null; foreach (DriveInfo d in allDrives) { - if (resolvedPath.StartsWith(d.RootDirectory.FullName) && - (bestMatch == null || d.RootDirectory.FullName.Length > bestMatch.RootDirectory.FullName.Length)) + if (resolvedPath.StartsWith(d.RootDirectory.FullName, StringComparison.InvariantCultureIgnoreCase) && + (bestMatch is null || d.RootDirectory.FullName.Length > bestMatch.RootDirectory.FullName.Length)) { bestMatch = d; } } + if (bestMatch is null) { throw new InvalidOperationException($"The path `{path}` has no matching parent device. Space check invalid."); } + return new FolderStorageInfo() { Path = path, From c22933260b1d9b8cd97980c00a70f53bbaaf4f54 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 24 Mar 2026 22:22:52 -0400 Subject: [PATCH 6/7] Fix linting issue --- MediaBrowser.Model/System/FolderStorageInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Model/System/FolderStorageInfo.cs b/MediaBrowser.Model/System/FolderStorageInfo.cs index 66356c6c48..ebca39228b 100644 --- a/MediaBrowser.Model/System/FolderStorageInfo.cs +++ b/MediaBrowser.Model/System/FolderStorageInfo.cs @@ -11,7 +11,7 @@ public record FolderStorageInfo public required string Path { get; init; } /// - /// Gets the fully resolved path of the folder in question (interpolating any symlinks if present) + /// Gets the fully resolved path of the folder in question (interpolating any symlinks if present). /// public required string ResolvedPath { get; init; } From fec78c8448bd19f96460d853732cf24812443b70 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 24 Mar 2026 22:31:17 -0400 Subject: [PATCH 7/7] Lint for the Linter Gods --- .../StorageHelpers/StorageHelper.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs index d3f94ad0bd..13c7895f83 100644 --- a/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs +++ b/Jellyfin.Server.Implementations/StorageHelpers/StorageHelper.cs @@ -43,7 +43,7 @@ public static class StorageHelper // This is required because simply calling `DriveInfo` on a path returns that path as // the Name and RootDevice, which is not at all how this should work. var allDrives = DriveInfo.GetDrives(); - DriveInfo? bestMatch = null; + DriveInfo? bestMatch = null; foreach (DriveInfo d in allDrives) { if (resolvedPath.StartsWith(d.RootDirectory.FullName, StringComparison.InvariantCultureIgnoreCase) && @@ -52,11 +52,12 @@ public static class StorageHelper bestMatch = d; } } - - if (bestMatch is null) { + + if (bestMatch is null) + { throw new InvalidOperationException($"The path `{path}` has no matching parent device. Space check invalid."); } - + return new FolderStorageInfo() { Path = path,