2025-09-25 15:13:02 +02:00
|
|
|
using Umbraco.Cms.Core.IO;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Services.FileSystem;
|
|
|
|
|
|
|
|
|
|
public class PhysicalFileSystemTreeService : FileSystemTreeServiceBase, IPhysicalFileSystemTreeService
|
|
|
|
|
{
|
2025-12-02 10:20:08 +09:00
|
|
|
private static readonly string[] _allowedRootFolders = { $"{Path.DirectorySeparatorChar}App_Plugins", $"{Path.DirectorySeparatorChar}wwwroot" };
|
|
|
|
|
|
2025-09-25 15:13:02 +02:00
|
|
|
private readonly IFileSystem _physicalFileSystem;
|
|
|
|
|
|
|
|
|
|
protected override IFileSystem FileSystem => _physicalFileSystem;
|
|
|
|
|
|
|
|
|
|
public PhysicalFileSystemTreeService(IPhysicalFileSystem physicalFileSystem) =>
|
|
|
|
|
_physicalFileSystem = physicalFileSystem;
|
2025-12-02 10:20:08 +09:00
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override string[] GetDirectories(string path) =>
|
|
|
|
|
IsTreeRootPath(path)
|
|
|
|
|
? _allowedRootFolders
|
|
|
|
|
: IsAllowedPath(path)
|
|
|
|
|
? base.GetDirectories(path)
|
|
|
|
|
: Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override string[] GetFiles(string path)
|
|
|
|
|
=> IsTreeRootPath(path) || IsAllowedPath(path) is false
|
|
|
|
|
? []
|
|
|
|
|
: base.GetFiles(path);
|
|
|
|
|
|
|
|
|
|
private static bool IsTreeRootPath(string path) => path == Path.DirectorySeparatorChar.ToString();
|
|
|
|
|
|
|
|
|
|
private static bool IsAllowedPath(string path) => _allowedRootFolders.Contains(path) || _allowedRootFolders.Any(folder => path.StartsWith($"{folder}{Path.DirectorySeparatorChar}"));
|
|
|
|
|
|
2025-09-25 15:13:02 +02:00
|
|
|
}
|