mirror of
https://github.com/systemd/systemd.git
synced 2025-03-08 08:58:27 +03:00
dissect: Add --mtree-hash= option
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.
This commit is contained in:
parent
2292fa1e31
commit
12d58b6c74
@ -422,6 +422,14 @@
|
||||
<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" />
|
||||
|
@ -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);
|
||||
|
@ -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" != ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user