]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Shortcut copy if source or target starts with exclude path
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 30 Sep 2024 11:41:11 +0000 (13:41 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 30 Sep 2024 11:41:11 +0000 (13:41 +0200)
If the source or target we're copying to is a subdirectory of any of the
directories specified in ExcludeFiles= or ExcludeFilesTarget=, shortcut the
entire copy operation.

src/partition/repart.c

index 48ba4d797323f8ed979dc925a5d212cd103e0725..026b424169723e36ffa23681bd4feb25cb5b0739 100644 (file)
@@ -5254,6 +5254,9 @@ static int make_copy_files_denylist(
         }
 
         STRV_FOREACH(e, override_exclude_src ?: p->exclude_files_source) {
+                if (path_startswith(source, *e))
+                        return 1;
+
                 r = add_exclude_path(*e, &denylist, endswith(*e, "/") ? DENY_CONTENTS : DENY_INODE);
                 if (r < 0)
                         return r;
@@ -5262,6 +5265,9 @@ static int make_copy_files_denylist(
         STRV_FOREACH(e, override_exclude_tgt ?: p->exclude_files_target) {
                 _cleanup_free_ char *path = NULL;
 
+                if (path_startswith(target, *e))
+                        return 1;
+
                 const char *s = path_startswith(*e, target);
                 if (!s)
                         continue;
@@ -5492,6 +5498,8 @@ static int do_copy_files(Context *context, Partition *p, const char *root) {
                 r = make_copy_files_denylist(context, p, *source, *target, &denylist);
                 if (r < 0)
                         return r;
+                if (r > 0)
+                        continue;
 
                 r = make_subvolumes_set(p, *source, *target, &subvolumes_by_source_inode);
                 if (r < 0)