diff options
| author | Jan <sentrycraft123@gmail.com> | 2023-11-11 21:56:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-11 20:56:32 +0000 |
| commit | 7c3ae9b62b0991cf9efcfa3d806e06c2fd664816 (patch) | |
| tree | 7c356b7705f3395a3fce6cc597a6680df6c007c4 /backend/src/localplatformlinux.py | |
| parent | 75ad98a7b2ce53bf2916a6bfb760599e7b50fc9d (diff) | |
| download | decky-loader-7c3ae9b62b0991cf9efcfa3d806e06c2fd664816.tar.gz decky-loader-7c3ae9b62b0991cf9efcfa3d806e06c2fd664816.zip | |
replace chmod implementation with os.chmod (#541)
Diffstat (limited to 'backend/src/localplatformlinux.py')
| -rw-r--r-- | backend/src/localplatformlinux.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/backend/src/localplatformlinux.py b/backend/src/localplatformlinux.py index 846fa074..1f857f27 100644 --- a/backend/src/localplatformlinux.py +++ b/backend/src/localplatformlinux.py @@ -58,8 +58,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) |
