o
    /ig                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ ddlmZ dd	lmZmZ ejd
krkd dlZd dlZd dlmZ dZdZejdddZejgej_ejej_dddZG dd deZnG dd deZdgZ dS )    )annotationsN)suppress)EACCES)Path)cast   )BaseFileLock)ensure_directory_existsraise_on_not_writable_filewin32)wintypesi   l    Zkernel32T)Zuse_last_errorpathstrreturnboolc                 C  sB   t | }|tkrt }|dkrdS |dkrdS dS t|t@ S )a  
        Check if a path is a reparse point (symlink, junction, etc.) on Windows.

        :param path: Path to check

        :returns: True if path is a reparse point, False otherwise

        :raises OSError: If GetFileAttributesW fails for reasons other than file-not-found

           F   )	_kernel32GetFileAttributesWINVALID_FILE_ATTRIBUTESctypesZget_last_errorr   FILE_ATTRIBUTE_REPARSE_POINT)r   attrserr r   K/home/kim/smarthome/.venv/lib/python3.10/site-packages/filelock/_windows.py_is_reparse_point   s   
r   c                   @  $   e Zd ZdZd	ddZd	ddZdS )
WindowsFileLocka~  
        Uses the :func:`msvcrt.locking` function to hard lock 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.
        r   Nonec              
   C  s   t | j t| j t| jrd| j }t|tjtjB }zt| j|| 	 }W n tyD } z|j
tkr9 W Y d }~d S d }~ww z
t|tjd W n tym } zt| |j
tkrb W Y d }~d S d }~ww || j_d S )Nz1Lock file is a reparse point (symlink/junction): r   )r
   	lock_filer	   r   OSErrorosO_RDWRO_CREATopenZ
_open_modeerrnor   msvcrtlockingZLK_NBLCKclose_contextlock_file_fd)selfmsgflagsfd	exceptionr   r   r   _acquire;   s6   





WindowsFileLock._acquirec                 C  sl   t d| jj}d | j_t|tjd t| tt	 t
| j  W d    d S 1 s/w   Y  d S )Nintr   )r   r*   r+   r'   r(   ZLK_UNLCKr"   r)   r   r!   r   r    unlink)r,   r/   r   r   r   _releaseX   s   

"WindowsFileLock._releaseNr   r   __name__
__module____qualname____doc__r1   r5   r   r   r   r   r   2   s    
r   c                   @  r   )
r   zWUses the :func:`msvcrt.locking` function to hard lock the lock file on Windows systems.r   r   c                 C     t NNotImplementedErrorr,   r   r   r   r1   f      r2   c                 C  r=   r>   r?   rA   r   r   r   r5   i   rB   r6   Nr7   r8   r   r   r   r   r   c   s    
)r   r   r   r   )!
__future__r   r"   sys
contextlibr   r&   r   pathlibr   typingr   Z_apir   Z_utilr	   r
   platformr   r'   r   r   r   ZWinDLLr   ZLPCWSTRr   argtypesZDWORDrestyper   r   __all__r   r   r   r   <module>   s.    


1