]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-files: add flag so that we don't always prefix returned paths with the root... 40446/head
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Sep 2025 13:12:40 +0000 (15:12 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 25 Jan 2026 19:51:50 +0000 (20:51 +0100)
This is useful in tools such as system-repart where we show the
definition file paths a lot in our output, but if prefixed with the root
path we'd show a temporary mount dir when operating on a image file.
Hence, let's drop the prefix here, and show only the path within the
image.

src/basic/conf-files.c
src/basic/conf-files.h
src/repart/repart.c

index ff40eb617b29607157cd07173c12e313c0351c6d..cd91c5bc1ab548bb13f08c14e0ad3b70cb1b9db7 100644 (file)
@@ -539,7 +539,7 @@ static int copy_and_sort_files_from_hashmap(
 
                 if (FLAGS_SET(flags, CONF_FILES_BASENAME))
                         add = c->filename;
-                else if (root) {
+                else if (root && !FLAGS_SET(flags, CONF_FILES_DONT_PREFIX_ROOT)) {
                         _cleanup_free_ char *p = NULL;
 
                         r = chaseat_prefix_root(c->result, root, &p);
index fa460b9e914fb452384e811aa74584c97b0c5ba8..031463172abbf1943ef1852a0d923938b6e91590 100644 (file)
@@ -15,6 +15,7 @@ typedef enum ConfFilesFlags {
         CONF_FILES_FILTER_MASKED            = CONF_FILES_FILTER_MASKED_BY_SYMLINK | CONF_FILES_FILTER_MASKED_BY_EMPTY,
         CONF_FILES_TRUNCATE_SUFFIX          = 1 << 6, /* truncate specified suffix from return filename or path */
         CONF_FILES_WARN                     = 1 << 7, /* warn on some errors */
+        CONF_FILES_DONT_PREFIX_ROOT         = 1 << 8, /* don't prefix the specified root path to the resulting paths */
 } ConfFilesFlags;
 
 typedef struct ConfFile {
index 97cc60c95b2fbb226327db7e7a028ee2d240f64f..3b5a541368920f72d2034e87cbac4389b5e1edba 100644 (file)
@@ -3397,7 +3397,7 @@ static int context_read_definitions(Context *context) {
                         &files,
                         ".conf",
                         context->definitions ? NULL : arg_root,
-                        CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED|CONF_FILES_WARN,
+                        CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED|CONF_FILES_WARN|CONF_FILES_DONT_PREFIX_ROOT,
                         dirs);
         if (r < 0)
                 return log_error_errno(r, "Failed to enumerate *.conf files: %m");