From b2a8697d3abe52e363f986b094914f7fd7b3301d Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 15 Sep 2023 22:35:25 +0200 Subject: [PATCH] replace chmod implementation with os.chmod --- backend/localplatformlinux.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/localplatformlinux.py b/backend/localplatformlinux.py index 811db8a62..45152abf6 100644 --- a/backend/localplatformlinux.py +++ b/backend/localplatformlinux.py @@ -62,8 +62,22 @@ def chown(path : str, user : UserType = UserType.HOST_USER, recursive : bool = def chmod(path : str, permissions : int, recursive : bool = True) -> bool: if _get_effective_user_id() != 0: return True - result = call(["chmod", "-R", str(permissions), path] if recursive else ["chmod", str(permissions), path]) - return result == 0 + + try: + octal_permissions = int(str(permissions), 8) + + if recursive: + for root, dirs, files in os.walk(path): + for d in dirs: + os.chmod(os.path.join(root, d), octal_permissions) + for d in files: + os.chmod(os.path.join(root, d), octal_permissions) + + os.chmod(path, octal_permissions) + except: + return False + + return True def folder_owner(path : str) -> UserType|None: user_owner = _get_user_owner(path)