pretty-print: do not fail when cat_files() tries to show a masked file
Before661b5bfd21, cat_files() does not check if a file is regular. If the file is a symlink to /dev/null, then cat_files() simply shows an empty contents for the file. With the offending commit, as the CHASE_MUST_BE_REGULAR flag is set, hence when we found a masked file, the function fails. Fixes #40313. Fixes regression caused by661b5bfd21. Co-authored-by: gvenugo3 <gvenugo3@asu.edu>
This commit is contained in:
@@ -324,7 +324,20 @@ static int cat_file_by_path(const char *p, bool *newline, CatFlags flags) {
|
||||
|
||||
assert(p);
|
||||
|
||||
r = conf_file_new(p, /* root= */ NULL, CONF_FILES_REGULAR, &c);
|
||||
r = conf_file_new(p, /* root= */ NULL, CONF_FILES_REGULAR | CONF_FILES_FILTER_MASKED, &c);
|
||||
if (r == -ERFKILL) { /* masked */
|
||||
if (newline) {
|
||||
if (*newline)
|
||||
putc('\n', stdout);
|
||||
*newline = true;
|
||||
}
|
||||
|
||||
printf("%s# %s is a mask.%s\n",
|
||||
ansi_highlight_magenta(),
|
||||
p,
|
||||
ansi_normal());
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to chase '%s': %m", p);
|
||||
|
||||
@@ -457,7 +470,8 @@ int conf_files_cat(const char *root, const char *name, CatFlags flags) {
|
||||
if (!p)
|
||||
return log_oom();
|
||||
|
||||
if (conf_file_new(p, root, CONF_FILES_REGULAR, &c) >= 0)
|
||||
r = conf_file_new(p, root, CONF_FILES_REGULAR | CONF_FILES_FILTER_MASKED, &c);
|
||||
if (r >= 0 || r == -ERFKILL) /* Found a regular file or masked file */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user