This is an automated email from the ASF dual-hosted git repository. root pushed a commit to branch testing/local-cache-expiry in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit a267684ebc4ff0c4815171cef5cb034bbae36a9b Author: Tristan Maat <[email protected]> AuthorDate: Tue Mar 20 13:19:13 2018 +0000 utils.py: Add get_dir_size helper --- buildstream/utils.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/buildstream/utils.py b/buildstream/utils.py index b81a6c8..df95d71 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -536,6 +536,33 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, raise +# _get_dir_size(): +# +# Get the disk usage of a given directory in bytes. +# +# Arguments: +# (str) The path whose size to check. +# +# Returns: +# (int) The size on disk. +# +def _get_dir_size(path): + path = os.path.abspath(path) + + def get_size(path): + total = 0 + + for f in os.scandir(path): + total += f.stat(follow_symlinks=False).st_size + + if f.is_dir(follow_symlinks=False): + total += get_size(f.path) + + return total + + return get_size(path) + + # A sentinel to be used as a default argument for functions that need # to distinguish between a kwarg set to None and an unset kwarg. _sentinel = object()
