[Python] How to check the program executor permissions on a certain path

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    os.access() doesn't work as expected; it always returns True.

    I found this method to verify if I have permission to read a file or directory, which should also imply that I have permission to check the path’s permissions.

    def _readable_path(abs_path: Path, uname: str):
    # Existing validation
    try:
    exists = abs_path.exists()
    except PermissionError as e:
    return build_not_path_access(abs_path, uname, e)
    except Exception as e:
    return build_general_path_access(abs_path, uname, e)

    if not exists:
    return build_file_not_found(abs_path)

    # Reading perm check
    try:
    security_descriptor = win32security.GetFileSecurity(
    str(abs_path), win32security.DACL_SECURITY_INFORMATION
    )
    except win32security.error as e:
    if e.winerror == 5: # Not reading perms
    return False
    return build_general_path_access(abs_path, uname, e)

    return True


    Is there a library that simplifies path permission validation on Windows in a way similar to how os.access() works on Linux?

    Continue reading...

Compartilhe esta Página