From cc1097378d095adf05a37261ac663a7019b3292c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 18 Feb 2022 12:55:52 +0100 Subject: vidhar: ... --- hosts/vidhar/borg/copy.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hosts/vidhar/borg/copy.py b/hosts/vidhar/borg/copy.py index 3de2a653..38e719cf 100755 --- a/hosts/vidhar/borg/copy.py +++ b/hosts/vidhar/borg/copy.py @@ -45,18 +45,19 @@ halo_args = { borg_pwd = getpwnam('borg') -def as_borg(caps=set()): - print('as_borg', 'pre-caps', file=stderr) +def as_borg(caps=set(), cwd=None): if caps: cap_permitted.add(*caps) cap_inheritable.add(*caps) cap_effective.add(*caps) cap_ambient.add(*caps) - print('as_borg', 'post-caps', file=stderr) os.setgid(borg_pwd.pw_gid) os.setuid(borg_pwd.pw_uid) + if cwd is not None: + os.chdir(cwd) + def read_repo(path): with Halo(text=f'Listing {path}', **halo_args) as sp: res = None @@ -191,12 +192,10 @@ def copy_archive(src_repo_path, dst_repo_path, entry): create_args += ['--files-cache=disabled'] create_args += [f'{dst_repo_path}::{entry["name"]}', '.'] - print(*create_args, file=stderr) - with subprocess.Popen(create_args, cwd=dir, stdin=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True, env=env, preexec_fn=lambda: as_borg(caps={Cap.DAC_READ_SEARCH})) as proc: + with subprocess.Popen(create_args, stdin=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True, env=env, preexec_fn=lambda: as_borg(caps={Cap.DAC_READ_SEARCH}, cwd=dir)) as proc: last_list = None last_list_time = None for line in proc.stderr: - print(line, file=stderr) try: json_line = json.loads(line) except json.decoder.JSONDecodeError: -- cgit v1.2.3