]> arthur.barton.de Git - bup.git/commitdiff
Add symbolic mode information to xstat output, i.e. (drwxr-xr-x).
authorRob Browning <rlb@defaultvalue.org>
Sun, 7 Aug 2011 16:26:28 +0000 (17:26 +0100)
committerRob Browning <rlb@defaultvalue.org>
Mon, 15 Oct 2012 02:42:14 +0000 (21:42 -0500)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Reviewed-by: Zoran Zaric <zz@zoranzaric.de>
cmd/xstat-cmd.py
lib/bup/xstat.py

index 83d264f016d37921f79a21d64b774f8b5498a15b..edd01f676e279080b73a2ccf5ab1ca8207c60b15 100755 (executable)
@@ -85,7 +85,8 @@ for path in remainder:
     if 'path' in active_fields:
         print 'path:', m.path
     if 'mode' in active_fields:
-        print 'mode:', oct(m.mode)
+        print 'mode: %s (%s)' % (oct(m.mode),
+                                 xstat.mode_str(m.mode))
     if 'link-target' in active_fields and stat.S_ISLNK(m.mode):
         print 'link-target:', m.symlink_target
     if 'rdev' in active_fields:
index f3e11de341fcb4f874bc3d77ede25c73261edcbd..7fcbe8aa8414a1f0fee3769a9ec5e8f110d89f2f 100644 (file)
@@ -1,5 +1,6 @@
 """Enhanced stat operations for bup."""
 import os
+import stat as pystat
 from bup import _helpers
 
 
@@ -92,3 +93,32 @@ def fstat(path):
 
 def lstat(path):
     return stat_result.from_xstat_rep(_helpers.lstat(path))
+
+
+def mode_str(mode):
+    result = ''
+    if pystat.S_ISREG(mode):
+        result += '-'
+    elif pystat.S_ISDIR(mode):
+        result += 'd'
+    elif pystat.S_ISCHR(mode):
+        result += 'c'
+    elif pystat.S_ISBLK(mode):
+        result += 'b'
+    elif pystat.S_ISFIFO(mode):
+        result += 'p'
+    elif pystat.S_ISLNK(mode):
+        result += 'l'
+    else:
+        result += '?'
+
+    result += 'r' if (mode & pystat.S_IRUSR) else '-'
+    result += 'w' if (mode & pystat.S_IWUSR) else '-'
+    result += 'x' if (mode & pystat.S_IXUSR) else '-'
+    result += 'r' if (mode & pystat.S_IRGRP) else '-'
+    result += 'w' if (mode & pystat.S_IWGRP) else '-'
+    result += 'x' if (mode & pystat.S_IXGRP) else '-'
+    result += 'r' if (mode & pystat.S_IROTH) else '-'
+    result += 'w' if (mode & pystat.S_IWOTH) else '-'
+    result += 'x' if (mode & pystat.S_IXOTH) else '-'
+    return result