From 839fd20cf4f933d43ce4698adead7bbb24a2f407 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Tue, 6 Oct 2026 15:56:25 +0200 Subject: [PATCH 1/9] src: Add input options exclude and only Allow restricting the paths of an input with the new input options "exclude" and "only". For tar archives, the paths are passed to tar during extraction. For all other inputs, the paths are removed from the partition after writing. Relative paths are resolved against the root of the partition and may contain wildcards. "exclude" takes precedence over "only". Also shell-quote all arguments passed to tar. Signed-off-by: Martin Schwan --- src/pu-emmc.c | 45 +++++++++- src/pu-utils.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++++- src/pu-utils.h | 10 +++ tests/utils.c | 2 +- 4 files changed, 279 insertions(+), 5 deletions(-) diff --git a/src/pu-emmc.c b/src/pu-emmc.c index 1100c172..c3d70337 100644 --- a/src/pu-emmc.c +++ b/src/pu-emmc.c @@ -24,6 +24,8 @@ typedef struct _PuEmmcInput { gchar *filename; gchar *md5sum; gchar *sha256sum; + GList *exclude; + GList *only; /* Internal members */ gsize _size; @@ -375,7 +377,8 @@ pu_emmc_write_data(PuFlash *flash, if (g_regex_match_simple(".tar", path, G_REGEX_CASELESS, 0)) { if (!pu_mount(part_path, part_mount, NULL, NULL, error)) return FALSE; - if (!pu_archive_extract(path, part_mount, error)) + if (!pu_archive_extract(path, part_mount, input->exclude, + input->only, error)) return FALSE; if (!pu_umount(part_mount, error)) return FALSE; @@ -387,6 +390,15 @@ pu_emmc_write_data(PuFlash *flash, return FALSE; if (!pu_set_ext_label(part_path, part->label, error)) return FALSE; + if (input->exclude || input->only) { + if (!pu_mount(part_path, part_mount, NULL, NULL, error)) + return FALSE; + if (!pu_path_remove_exclude_only(part_mount, input->exclude, + input->only, error)) + return FALSE; + if (!pu_umount(part_mount, error)) + return FALSE; + } } else if (!part->filesystem) { if (!pu_write_raw(path, part_path, self->device, 0, 0, 0, error)) return FALSE; @@ -395,6 +407,11 @@ pu_emmc_write_data(PuFlash *flash, return FALSE; if (!pu_file_copy(path, part_mount, error)) return FALSE; + if (input->exclude || input->only) { + if (!pu_path_remove_exclude_only(part_mount, input->exclude, + input->only, error)) + return FALSE; + } if (!pu_umount(part_mount, error)) return FALSE; } @@ -601,6 +618,8 @@ pu_emmc_class_finalize(GObject *object) g_free(in->filename); g_free(in->md5sum); g_free(in->sha256sum); + g_list_free_full(g_steal_pointer(&in->exclude), g_free); + g_list_free_full(g_steal_pointer(&in->only), g_free); g_free(in); } g_list_free(g_steal_pointer(&part->input)); @@ -1058,6 +1077,30 @@ pu_emmc_parse_partitions(PuEmmc *emmc, input->filename = pu_hash_table_lookup_string(iv->data.mapping, "filename", ""); input->md5sum = pu_hash_table_lookup_string(iv->data.mapping, "md5sum", ""); input->sha256sum = pu_hash_table_lookup_string(iv->data.mapping, "sha256sum", ""); + GList *exclude_list = pu_hash_table_lookup_list(iv->data.mapping, "exclude", NULL); + if (exclude_list) { + for (GList *e = exclude_list; e; e = e->next) { + PuConfigValue *ev = e->data; + if (ev->type != PU_CONFIG_VALUE_TYPE_STRING) { + g_set_error(error, PU_ERROR, PU_ERROR_EMMC_PARSE, + "'exclude' does not contain a sequence of strings"); + return FALSE; + } + input->exclude = g_list_append(input->exclude, g_strdup(ev->data.string)); + } + } + GList *only_list = pu_hash_table_lookup_list(iv->data.mapping, "only", NULL); + if (only_list) { + for (GList *o = only_list; o; o = o->next) { + PuConfigValue *ov = o->data; + if (ov->type != PU_CONFIG_VALUE_TYPE_STRING) { + g_set_error(error, PU_ERROR, PU_ERROR_EMMC_PARSE, + "'only' does not contain a sequence of strings"); + return FALSE; + } + input->only = g_list_append(input->only, g_strdup(ov->data.string)); + } + } part->input = g_list_prepend(part->input, input); g_debug("Parsed partition input: filename=%s md5sum=%s sha256sum=%s", diff --git a/src/pu-utils.c b/src/pu-utils.c index 863e3a3b..8c05c4db 100644 --- a/src/pu-utils.c +++ b/src/pu-utils.c @@ -9,7 +9,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -59,9 +61,11 @@ pu_spawn_command_line_sync(const gchar *command_line, gboolean pu_archive_extract(const gchar *filename, const gchar *dest, + GList *exclude, + GList *only, GError **error) { - g_autofree gchar *cmd = NULL; + g_autoptr(GString) cmd = NULL; g_return_val_if_fail(filename != NULL, FALSE); g_return_val_if_fail(dest != NULL, FALSE); @@ -69,9 +73,29 @@ pu_archive_extract(const gchar *filename, g_debug("Extracting '%s' to '%s'", filename, dest); - cmd = g_strdup_printf("tar -xf %s -C %s", filename, dest); + cmd = g_string_new("tar"); - if (!pu_spawn_command_line_sync(cmd, error)) { + for (GList *e = exclude; e; e = e->next) { + g_autofree gchar *quoted = g_shell_quote(e->data); + g_string_append_printf(cmd, " --exclude %s", quoted); + } + + { + g_autofree gchar *qdest = g_shell_quote(dest); + g_autofree gchar *qfile = g_shell_quote(filename); + g_string_append_printf(cmd, " -C %s -xf %s", qdest, qfile); + } + + for (GList *o = only; o; o = o->next) { + g_autofree gchar *quoted = g_shell_quote(o->data); + if (g_regex_match_simple("[!^*?\\[\\]]", o->data, 0, 0)) { + g_string_append_printf(cmd, " --wildcards %s", quoted); + } else { + g_string_append_printf(cmd, " --no-wildcards %s", quoted); + } + } + + if (!pu_spawn_command_line_sync(cmd->str, error)) { g_prefix_error(error, "Failed extracting '%s' to '%s': ", filename, dest); return FALSE; } @@ -584,3 +608,200 @@ pu_str_pre_remove(gchar *string, return string; } + + +static gboolean +path_is_same_or_child(const gchar *path, + const gchar *parent) +{ + gsize len = strlen(parent); + + if (!g_str_has_prefix(path, parent)) { + return FALSE; + } + + return path[len] == '\0' || path[len] == '/' || g_str_equal(parent, "/"); +} + +gboolean +pu_file_remove_recursive(GFile *file, + GHashTable *skip, + GError **error) +{ + g_autoptr(GFileEnumerator) dir_enum = NULL; + g_autoptr(GFileInfo) info = NULL; + gboolean skip_delete = FALSE; + + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + if (skip) { + g_autofree gchar *file_path = NULL; + GHashTableIter iter; + gpointer key; + + file_path = g_file_get_path(file); + g_hash_table_iter_init(&iter, skip); + while (g_hash_table_iter_next(&iter, &key, NULL)) { + if (path_is_same_or_child(file_path, key)) { + /* "file_path" is retained itself or lies within a retained + * directory */ + return TRUE; + } + if (path_is_same_or_child(key, file_path)) { + /* "file_path" is a parent of a retained path. Retain it, but + * still evaluate its children */ + skip_delete = TRUE; + } + } + } + + dir_enum = g_file_enumerate_children(file, G_FILE_ATTRIBUTE_STANDARD_NAME, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, NULL); + if (dir_enum) { + while ((info = g_file_enumerator_next_file(dir_enum, NULL, NULL)) != NULL) { + g_autoptr(GFile) child = NULL; + + child = g_file_enumerator_get_child(dir_enum, info); + if (!pu_file_remove_recursive(child, skip, error)) { + g_prefix_error(error, "Failed recursive file removal: "); + return FALSE; + } + g_clear_object(&info); + } + } + + if (skip_delete) { + return TRUE; + } + + return g_file_delete(file, NULL, error); +} + +static GHashTable * +resolve_path_list(const gchar *root, + GList *paths, + GError **error) +{ + g_autoptr(GHashTable) table = NULL; + + g_return_val_if_fail(error == NULL || *error == NULL, NULL); + + table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + + for (GList *p = paths; p; p = p->next) { + const gchar *ps = p->data; + g_autofree gchar *pattern = NULL; + glob_t gl = {0}; + gint ret; + + if (g_path_is_absolute(ps)) { + pattern = g_strdup(ps); + } else { + pattern = g_build_filename(root, ps, NULL); + } + + ret = glob(pattern, GLOB_NOSORT, NULL, &gl); + if (ret == GLOB_NOMATCH) { + g_debug("Pattern '%s' did not match anything", pattern); + globfree(&gl); + continue; + } else if (ret != 0) { + g_set_error(error, PU_ERROR, PU_ERROR_FAILED, + "glob() failed on '%s': %d", ps, ret); + globfree(&gl); + return NULL; + } + + for (gsize i = 0; i < gl.gl_pathc; i++) { + gchar *canon = g_canonicalize_filename(gl.gl_pathv[i], NULL); + + if (g_str_equal(canon, root) || !path_is_same_or_child(canon, root)) { + g_set_error(error, PU_ERROR, PU_ERROR_FAILED, + "Path '%s' is not located within '%s'", ps, root); + g_free(canon); + globfree(&gl); + return NULL; + } + g_debug("Resolved '%s' to '%s'", ps, canon); + g_hash_table_replace(table, canon, NULL); + } + globfree(&gl); + } + + return g_steal_pointer(&table); +} + +gboolean +pu_path_remove_exclude_only(const gchar *path, + GList *exclude, + GList *only, + GError **error) +{ + g_autofree gchar *root = NULL; + GHashTableIter iter; + gpointer key; + + g_return_val_if_fail(g_strcmp0(path, "") > 0, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + root = g_canonicalize_filename(path, NULL); + + if (exclude) { + g_autoptr(GHashTable) exclude_table = NULL; + + exclude_table = resolve_path_list(root, exclude, error); + if (!exclude_table) { + g_prefix_error(error, "Failed parsing 'exclude' paths: "); + return FALSE; + } + + g_hash_table_iter_init(&iter, exclude_table); + while (g_hash_table_iter_next(&iter, &key, NULL)) { + g_autoptr(GFile) file = NULL; + + /* An entry may already be gone if a parent was removed before */ + if (!g_file_test(key, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK)) + continue; + file = g_file_new_for_path(key); + if (!pu_file_remove_recursive(file, NULL, error)) + return FALSE; + } + } + + if (only) { + g_autoptr(GHashTable) only_table = NULL; + g_autoptr(GFile) root_file = NULL; + g_autoptr(GFileEnumerator) dir_enum = NULL; + g_autoptr(GFileInfo) info = NULL; + + only_table = resolve_path_list(root, only, error); + if (!only_table) { + g_prefix_error(error, "Failed parsing 'only' paths: "); + return FALSE; + } + + /* Delete every top-level entry (including hidden ones), except the + * ones in "only" */ + root_file = g_file_new_for_path(root); + dir_enum = g_file_enumerate_children(root_file, G_FILE_ATTRIBUTE_STANDARD_NAME, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, error); + if (!dir_enum) { + g_prefix_error(error, "Failed listing '%s': ", root); + return FALSE; + } + while ((info = g_file_enumerator_next_file(dir_enum, NULL, error)) != NULL) { + g_autoptr(GFile) child = NULL; + + child = g_file_enumerator_get_child(dir_enum, info); + if (!pu_file_remove_recursive(child, only_table, error)) + return FALSE; + g_clear_object(&info); + } + if (error && *error) + return FALSE; + } + + return TRUE; +} diff --git a/src/pu-utils.h b/src/pu-utils.h index 8b488a98..459e20ad 100644 --- a/src/pu-utils.h +++ b/src/pu-utils.h @@ -7,12 +7,15 @@ #define PARTUP_UTILS_H #include +#include #include gboolean pu_spawn_command_line_sync(const gchar *command_line, GError **error); gboolean pu_archive_extract(const gchar *filename, const gchar *dest, + GList *exclude, + GList *only, GError **error); gboolean pu_make_filesystem(const gchar *part, const gchar *type, @@ -65,5 +68,12 @@ gchar * pu_device_get_partition_pattern(const gchar *device, GError **error); gchar * pu_str_pre_remove(gchar *string, guint n); +gboolean pu_file_remove_recursive(GFile *file, + GHashTable *skip, + GError **error); +gboolean pu_path_remove_exclude_only(const gchar *path, + GList *exclude, + GList *only, + GError **error); #endif /* PARTUP_UTILS_H */ diff --git a/tests/utils.c b/tests/utils.c index 3e4431b0..4c37c626 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -24,7 +24,7 @@ test_archive_extract(void) out_file = g_build_filename(dest, "lorem.txt", NULL); - g_assert_true(pu_archive_extract(source, dest, &error)); + g_assert_true(pu_archive_extract(source, dest, NULL, NULL, &error)); g_assert_no_error(error); g_assert_true(g_file_test(out_file, G_FILE_TEST_IS_REGULAR)); From bff2ea457eb117f722cf650dbbc5aee8512c4ff6 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Thu, 12 Nov 2026 15:08:21 +0100 Subject: [PATCH 2/9] meson.build: Bump to version 5.0.0 Bump version early now, so the development version can be used with the newly introduced selective exclusion/inclusion feature. Signed-off-by: Martin Schwan --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index d873bd5f..fc017725 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'partup', 'c', - version : '4.0.0', + version : '5.0.0', license : 'GPL-3.0-or-later', default_options : [ 'c_std=c99', From a16041a83f342ff3fdeebb2b1bb9643cbb962de4 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Tue, 6 Oct 2026 15:56:25 +0200 Subject: [PATCH 3/9] tests: utils: Add tests for exclude and only Test extracting archives and removing paths from a directory with exclude and only lists, including wildcards, relative paths and paths outside of the root directory. Signed-off-by: Martin Schwan --- tests/data/dir-struct.tar | Bin 0 -> 10240 bytes tests/data/foobar.tar | Bin 0 -> 10240 bytes tests/data/lorem.tar | Bin 10240 -> 10240 bytes tests/utils.c | 314 +++++++++++++++++++++++++++++++++++++- 4 files changed, 308 insertions(+), 6 deletions(-) create mode 100644 tests/data/dir-struct.tar create mode 100644 tests/data/foobar.tar diff --git a/tests/data/dir-struct.tar b/tests/data/dir-struct.tar new file mode 100644 index 0000000000000000000000000000000000000000..813319e702110caf57ee020c8d4901505172d515 GIT binary patch literal 10240 zcmeI0>u$m@42AP3eS$96_IbDjHffNl4I1?67iUx&2(lI>Y(GvUR5cb(bv`?GVs{_@ z^ume`9!6^nqh}b`&p0QHRE;u5>R=bV6)mew(XTo?KlFalRTb-;^QrZIv#0+1k8K<0 z3e#ti_f-B$HN;;T3I5Lr8{)rQbVXx;5_~d$BLe?06!<@r|MD;ti-9@(wV?f9v>f~Y zGw`!9|B3(F4TJ6K(_;6Yb#3C`XnkGx$9FQbvHpMa*Su|5#j}3J9cQTjasMa&;rI9a zIqm-;3PSw{|2r|8aeB=E-g^JG-}d!tv(4x}x|);!D%O9cCHUvYaMK_0_qO-->ZUo% z5(D&i~42od0tnPWrjYf8!2a z?T^X(@TAvEBk`Yl{+E%zk>MDC{_j#oyg>md00p1`6o3Ly017|>C;$bZ02FvwfiI4i B6np>x literal 0 HcmV?d00001 diff --git a/tests/data/foobar.tar b/tests/data/foobar.tar new file mode 100644 index 0000000000000000000000000000000000000000..61cc877dc1fe3a8ab84728b842cd6794b217b3cd GIT binary patch literal 10240 zcmeH}-3o#*7>0M;RqP6EbAQm?Xk;gaUy75WeDD8V?LQU*`5#J0XI^r@2Uj6EjmY1_MJw6Eiag1%t_k oj46{D8UM3^HE?YfWctO(nUbHAUxY)mnK4+i35sU02C!yX0E~qt2LJ#7 delta 16 WcmZn&Xb4!qvRQ%afh>?vU;_X%8wDZ& diff --git a/tests/utils.c b/tests/utils.c index 4c37c626..74ddc955 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -16,19 +16,108 @@ test_archive_extract(void) { g_autoptr(GError) error = NULL; g_autofree gchar *dest = NULL; - g_autofree gchar *out_file = NULL; - const gchar *source = "data/lorem.tar"; + g_autofree gchar *lorem_file = NULL; + g_autofree gchar *ipsum_file = NULL; + g_autofree gchar *dolor_file = NULL; + g_autofree gchar *foo_dir = NULL; + g_autofree gchar *foo_file = NULL; + g_autofree gchar *bar_dir = NULL; + g_autofree gchar *bar_file = NULL; + g_autofree gchar *baz_dir = NULL; + g_autofree gchar *baz_file = NULL; + g_autoptr(GList) exclude = NULL; + g_autoptr(GList) list_ba = NULL; + g_autoptr(GList) list_notfound = NULL; + g_autoptr(GList) only = NULL; dest = g_dir_make_tmp("partup-XXXXXX", &error); g_assert_no_error(error); - out_file = g_build_filename(dest, "lorem.txt", NULL); + lorem_file = g_build_filename(dest, "lorem.txt", NULL); + ipsum_file = g_build_filename(dest, "ipsum.txt", NULL); + dolor_file = g_build_filename(dest, "dolor.txt", NULL); - g_assert_true(pu_archive_extract(source, dest, NULL, NULL, &error)); + exclude = g_list_prepend(exclude, "lorem.txt"); + exclude = g_list_prepend(exclude, "ipsum.txt"); + + only = g_list_prepend(only, "ipsum.txt"); + only = g_list_prepend(only, "dolor.txt"); + + list_ba = g_list_prepend(list_ba, "ba*"); + list_notfound = g_list_prepend(list_notfound, "notfound*"); + + foo_dir = g_build_filename(dest, "foo", NULL); + foo_file = g_build_filename(dest, "foo/foo.txt", NULL); + bar_dir = g_build_filename(dest, "bar", NULL); + bar_file = g_build_filename(dest, "bar/bar.cfg", NULL); + baz_dir = g_build_filename(dest, "baz", NULL); + baz_file = g_build_filename(dest, "baz/baz.yaml", NULL); + + /* Extract all */ + g_assert_true(pu_archive_extract("data/lorem.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + g_assert_true(g_file_test(lorem_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(ipsum_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(dolor_file, G_FILE_TEST_IS_REGULAR)); + g_assert_cmpint(g_remove(lorem_file), ==, 0); + g_assert_cmpint(g_remove(ipsum_file), ==, 0); + g_assert_cmpint(g_remove(dolor_file), ==, 0); + + /* Extract all excluding two */ + g_assert_true(pu_archive_extract("data/lorem.tar", dest, exclude, NULL, &error)); + g_assert_no_error(error); + g_assert_false(g_file_test(lorem_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(ipsum_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(dolor_file, G_FILE_TEST_IS_REGULAR)); + g_assert_cmpint(g_remove(dolor_file), ==, 0); + + /* Extract only two */ + g_assert_true(pu_archive_extract("data/lorem.tar", dest, NULL, only, &error)); g_assert_no_error(error); - g_assert_true(g_file_test(out_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(lorem_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(ipsum_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(dolor_file, G_FILE_TEST_IS_REGULAR)); + g_assert_cmpint(g_remove(ipsum_file), ==, 0); + g_assert_cmpint(g_remove(dolor_file), ==, 0); + + /* Extract only two excluding two */ + g_assert_true(pu_archive_extract("data/lorem.tar", dest, exclude, only, &error)); + g_assert_no_error(error); + g_assert_false(g_file_test(lorem_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(ipsum_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(dolor_file, G_FILE_TEST_IS_REGULAR)); + g_assert_cmpint(g_remove(dolor_file), ==, 0); + + /* Extract all excluding "ba*" */ + g_assert_true(pu_archive_extract("data/foobar.tar", dest, list_ba, NULL, &error)); + g_assert_no_error(error); + g_assert_true(g_file_test(foo_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(bar_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(bar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(baz_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(baz_file, G_FILE_TEST_IS_REGULAR)); + g_assert_cmpint(g_remove(foo_file), ==, 0); + g_assert_cmpint(g_rmdir(foo_dir), ==, 0); + + /* Extract only "ba*" (includes wildcards) */ + g_assert_true(pu_archive_extract("data/foobar.tar", dest, NULL, list_ba, &error)); + g_assert_no_error(error); + g_assert_false(g_file_test(foo_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(bar_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(bar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(baz_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(baz_file, G_FILE_TEST_IS_REGULAR)); + g_assert_cmpint(g_remove(bar_file), ==, 0); + g_assert_cmpint(g_rmdir(bar_dir), ==, 0); + g_assert_cmpint(g_remove(baz_file), ==, 0); + g_assert_cmpint(g_rmdir(baz_dir), ==, 0); + + /* Member not found in archive */ + g_assert_false(pu_archive_extract("data/foobar.tar", dest, NULL, list_notfound, &error)); + g_assert_error(error, G_SPAWN_EXIT_ERROR, 2); - g_assert_cmpint(g_remove(out_file), ==, 0); g_assert_cmpint(g_rmdir(dest), ==, 0); } @@ -205,6 +294,217 @@ test_is_ext234_image(void) g_assert_false(pu_is_ext234_image("data/lorem.txt")); } +static void +test_remove_exclude_only(void) +{ + g_autoptr(GError) error = NULL; + g_autoptr(GFile) dest_file = NULL; + g_autoptr(GList) exclude = NULL; + g_autoptr(GList) only = NULL; + g_autofree gchar *dest = NULL; + g_autofree gchar *all_dir = NULL; + g_autofree gchar *empty_dir = NULL; + g_autofree gchar *nested_dir = NULL; + g_autofree gchar *nested_file = NULL; + g_autofree gchar *foo_file = NULL; + g_autofree gchar *foobar_file = NULL; + g_autofree gchar *foobarbuz1_file = NULL; + g_autofree gchar *foobarbuz2_file = NULL; + g_autofree gchar *yaml_file = NULL; + + dest = g_dir_make_tmp("partup-XXXXXX", &error); + g_assert_no_error(error); + + all_dir = g_build_filename(dest, "*", NULL); + empty_dir = g_build_filename(dest, "empty", NULL); + nested_dir = g_build_filename(dest, "nested", "one", "two", "three", NULL); + nested_file = g_build_filename(dest, "nested", "one", "two", "three", "four.txt", NULL); + foo_file = g_build_filename(dest, "foo", "test.c", NULL); + foobar_file = g_build_filename(dest, "foo", "bar", "settings.cfg", NULL); + foobarbuz1_file = g_build_filename(dest, "foo", "bar", "buz", "buzzer.yaml", NULL); + foobarbuz2_file = g_build_filename(dest, "foo", "bar", "buz", "dozzer.yaml", NULL); + yaml_file = g_build_filename(dest, "foo", "bar", "buz", "*.yaml", NULL); + + /* NULL checks */ + g_assert_true(pu_archive_extract("data/dir-struct.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + + g_assert_true(pu_path_remove_exclude_only(dest, NULL, NULL, &error)); + g_assert_true(g_file_test(empty_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(nested_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(nested_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobarbuz1_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobarbuz2_file, G_FILE_TEST_IS_REGULAR)); + + /* Exclude all */ + g_assert_true(pu_archive_extract("data/dir-struct.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + + g_list_free(exclude); + exclude = NULL; + exclude = g_list_prepend(exclude, all_dir); + g_list_free(only); + only = NULL; + g_assert_true(pu_path_remove_exclude_only(dest, exclude, only, &error)); + g_assert_false(g_file_test(empty_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(nested_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(nested_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobarbuz1_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobarbuz2_file, G_FILE_TEST_IS_REGULAR)); + + /* Preserve all */ + g_assert_true(pu_archive_extract("data/dir-struct.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + + g_list_free(exclude); + exclude = NULL; + g_list_free(only); + only = NULL; + only = g_list_prepend(only, all_dir); + g_assert_true(pu_path_remove_exclude_only(dest, exclude, only, &error)); + g_assert_true(g_file_test(empty_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(nested_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(nested_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobarbuz1_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobarbuz2_file, G_FILE_TEST_IS_REGULAR)); + + /* Preserve only nested file */ + g_assert_true(pu_archive_extract("data/dir-struct.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + + g_list_free(exclude); + exclude = NULL; + g_list_free(only); + only = NULL; + only = g_list_prepend(only, foo_file); + only = g_list_prepend(only, foobarbuz1_file); + g_assert_true(pu_path_remove_exclude_only(dest, exclude, only, &error)); + g_assert_false(g_file_test(empty_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(nested_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(nested_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobarbuz1_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobarbuz2_file, G_FILE_TEST_IS_REGULAR)); + + /* Preserve only *.yaml file */ + g_assert_true(pu_archive_extract("data/dir-struct.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + + g_list_free(exclude); + exclude = NULL; + g_list_free(only); + only = NULL; + only = g_list_prepend(only, yaml_file); + g_assert_true(pu_path_remove_exclude_only(dest, exclude, only, &error)); + g_assert_false(g_file_test(empty_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(nested_dir, G_FILE_TEST_IS_DIR)); + g_assert_false(g_file_test(nested_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobarbuz1_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobarbuz2_file, G_FILE_TEST_IS_REGULAR)); + + /* Exclude *.yaml file */ + g_assert_true(pu_archive_extract("data/dir-struct.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + + g_list_free(exclude); + exclude = NULL; + exclude = g_list_prepend(exclude, yaml_file); + g_list_free(only); + only = NULL; + g_assert_true(pu_path_remove_exclude_only(dest, exclude, only, &error)); + g_assert_true(g_file_test(empty_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(nested_dir, G_FILE_TEST_IS_DIR)); + g_assert_true(g_file_test(nested_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foo_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobarbuz1_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(foobarbuz2_file, G_FILE_TEST_IS_REGULAR)); + + /* Clean up */ + dest_file = g_file_new_for_path(dest); + g_assert_true(pu_file_remove_recursive(dest_file, NULL, &error)); +} + +static void +test_remove_exclude_only_relative(void) +{ + g_autoptr(GError) error = NULL; + g_autoptr(GFile) dest_file = NULL; + g_autoptr(GList) exclude = NULL; + g_autoptr(GList) only = NULL; + g_autofree gchar *dest = NULL; + g_autofree gchar *empty_dir = NULL; + g_autofree gchar *nested_file = NULL; + g_autofree gchar *foo_file = NULL; + g_autofree gchar *foobar_file = NULL; + g_autofree gchar *sibling_dir = NULL; + g_autofree gchar *sibling_file = NULL; + + dest = g_dir_make_tmp("partup-XXXXXX", &error); + g_assert_no_error(error); + dest_file = g_file_new_for_path(dest); + + empty_dir = g_build_filename(dest, "empty", NULL); + nested_file = g_build_filename(dest, "nested", "one", "two", "three", "four.txt", NULL); + foo_file = g_build_filename(dest, "foo", "test.c", NULL); + foobar_file = g_build_filename(dest, "foo", "bar", "settings.cfg", NULL); + sibling_dir = g_build_filename(dest, "foo2", NULL); + sibling_file = g_build_filename(dest, "foo2", "sibling.txt", NULL); + + g_assert_true(pu_archive_extract("data/dir-struct.tar", dest, NULL, NULL, &error)); + g_assert_no_error(error); + g_assert_cmpint(g_mkdir(sibling_dir, 0755), ==, 0); + g_assert_true(g_file_set_contents(sibling_file, "x", -1, &error)); + g_assert_no_error(error); + + /* Relative exclude, relative to the given root and not to the cwd */ + exclude = g_list_prepend(exclude, "empty"); + exclude = g_list_prepend(exclude, "foo/*.c"); + g_assert_true(pu_path_remove_exclude_only(dest, exclude, NULL, &error)); + g_assert_no_error(error); + g_assert_false(g_file_test(empty_dir, G_FILE_TEST_EXISTS)); + g_assert_false(g_file_test(foo_file, G_FILE_TEST_EXISTS)); + g_assert_true(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(nested_file, G_FILE_TEST_IS_REGULAR)); + g_assert_true(g_file_test(sibling_file, G_FILE_TEST_IS_REGULAR)); + + /* Relative only: "foo" must not retain the sibling "foo2" */ + only = g_list_prepend(only, "foo"); + g_assert_true(pu_path_remove_exclude_only(dest, NULL, only, &error)); + g_assert_no_error(error); + g_assert_true(g_file_test(foobar_file, G_FILE_TEST_IS_REGULAR)); + g_assert_false(g_file_test(nested_file, G_FILE_TEST_EXISTS)); + g_assert_false(g_file_test(sibling_dir, G_FILE_TEST_EXISTS)); + + /* Exclude takes precedence over only */ + g_list_free(exclude); + exclude = NULL; + exclude = g_list_prepend(exclude, "foo/bar"); + g_assert_true(pu_path_remove_exclude_only(dest, exclude, only, &error)); + g_assert_no_error(error); + g_assert_false(g_file_test(foobar_file, G_FILE_TEST_EXISTS)); + + /* Paths outside of the root are rejected */ + g_list_free(exclude); + exclude = NULL; + exclude = g_list_prepend(exclude, "../*"); + g_assert_false(pu_path_remove_exclude_only(dest, exclude, NULL, &error)); + g_assert_nonnull(error); + g_clear_error(&error); + + g_assert_true(pu_file_remove_recursive(dest_file, NULL, &error)); + g_assert_no_error(error); +} + int main(int argc, char *argv[]) @@ -235,6 +535,8 @@ main(int argc, g_test_add_func("/utils/str_pre_remove", test_str_pre_remove); g_test_add_func("/utils/device_get_partition_pattern", test_device_get_partition_pattern); g_test_add_func("/utils/is_ext234_image", test_is_ext234_image); + g_test_add_func("/utils/remove_exclude_only", test_remove_exclude_only); + g_test_add_func("/utils/remove_exclude_only_relative", test_remove_exclude_only_relative); return g_test_run(); } From 157f07d64dc089463f671be9ec5e4ba57877900e Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Tue, 6 Oct 2026 15:56:25 +0200 Subject: [PATCH 4/9] tests: emmc: Add tests for parsing exclude and only Add tests for parsing a layout config with the input options exclude and only, and for a config with an invalid exclude entry. Signed-off-by: Martin Schwan --- tests/config/exclude-invalid.yaml | 12 ++++++++++ tests/config/exclude-only.yaml | 16 +++++++++++++ tests/emmc.c | 40 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 tests/config/exclude-invalid.yaml create mode 100644 tests/config/exclude-only.yaml diff --git a/tests/config/exclude-invalid.yaml b/tests/config/exclude-invalid.yaml new file mode 100644 index 00000000..59f7db5e --- /dev/null +++ b/tests/config/exclude-invalid.yaml @@ -0,0 +1,12 @@ +api-version: 5 +disklabel: gpt + +partitions: + - label: root + filesystem: ext4 + size: 64MiB + offset: 1MiB + input: + - filename: dir-struct.tar + exclude: + - - nested diff --git a/tests/config/exclude-only.yaml b/tests/config/exclude-only.yaml new file mode 100644 index 00000000..c0bf6150 --- /dev/null +++ b/tests/config/exclude-only.yaml @@ -0,0 +1,16 @@ +api-version: 5 +disklabel: gpt + +partitions: + - label: root + filesystem: ext4 + size: 64MiB + offset: 1MiB + input: + - filename: dir-struct.tar + exclude: + - empty + - foo/*.c + only: + - foo + - nested diff --git a/tests/emmc.c b/tests/emmc.c index c52a6264..5e9d9e9a 100644 --- a/tests/emmc.c +++ b/tests/emmc.c @@ -118,6 +118,42 @@ test_raw_overwrite_fail_raw(EmptyFileFixture *fixture, g_clear_error(&fixture->error); } +static void +test_exclude_only_pass(EmptyFileFixture *fixture, + G_GNUC_UNUSED gconstpointer user_data) +{ + g_autoptr(PuConfig) config = NULL; + g_autoptr(PuEmmc) emmc = NULL; + + config = pu_config_new_from_file("config/exclude-only.yaml", &fixture->error); + g_assert_no_error(fixture->error); + g_assert_nonnull(config); + + emmc = pu_emmc_new(g_file_get_path(fixture->file), config, "data", FALSE, + &fixture->error); + g_assert_no_error(fixture->error); + g_assert_nonnull(emmc); +} + +static void +test_exclude_invalid(EmptyFileFixture *fixture, + G_GNUC_UNUSED gconstpointer user_data) +{ + g_autoptr(PuConfig) config = NULL; + g_autoptr(PuEmmc) emmc = NULL; + + config = pu_config_new_from_file("config/exclude-invalid.yaml", &fixture->error); + g_assert_no_error(fixture->error); + g_assert_nonnull(config); + + emmc = pu_emmc_new(g_file_get_path(fixture->file), config, "data", FALSE, + &fixture->error); + g_assert_error(fixture->error, PU_ERROR, PU_ERROR_EMMC_PARSE); + g_assert_null(emmc); + + g_clear_error(&fixture->error); +} + int main(int argc, char *argv[]) @@ -137,6 +173,10 @@ main(int argc, g_test_add("/emmc/raw_overwrite_fail_partition", EmptyFileFixture, "mmcblk0", empty_file_set_up, test_raw_overwrite_fail_partition, empty_file_tear_down); + g_test_add("/emmc/exclude_only_pass", EmptyFileFixture, "mmcblk0", + empty_file_set_up, test_exclude_only_pass, empty_file_tear_down); + g_test_add("/emmc/exclude_invalid", EmptyFileFixture, "mmcblk0", + empty_file_set_up, test_exclude_invalid, empty_file_tear_down); g_test_add("/emmc/raw_overwrite_fail_raw", EmptyFileFixture, "mmcblk0", empty_file_set_up, test_raw_overwrite_fail_raw, empty_file_tear_down); From ecda934f5f1af0f847fb3338c85fde04e154dab1 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Tue, 6 Oct 2026 15:56:25 +0200 Subject: [PATCH 5/9] doc: layout-config-reference: Document exclude and only Describe the input options exclude and only, how their paths are interpreted for tar archives and for other inputs, and add an example. Signed-off-by: Martin Schwan --- doc/layout-config-reference.rst | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/doc/layout-config-reference.rst b/doc/layout-config-reference.rst index 053737c2..3c479913 100644 --- a/doc/layout-config-reference.rst +++ b/doc/layout-config-reference.rst @@ -339,6 +339,58 @@ into a filesystem, or raw ext[234] filesystem images. See ``--skip-checksums`` is given as a runtime argument. See :ref:`checksum-verification` for details. +``exclude`` (sequence) + Paths to exclude for this input. Paths to be excluded should be provided as a + sequence of strings. This requires a partition with a valid filesystem. + + Relative paths are interpreted relative to the root of the partition and + may contain wildcards (e.g. ``foo/*.c``). Paths that do not match anything + are ignored. + + If the input is a ``.tar`` archive, the specified paths are excluded from + extraction using tar's ``--exclude`` option: + https://manpages.debian.org/unstable/tar/tar.1.en.html#exclude + + For other input file types, the specified paths are deleted on the partition + after writing the input files. + + ``exclude`` takes precedence over ``only``. + + Available since: :ref:`release-5.0.0` + +``only`` (sequence) + A list of paths to only extract/keep on the corresponding partition. This + requires a partition with a valid filesystem. + + If the input is a ``.tar`` archive, only the specified members are extracted + (names are matched as given to tar, wildcards are supported): + https://manpages.debian.org/unstable/tar/tar.1.en.html + + For other input file types, any other paths are deleted on the partition + after writing the input files, except the ones specified. Relative paths are + interpreted relative to the root of the partition and may contain wildcards. + + Available since: :ref:`release-5.0.0` + +Example: + +.. code-block:: yaml + + api-version: 5 + partitions: + - label: root + filesystem: ext4 + expand: true + input: + - filename: rootfs.tar + exclude: + - var/cache + - usr/share/doc + only: + - etc + - usr + - var + .. _supported-file-types: Supported File Types From 9bb10a34bc4ce0f3689ee3f884e1a98522d66e65 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Tue, 6 Oct 2026 15:56:25 +0200 Subject: [PATCH 6/9] CHANGELOG: Add input options exclude and only Signed-off-by: Martin Schwan --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5c97a8f6..df8d5ce3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,10 @@ - Add a FAQ section to the documentation explaining the ``Filesystem has unsupported feature(s)`` error of ``resize2fs``, caused by the ext4 ``orphan_file`` feature and old e2fsprogs versions. +- Add the input options ``exclude`` and ``only``, which allow excluding paths + from, or restricting an input to, specific paths. For ``.tar`` archives they + are passed to tar during extraction, for other inputs the paths are removed + from the partition after writing. See :ref:`input-files`. .. _release-4.0.0: From a00c82aa38f7cb548c1e6d0928c88dc2a0e8b95c Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Tue, 6 Oct 2026 15:56:25 +0200 Subject: [PATCH 7/9] github: workflows: system-tests: Test exclude and only Add a layout using the input options exclude and only to the system tests and add the directory structure archive to the test packages. Signed-off-by: Martin Schwan --- .github/workflows/system-tests.yml | 2 +- tests/config/system-tests/exclude-only.yaml | 37 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/config/system-tests/exclude-only.yaml diff --git a/.github/workflows/system-tests.yml b/.github/workflows/system-tests.yml index 4525f902..61dc956c 100644 --- a/.github/workflows/system-tests.yml +++ b/.github/workflows/system-tests.yml @@ -36,7 +36,7 @@ jobs: echo "Create package" cp $f tests/data/layout.yaml G_DEBUG=fatal-warnings partup -d -C tests/data package pkg.partup \ - layout.yaml random.bin lorem.txt lorem.tar root.ext4 + layout.yaml random.bin lorem.txt lorem.tar dir-struct.tar root.ext4 echo "Show package content" sudo G_DEBUG=fatal-warnings partup -s show pkg.partup echo "Install package to loop device" diff --git a/tests/config/system-tests/exclude-only.yaml b/tests/config/system-tests/exclude-only.yaml new file mode 100644 index 00000000..6a395c69 --- /dev/null +++ b/tests/config/system-tests/exclude-only.yaml @@ -0,0 +1,37 @@ +api-version: 5 +disklabel: gpt + +partitions: + - label: boot + filesystem: fat32 + size: 16MiB + offset: 1MiB + flags: + - boot + input: + - filename: lorem.txt + - label: root1 + filesystem: ext4 + expand: true + input: + - filename: dir-struct.tar + exclude: + - empty + - label: root2 + filesystem: ext4 + expand: true + input: + - filename: dir-struct.tar + only: + - foo + - label: root3 + filesystem: ext4 + expand: true + input: + - filename: dir-struct.tar + exclude: + - empty + - foo/test.c + only: + - foo + - nested From e1194e0c379d9d33d04c554a8e912c6c308fa035 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Fri, 13 Nov 2026 09:39:36 +0100 Subject: [PATCH 8/9] github: workflows: system-tests: Allow running verification script Allow running a verification script, which has the same basename as it corresponding YAML layout config file. This is meant for checking the desired output. Signed-off-by: Martin Schwan --- .github/workflows/system-tests.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/system-tests.yml b/.github/workflows/system-tests.yml index 61dc956c..6f8acdb8 100644 --- a/.github/workflows/system-tests.yml +++ b/.github/workflows/system-tests.yml @@ -30,7 +30,7 @@ jobs: - name: Run system tests with loop device timeout-minutes: 2 run: | - for f in tests/config/system-tests/* + for f in tests/config/system-tests/*.yaml do echo "Testing with $f" echo "Create package" @@ -46,6 +46,11 @@ jobs: echo "Show loop device info" sudo fdisk -l ${{ env.loop_dev }} sudo blkid ${{ env.loop_dev }} + verify_script=${f%.*}.sh + if [ -f $verify_script ]; then + echo "Running verification script" + ./$verify_script ${{ env.loop_dev }} + fi git clean -xdf -e loop-file done - name: Remove loopdev From 18db714238ccd32122d4c0bcffa899d21104e362 Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Fri, 13 Nov 2026 09:41:44 +0100 Subject: [PATCH 9/9] system-tests: Add verification script for exclude-only layout Add a verification script for the "exclude-only.yaml" layout configuration, which checks the resulting partitions for the desired files and directories. Signed-off-by: Martin Schwan --- tests/config/system-tests/exclude-only.sh | 76 +++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 tests/config/system-tests/exclude-only.sh diff --git a/tests/config/system-tests/exclude-only.sh b/tests/config/system-tests/exclude-only.sh new file mode 100755 index 00000000..197534f9 --- /dev/null +++ b/tests/config/system-tests/exclude-only.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +DEVICE=$1 + +verify_partition() { + part=$1 + expected=$2 + excluded=$3 + [ -n "$part" ] || { echo "usage: verify_partition DEV [EXPECTED [EXCLUDED]]" >&2; return 2; } + + mnt=$(mktemp -d) || return 2 + if ! sudo mount -o ro "$part" "$mnt"; then + rmdir "$mnt" + return 2 + fi + + echo "Content of $part:" + (cd "$mnt"; find \( -name lost+found \) -prune -o -print) + + rc=0 + nl=' +' + old_ifs=$IFS + set -f # no globbing while splitting + IFS=$nl + + for p in $expected; do + rel=${p#"${p%%[!/]*}"} # strip leading slashes + if [ -e "$mnt/$rel" ]; then + echo "OK $p" + else + echo "MISSING $p" + rc=1 + fi + done + + for p in $excluded; do + rel=${p#"${p%%[!/]*}"} + if [ -e "$mnt/$rel" ]; then + echo "UNWANTED $p" + rc=1 + else + echo "OK $p (absent)" + fi + done + + IFS=$old_ifs + set +f + sudo umount "$mnt" + rmdir "$mnt" + return $rc +} + +verify_partition ${DEVICE}p2 \ +"foo/bar/buz/dozzer.yaml +foo/bar/buz/buzzer.yaml +foo/bar/settings.cfg +foo/test.c +nested/one/two/three/four.txt" \ +"empty/" || exit $? + +verify_partition ${DEVICE}p3 \ +"foo/bar/buz/dozzer.yaml +foo/bar/buz/buzzer.yaml +foo/bar/settings.cfg +foo/test.c" \ +"empty/ +nested/" || exit $? + +verify_partition ${DEVICE}p4 \ +"foo/bar/buz/dozzer.yaml +foo/bar/buz/buzzer.yaml +foo/bar/settings.cfg +nested/one/two/three/four.txt" \ +"empty/ +foo/test.c" || exit $?