Browse Source

acls (linux): add a test for acl_use_local_uid_gid and fix this function

this has never worked as intended as the function was not using the computed "fields[1]" value at all.
plus there were type issues after that was fixed.
Thomas Waldmann 9 years ago
parent
commit
55179fe64d
2 changed files with 10 additions and 3 deletions
  1. 3 3
      borg/platform_linux.pyx
  2. 7 0
      borg/testsuite/platform.py

+ 3 - 3
borg/platform_linux.pyx

@@ -35,10 +35,10 @@ def acl_use_local_uid_gid(acl):
         if entry:
             fields = entry.split(':')
             if fields[0] == 'user' and fields[1]:
-                fields[1] = user2uid(fields[1], fields[3])
+                fields[1] = str(user2uid(fields[1], int(fields[3])))
             elif fields[0] == 'group' and fields[1]:
-                fields[1] = group2gid(fields[1], fields[3])
-            entries.append(':'.join(entry.split(':')[:3]))
+                fields[1] = str(group2gid(fields[1], int(fields[3])))
+            entries.append(':'.join(fields[:3]))
     return ('\n'.join(entries)).encode('ascii')
 
 

+ 7 - 0
borg/testsuite/platform.py

@@ -97,6 +97,13 @@ class PlatformLinuxTestCase(BaseTestCase):
         self.assert_in(user_entry_numeric, acl_access)
         self.assert_in(group_entry_numeric, acl_access)
 
+    def test_utils(self):
+        from ..platform_linux import acl_use_local_uid_gid
+        self.assert_equal(acl_use_local_uid_gid(b'user:nonexistent1234:rw-:1234'), b'user:1234:rw-')
+        self.assert_equal(acl_use_local_uid_gid(b'group:nonexistent1234:rw-:1234'), b'group:1234:rw-')
+        self.assert_equal(acl_use_local_uid_gid(b'user:root:rw-:0'), b'user:0:rw-')
+        self.assert_equal(acl_use_local_uid_gid(b'group:root:rw-:0'), b'group:0:rw-')
+
 
 @unittest.skipUnless(sys.platform.startswith('darwin'), 'OS X only test')
 @unittest.skipIf(fakeroot_detected(), 'not compatible with fakeroot')