Browse Source

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.
master
Jim Paris 7 months ago
parent
commit
35c72e7ce6
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      backup.py

+ 5
- 4
backup.py View File

@@ -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}")



Loading…
Cancel
Save