From 4aafbbf669a60115d0eab0774e796f9b99abdc2b Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Thu, 17 Nov 2022 11:17:41 +0100 Subject: [PATCH] V10: merge v8 blobstorage file deletion fix (#13415) * Implement fix from v8 https://github.com/umbraco/Umbraco-CMS/pull/11998 * Clean-up Co-authored-by: Elitsa Marinovska --- .../Controllers/CodeFileController.cs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs index d1f92953ad..26643da9f0 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs @@ -467,7 +467,7 @@ public class CodeFileController : BackOfficeNotificationsController { case Constants.Trees.PartialViews: if (IsDirectory( - _hostingEnvironment.MapPathContentRoot(Path.Combine(Constants.SystemDirectories.PartialViews, virtualPath)))) + _hostingEnvironment.MapPathContentRoot(Path.Combine(Constants.SystemDirectories.PartialViews, virtualPath)), _fileSystems.PartialViewsFileSystem!)) { _fileService.DeletePartialViewFolder(virtualPath); return Ok(); @@ -482,7 +482,7 @@ public class CodeFileController : BackOfficeNotificationsController case Constants.Trees.PartialViewMacros: if (IsDirectory( - _hostingEnvironment.MapPathContentRoot(Path.Combine(Constants.SystemDirectories.MacroPartials, virtualPath)))) + _hostingEnvironment.MapPathContentRoot(Path.Combine(Constants.SystemDirectories.MacroPartials, virtualPath)), _fileSystems.MacroPartialsFileSystem!)) { _fileService.DeletePartialViewMacroFolder(virtualPath); return Ok(); @@ -497,7 +497,7 @@ public class CodeFileController : BackOfficeNotificationsController case Constants.Trees.Scripts: if (IsDirectory( - _hostingEnvironment.MapPathWebRoot(Path.Combine(_globalSettings.UmbracoScriptsPath, virtualPath)))) + _hostingEnvironment.MapPathWebRoot(Path.Combine(_globalSettings.UmbracoScriptsPath, virtualPath)), _fileSystems.ScriptsFileSystem!)) { _fileService.DeleteScriptFolder(virtualPath); return Ok(); @@ -512,7 +512,7 @@ public class CodeFileController : BackOfficeNotificationsController return new UmbracoProblemResult("No Script or folder found with the specified path", HttpStatusCode.NotFound); case Constants.Trees.Stylesheets: if (IsDirectory( - _hostingEnvironment.MapPathWebRoot(Path.Combine(_globalSettings.UmbracoCssPath, virtualPath)))) + _hostingEnvironment.MapPathWebRoot(Path.Combine(_globalSettings.UmbracoCssPath, virtualPath)), _fileSystems.StylesheetsFileSystem!)) { _fileService.DeleteStyleSheetFolder(virtualPath); return Ok(); @@ -827,13 +827,21 @@ public class CodeFileController : BackOfficeNotificationsController return value; } - private bool IsDirectory(string path) + private bool IsDirectory(string path, IFileSystem fileSystem) { - var dirInfo = new DirectoryInfo(path); + // If it's a physical filesystem check with directory info + if (fileSystem.CanAddPhysical) + { + var dirInfo = new DirectoryInfo(path); - // If you turn off indexing in Windows this will have the attribute: - // `FileAttributes.Directory | FileAttributes.NotContentIndexed` - return (dirInfo.Attributes & FileAttributes.Directory) != 0; + // If you turn off indexing in Windows this will have the attribute: + // `FileAttributes.Directory | FileAttributes.NotContentIndexed` + return (dirInfo.Attributes & FileAttributes.Directory) != 0; + } + + // Otherwise check the filesystem abstraction to see if the folder exists + // Since this is used for delete, it presumably exists if we're trying to delete it + return fileSystem.DirectoryExists(path); } // this is an internal class for passing stylesheet data from the client to the controller while editing