mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-26 14:01:30 +00:00
7935de0fe1
Co-authored-by: inexcode <inex.code@selfprivacy.org> Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api/pulls/13
17 lines
445 B
Python
17 lines
445 B
Python
"""Generic size counter using pathlib"""
|
|
import pathlib
|
|
|
|
|
|
def get_storage_usage(path: str) -> int:
|
|
"""
|
|
Calculate the real storage usage of path and all subdirectories.
|
|
Calculate using pathlib.
|
|
Do not follow symlinks.
|
|
"""
|
|
storage_usage = 0
|
|
for iter_path in pathlib.Path(path).rglob("**/*"):
|
|
if iter_path.is_dir():
|
|
continue
|
|
storage_usage += iter_path.stat().st_size
|
|
return storage_usage
|