Skip to content

Commit a659ccd

Browse files
authored
Use find -print0 and xargs -0 to fix file hashing (#279)
Example: ``` ++ find images/hook-embedded -type f -not -type l -print ++ LC_ALL=C ++ sort ++ xargs sha256sum ++ sha256sum ++ cut '-d ' -f1 sha256sum: images/hook-embedded/images/overlay2/4f2b976a728e2f978ec5a0728e7a7de5ac8e86d05424567038829628a23a0787/diff/nix/store/q94x70qac6cnly6w60mlgfkaa8npk9xw-systemd-257.5/example/systemd/system/system-systemdx2dcryptsetup.slice: No such file or directory ``` File enumeration should use a null-terminated approach that safely preserves file names regardless of any whitespace or special characters. `-print0` and `-0` Options: These ensure file names are treated as complete, atomic strings. `LC_ALL=C sort -z`: This guarantees a consistent, bytewise sort order while preserving the null termination. Fixes: #260
2 parents 0182cbc + a4ec7f5 commit a659ccd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bash/hook-lk-containers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function build_hook_linuxkit_container() {
2424
# Lets hash the contents of the directory and use that as a tag
2525
declare container_files_hash
2626
# NOTE: linuxkit containers must be in the images/ directory
27-
container_files_hash="$(find "${container_base_dir}/${container_dir}" -type f -print | LC_ALL=C sort | xargs sha256sum | sha256sum | cut -d' ' -f1)"
27+
container_files_hash="$(find "${container_base_dir}/${container_dir}" -type f -print0 | LC_ALL=C sort -z | xargs -0 sha256sum | sha256sum | cut -d' ' -f1)"
2828
declare container_files_hash_short="${container_files_hash:0:8}"
2929

3030
declare container_oci_ref="${HOOK_LK_CONTAINERS_OCI_BASE}${container_dir}:${container_files_hash_short}-${DOCKER_ARCH}"

0 commit comments

Comments
 (0)