Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs
Original file line number Diff line number Diff line change
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