]> arthur.barton.de Git - bup.git/commitdiff
drecurse: use portable S_ISDIR() instead of deriving S_IFMT
authorRob Browning <rlb@defaultvalue.org>
Sat, 27 Jun 2020 16:47:31 +0000 (11:47 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 5 Jul 2020 16:16:23 +0000 (11:16 -0500)
In some simple testing, there didn't appear to be any notable,
consistent performance difference, and the S_IFMT(0xffffffff) call
fails with an OverflowError on at least macos.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/drecurse.py

index 1d9a4e14b5e5d91c3951acd587c88be619955319..ba41a12758268da40509726926c818efa7208250 100644 (file)
@@ -37,8 +37,6 @@ class OsFile:
     def stat(self):
         return xstat.fstat(self.fd)
 
-
-_IFMT = stat.S_IFMT(0xffffffff)  # avoid function call in inner loop
 def _dirlist():
     l = []
     for n in os.listdir(b'.'):
@@ -47,13 +45,12 @@ def _dirlist():
         except OSError as e:
             add_error(Exception('%s: %s' % (resolve_parent(n), str(e))))
             continue
-        if (st.st_mode & _IFMT) == stat.S_IFDIR:
+        if stat.S_ISDIR(st.st_mode):
             n += b'/'
         l.append((n,st))
     l.sort(reverse=True)
     return l
 
-
 def _recursive_dirlist(prepend, xdev, bup_dir=None,
                        excluded_paths=None,
                        exclude_rxs=None,