From 332e528012f321c42a0e9945503b18d9c055c71c Mon Sep 17 00:00:00 2001 From: Ikuo Ohba Date: Fri, 3 May 2024 21:18:28 +0900 Subject: [PATCH 1/2] Fix #4223 --- Oqtane.Server/Controllers/FileController.cs | 22 ++++++--------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index aeeda0b2..677d922d 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -760,23 +760,13 @@ namespace Oqtane.Controllers { if (!Directory.Exists(folderpath)) { - string path = ""; - var separators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; - string[] folders = folderpath.Split(separators, StringSplitOptions.RemoveEmptyEntries); - foreach (string folder in folders) + try { - path = Utilities.PathCombine(path, folder, Path.DirectorySeparatorChar.ToString()); - if (!Directory.Exists(path)) - { - try - { - Directory.CreateDirectory(path); - } - catch (Exception ex) - { - _logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Unable To Create Folder {Folder}", path); - } - } + Directory.CreateDirectory(folderpath); + } + catch (Exception ex) + { + _logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Unable To Create Folder {Folder}", folderpath); } } } From d047d26dbf43f958350d07a39a095d72a9201ee8 Mon Sep 17 00:00:00 2001 From: Ikuo Ohba Date: Sun, 5 May 2024 12:12:40 +0900 Subject: [PATCH 2/2] Reverted and fixed the source code. --- Oqtane.Server/Controllers/FileController.cs | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 677d922d..4f5bcb2f 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -760,13 +760,23 @@ namespace Oqtane.Controllers { if (!Directory.Exists(folderpath)) { - try + string path = folderpath.StartsWith(Path.DirectorySeparatorChar) ? Path.DirectorySeparatorChar.ToString() : string.Empty; + var separators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; + string[] folders = folderpath.Split(separators, StringSplitOptions.RemoveEmptyEntries); + foreach (string folder in folders) { - Directory.CreateDirectory(folderpath); - } - catch (Exception ex) - { - _logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Unable To Create Folder {Folder}", folderpath); + path = Utilities.PathCombine(path, folder, Path.DirectorySeparatorChar.ToString()); + if (!Directory.Exists(path)) + { + try + { + Directory.CreateDirectory(path); + } + catch (Exception ex) + { + _logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Unable To Create Folder {Folder}", path); + } + } } } }