]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: make sure CopyFiles= works with a / suffixed path
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Mar 2021 13:05:56 +0000 (14:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 31 Mar 2021 08:35:45 +0000 (10:35 +0200)
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}()

src/partition/repart.c

index f6d337ee2bfed8ffadd3afd1324f75c9af09dc36..195a909bf3899b2899ea791719f72ba923ac4ae8 100644 (file)
@@ -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