From: Lennart Poettering Date: Tue, 23 Mar 2021 13:05:56 +0000 (+0100) Subject: repart: make sure CopyFiles= works with a / suffixed path X-Git-Tag: v249-rc1~505 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6020d00d7e2cf15565bb9c749386a8c00303ecfa;p=thirdparty%2Fsystemd.git repart: make sure CopyFiles= works with a / suffixed path If we define a partition with CopyFiles=/efi/ this should just work. However it previously didn't because basename() would return the trailing slash. Let's fix this by moving things to path_extract_{directory|filename}() --- diff --git a/src/partition/repart.c b/src/partition/repart.c index f6d337ee2bf..195a909bf38 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -2655,11 +2655,15 @@ static int do_copy_files(Partition *p, const char *fs) { STRV_FOREACH_PAIR(source, target, p->copy_files) { _cleanup_close_ int sfd = -1, pfd = -1, tfd = -1; - _cleanup_free_ char *dn = NULL; + _cleanup_free_ char *dn = NULL, *fn = NULL; - dn = dirname_malloc(*target); - if (!dn) - return log_oom(); + r = path_extract_directory(*target, &dn); + if (r < 0) + return log_error_errno(r, "Failed to extract directory from '%s': %m", *target); + + r = path_extract_filename(*target, &fn); + if (r < 0) + return log_error_errno(r, "Failed to extract filename from '%s': %m", *target); sfd = chase_symlinks_and_open(*source, arg_root, CHASE_PREFIX_ROOT|CHASE_WARN, O_CLOEXEC|O_NOCTTY, NULL); if (sfd < 0) @@ -2686,7 +2690,7 @@ static int do_copy_files(Partition *p, const char *fs) { r = copy_tree_at( sfd, ".", - pfd, basename(*target), + pfd, fn, UID_INVALID, GID_INVALID, COPY_REFLINK|COPY_MERGE|COPY_REPLACE|COPY_SIGINT|COPY_HARDLINKS); } else