Browse Source

backup: use helper to format binary paths as strings

master
Jim Paris 7 months ago
parent
commit
5152a316c6
1 changed files with 7 additions and 7 deletions
  1. +7
    -7
      backup.py

+ 7
- 7
backup.py View File

@@ -19,6 +19,9 @@ import yaml
import wcmatch.glob # type: ignore
import humanfriendly # type: ignore

def pstr(path: bytes) -> str:
return path.decode(errors='backslashreplace')

class Config:
root: bytes
max_file_size: typing.Optional[int]
@@ -138,10 +141,6 @@ class Backup:
raise Exception(f"relative path (from {repr(base)}, {repr(path)})"
+ f" must start with /")

# Copy the path in string form, for logging. Otherwise, we use
# bytes directly.
pathstr = path.decode(errors='backslashreplace')

try:
st = os.lstat(path)
is_dir = stat.S_ISDIR(st.st_mode)
@@ -177,7 +176,8 @@ class Backup:
force = self.config.match_re(
self.config.force_include_re, relpath, is_dir)
if exclude_reason and not force:
self.log(exclude_reason[0], f"{exclude_reason[1]}: {pathstr}")
self.log(exclude_reason[0],
f"{exclude_reason[1]}: {pstr(path)}")
return

# Print path for Borg
@@ -194,7 +194,7 @@ class Backup:
with open(path + b'/CACHEDIR.TAG', 'rb') as f:
if f.read(len(tag)) == tag:
self.log(
'I', f"skipping, cache dir: {pathstr}")
'I', f"skipping, cache dir: {pstr(path)}")
return
except:
pass
@@ -206,7 +206,7 @@ class Backup:
parent_st=st)

except PermissionError as e:
self.log('E', f"can't read {pathstr}")
self.log('E', f"can't read {pstr(path)}")
return

def main(argv: list[str]):


Loading…
Cancel
Save