island: Split has_expected_permissions() into os-specific functions

This commit is contained in:
Mike Salvatore 2021-06-09 09:47:23 -04:00
parent dc8e2b018d
commit 945e1adf58
1 changed files with 44 additions and 37 deletions

View File

@ -9,6 +9,19 @@ def expand_path(path: str) -> str:
def has_expected_permissions(path: str, expected_permissions: int) -> bool: def has_expected_permissions(path: str, expected_permissions: int) -> bool:
if is_windows_os(): if is_windows_os():
return _has_expected_windows_permissions(path, expected_permissions)
return _has_expected_linux_permissions(path, expected_permissions)
def _has_expected_linux_permissions(path: str, expected_permissions: int) -> bool:
file_mode = os.stat(path).st_mode
file_permissions = file_mode & 0o777
return file_permissions == expected_permissions
def _has_expected_windows_permissions(path: str, expected_permissions: int) -> bool:
# checks that admin has any permissions, user has `expected_permissions`, # checks that admin has any permissions, user has `expected_permissions`,
# and everyone else has no permissions # and everyone else has no permissions
@ -45,9 +58,3 @@ def has_expected_permissions(path: str, expected_permissions: int) -> bool:
return False return False
return True return True
else:
file_mode = os.stat(path).st_mode
file_permissions = file_mode & 0o777
return file_permissions == expected_permissions