Mercurial > hgrepos > Python > apps > py-cutils
changeset 344:0a58948df713
Move the computation of the special tag string marker for special files into a property
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 01 Apr 2025 12:45:56 +0200 |
| parents | b3931b511ed0 |
| children | 7117f06fefb0 |
| files | cutils/treesum.py cutils/util/walk.py |
| diffstat | 2 files changed, 26 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/cutils/treesum.py Tue Apr 01 12:15:05 2025 +0200 +++ b/cutils/treesum.py Tue Apr 01 12:45:56 2025 +0200 @@ -913,23 +913,7 @@ else: opath = walk.WalkDirEntry.alt_fs(opath) if fso.is_special: - # Determine the tag character - if fso.is_chr: - special_tag = b':' - elif fso.is_blk: - special_tag = b';' - elif fso.is_fifo: - special_tag = b'|' - elif fso.is_socket: - special_tag = b'=' - elif fso.is_door: - special_tag = b'>' - elif fso.is_whiteout: - special_tag = b'%' - elif fso.is_eventport: - special_tag = b'+' - else: - assert False, "unknown special filesystem object" + special_tag = util.b(fso.special_tag) assert fso.stat is not None # because .is_special is True if fso.is_symlink and not self._follow_symlinks.file: linktgt = walk.WalkDirEntry.from_readlink(
--- a/cutils/util/walk.py Tue Apr 01 12:15:05 2025 +0200 +++ b/cutils/util/walk.py Tue Apr 01 12:45:56 2025 +0200 @@ -13,6 +13,7 @@ __all__ = ["WalkDirEntry", "ScanDir", "getfsencoding"] +import logging import os try: from os import scandir @@ -29,6 +30,7 @@ _notset = object() +_logger = logging.getLogger(__name__) _FSENCODING = sys.getfilesystemencoding() @@ -345,6 +347,29 @@ return not (self.is_reg or self.is_dir) @property + def special_tag(self): + """Return a special tag (string) for a special file""" + assert self.is_special + if self.is_chr: + return ':' + elif self.is_blk: + return ';' + elif self.is_fifo: + return '|' + elif self.is_socket: + return '=' + elif self.is_door: + return '>' + elif self.is_whiteout: + return '%' + elif self.is_eventport: + return '+' + _logger.warning( + "unknown special file type: 0x%X", + stat.S_IFMT(self._stat_result.st_mode)) + return '?' + + @property def stat(self): return self._stat_result
