# HG changeset patch # User Franz Glasner # Date 1737065884 -3600 # Node ID c1e875ba4bdc79acfe73bfca11bd0aac72769d08 # Parent 48e2610978e5dee3f48c052d9cc3f4a8ae0a9b16 Put the effective filesystem encoding into the treesum digest file using FSENCODING = diff -r 48e2610978e5 -r c1e875ba4bdc cutils/treesum.py --- a/cutils/treesum.py Thu Jan 16 20:40:24 2025 +0100 +++ b/cutils/treesum.py Thu Jan 16 23:18:04 2025 +0100 @@ -352,6 +352,8 @@ self._outfp = outfp self._outfp.resetdigest() self._outfp.write(format_bsd_line("VERSION", "1", None, False)) + self._outfp.write(format_bsd_line( + "FSENCODING", util.n(walk.getfsencoding()), None, False)) self._outfp.flush() # @@ -628,7 +630,8 @@ if what == b"TIMESTAMP": assert filename is None return util.interpolate_bytes(b"TIMESTAMP = %d%s", value, ls) - if what in (b"ISOTIMESTAMP", b"FLAGS", b"VERSION", b"CRC32"): + if what in (b"FSENCODING", b"ISOTIMESTAMP", b"FLAGS", b"VERSION", + b"CRC32"): assert filename is None return util.interpolate_bytes(b"%s = %s%s", what, util.b(value), ls) assert filename is not None @@ -664,7 +667,7 @@ """ PATTERN0 = re.compile(br"\A[ \t]*\r?\n\Z") # empty lines - PATTERN1 = re.compile(br"\A(VERSION|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z") # noqa: E501 line too long + PATTERN1 = re.compile(br"\A(VERSION|FSENCODING|FLAGS|TIMESTAMP|ISOTIMESTAMP|CRC32)[ \t]*=[ \t]*([^ \t]+)[ \t]*\r?\n\Z") # noqa: E501 line too long PATTERN2 = re.compile(br"\A(ROOT|COMMENT)[ \t]*\((.*)\)[ \t]*\r?\n\Z") PATTERN3 = re.compile(br"\ASIZE[ \t]*\((.*)\)[ \t]*=[ \t]*(\d+)[ \t]*\r?\n\Z") # noqa: E501 line too long PATTERN4 = re.compile(br"\A([A-Za-z0-9_-]+)[ \t]*\((.*)\)[ \t]*=[ \t]*([A-Za-z0-9=+/]+)(,(\d+))?[ \t]*\r?\n\Z") # noqa: E501 line too long @@ -880,7 +883,7 @@ root = record[1] elif record[0] == "COMMENT": comments.append(record[1]) - elif record[0] in ("TIMESTAMP", "ISOTIMESTAMP"): + elif record[0] in ("FSENCODING", "TIMESTAMP", "ISOTIMESTAMP"): pass elif record[0] == "CRC32": pass diff -r 48e2610978e5 -r c1e875ba4bdc cutils/util/walk.py --- a/cutils/util/walk.py Thu Jan 16 20:40:24 2025 +0100 +++ b/cutils/util/walk.py Thu Jan 16 23:18:04 2025 +0100 @@ -10,7 +10,7 @@ from __future__ import print_function, absolute_import -__all__ = ["ScanDir"] +__all__ = ["ScanDir", "getfsencoding"] import os @@ -21,10 +21,14 @@ from scandir import scandir except ImportError: scandir = None +import sys from . import PY2 +_FSENCODING = sys.getfilesystemencoding() + + class WalkDirEntry(object): """A :class:`os.DirEntry` alike to be used in :func:`walk` and for @@ -41,6 +45,7 @@ assert isinstance(name, bytes) self._fsname = name else: + self._name = name self._fsname = os.fsencode(name) self._path = None self._fspath = None @@ -209,3 +214,8 @@ def __exit__(self, *args, **kwds): pass + + +def getfsencoding(): + """Return the stored _FSENCODING of this module""" + return _FSENCODING diff -r 48e2610978e5 -r c1e875ba4bdc docs/notes.rst --- a/docs/notes.rst Thu Jan 16 20:40:24 2025 +0100 +++ b/docs/notes.rst Thu Jan 16 23:18:04 2025 +0100 @@ -21,3 +21,11 @@ ``/./@` Symlink to other filesystem object + + +Fields: + + ``FSENCODING`` + + The result of :func:`os.getfilesystemencoding` that is in effect when + generating treesum digests