浏览代码

extract: chown only if we have u/g info in archived item, see #7249

also: move get_item_uid_gid() to "not is_win32" block for now.
Thomas Waldmann 2 年之前
父节点
当前提交
4dcc48f5c4
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      src/borg/archive.py

+ 5 - 2
src/borg/archive.py

@@ -928,9 +928,12 @@ Duration: {0.duration}
         Does not access the repository.
         """
         backup_io.op = "attrs"
-        uid, gid = get_item_uid_gid(item, numeric=self.numeric_ids)
-        # This code is a bit of a mess due to os specific differences
+        # This code is a bit of a mess due to OS specific differences.
         if not is_win32:
+            # by using uid_default = -1 and gid_default = -1, they will not be restored if
+            # the archived item has no information about them.
+            uid, gid = get_item_uid_gid(item, numeric=self.numeric_ids, uid_default=-1, gid_default=-1)
+            # if uid and/or gid is -1, chown will keep it as is and not change it.
             try:
                 if fd:
                     os.fchown(fd, uid, gid)