From 413d3ce1b76b42ba691eea54cd1704b14602442e Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 4 Oct 2024 21:33:52 +0200 Subject: [PATCH 1/2] repart: Don't copy root directory mode from source file If the source is a file, don't copy the mode and such from it to the root directory, even if the target is /. --- src/partition/repart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/partition/repart.c b/src/partition/repart.c index 95ae0a3158..c87cceb4da 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -5518,6 +5518,8 @@ static int do_copy_files(Context *context, Partition *p, const char *root) { return -errno; sfd = chase_and_open(*source, arg_copy_source, CHASE_PREFIX_ROOT, O_PATH|O_DIRECTORY|O_CLOEXEC|O_NOCTTY, NULL); + if (sfd == -ENOTDIR) + continue; if (sfd < 0) return log_error_errno(sfd, "Failed to open source file '%s%s': %m", strempty(arg_copy_source), *source); From 87333bd1dc69195b93e9aee9b91c06fb167b152e Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 4 Oct 2024 21:34:33 +0200 Subject: [PATCH 2/2] chase: Fix shortcut We can't shortcut chaseat() if CHASE_PARENT is set. --- src/basic/chase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/chase.c b/src/basic/chase.c index 4576e4b058..8eac356665 100644 --- a/src/basic/chase.c +++ b/src/basic/chase.c @@ -192,7 +192,7 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int if (!(flags & (CHASE_AT_RESOLVE_IN_ROOT|CHASE_NONEXISTENT|CHASE_NO_AUTOFS|CHASE_SAFE|CHASE_STEP| - CHASE_PROHIBIT_SYMLINKS|CHASE_MKDIR_0755)) && + CHASE_PROHIBIT_SYMLINKS|CHASE_MKDIR_0755|CHASE_PARENT)) && !ret_path && ret_fd) { /* Shortcut the ret_fd case if the caller isn't interested in the actual path and has no root