changeset 278:822cf3a1da22

treesum: FIX: Removal of backslashes in output: do this only where really needed. Otherwise "backslashreplace" error encodings are "corrected" too.
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 21 Feb 2025 17:27:59 +0100
parents 9676ecd32a07
children 44e62e36cad4
files cutils/treesum.py cutils/util/__init__.py
diffstat 2 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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