conf-files: rename .name field to .filename to make clearer what precisely it is the name of

This commit is contained in:
Lennart Poettering
2025-09-15 14:45:08 +02:00
parent 9b116a0871
commit 8a4f856977
3 changed files with 21 additions and 21 deletions

View File

@@ -24,7 +24,7 @@ ConfFile* conf_file_free(ConfFile *c) {
if (!c)
return NULL;
free(c->name);
free(c->filename);
free(c->result);
free(c->original_path);
free(c->resolved_path);
@@ -302,7 +302,7 @@ int conf_file_new_at(
if (!c->original_path)
return log_oom_full(log_level);
r = path_extract_filename(path, &c->name);
r = path_extract_filename(path, &c->filename);
if (r < 0)
return log_full_errno(log_level, r, "Failed to extract filename from '%s': %m", path);
@@ -318,7 +318,7 @@ int conf_file_new_at(
return log_full_errno(log_level, r, "Failed to chase '%s%s': %m", empty_to_root(root), skip_leading_slash(dirpath));
}
c->result = path_join(resolved_dirpath, c->name);
c->result = path_join(resolved_dirpath, c->filename);
if (!c->result)
return log_oom_full(log_level);
@@ -327,7 +327,7 @@ int conf_file_new_at(
rfd,
c->original_path,
c->result,
c->name,
c->filename,
/* masked= */ NULL,
flags,
&c->resolved_path,
@@ -456,7 +456,7 @@ static int files_add(
return log_oom_full(log_level);
*c = (ConfFile) {
.name = strdup(de->d_name),
.filename = strdup(de->d_name),
.result = TAKE_PTR(p),
.original_path = TAKE_PTR(original_path),
.resolved_path = TAKE_PTR(resolved_path),
@@ -464,10 +464,10 @@ static int files_add(
.st = st,
};
if (!c->name)
if (!c->filename)
return log_oom_full(log_level);
r = hashmap_ensure_put(files, &conf_file_hash_ops, c->name, c);
r = hashmap_ensure_put(files, &conf_file_hash_ops, c->filename, c);
if (r < 0) {
assert(r == -ENOMEM);
return log_oom_full(log_level);
@@ -497,7 +497,7 @@ static int dump_files(Hashmap *fh, const char *root, ConfFilesFlags flags, ConfF
/* Hence, we need to remove them from the hashmap. */
FOREACH_ARRAY(i, files, n_files)
assert_se(hashmap_remove(fh, (*i)->name) == *i);
assert_se(hashmap_remove(fh, (*i)->filename) == *i);
if (root)
FOREACH_ARRAY(i, files, n_files) {
@@ -538,7 +538,7 @@ static int copy_and_sort_files_from_hashmap(
const char *add = NULL;
if (FLAGS_SET(flags, CONF_FILES_BASENAME))
add = c->name;
add = c->filename;
else if (root) {
_cleanup_free_ char *p = NULL;
@@ -590,22 +590,22 @@ static int insert_replacement(Hashmap **fh, ConfFile *replacement, ConfFilesFlag
/* This consumes the input ConfFile. */
ConfFile *existing = hashmap_get(*fh, c->name);
ConfFile *existing = hashmap_get(*fh, c->filename);
if (existing) {
log_debug("An entry with higher priority '%s' -> '%s' already exists, ignoring the replacement: %s",
existing->name, existing->result, c->original_path);
existing->filename, existing->result, c->original_path);
*ret = NULL;
return 0;
}
r = hashmap_ensure_put(fh, &conf_file_hash_ops, c->name, c);
r = hashmap_ensure_put(fh, &conf_file_hash_ops, c->filename, c);
if (r < 0) {
assert(r == -ENOMEM);
return log_oom_full(conf_files_log_level(flags));
}
assert(r > 0);
log_debug("Inserted replacement: '%s' -> '%s'", c->name, c->result);
log_debug("Inserted replacement: '%s' -> '%s'", c->filename, c->result);
*ret = TAKE_PTR(c);
return 0;
@@ -651,7 +651,7 @@ static int conf_files_list_impl(
continue;
}
if (c && streq_ptr(path_startswith(c->result, path), c->name)) {
if (c && streq_ptr(path_startswith(c->result, path), c->filename)) {
r = insert_replacement(&fh, TAKE_PTR(c), flags, &inserted);
if (r < 0)
return r;

View File

@@ -18,11 +18,11 @@ typedef enum ConfFilesFlags {
} ConfFilesFlags;
typedef struct ConfFile {
char *name; /* name of a file found in config directories */
char *result; /* resolved config directory with the original file name found in the directory */
char *original_path; /* original config directory with the original file name found in the directory */
char *resolved_path; /* fully resolved path, where the filename part of the path may be different from the original name */
int fd; /* O_PATH fd to resolved_path, -EBADF if the resolved_path does not exist */
char *filename; /* filename of the discovered file (i.e. without any directory prefix) */
char *result; /* full path to the file (with the directory prefix fully resolved, but the filename part left as is) */
char *original_path; /* full path to the file (original non-resolved directory prefix + filename part left as is) */
char *resolved_path; /* fully resolved path to the file with both directory prefix and filename fully resolved */
int fd; /* O_PATH fd to resolved_path, -EBADF if resolved_path does not exist */
struct stat st; /* stat of the file. */
} ConfFile;

View File

@@ -1568,12 +1568,12 @@ static int verb_components(int argc, char **argv, void *userdata) {
FOREACH_ARRAY(i, directories, n_directories) {
ConfFile *e = *i;
if (streq(e->name, "sysupdate.d")) {
if (streq(e->filename, "sysupdate.d")) {
has_default_component = true;
continue;
}
const char *s = startswith(e->name, "sysupdate.");
const char *s = startswith(e->filename, "sysupdate.");
if (!s)
continue;