From 35c72e7ce6c714af948e1d5d37f4e0cee0b97a03 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Thu, 14 Oct 2021 12:29:43 -0400 Subject: [PATCH] backup: calculate size only once We need to calculate size so we get an idea of actual used disk space (which is closer to how much maximum space will be used in the backup, in case files have huge holes). Calculate it once to avoid errors. --- backup.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backup.py b/backup.py index bbef16f..f0281fb 100755 --- a/backup.py +++ b/backup.py @@ -140,6 +140,7 @@ class Backup: st = os.lstat(path) is_dir = stat.S_ISDIR(st.st_mode) is_reg = stat.S_ISREG(st.st_mode) + size = st.st_blocks * 512 # Decorated path ends with a '/' if it's a directory. decorated_path = path @@ -160,14 +161,14 @@ class Backup: # Crosses a mount point exclude_reason = ('I', "skipping, on different filesystem") - elif (self.config.max_file_size - and is_reg - and (st.st_blocks * 512) > self.config.max_file_size): + elif (is_reg + and self.config.max_file_size + and size > self.config.max_file_size): # Too big def format_size(n): return humanfriendly.format_size( n, keep_width=True, binary=True) - a = format_size(st.st_blocks * 512) + a = format_size(size) b = format_size(self.config.max_file_size) exclude_reason = ('W', f"file size {a} exceeds limit {b}")