diff cutils/util/walk.py @ 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 b256ae4f4bc8
line wrap: on
line diff
--- 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