File: //opt/saltstack/salt/lib/python3.10/site-packages/filelock/__pycache__/_unix.cpython-310.pyc
o
;j� � @ s� d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm Z m
Z
d dlmZ d dl
mZ ddlmZ dd lmZ d
ZejdkrJG dd
� d
e�Zn&zd dlZejejejejfZW n eefye Y nw dZG dd
� d
e�Zd
dgZdS )� )�annotationsN)�suppress)�EAGAIN�ENOSYS�EWOULDBLOCK)�Path)�cast� )�BaseFileLock)�ensure_directory_existsF�win32c @ s$ e Zd ZdZd dd�Zd dd�ZdS )
�UnixFileLockzHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.�return�Nonec C � t ��N��NotImplementedError��self� r �B/opt/saltstack/salt/lib/python3.10/site-packages/filelock/_unix.py�_acquire � �UnixFileLock._acquirec C r r r r r r r �_release r �UnixFileLock._releaseN�r r )�__name__�
__module__�__qualname__�__doc__r r r r r r r
s
r
Tc @ s. e Zd ZdZddd�Zddd�Zddd �Zd
S )r
a0
Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems.
Lock file cleanup: Unix and macOS delete the lock file reliably after release, even in
multi-threaded scenarios. Unlike Windows, Unix allows unlinking files that other processes
have open.
r r c C s� t | j� tjtjB }ttdd �}|d ur||O }|tjO }| �� }z
t�| j||�}W n@ t yB | jrAt
| j�j�� rAY d S � t
yl t
| j��� sP� zt�| j|tj @ |�}W n t yi Y Y d S w Y nw | jr�tt
�� t�|| jj� W d � n1 s�w Y zt�|tjtjB � W nO ty� } zCt�|� |jtkr�tt�� t
| j��� W d � n1 s�w Y | �� | �� W Y d }~d S |jtthvr܂ W Y d }~d S d }~ww t� |�j!dkr�t�|� d S || j_"d S )N�
O_NOFOLLOWr )#r � lock_file�os�O_RDWR�O_TRUNC�getattr�O_CREATZ
_open_mode�open�FileNotFoundErrorr �parent�exists�PermissionErrorZhas_explicit_moder �fchmod�_context�mode�fcntl�flock�LOCK_EX�LOCK_NB�OSError�close�errnor �unlink�_fallback_to_soft_lockr r r �fstat�st_nlink�lock_file_fd)r Z
open_flagsZ
o_nofollowZ open_mode�fd� exceptionr r r r . s\
���
�
����
r c C sH ddl m} tjddd� ddlm}m} t| |�r|| _d S || _d S )Nr )�SoftFileLockzDflock not supported on this filesystem, falling back to SoftFileLock� )�
stacklevel)�AsyncSoftFileLock�BaseAsyncFileLock) Z_softr? �warnings�warnZasynciorB rC �
isinstance� __class__)r r? rB rC r r r r9 _ s z#UnixFileLock._fallback_to_soft_lockc C s� t d| jj�}d | j_tt�� t| j��� W d � n1 s!w Y t� |tj
� tt�� t�|� W d � d S 1 sBw Y d S )N�int)
r r/ r<