# HG changeset patch # User Franz Glasner # Date 1740155279 -3600 # Node ID 822cf3a1da2267c2faefa8854950324bffafbf68 # Parent 9676ecd32a07deabcbd5220193e501b2958fa86e treesum: FIX: Removal of backslashes in output: do this only where really needed. Otherwise "backslashreplace" error encodings are "corrected" too. diff -r 9676ecd32a07 -r 822cf3a1da22 cutils/treesum.py --- a/cutils/treesum.py Fri Feb 21 16:51:03 2025 +0100 +++ b/cutils/treesum.py Fri Feb 21 17:27:59 2025 +0100 @@ -551,7 +551,8 @@ (walk.WalkDirEntry.alt_u8(self._minimal) if self._minimal else b"")) else: - self._writer.write_root(walk.WalkDirEntry.alt_u8(root)) + self._writer.write_root(walk.WalkDirEntry.alt_u8( + util.normalize_filename(root, True))) self._writer.flush() if not self._follow_symlinks.command_line and os.path.islink(root): @@ -1164,8 +1165,6 @@ digest = (base64.b64encode(digest) if use_base64 else binascii.hexlify(digest)) - if filename != b"./@/": - filename = util.normalize_filename(filename, True) self.write(util.b(algorithm)) self.write(b" (") self.write(filename) diff -r 9676ecd32a07 -r 822cf3a1da22 cutils/util/__init__.py --- a/cutils/util/__init__.py Fri Feb 21 16:51:03 2025 +0100 +++ b/cutils/util/__init__.py Fri Feb 21 17:27:59 2025 +0100 @@ -270,17 +270,23 @@ raise ValueError("unknown algorithm: {}".format(s)) -def normalize_filename(filename, strip_leading_dot_slash=False): +def normalize_filename(filename, strip_dot_slashes=False): if isinstance(filename, bytes): filename = filename.replace(b"\\", b"/") - if strip_leading_dot_slash: + if strip_dot_slashes: while filename.startswith(b"./"): filename = filename[2:] + # This also handles adjacent /./ cases + while b"/./" in filename: + filename = filename.replace(b"/./", b"/", 1) else: filename = filename.replace(u"\\", u"/") - if strip_leading_dot_slash: + if strip_dot_slashes: while filename.startswith(u"./"): filename = filename[2:] + # This also handles adjacent /./ cases + while u"/./" in filename: + filename = filename.replace(u"/./", u"/", 1) return filename