diff --git a/tests/dumpdir b/tests/dumpdir new file mode 100755 index 00000000..52cf357d --- /dev/null +++ b/tests/dumpdir @@ -0,0 +1,47 @@ +#!/usr/bin/python3 + +import os +import sys +import shlex +import hashlib +import stat +import argparse + +def log_error(error): + print("Readdir error: " + error) + +def dumpfile(file, root): + rel = os.path.relpath(file, root) + s = os.lstat(file) + nlink = s.st_nlink; + if args.no_nlink: + nlink = 1 + print(f"{shlex.quote(rel)} {s.st_mode} {nlink} {s.st_uid}:{s.st_gid} {s.st_rdev} {s.st_mtime_ns}",end="") + if stat.S_ISREG(s.st_mode): + digest = hashlib.sha256(open(file,'rb').read()).hexdigest() + print(f" {s.st_size} sha256:{digest}",end="") + elif stat.S_ISLNK(s.st_mode): + link = os.readlink(file) + print(f" ->{shlex.quote(link)}",end="") + + for attr in sorted(os.listxattr(file, follow_symlinks=False)): + v = os.getxattr(file, attr, follow_symlinks=False) + print(f" {attr}={v}", end="") + + print() + + + +def dumpdir(root): + dumpfile(root, root) + for parent, dirs, files in os.walk(root, topdown=True, onerror=log_error): + for file in sorted(dirs + files): + dumpfile(os.path.join(parent, file), root) + +argParser = argparse.ArgumentParser() +argParser.add_argument("--no-nlink", action='store_true') +argParser.add_argument('path') + +args = argParser.parse_args() + +dumpdir(args.path) diff --git a/tests/integration.sh b/tests/integration.sh index 5a174f5c..074dd912 100755 --- a/tests/integration.sh +++ b/tests/integration.sh @@ -4,11 +4,7 @@ # the output of ls -lR (without hardlink counts). set -xeuo pipefail -# ls -l but without hardlinks -nonhardlink_ls() { - ls "$@" | sed -e 's,^\([^ ]*\) *\([0-9][0-9]*\)\(.*\)$,\1\3,' -} - +orig=$(pwd) cfsroot=${cfsroot:-/composefs} rm ${cfsroot}/tmp -rf mkdir -p ${cfsroot}/{objects,roots,tmp} @@ -22,13 +18,18 @@ test "$prev_digest" = "$new_digest" mkdir -p mnt mount.composefs -o basedir=${cfsroot}/objects ${cfsroot}/roots/test.cfs mnt -(cd ${testsrc} && nonhardlink_ls -lR .) > src-ls.txt -(cd mnt && nonhardlink_ls -lR .) > mnt-ls.txt +$orig/tests/dumpdir --no-nlink ${testsrc} > src-dump.txt +$orig/tests/dumpdir --no-nlink mnt > mnt-dump.txt failed= -if ! diff -u src-ls.txt mnt-ls.txt; then +if ! diff -u src-dump.txt mnt-dump.txt; then failed=1 fi -umount mnt if test -n "${failed}"; then + umount mnt exit 1 fi + +new_digest=$(mkcomposefs --by-digest --print-digest-only mnt) +test "$prev_digest" = "$new_digest" + +umount mnt