From f87447a12083788e4f4a107e1be3711adc45e57b Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 16 Feb 2021 18:36:15 +0100 Subject: [PATCH] treesum: handle special device files When a special file, i.e. character or block device node, is encountered, add its device id to the hash. --- osbuild/treesum.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osbuild/treesum.py b/osbuild/treesum.py index 7ef7aa11..b17c5817 100644 --- a/osbuild/treesum.py +++ b/osbuild/treesum.py @@ -1,7 +1,10 @@ import errno import json import os +import stat + +#pylint: disable=too-many-branches def treesum(m, dir_fd): """Compute a content hash of a filesystem tree @@ -52,7 +55,9 @@ def treesum(m, dir_fd): # hash a page at a time (using f with fd as default is a hack to please pylint) for byte_block in iter(lambda f=fd: os.read(f, 4096), b""): m.update(byte_block) + elif stat.S_ISCHR(stat_result.st_mode) or stat.S_ISBLK(stat_result.st_mode): + m.update(json.dumps({"dev": stat_result.st_rdev}).encode()) else: - raise ValueError("Found unexpected filetype on OS image") + raise ValueError("Found unexpected filetype on OS image.") finally: os.close(fd)