conf-files: introduce CONF_FILES_CHASE_BASENAME flag

Previously, when a root directory is specified to conf_files_list() and
friends, the last component of each result was not resolved, even though
they internally chases the last component. So the caller needs to chase
the path again when the file is used.

This introduce a new flag that makes the whole path of each result is
resolved, hence caller can use it as is.
This commit is contained in:
Yu Watanabe
2025-06-28 04:13:43 +09:00
parent 50c81130b6
commit 49653adef3
3 changed files with 38 additions and 2 deletions
+3
View File
@@ -164,6 +164,9 @@ static int files_add(
if (!n)
return log_oom_debug();
if (FLAGS_SET(flags, CONF_FILES_CHASE_BASENAME))
free_and_replace(p, resolved_path);
r = hashmap_ensure_put(files, &string_hash_ops_free_free, n, p);
if (r < 0) {
assert(r == -ENOMEM);
+3 -2
View File
@@ -8,8 +8,9 @@ typedef enum ConfFilesFlags {
CONF_FILES_REGULAR = 1 << 1,
CONF_FILES_DIRECTORY = 1 << 2,
CONF_FILES_BASENAME = 1 << 3,
CONF_FILES_FILTER_MASKED_BY_SYMLINK = 1 << 4,
CONF_FILES_FILTER_MASKED_BY_EMPTY = 1 << 5,
CONF_FILES_CHASE_BASENAME = 1 << 4, /* If set, also resolve symlink files in config directories. */
CONF_FILES_FILTER_MASKED_BY_SYMLINK = 1 << 5,
CONF_FILES_FILTER_MASKED_BY_EMPTY = 1 << 6,
CONF_FILES_FILTER_MASKED = CONF_FILES_FILTER_MASKED_BY_SYMLINK | CONF_FILES_FILTER_MASKED_BY_EMPTY,
} ConfFilesFlags;