From 3b9d4cb78c61af51b3b3b02e2be4ee6cdc792340 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:51:14 -0800 Subject: [PATCH] Relative Config $imports (#89418) ## About The Pull Request When you import a config file inside a subdirectory, the config loader will now look IN that subdirectory, instead of exiting out to the parent folder. As a consequence, adds support for ".." to our deduplication system to avoid infinite loops due to headmin brain. ## Why It's Good For The Game jannies are on some shit wanna make their lives a bit nicer Note: I am testing on windows and also have only a loose grasp of how linux works, might fuck up in that environment idk ## Changelog :cl: config: the config loader now supports relatively pathed imports (importing a file inside a subfolder now acts as if you were IN that subfolder) /:cl: --- .../configuration/configuration.dm | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/code/controllers/configuration/configuration.dm b/code/controllers/configuration/configuration.dm index 5af3f7b8422..cd69a37a790 100644 --- a/code/controllers/configuration/configuration.dm +++ b/code/controllers/configuration/configuration.dm @@ -170,6 +170,25 @@ if(IsAdminAdvancedProcCall()) return + var/list/separate_levels = splittext(filename, "/") + // allows for inheriting our folder from the thing that included us + var/subfolder = "" + // do we have an actual directory or is this just one file + if(length(separate_levels) > 1) + var/actual_filename = separate_levels[length(separate_levels)] + // We need to sanitize out .. to ensure filename_to_test doesn't accidentially an infinte loop here + // Need filename in absolute form + var/list/parsed_folder_bits = list() + // look at just the relative directory referenced + for(var/entry in separate_levels - actual_filename) + if(entry == ".." && length(parsed_folder_bits)) + parsed_folder_bits.Cut(length(parsed_folder_bits), 0) + else + parsed_folder_bits += entry + if(length(parsed_folder_bits)) + subfolder = "[parsed_folder_bits.Join("/")]/" + filename = "[subfolder][actual_filename]" + var/filename_to_test = world.system_type == MS_WINDOWS ? LOWER_TEXT(filename) : filename if(filename_to_test in stack) log_config_error("Warning: Config recursion detected ([english_list(stack)]), breaking!") @@ -209,7 +228,7 @@ if(!value) log_config_error("Warning: Invalid $include directive: [value]") else - LoadEntries(value, stack) + LoadEntries("[subfolder][value]", stack) ++. continue