From 59f66ff4807b3c382367aadd1eaa87beef80e1f4 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 14 Nov 2025 13:43:54 -0700 Subject: [PATCH] Fix subdirectory create failing on root drive (#1432) This appears to be a bug in .NET. Someone started to fix it in a PR, but it went stale and was auto-closed. https://github.com/dotnet/runtime/pull/117519 --- Source/FileManager/FileUtility.cs | 22 ++++++++++++++++++++ Source/LibationFileManager/PictureStorage.cs | 5 +++-- Source/LibationSearchEngine/SearchEngine.cs | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Source/FileManager/FileUtility.cs b/Source/FileManager/FileUtility.cs index 137b817f..387178a1 100644 --- a/Source/FileManager/FileUtility.cs +++ b/Source/FileManager/FileUtility.cs @@ -263,5 +263,27 @@ namespace FileManager return foundFiles; } + + /// + /// Creates a subdirectory or subdirectories on the specified path. + /// The specified path can be relative to this instance of the class. + /// + /// Fixes an issue with where it fails when the parent is a drive root. + /// + /// The specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name. + /// The last directory specified in + public static DirectoryInfo CreateSubdirectoryEx(this DirectoryInfo parent, string path) + { + if (parent.Root.FullName != parent.FullName || Path.IsPathRooted(path)) + return parent.CreateSubdirectory(path); + + // parent is a drive root and subDirectory is relative + //Solves a problem with DirectoryInfo.CreateSubdirectory where it fails + //If the parent DirectoryInfo is a drive root. + var fullPath = Path.GetFullPath(Path.Combine(parent.FullName, path)); + var directoryInfo = new DirectoryInfo(fullPath); + directoryInfo.Create(); + return directoryInfo; + } } } diff --git a/Source/LibationFileManager/PictureStorage.cs b/Source/LibationFileManager/PictureStorage.cs index 582d55d8..dccd4d42 100644 --- a/Source/LibationFileManager/PictureStorage.cs +++ b/Source/LibationFileManager/PictureStorage.cs @@ -1,4 +1,5 @@ -using System; +using FileManager; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -42,7 +43,7 @@ namespace LibationFileManager { // not customizable. don't move to config private static string ImagesDirectory { get; } - = new DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectory("Images").FullName; + = new DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectoryEx("Images").FullName; private static string getPath(PictureDefinition def) => Path.Combine(ImagesDirectory, $"{def.PictureId}{def.Size}.jpg"); diff --git a/Source/LibationSearchEngine/SearchEngine.cs b/Source/LibationSearchEngine/SearchEngine.cs index b922175b..f1bd1075 100644 --- a/Source/LibationSearchEngine/SearchEngine.cs +++ b/Source/LibationSearchEngine/SearchEngine.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using DataLayer; using Dinah.Core; +using FileManager; using LibationFileManager; using Lucene.Net.Analysis.Standard; using Lucene.Net.Documents; @@ -279,6 +280,6 @@ namespace LibationSearchEngine // not customizable. don't move to config private static string SearchEngineDirectory { get; } - = new System.IO.DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectory("SearchEngine").FullName; + = new System.IO.DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectoryEx("SearchEngine").FullName; } }