From 555b4fadf13813ffb680ca205687062f4e72ced8 Mon Sep 17 00:00:00 2001 From: Matt Brailsford Date: Wed, 16 Feb 2022 23:04:41 +0000 Subject: [PATCH] Lookup plugin lang / icons folders in a case insensitive way (#11985) * Use lowercase lang folder name for packages lang files Use lowercase lang folder name for packages lang files to be consistent with Umbraco's casing * Case insensitive `lang` folder lookup * Comment grammar * Setup lower case appl_plugin icons folder path * Update Constants-SystemDirectories.cs * Check both casings for the AppPluginIcons path * Fixed spelling mistake + avoid multiple Exists checks * Add IsCaseSensitiveFileSystem to IHostingEnvironment * Add IsCaseSensitiveFileSystem to AspNetCoreHostingEnvironment * Undo last changes * Undo last changed * Add FileSystemUtility * Only perform second iconPath if OS is case sensitive * Undo changes * Undo changes * Remove filesystem utils file * Added HostingEnvironmentExtensions.cs * Use IsCaseSensitiveFileSystem extension method * Use the Umbraco.Extensions namespace * Simplify IsCaseSensitiveFileSystem * Better naming * Use PluginIcons * Remove unused using statement * Delete HostingEnvironmentExtensions.cs * Update IconService.cs * Comment clarity * Update src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs Co-authored-by: Paul Johnson Co-authored-by: Paul Johnson Co-authored-by: Michael Latouche --- src/Umbraco.Core/Constants-SystemDirectories.cs | 8 +++++++- .../DependencyInjection/UmbracoBuilder.Services.cs | 3 ++- src/Umbraco.Web.BackOffice/Services/IconService.cs | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Core/Constants-SystemDirectories.cs b/src/Umbraco.Core/Constants-SystemDirectories.cs index bf34aab989..40b0267d73 100644 --- a/src/Umbraco.Core/Constants-SystemDirectories.cs +++ b/src/Umbraco.Core/Constants-SystemDirectories.cs @@ -1,3 +1,5 @@ +using System; + namespace Umbraco.Cms.Core { public static partial class Constants @@ -42,7 +44,11 @@ namespace Umbraco.Cms.Core public const string Install = "~/install"; public const string AppPlugins = "/App_Plugins"; - public static string AppPluginIcons => "/Backoffice/Icons"; + + [Obsolete("Use PluginIcons instead")] + public const string AppPluginIcons = "/Backoffice/Icons"; + public const string PluginIcons = "/backoffice/icons"; + public const string CreatedPackages = "/created-packages"; diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs index c79cbf9d94..fa448bdc86 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs @@ -122,7 +122,8 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection var pluginLangFolders = appPlugins.Exists == false ? Enumerable.Empty() : appPlugins.GetDirectories() - .SelectMany(x => x.GetDirectories("Lang", SearchOption.AllDirectories)) + // Check for both Lang & lang to support case sensitive file systems. + .SelectMany(x => x.GetDirectories("?ang", SearchOption.AllDirectories).Where(x => x.Name.InvariantEquals("lang"))) .SelectMany(x => x.GetFiles("*.xml", SearchOption.TopDirectoryOnly)) .Select(x => new LocalizedTextServiceSupplementaryFileSource(x, false)); diff --git a/src/Umbraco.Web.BackOffice/Services/IconService.cs b/src/Umbraco.Web.BackOffice/Services/IconService.cs index a1d634f41b..f1ab9ffb0e 100644 --- a/src/Umbraco.Web.BackOffice/Services/IconService.cs +++ b/src/Umbraco.Web.BackOffice/Services/IconService.cs @@ -104,8 +104,18 @@ namespace Umbraco.Cms.Web.BackOffice.Services // iterate sub directories of app plugins foreach (var dir in appPlugins.EnumerateDirectories()) { - var iconPath = _hostingEnvironment.MapPathContentRoot($"{Constants.SystemDirectories.AppPlugins}/{dir.Name}{Constants.SystemDirectories.AppPluginIcons}"); - if (Directory.Exists(iconPath)) + // AppPluginIcons path was previoulsy the wrong case, so we first check for the prefered directory + // and then check the legacy directory. + var iconPath = _hostingEnvironment.MapPathContentRoot($"{Constants.SystemDirectories.AppPlugins}/{dir.Name}{Constants.SystemDirectories.PluginIcons}"); + var iconPathExists = Directory.Exists(iconPath); + + if (!iconPathExists) + { + iconPath = _hostingEnvironment.MapPathContentRoot($"{Constants.SystemDirectories.AppPlugins}/{dir.Name}{Constants.SystemDirectories.AppPluginIcons}"); + iconPathExists = Directory.Exists(iconPath); + } + + if (iconPathExists) { var dirIcons = new DirectoryInfo(iconPath).EnumerateFiles("*.svg", SearchOption.TopDirectoryOnly); icons.UnionWith(dirIcons);