Browse Source

split stat_attrs into cheap and expensive part

we already have stat results in st, so computing stat_simple_attrs is
rather cheap (except the username/groupname lookup maybe) and gets the
most important stuff right in the Item, so it is brought early into a
good state.

after chunking, stat_ext_attrs is called to add the more expensive-to-get
attributes, like bsdflags, xattrs and ACLs.
Thomas Waldmann 9 years ago
parent
commit
9226fc6f6f
1 changed files with 16 additions and 3 deletions
  1. 16 3
      src/borg/archive.py

+ 16 - 3
src/borg/archive.py

@@ -651,17 +651,24 @@ Number of files: {0.stats.nfiles}'''.format(
             logger.warning('forced deletion succeeded, but the deleted archive was corrupted.')
             logger.warning('forced deletion succeeded, but the deleted archive was corrupted.')
             logger.warning('borg check --repair is required to free all space.')
             logger.warning('borg check --repair is required to free all space.')
 
 
-    def stat_attrs(self, st, path):
+    def stat_simple_attrs(self, st):
         attrs = dict(
         attrs = dict(
             mode=st.st_mode,
             mode=st.st_mode,
-            uid=st.st_uid, user=uid2user(st.st_uid),
-            gid=st.st_gid, group=gid2group(st.st_gid),
+            uid=st.st_uid,
+            gid=st.st_gid,
             atime=st.st_atime_ns,
             atime=st.st_atime_ns,
             ctime=st.st_ctime_ns,
             ctime=st.st_ctime_ns,
             mtime=st.st_mtime_ns,
             mtime=st.st_mtime_ns,
         )
         )
         if self.numeric_owner:
         if self.numeric_owner:
             attrs['user'] = attrs['group'] = None
             attrs['user'] = attrs['group'] = None
+        else:
+            attrs['user'] = uid2user(st.st_uid)
+            attrs['group'] = gid2group(st.st_gid)
+        return attrs
+
+    def stat_ext_attrs(self, st, path):
+        attrs = {}
         with backup_io():
         with backup_io():
             xattrs = xattr.get_all(path, follow_symlinks=False)
             xattrs = xattr.get_all(path, follow_symlinks=False)
             bsdflags = get_flags(path, st)
             bsdflags = get_flags(path, st)
@@ -672,6 +679,11 @@ Number of files: {0.stats.nfiles}'''.format(
             attrs['bsdflags'] = bsdflags
             attrs['bsdflags'] = bsdflags
         return attrs
         return attrs
 
 
+    def stat_attrs(self, st, path):
+        attrs = self.stat_simple_attrs(st)
+        attrs.update(self.stat_ext_attrs(st, path))
+        return attrs
+
     def process_dir(self, path, st):
     def process_dir(self, path, st):
         item = Item(path=make_path_safe(path))
         item = Item(path=make_path_safe(path))
         item.update(self.stat_attrs(st, path))
         item.update(self.stat_attrs(st, path))
@@ -760,6 +772,7 @@ Number of files: {0.stats.nfiles}'''.format(
             path=safe_path,
             path=safe_path,
             hardlink_master=st.st_nlink > 1,  # item is a hard link and has the chunks
             hardlink_master=st.st_nlink > 1,  # item is a hard link and has the chunks
         )
         )
+        item.update(self.stat_simple_attrs(st))
         # Only chunkify the file if needed
         # Only chunkify the file if needed
         if chunks is None:
         if chunks is None:
             compress = self.compression_decider1.decide(path)
             compress = self.compression_decider1.decide(path)