HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/filelock/__pycache__/_soft.cpython-310.pyc
o

;j�!�@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZddl
mZddlmZddlmZmZd	Zd
ZdZdZd
ZGdd�de�Zddd�ZdgZdS)�)�annotationsN)�suppress)�EACCES�EEXIST�EPERM�ESRCH)�Path�)�BaseFileLock)�ensure_directory_exists�raise_on_not_writable_filei�Wig@ic@s�eZdZdZd dd�Zd dd�Zd dd	�Zed!d
d��Zed"dd��Z	ed#dd��Z
ed$dd��Zed%dd��Z
d dd�Zd dd�Zd dd�ZdS)&�SoftFileLocka�
    Portable file lock based on file existence.

    Unlike :class:`UnixFileLock <filelock.UnixFileLock>` and :class:`WindowsFileLock <filelock.WindowsFileLock>`, this
    lock does not use OS-level locking primitives. Instead, it creates the lock file with ``O_CREAT | O_EXCL`` and
    treats its existence as the lock indicator. This makes it work on any filesystem but leaves stale lock files behind
    if the process crashes without releasing the lock.

    To mitigate stale locks, the lock file contains the PID and hostname of the holding process. On contention, if the
    holder is on the same host and its PID no longer exists, the stale lock is broken automatically.

    �return�Nonec
Cs�t|j�t|j�tjtjBtjBtjB}ttdd�}dur$||O}zt�	|j||�
��}Wn'tyW}z|jt
ksH|jtkrGtjdksH�|��WYd}~dSd}~ww|�|�||j_dS)N�
O_NOFOLLOW�win32)r�	lock_filer�os�O_WRONLY�O_CREAT�O_EXCL�O_TRUNC�getattr�openZ
_open_mode�OSError�errnorr�sys�platform�_try_break_stale_lock�_write_lock_info�_context�lock_file_fd)�self�flagsZ
o_nofollowZfile_handler�	exception�r&�B/opt/saltstack/salt/lib/python3.10/site-packages/filelock/_soft.py�_acquire#s,

������
zSoftFileLock._acquirec
CsDttt���t|j�\}}|r|����ng}t|�dvr2t��|t	kr)|�
�	Wd�dS|d|d}}t|�dkrE|dnd}|t��krV	Wd�dSt
|�}|�|�r�tjdkr�|dur�t
|�}|�|�}	|	durz|	|krzn	Wd�dS	Wd�dS|�
�Wd�dS1s�wYdS)N>��rr	r*r)r)rr�
ValueError�_read_lock_filer�strip�
splitlines�len�time�_MALFORMED_LOCK_AGE_THRESHOLD�_evict_lock_file�socket�gethostname�int�_is_process_aliverr�_get_process_creation_time)
r#�content�mtime�linesZpid_str�hostnameZcreation_time_str�pidZstored�actualr&r&r'r:s4�	�

��
"�z"SoftFileLock._try_break_stale_lockcCs4|j�dt����}t|j��|�t|���dS)Nz.break.)rr�getpidr�rename�unlink)r#Z
break_pathr&r&r'r2YszSoftFileLock._evict_lock_filer<r5�boolc
Cs�tjdkr#ddl}|jj}|�td|�}|r|�|�dS|��t	kSz	t
�|d�WdStyQ}z|j
tkr@WYd}~dS|j
tkrLWYd}~dS�d}~ww)NrrTF)rr�ctypes�windll�kernel32�OpenProcess�_WIN_SYNCHRONIZE�CloseHandleZGetLastError�_WIN_ERROR_INVALID_PARAMETERr�killrrrr)r<rBrD�handle�excr&r&r'r6^s&

�

��zSoftFileLock._is_process_alive�
int | Nonec		Cs�tjdkrdSddl}ddlm}|jj}|�td|�}|s dSz4|��}|��}|��}|��}|�	||�
|�|�
|�|�
|�|�
|��sNW|�|�dSW|�|�n|�|�w|jd>|j
BS)zRReturn the process creation FILETIME as an integer on Windows, ``None`` otherwise.rNr)�wintypes� )rrrBrMrCrDrE�&_WIN_PROCESS_QUERY_LIMITED_INFORMATIONZFILETIMEZGetProcessTimes�byrefrGZdwHighDateTimeZ
dwLowDateTime)	r<rBrMrDrJZcreationZ	exit_timeZkernel_timeZ	user_timer&r&r'r7ss2
��	z'SoftFileLock._get_process_creation_time�fdcCs�tt��4t���dt���d�}tjdkr(t�	t���}dur(||�d�7}t�
||���Wd�dS1s;wYdS)N�
r)rrrr>r3r4rrrr7�write�encode)rQ�info�ctr&r&r'r �s
 "�zSoftFileLock._write_lock_infocCs|ttt��/t|j�\}}|r$|����}r,t|d�Wd�SWd�dSWd�dS1s7wYdS)z�
        The PID of the process holding this lock, read from the lock file.

        :returns: the PID as an integer, or ``None`` if the lock file does not exist or cannot be parsed

        rN)rrr+r,rr-r.r5)r#r8�_r:r&r&r'r<�s
�
��
��zSoftFileLock.pidcCs|jt��kS)z�
        Whether this lock is held by the current process.

        :returns: ``True`` if the lock file exists and contains the current process's PID

        )r<rr>�r#r&r&r'�is_lock_held_by_us�szSoftFileLock.is_lock_held_by_uscCs<tt��t|j���Wd�dS1swYdS)zNForcibly break the lock by removing the lock file, regardless of who holds it.N)rrrrr@rXr&r&r'�
break_lock�s
"�zSoftFileLock.break_lockcCsx|jjdusJ�t�|jj�d|j_tjdkr|��dStt��t	|j
���Wd�dS1s5wYdS)Nr)r!r"r�closerr�_windows_unlink_with_retryrrrrr@rXr&r&r'�_release�s

"�zSoftFileLock._releasecCs�d}d}t|�D]=}zt|j���WdStyE}z$|jtthvr,WYd}~dS||dkr;t�	|�|d9}WYd}~qd}~wwdS)N�
g����MbP?r	r))
�rangerrr@rrrrr0�sleep)r#Zmax_retriesZretry_delay�attemptrKr&r&r'r\�s�
���z'SoftFileLock._windows_unlink_with_retryN)rr)r<r5rrA)r<r5rrL)rQr5rr)rrL)rrA)�__name__�
__module__�__qualname__�__doc__r(rr2�staticmethodr6r7r �propertyr<rYrZr]r\r&r&r&r'rs$




	

r�path�strr�tuple[str | None, float]c	Cs�t�|tjttdd�Bttdd�B�}zt�|�jt�|td�}}Wt�|�nt�|�wt	|�tkrQt
t��|�d�|fWd�S1sLwYd|fS)Nrr�
O_NONBLOCKr	zutf-8)
rr�O_RDONLYr�fstat�st_mtime�read�_MAX_LOCK_FILE_SIZEr[r/r�UnicodeDecodeError�decode)rhrQr9�datar&r&r'r,�s& 
 �r,)rhrirrj)�
__future__rrr3rr0�
contextlibrrrrrr�pathlibrZ_apir
Z_utilrrrFrHrOr1rprr,�__all__r&r&r&r'�<module>s(
<�