Skip to content

Commit

Permalink
V10: merge v8 blobstorage file deletion fix (#13415)
Browse files Browse the repository at this point in the history
* Implement fix from v8 #11998

* Clean-up

Co-authored-by: Elitsa Marinovska <elm@umbraco.dk>
  • Loading branch information
Zeegaan and elit0451 committed Nov 17, 2022
1 parent 57ef091 commit 4aafbbf
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs
Expand Up @@ -467,7 +467,7 @@ public IActionResult Delete(string type, string virtualPath)
{
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();
Expand All @@ -482,7 +482,7 @@ public IActionResult Delete(string type, string virtualPath)

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();
Expand All @@ -497,7 +497,7 @@ public IActionResult Delete(string type, string virtualPath)

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();
Expand All @@ -512,7 +512,7 @@ public IActionResult Delete(string type, string virtualPath)
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();
Expand Down Expand Up @@ -827,13 +827,21 @@ private string NormalizeVirtualPath(string? virtualPath, string systemDirectory)
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
Expand Down

0 comments on commit 4aafbbf

Please sign in to comment.