File: //opt/saltstack/salt/lib/python3.10/site-packages/filelock/__pycache__/_soft.cpython-310.pyc
o
;j�! � @ s� d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm Z m
Z
mZmZ d dl
mZ ddlmZ ddlmZmZ d Zd
ZdZdZd
ZG dd� de�Zddd�ZdgZdS )� )�annotationsN)�suppress)�EACCES�EEXIST�EPERM�ESRCH)�Path� )�BaseFileLock)�ensure_directory_exists�raise_on_not_writable_filei �W i g @i c @ s� e Zd ZdZd dd�Zd dd�Zd dd �Zed!d
d��Zed"dd��Z ed#dd��Z
ed$dd��Zed%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
C s� t | j� t| j� tjtjB tjB tjB }ttdd � }d ur$||O }zt� | j|| �
� �}W n' tyW } z|jt
ksH|jtkrGtjdksH� | �� W Y d }~d S d }~ww | �|� || j_d S )N�
O_NOFOLLOW�win32)r � lock_filer �os�O_WRONLY�O_CREAT�O_EXCL�O_TRUNC�getattr�openZ
_open_mode�OSError�errnor r �sys�platform�_try_break_stale_lock�_write_lock_info�_context�lock_file_fd)�self�flagsZ
o_nofollowZfile_handler� exception� r&