From a95095830a04cc83ce3a8f26f1d31ff1f04e6cb7 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Tue, 26 Nov 2024 13:02:57 +0100 Subject: [PATCH] add `?` separator for unknown file types --- conda_build/utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/conda_build/utils.py b/conda_build/utils.py index 98f66ca7f9..470c6985e3 100644 --- a/conda_build/utils.py +++ b/conda_build/utils.py @@ -1998,12 +1998,16 @@ def compute_content_hash( - UTF-8 encoded path, relative to the input directory. Backslashes are normalized to forward slashes before encoding. - Then, depending on the type: - - For regular files, the UTF-8 bytes of an `F` separator, followed by the bytes of its - contents. + - For regular files, the UTF-8 bytes of an `F` separator, followed by: + - UTF-8 bytes of the line-ending normalized text (`\r\n` to `\n`), if the file is text. + - The raw bytes of the file contents, if binary. + - Note: If the file can't be opened or read, no contents are hashed; + it's treated as empty. - For a directory, the UTF-8 bytes of a `D` separator, and nothing else. - For a symlink, the UTF-8 bytes of an `L` separator, followed by the UTF-8 encoded bytes for the path it points to. Backslashes MUST be normalized to forward slashes before encoding. + - For any other types, the UTF-8 bytes of a `?` separator, and nothing else. - UTF-8 encoded bytes of the string `-`, as separator. Parameters @@ -2012,7 +2016,7 @@ def compute_content_hash( algorithm: Name of the algorithm to be used, as expected by `hashlib.new()` skip: iterable of paths that should not be checked. If a path ends with a slash, it's interpreted as a directory that won't be traversed. It matches the relative paths - already slashed-normalized. + already slashed-normalized (i.e. backwards slashes replaced with forward slashes). Returns ------- @@ -2067,9 +2071,10 @@ def compute_content_hash( for chunk in iter(partial(fh.read, 8192), b""): hasher.update(chunk) except OSError as exc: - log.debug("Skipping %s for hashing", path.name, exc_info=exc) + log.warning("Can't open file %s. Hashing path only...", path.name, exc_info=exc) else: - log.debug("Can't detect type for path %s. Skipping...", path) + log.warning("Can't detect type for path %s. Hashing path only...", path) + hasher.update(b"?") hasher.update(b"-") return hasher.hexdigest()