From b2dccfb111e8f9993c842224cb75a532296baf2a Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 13 Sep 2023 13:35:13 +0200 Subject: [PATCH] replace platform chmod with os.chmod --- backend/localplatform.py | 17 +++++++++++++++++ backend/localplatformlinux.py | 6 ------ backend/localplatformwin.py | 3 --- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/backend/localplatform.py b/backend/localplatform.py index 43043ad03..4c4fc8c1c 100644 --- a/backend/localplatform.py +++ b/backend/localplatform.py @@ -50,3 +50,20 @@ def get_selinux() -> bool: except FileNotFoundError: pass return False + +def chmod(path : str, permissions : int, recursive : bool = True) -> bool: + octal_permissions = int(str(permissions), 8) + + try: + 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.chown(os.path.join(root, d), octal_permissions) + else: + os.chmod(path, octal_permissions) + except: + return False + + return True diff --git a/backend/localplatformlinux.py b/backend/localplatformlinux.py index 811db8a62..cdd089aaf 100644 --- a/backend/localplatformlinux.py +++ b/backend/localplatformlinux.py @@ -59,12 +59,6 @@ def chown(path : str, user : UserType = UserType.HOST_USER, recursive : bool = result = call(["chown", "-R", user_str, path] if recursive else ["chown", user_str, path]) return result == 0 -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 - def folder_owner(path : str) -> UserType|None: user_owner = _get_user_owner(path) diff --git a/backend/localplatformwin.py b/backend/localplatformwin.py index b6bee330b..5c30482e1 100644 --- a/backend/localplatformwin.py +++ b/backend/localplatformwin.py @@ -4,9 +4,6 @@ def chown(path : str, user : UserType = UserType.HOST_USER, recursive : bool = True) -> bool: return True # Stubbed -def chmod(path : str, permissions : int, recursive : bool = True) -> bool: - return True # Stubbed - def folder_owner(path : str) -> UserType|None: return UserType.HOST_USER # Stubbed