From ceedf4bced088d3e7ae2b0d657a3a7c34a9bed88 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Mon, 15 Aug 2022 23:31:57 +0200 Subject: [PATCH] file.chown() add recursive=False parameter --- exec/file.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec/file.py b/exec/file.py index 2772c86..8c33ace 100644 --- a/exec/file.py +++ b/exec/file.py @@ -24,14 +24,15 @@ def try_native_filewrite(path: str, content: Union[str, bytes], chmod: Optional[ return None -def chown(path: str, user: Optional[Union[str, int]] = None, group: Optional[Union[str, int]] = None): +def chown(path: str, user: Optional[Union[str, int]] = None, group: Optional[Union[str, int]] = None, recursive: bool = False): owner = '' if user is not None: owner += get_user_name(user) if group is not None: owner += f':{get_group_name(group)}' if owner: - result = run_root_cmd(["chown", owner, path]) + cmd = ["chown"] + (['-R'] if recursive else []) + result = run_root_cmd(cmd + [owner, path]) assert isinstance(result, subprocess.CompletedProcess) if result.returncode: raise Exception(f"Failed to change owner of '{path}' to '{owner}'")