Browse Source

"extract" micro optimization: first check for regular files, then for directories, check for fifos late

regular files are most common, more than directories. fifos are rare.

was no big issue, the calls are cheap, but also no big issue to just fix the order.
Thomas Waldmann 10 năm trước cách đây
mục cha
commit
646cdca312
1 tập tin đã thay đổi với 11 bổ sung11 xóa
  1. 11 11
      borg/archive.py

+ 11 - 11
borg/archive.py

@@ -273,12 +273,7 @@ class Archive:
         except OSError:
         except OSError:
             pass
             pass
         mode = item[b'mode']
         mode = item[b'mode']
-        if stat.S_ISDIR(mode):
-            if not os.path.exists(path):
-                os.makedirs(path)
-            if restore_attrs:
-                self.restore_attrs(path, item)
-        elif stat.S_ISREG(mode):
+        if stat.S_ISREG(mode):
             if not os.path.exists(os.path.dirname(path)):
             if not os.path.exists(os.path.dirname(path)):
                 os.makedirs(os.path.dirname(path))
                 os.makedirs(os.path.dirname(path))
             # Hard link?
             # Hard link?
@@ -300,11 +295,11 @@ class Archive:
                     fd.truncate(pos)
                     fd.truncate(pos)
                     fd.flush()
                     fd.flush()
                     self.restore_attrs(path, item, fd=fd.fileno())
                     self.restore_attrs(path, item, fd=fd.fileno())
-        elif stat.S_ISFIFO(mode):
-            if not os.path.exists(os.path.dirname(path)):
-                os.makedirs(os.path.dirname(path))
-            os.mkfifo(path)
-            self.restore_attrs(path, item)
+        elif stat.S_ISDIR(mode):
+            if not os.path.exists(path):
+                os.makedirs(path)
+            if restore_attrs:
+                self.restore_attrs(path, item)
         elif stat.S_ISLNK(mode):
         elif stat.S_ISLNK(mode):
             if not os.path.exists(os.path.dirname(path)):
             if not os.path.exists(os.path.dirname(path)):
                 os.makedirs(os.path.dirname(path))
                 os.makedirs(os.path.dirname(path))
@@ -313,6 +308,11 @@ class Archive:
                 os.unlink(path)
                 os.unlink(path)
             os.symlink(source, path)
             os.symlink(source, path)
             self.restore_attrs(path, item, symlink=True)
             self.restore_attrs(path, item, symlink=True)
+        elif stat.S_ISFIFO(mode):
+            if not os.path.exists(os.path.dirname(path)):
+                os.makedirs(os.path.dirname(path))
+            os.mkfifo(path)
+            self.restore_attrs(path, item)
         elif stat.S_ISCHR(mode) or stat.S_ISBLK(mode):
         elif stat.S_ISCHR(mode) or stat.S_ISBLK(mode):
             os.mknod(path, item[b'mode'], item[b'rdev'])
             os.mknod(path, item[b'mode'], item[b'rdev'])
             self.restore_attrs(path, item)
             self.restore_attrs(path, item)