Skip to content

Commit

Permalink
replace platform chmod with os.chmod
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan200101 committed Sep 13, 2023
1 parent 22d5795 commit b2dccfb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
17 changes: 17 additions & 0 deletions backend/localplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions backend/localplatformlinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions backend/localplatformwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b2dccfb

Please sign in to comment.