Browse Source

Item.user_sid for owner SID (instead of Item.uid for unix owner ID)

Marian Beermann 9 năm trước cách đây
mục cha
commit
d9e7d3e3d8
3 tập tin đã thay đổi với 11 bổ sung15 xóa
  1. 8 14
      src/borg/archive.py
  2. 2 1
      src/borg/constants.py
  3. 1 0
      src/borg/item.py

+ 8 - 14
src/borg/archive.py

@@ -546,26 +546,20 @@ Number of files: {0.stats.nfiles}'''.format(
             try:
                 if fd:
                     os.fchown(fd, uid, gid)
+                    os.fchmod(fd, item.mode)
                 else:
                     os.lchown(path, uid, gid)
+                if not symlink:
+                    os.chmod(path, item.mode)
+                elif has_lchmod:  # Not available on Linux
+                    os.lchmod(path, item.mode)
             except OSError:
                 pass
         else:
             try:
-                set_owner(path, item.user, safe_decode(item.uid))
+                set_owner(path, item.user, item.user_sid)
             except OSError:
                 pass
-        if sys.platform != 'win32':
-            if fd:
-                os.fchown(fd, uid, gid)
-            else:
-                os.lchown(path, uid, gid)
-            if fd:
-                os.fchmod(fd, item.mode)
-            elif not symlink:
-                os.chmod(path, item.mode)
-            elif has_lchmod:  # Not available on Linux
-                os.lchmod(path, item.mode)
         mtime = item.mtime
         if 'atime' in item:
             atime = item.atime
@@ -681,9 +675,9 @@ Number of files: {0.stats.nfiles}'''.format(
             mtime=st.st_mtime_ns,
         )
         if sys.platform == 'win32':
-            owner = get_owner(path)
+            user_name, user_sid = get_owner(path)
             attrs.update({
-                'uid': owner[1], 'user': owner[0],
+                'uid': 0, 'user_sid': user_sid, 'user': user_name,
                 'gid': st.st_gid, 'group': gid2group(st.st_gid),
             })
         else:

+ 2 - 1
src/borg/constants.py

@@ -1,7 +1,8 @@
 # this set must be kept complete, otherwise the RobustUnpacker might malfunction:
 ITEM_KEYS = frozenset(['path', 'source', 'rdev', 'chunks', 'chunks_healthy', 'hardlink_master',
                        'mode', 'user', 'group', 'uid', 'gid', 'mtime', 'atime', 'ctime',
-                       'xattrs', 'bsdflags', 'acl_nfs4', 'acl_access', 'acl_default', 'acl_extended', 'win_dacl'])
+                       'xattrs', 'bsdflags', 'acl_nfs4', 'acl_access', 'acl_default', 'acl_extended', 'win_dacl',
+                       'user_sid', ])
 
 # this is the set of keys that are always present in items:
 REQUIRED_ITEM_KEYS = frozenset(['path', 'mtime', ])

+ 1 - 0
src/borg/item.py

@@ -139,6 +139,7 @@ class Item(PropDict):
     mode = PropDict._make_property('mode', int)
     uid = PropDict._make_property('uid', int)
     gid = PropDict._make_property('gid', int)
+    user_sid = PropDict._make_property('user_sid', str, encode=safe_encode, decode=safe_decode)
     rdev = PropDict._make_property('rdev', int)
     bsdflags = PropDict._make_property('bsdflags', int)