summaryrefslogtreecommitdiff
path: root/hosts/vidhar/borg
diff options
context:
space:
mode:
Diffstat (limited to 'hosts/vidhar/borg')
-rwxr-xr-xhosts/vidhar/borg/copy.py11
1 files 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 = {
45 45
46borg_pwd = getpwnam('borg') 46borg_pwd = getpwnam('borg')
47 47
48def as_borg(caps=set()): 48def as_borg(caps=set(), cwd=None):
49 print('as_borg', 'pre-caps', file=stderr)
50 if caps: 49 if caps:
51 cap_permitted.add(*caps) 50 cap_permitted.add(*caps)
52 cap_inheritable.add(*caps) 51 cap_inheritable.add(*caps)
53 cap_effective.add(*caps) 52 cap_effective.add(*caps)
54 cap_ambient.add(*caps) 53 cap_ambient.add(*caps)
55 print('as_borg', 'post-caps', file=stderr)
56 54
57 os.setgid(borg_pwd.pw_gid) 55 os.setgid(borg_pwd.pw_gid)
58 os.setuid(borg_pwd.pw_uid) 56 os.setuid(borg_pwd.pw_uid)
59 57
58 if cwd is not None:
59 os.chdir(cwd)
60
60def read_repo(path): 61def read_repo(path):
61 with Halo(text=f'Listing {path}', **halo_args) as sp: 62 with Halo(text=f'Listing {path}', **halo_args) as sp:
62 res = None 63 res = None
@@ -191,12 +192,10 @@ def copy_archive(src_repo_path, dst_repo_path, entry):
191 create_args += ['--files-cache=disabled'] 192 create_args += ['--files-cache=disabled']
192 create_args += [f'{dst_repo_path}::{entry["name"]}', '.'] 193 create_args += [f'{dst_repo_path}::{entry["name"]}', '.']
193 194
194 print(*create_args, file=stderr) 195 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:
195 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:
196 last_list = None 196 last_list = None
197 last_list_time = None 197 last_list_time = None
198 for line in proc.stderr: 198 for line in proc.stderr:
199 print(line, file=stderr)
200 try: 199 try:
201 json_line = json.loads(line) 200 json_line = json.loads(line)
202 except json.decoder.JSONDecodeError: 201 except json.decoder.JSONDecodeError: