← back to Atmos Game

assets/gen/.venv/lib/python3.12/site-packages/filelock/__pycache__/_windows.cpython-312.pyc

98 lines

�

c�bjt>��d	�UddlmZddlZddlZddlmZddlmZddlm	Z	m
Z
ddlmZddl
mZmZej d	k(�raddlZddlZdd
lmZdZded
<dZded<dZded<eezezZded<dZded<dZded<dZded<dZded<dZded<dZded<dZded<dZ ded <eeze zZ!ded!<dZ"ded"<dZ#ded#<dZ$ded$<d%Z%ded&<d'Z&ded(<dZ'ded)<d*Z(ded+<d,Z)ded-<d.Z*ded/<ejVd0�Z,d1ed2<ejVd3d4�5�Z-d1ed6<Gd7�d8ej\�Z/Gd9�d:ej\�Z0Gd;�d<ej\�Z1Gd=�d>ej\�Z2Gd?�d@ej\�Z3ejhe,jj_6ejnejp�ejrejne0�ejne1�ejnejt�ejvejvejvejvejxejvge,jj_=ejhe,j|_6ej~ejne/�ejxejxge,j|_=de,j�_6ejne/�ge,j�_=ejve,j�_6ejhge,j�_=ejpge-j�_=ej�e-j�_6ejpejne3�ge-j�_=ej�e-j�_6ejpejrejrejrejrejne2�ge-j�_=ej�e-j�_6ejpejrejrejrejne2�ge-j�_=ej�e-j�_6dHdA�ZGdIdB�ZHGdC�dDe�ZIdJdE�ZJdKdF�ZKdDgZLyGdG�dDe�ZIdDgZLy)L�)�annotationsN)�suppress)�Path)�Final�cast�)�BaseFileLock)�ensure_directory_exists�raise_on_not_writable_file�win32)�wintypeslz
Final[int]�
_GENERIC_READi@�_GENERIC_WRITEi�_SYNCHRONIZE�_DESIRED_ACCESS��_FILE_SHARE_READ_WRITE�
_FILE_OPEN_IF�_FILE_ATTRIBUTE_READONLY��_FILE_ATTRIBUTE_NORMALi�_FILE_ATTRIBUTE_REPARSE_POINT� �_FILE_SYNCHRONOUS_IO_NONALERT�@�_FILE_NON_DIRECTORY_FILEi �_FILE_OPEN_REPARSE_POINT�_CREATE_OPTIONS�_OBJ_CASE_INSENSITIVE�_OWNER_WRITE�_LOCKFILE_FAIL_IMMEDIATELY��_LOCKFILE_EXCLUSIVE_LOCK�!�_ERROR_LOCK_VIOLATION�_STATUS_SUCCESSl"�_STATUS_ACCESS_DENIEDlC�_STATUS_SHARING_VIOLATIONlV�_STATUS_DELETE_PENDING�ntdllzFinal[ctypes.WinDLL]�_ntdll�kernel32T)�use_last_error�	_kernel32c�^�eZdZdejfdejfdej
ffZy)�_UNICODE_STRING�Length�
MaximumLength�BufferN)�__name__�
__module__�__qualname__r
�USHORT�LPWSTR�_fields_���h/Users/macstudio3/Projects/atmos-game/assets/gen/.venv/lib/python3.12/site-packages/filelock/_windows.pyr0r08s-��
�x���'�
�h�o�o�.�
�x���'�
�r;r0c��eZdZdejfdej
fdeje�fdejfdejfdejffZ
y)�_OBJECT_ATTRIBUTESr1�
RootDirectory�
ObjectName�
Attributes�SecurityDescriptor�SecurityQualityOfServiceN)r4r5r6r
�ULONG�HANDLE�ctypes�POINTERr0�c_void_pr9r:r;r<r>r>?sX��
�x�~�~�&�
�h�o�o�.�
�>�6�>�>�/�:�;�
�8�>�>�*�
!�6�?�?�3�
'����9�

�r;r>c�D�eZdZdejfdejffZy)�_IO_STATUS_BLOCK�Status�InformationN)r4r5r6rFrHr9r:r;r<rJrJIs!��
�v���'�
�F�O�O�,�
�r;rJc��eZdZdejfdejfdejfdejfdejffZy)�_OVERLAPPED�Internal�InternalHigh�Offset�
OffsetHigh�hEventN)	r4r5r6rFrHr
�DWORDrEr9r:r;r<rNrNOsE��
����)�
�V�_�_�-�
�x�~�~�&�
�8�>�>�*�
�x���'�
�r;rNc��eZdZdejfdej
fdej
fdej
fdejfdejfdejfdejfd	ejfd
ejff
Zy)�_BY_HANDLE_FILE_INFORMATION�dwFileAttributes�ftCreationTime�ftLastAccessTime�ftLastWriteTime�dwVolumeSerialNumber�
nFileSizeHigh�nFileSizeLow�nNumberOfLinks�nFileIndexHigh�
nFileIndexLowN)r4r5r6r
rT�FILETIMEr9r:r;r<rVrVXs���
����0�
�x�0�0�1�
��!2�!2�3�
�� 1� 1�2�
#�X�^�^�4�
�h�n�n�-�
�X�^�^�,�
�x�~�~�.�
�x�~�~�.�
�h�n�n�-�
�r;rVc
��t�}ttz}tj	tj|�|dddtj|��rytj�}|tk(rytj|��)NrrTF)rNr#r!r.�
LockFileEx�msvcrt�
get_osfhandlerF�byref�get_last_errorr%�WinError)�fd�
overlapped�flags�errs    r<�_lock_fd_nonblockingrm�so��!�]�
�(�+E�E������ 4� 4�R� 8�%��A�q�&�,�,�Wa�Jb�c���#�#�%���'�'���o�o�c�"�"r;c	���t�}tjtj|�dddtj|��s'tjtj���y)Nrr)	rNr.�UnlockFileExrdrerFrfrhrg)rirjs  r<�
_unlock_fdrp�sR�� �]�
��%�%�f�&:�&:�2�&>��1�a����V`�Ia�b��/�/�&�"7�"7�"9�:�:�cr;c� �eZdZdZdd�Zdd�Zy)�WindowsFileLockay
        Uses ``LockFileEx`` to hard lock a byte range of the lock file on Windows systems.

        Lock file cleanup: Windows attempts to delete the lock file after release, but deletion is
        not guaranteed in multi-threaded scenarios where another thread holds an open handle. The lock
        file may persist on disk, which does not affect lock correctness.
        c�Z�t|j�t|j�t|j|j	��}|�y	t|�}|r|j
|�|stj|�yy#t$rtj|��wxYw�N)
r�	lock_filer
�_open_non_reparse_fd�
_open_moderm�_mark_descriptor_owned�
BaseException�os�close)�selfri�lockeds   r<�_acquirezWindowsFileLock._acquire�s���&�t�~�~�6�#�D�N�N�3�&�d�n�n�d�o�o�6G�H�B��z��
�-�b�1����/�/��3���������!�
�������
�s�B
�
 B*c�H�td|jj�}t|�|j	�|j|d��|js<tt�5t|j�j�ddd�yy#1swYyxYw)N�intF)�default_suppresses)r�_context�lock_file_fdrp�_mark_descriptor_released�_close_released_fd�_preserve_lock_filer�OSErrorrru�unlink)r|ris  r<�_releasezWindowsFileLock._release�sz���e�T�]�]�7�7�8�B�
�r�N��*�*�,��#�#�B�5�#�A��+�+��g�&�����(�/�/�1�'�&�,�&�&�s�*$B�B!N��return�None�r4r5r6�__doc__r~r�r:r;r<rrrr�s��	�	�&
	2r;rrc�\�tjd|dtjtjz�t||tz��\}}|tk7rS|tthvrytj|�}tdtj|�j�||��t!�}t"j%|tj&|��s>tj(�}t"j+|�tj,|��|j.t0zr%t"j+|�d|��}t|��	t3j4|tjtj6z�S#t8$rt"j+|��wxYw)a
        Open *path* for locking while refusing reparse points, bound to the handle actually locked.

        The file is opened through ``NtCreateFile`` with ``FILE_OPEN_REPARSE_POINT`` so a symlink or junction planted
        at the path is not followed, and the reparse decision is read from *that* handle via
        ``GetFileInformationByHandle`` rather than from a prior pathname query. Reading the held handle closes the
        check-then-open race: an attacker cannot swap the path between validation and use because both act on the same
        handle. Share mode omits delete so a peer cannot unlink or rename the file out from under a live holder,
        matching ``os.open``'s ``_SH_DENYNO``.

        ``NtCreateFile`` is used instead of ``CreateFileW`` because its return value carries the raw ``NTSTATUS``.
        Windows collapses a transient delete-pending name and a permanent access denial into the same Win32
        ``ERROR_ACCESS_DENIED``; the status keeps them apart, so a real denial fails fast instead of spinning until the
        caller's timeout (#604).

        The reparse option only guards the final path component; Windows still follows reparse points in intermediate
        directories. This assumes the lock file sits in a lock directory untrusted users cannot modify. A path with
        attacker-controlled parent directories would need component-by-component handle validation.

        :param path: the lock file path.
        :param mode: the permission mode; as ``os.open`` does on Windows, a cleared owner-write bit creates the file
            read-only. The attribute only takes effect when the file is created, not when an existing one is opened.

        :returns: a file descriptor owning the opened handle, or ``None`` on a sharing violation or a delete-pending
            name the caller should treat as contention and retry.

        :raises OSError: if the path resolves to a reparse point, or the open fails for any other reason, raised with
            the Win32 error the status maps to.

        �openN)�	read_onlyz1Lock file is a reparse point (symlink/junction): )�sys�auditrz�O_RDWR�O_CREAT�_nt_openr r&r(r)r+�RtlNtStatusToDosErrorr�rF�FormatError�striprVr.�GetFileInformationByHandlerfrg�CloseHandlerhrWrrd�open_osfhandle�O_NOINHERITry)�path�mode�handle�status�winerror�inforl�msgs        r<rvrv�sO��@	�	�	�&�$��b�i�i�"�*�*�&<�=�!�$�d�\�6I�2I�J�����_�$��3�5K�L�L���3�3�F�;�H��$�� 2� 2�8� <� B� B� D�d�H�U�U�*�,���3�3�F�F�L�L��<N�O��'�'�)�C��!�!�&�)��/�/�#�&�&�� � �#@�@��!�!�&�)�E�d�V�L�C��#�,��	��(�(�����R�^�^�1K�L�L���	��!�!�&�)��	�s�4F� F+c
�:�t�}tj|tj|�dd�dz}|t
k7rd|fS	t
�}tjt�|_tj|�|_
t|_tj�}t�}tj!tj|�t"tj|�tj|�d|rt$nt&t(t*t,dd�dz}tj/tj|��|t
k7rd|fS|j0xsd|fS#tj/tj|��wxYw)a�
        Open *path* through ``NtCreateFile`` and return ``(handle, status)``.

        ``RtlDosPathNameToNtPathName_U_WithStatus`` translates the Win32 path to the NT namespace, handling relative,
        drive, UNC and extended-length path forms as Win32 itself would, and allocates a buffer that
        ``RtlFreeUnicodeString`` releases. The handle is ``0`` unless the status is ``STATUS_SUCCESS``.
        Nl��r)r0r+�'RtlDosPathNameToNtPathName_U_WithStatusrFrfr&r>�sizeofr1�pointerr@rrAr
rErJ�NtCreateFilerrrrrr�RtlFreeUnicodeString�value)r�r��nt_namer��
attributesr��	io_statuss       r<r�r�sK��"�#���?�?��f�l�l�SZ�F[�]a�cg�h�ku�u���_�$��f�9��	?�+�-�J� &�
�
�.@� A�J��$*�N�N�7�$;�J�!�$9�J�!��_�_�&�F�(�*�I��#�#��L�L��(�#��L�L��,��L�L��+��09�,�?U�*�!�#�����
�
�"
�'�'����W�(=�>��_�$��f�9���|�|� �q�&�(�(��
�'�'����W�(=�>�s
�C"E0�0*Fc� �eZdZdZdd�Zdd�Zy)rrzRUses ``LockFileEx`` to hard lock a byte range of the lock file on Windows systems.c��t�rt��NotImplementedError�r|s r<r~zWindowsFileLock._acquire:���%�%r;c��t�rtr�r�s r<r�zWindowsFileLock._release=r�r;Nr�r�r:r;r<rrrr7s��`�	&�	&r;)rir�r��bool)rir�r�r�)r��strr�r�r�z
int | None)r�r�r�r�r�ztuple[int, int])M�
__future__rrzr��
contextlibr�pathlibr�typingrr�_apir	�_utilr
r�platformrFrdr
r�__annotations__rrrrrrrrrrrrrr r!r#r%r&r'r(r)�WinDLLr+r.�	Structurer0r>rJrNrV�LONGr��restyperGrErT�
c_longlongrDrH�argtypesr��LPCWSTRr�r�r��BOOLr�rcrormrprrrvr��__all__r:r;r<�<module>r�sA��"�	�
�����F��<�<�7����� *�M�:�*�!+�N�J�+�)�L�*�)�"/�.�"@�<�"O�O�Z�O���J��!"�M�:�!�+5��j�5�)3��J�3�0:�!�:�:�1;�!�:�:�+5��j�5�+5��j�5�"?�BZ�"Z�]u�"u�O�Z�u�(2��:�2�$�L�*�$�.8��
�7�+5��j�5�(*��:�*�
#-�O�Z�,�(2��:�2�,6��z�6�)3��J�3�#0�6�=�=��#9�F� �9�&3�f�m�m�J�t�&T�I�#�T�
�&�*�*�
�
�V�-�-�
�
�6�+�+�
�
�f�&�&�
�
�f�&6�&6�
�#+�-�-�F��������x���'��������)�*�����'�(�����v�(�(�)�������������������$�F��� �>F�]�]�F�2�2�:���������'�������	?�F�2�2�;�+/�F���'�,:�F�N�N�?�,K�+L�F���(�+3�>�>�F� � �(�-5�]�]�O�F� � �)�&.�o�o�%6�I���"�$,�M�M�I���!�5=�_�_�n�f�n�n�Up�Fq�4r�I�(�(�1�3;�=�=�I�(�(�0��������������������{�#�
%�I���!�$,�=�=�I��� �����������������{�#�'�I���#�&.�]�]�I���"�#�;�&2�,�&2�P8�t')�l���&�,�&���r;