backup: rename pstr() helper to b2s()
The helper is just bytes->str conversion with errors=backslashreplace, which we can use for more than just paths.
This commit is contained in:
parent
e2f92ccb7a
commit
1115d1f821
18
backup.py
18
backup.py
|
@ -23,8 +23,8 @@ import yaml
|
|||
import wcmatch.glob # type: ignore
|
||||
import humanfriendly # type: ignore
|
||||
|
||||
def pstr(path: bytes) -> str:
|
||||
return path.decode(errors='backslashreplace')
|
||||
def b2s(raw: bytes) -> str:
|
||||
return raw.decode(errors='backslashreplace')
|
||||
|
||||
def format_size(n: int) -> str:
|
||||
return humanfriendly.format_size(n, keep_width=True, binary=True)
|
||||
|
@ -132,7 +132,7 @@ class Backup:
|
|||
self.outfile = outfile
|
||||
for root in self.config.roots:
|
||||
if root in self.root_seen:
|
||||
self.log('I', f"ignoring root, already seen: {pstr(root)}")
|
||||
self.log('I', f"ignoring root, already seen: {b2s(root)}")
|
||||
continue
|
||||
|
||||
try:
|
||||
|
@ -140,13 +140,13 @@ class Backup:
|
|||
if not stat.S_ISDIR(st.st_mode):
|
||||
raise NotADirectoryError
|
||||
except FileNotFoundError:
|
||||
self.log('E', f"root does not exist: {pstr(root)}")
|
||||
self.log('E', f"root does not exist: {b2s(root)}")
|
||||
continue
|
||||
except NotADirectoryError:
|
||||
self.log('E', f"root is not a directory: {pstr(root)}")
|
||||
self.log('E', f"root is not a directory: {b2s(root)}")
|
||||
continue
|
||||
|
||||
self.log('I', f"processing root {pstr(root)}")
|
||||
self.log('I', f"processing root {b2s(root)}")
|
||||
self.scan(root)
|
||||
|
||||
def scan(self, path: bytes, parent_st: os.stat_result=None):
|
||||
|
@ -199,7 +199,7 @@ class Backup:
|
|||
force = self.config.match_re(self.config.unexclude, decorated_path)
|
||||
if exclude_reason and not force:
|
||||
self.log(exclude_reason[0],
|
||||
f"{exclude_reason[1]}: {pstr(path)}")
|
||||
f"{exclude_reason[1]}: {b2s(path)}")
|
||||
return
|
||||
|
||||
# Print path for Borg
|
||||
|
@ -221,7 +221,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: {pstr(path)}")
|
||||
'I', f"skipping, cache dir: {b2s(path)}")
|
||||
return
|
||||
except:
|
||||
pass
|
||||
|
@ -235,7 +235,7 @@ class Backup:
|
|||
IsADirectoryError,
|
||||
NotADirectoryError,
|
||||
PermissionError) as e:
|
||||
self.log('E', f"can't read {pstr(path)}: {str(e)}")
|
||||
self.log('E', f"can't read {b2s(path)}: {str(e)}")
|
||||
return
|
||||
|
||||
def run_borg(self, argv: typing.List[str],
|
||||
|
|
Loading…
Reference in New Issue
Block a user