]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: Add --mtree-hash= option 28274/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 6 Jul 2023 09:24:22 +0000 (11:24 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 6 Jul 2023 10:11:45 +0000 (12:11 +0200)
Let's make including hashes in the mtree output configurable to allow
speeding up the --mtree command in cases where file hashes are not
required.

man/systemd-dissect.xml
src/dissect/dissect.c
test/units/testsuite-50.sh

index ce41faaf1a2338b465aa9e5a1302d3c2b8fcc357..2b8620a5f0e9f2ade9d859da5f9afc2f6a36ce89 100644 (file)
         <command>cfdisk /dev/loop/by-ref/quux</command>.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--mtree-hash=no</option></term>
+
+        <listitem><para>If combined with <option>--mtree</option>, turns off inclusion of file hashes in the
+        mtree output. This makes the <option>--mtree</option> faster when operating on large images.
+        </para></listitem>
+      </varlistentry>
+
       <xi:include href="standard-options.xml" xpointer="image-policy-open" />
       <xi:include href="standard-options.xml" xpointer="no-pager" />
       <xi:include href="standard-options.xml" xpointer="no-legend" />
index 9db8f862e8e57c05f0167352dffaff4145f86d4e..24e17bcad9ef425bd25eb4704eb57009ab657a9a 100644 (file)
@@ -86,6 +86,7 @@ static bool arg_in_memory = false;
 static char **arg_argv = NULL;
 static char *arg_loop_ref = NULL;
 static ImagePolicy* arg_image_policy = NULL;
+static bool arg_mtree_hash = true;
 
 STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
@@ -137,6 +138,7 @@ static int help(void) {
                "     --json=pretty|short|off\n"
                "                          Generate JSON output\n"
                "     --loop-ref=NAME      Set reference string for loopback device\n"
+               "     --mtree-hash=BOOL    Whether to include SHA256 hash in the mtree output\n"
                "\n%3$sCommands:%4$s\n"
                "  -h --help               Show this help\n"
                "     --version            Show package version\n"
@@ -257,6 +259,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_LOOP_REF,
                 ARG_IMAGE_POLICY,
                 ARG_VALIDATE,
+                ARG_MTREE_HASH,
         };
 
         static const struct option options[] = {
@@ -288,6 +291,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "loop-ref",      required_argument, NULL, ARG_LOOP_REF      },
                 { "image-policy",  required_argument, NULL, ARG_IMAGE_POLICY  },
                 { "validate",      no_argument,       NULL, ARG_VALIDATE      },
+                { "mtree-hash",    required_argument, NULL, ARG_MTREE_HASH    },
                 {}
         };
 
@@ -505,6 +509,12 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_action = ACTION_VALIDATE;
                         break;
 
+                case ARG_MTREE_HASH:
+                        r = parse_boolean_argument("--mtree-hash=", optarg, &arg_mtree_hash);
+                        if (r < 0)
+                                return r;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -1202,7 +1212,7 @@ static int mtree_print_item(
                        ansi_normal(),
                        (uint64_t) sx->stx_size);
 
-                if (inode_fd >= 0 && sx->stx_size > 0) {
+                if (arg_mtree_hash && inode_fd >= 0 && sx->stx_size > 0) {
                         uint8_t hash[SHA256_DIGEST_SIZE];
 
                         r = get_file_sha256(inode_fd, hash);
index ab2c2959c05ce9a44b606655873073a588d6d6aa..52d11b9cb98f2aa89c192092a4b139ea497ccb58 100755 (executable)
@@ -43,7 +43,8 @@ systemd-dissect "${image}.raw" | grep -q -F "MARKER=1"
 systemd-dissect "${image}.raw" | grep -q -F -f <(sed 's/"//g' "$os_release")
 
 systemd-dissect --list "${image}.raw" | grep -q '^etc/os-release$'
-systemd-dissect --mtree "${image}.raw" | grep -q "./usr/bin/cat type=file mode=0755 uid=0 gid=0"
+systemd-dissect --mtree "${image}.raw" --mtree-hash yes | grep -qe "^./usr/bin/cat type=file mode=0755 uid=0 gid=0 size=[0-9]* sha256sum=[a-z0-9]*$"
+systemd-dissect --mtree "${image}.raw" --mtree-hash no  | grep -qe "^./usr/bin/cat type=file mode=0755 uid=0 gid=0 size=[0-9]*$"
 
 read -r SHA256SUM1 _ < <(systemd-dissect --copy-from "${image}.raw" etc/os-release | sha256sum)
 test "$SHA256SUM1" != ""