diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-18 12:55:52 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-18 12:55:52 +0100 |
commit | cc1097378d095adf05a37261ac663a7019b3292c (patch) | |
tree | 86e1f3c7fa227517271984870c474ff432511e84 /hosts/vidhar/borg | |
parent | 88bfd77de0d0a6ab596013898a72e4df04d06bf8 (diff) | |
download | nixos-cc1097378d095adf05a37261ac663a7019b3292c.tar nixos-cc1097378d095adf05a37261ac663a7019b3292c.tar.gz nixos-cc1097378d095adf05a37261ac663a7019b3292c.tar.bz2 nixos-cc1097378d095adf05a37261ac663a7019b3292c.tar.xz nixos-cc1097378d095adf05a37261ac663a7019b3292c.zip |
vidhar: ...
Diffstat (limited to 'hosts/vidhar/borg')
-rwxr-xr-x | hosts/vidhar/borg/copy.py | 11 |
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 | ||
46 | borg_pwd = getpwnam('borg') | 46 | borg_pwd = getpwnam('borg') |
47 | 47 | ||
48 | def as_borg(caps=set()): | 48 | def 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 | |||
60 | def read_repo(path): | 61 | def 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: |