]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/xstat.py
Move Cygwin uid/gid fixup from index to xstat
[bup.git] / lib / bup / xstat.py
index 8daa2c2509e34246f917cadf08e94046aa4d02f1..7408414ce167bfed075cb02d0578ce3f6b5221c4 100644 (file)
@@ -81,6 +81,13 @@ else: # Must have these if utimensat isn't available.
         _bup_lutimes(path, (atime, mtime))
 
 
+def _fix_cygwin_id(id):
+    if id < 0:
+        id += 0x100000000
+        assert(id >= 0)
+    return id
+
+
 class stat_result:
     @staticmethod
     def from_xstat_rep(st):
@@ -99,6 +106,8 @@ class stat_result:
         result.st_atime = timespec_to_nsecs(result.st_atime)
         result.st_mtime = timespec_to_nsecs(result.st_mtime)
         result.st_ctime = timespec_to_nsecs(result.st_ctime)
+        result.st_uid = _fix_cygwin_id(result.st_uid)
+        result.st_gid = _fix_cygwin_id(result.st_gid)
         return result
 
 
@@ -116,6 +125,7 @@ def lstat(path):
 
 def mode_str(mode):
     result = ''
+    # FIXME: Other types?
     if pystat.S_ISREG(mode):
         result += '-'
     elif pystat.S_ISDIR(mode):
@@ -143,3 +153,23 @@ def mode_str(mode):
     result += 'w' if (mode & pystat.S_IWOTH) else '-'
     result += 'x' if (mode & pystat.S_IXOTH) else '-'
     return result
+
+
+def classification_str(mode, include_exec):
+    if pystat.S_ISREG(mode):
+        if include_exec \
+           and (pystat.S_IMODE(mode) \
+                & (pystat.S_IXUSR | pystat.S_IXGRP | pystat.S_IXOTH)):
+            return '*'
+        else:
+            return ''
+    elif pystat.S_ISDIR(mode):
+        return '/'
+    elif pystat.S_ISLNK(mode):
+        return '@'
+    elif pystat.S_ISFIFO(mode):
+        return '|'
+    elif pystat.S_ISSOCK(mode):
+        return '='
+    else:
+        return ''