You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:24:52 UTC

[buildstream] 04/15: utils.py: Optimise get_walk_dir_size()

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch jennis/136-clean-remote-cache
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit b031c1eaf2acadaa326eb26a30aba2286b3a293e
Author: James Ennis <ja...@codethink.com>
AuthorDate: Tue May 22 16:36:54 2018 +0100

    utils.py: Optimise get_walk_dir_size()
---
 buildstream/utils.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/buildstream/utils.py b/buildstream/utils.py
index f22b57f..e6e5989 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -578,13 +578,17 @@ def _get_dir_size(path):
         for dirpath, dirs, files in os.walk(path):
             for d in dirs:
                 path = os.path.join(dirpath, d)
-                if os.path.exists(path):
-                    total += os.stat(path, follow_symlinks=False).st_size
+                try:
+                    total += os.lstat(path).st_size
+                except FileNotFoundError:
+                    pass
 
             for f in files:
                 path = os.path.join(dirpath, f)
-                if os.path.exists(path):
-                    total += os.stat(path, follow_symlinks=False).st_size
+                try:
+                    total += os.lstat(path).st_size
+                except FileNotFoundError:
+                    pass
 
         return total