JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/certbot/_internal/__pycache__/lock.cpython-39.pyc

a

}|�g�'�@s�dZddlZddlZddlmZddlmZddlmZddlm	Z	zddl
Z
WneynddlZdZ
Yn0dZ
e�e�ZGd	d
�d
�ZGdd�d�ZGd
d�de�ZGdd�de�Zeed�dd�ZdS)zZImplements file locks compatible with Linux and Windows for locking files and directories.�N)�Optional)�errors)�
filesystem)�osFTc@sXeZdZdZedd�dd�Zed�dd�Zdd�d	d
�Zdd�dd�Ze	d�d
d�Z
dS)�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.
    N��path�returncCs(||_trtnt}||�|_|��dS)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)�selfrZ	mechanism�r�:/usr/lib/python3.9/site-packages/certbot/_internal/lock.py�__init__$s
zLockFile.__init__�r	cCs0d�|jj|j�}|��r$|d7}n|d7}|S)Nz
{0}({1}) <z	acquired>z	released>)�format�	__class__�__name__r
�	is_locked)r�repr_strrrr�__repr__/s

zLockFile.__repr__cCs|j��dS)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�rrrrr7szLockFile.acquirecCs|j��dS)zb
        Release the lock on the file, allowing any other Certbot instance to acquire it.
        N)r�releaserrrrr>szLockFile.releasecCs
|j��S)zu
        Check if the file is currently locked.
        :return: True if the file is locked, False otherwise
        )rrrrrrrDszLockFile.is_locked)r�
__module__�__qualname__�__doc__�strrrrr�boolrrrrrrs
rc@sFeZdZedd�dd�Zed�dd�Zdd�dd	�Zdd�d
d�ZdS)�_BaseLockMechanismNrcCs||_d|_dS)zk
        Create a lock file mechanism for Unix.
        :param str path: the path to the lock file
        N)r
�_fd)rrrrrrMsz_BaseLockMechanism.__init__rcCs
|jduS)zvCheck if lock file is currently locked.
        :return: True if the lock file is locked
        :rtype: bool
        N)r#rrrrrUsz_BaseLockMechanism.is_lockedcCsdS�Nrrrrrr\sz_BaseLockMechanism.acquirecCsdSr$rrrrrr_sz_BaseLockMechanism.release)	rrrr rr!rrrrrrrr"Lsr"c@sLeZdZdZdd�dd�Zedd�dd�Zeed�d	d
�Zdd�dd�Z	dS)
rz�
    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.
    Nrc	Csr|jdurnt�|jtjtjBd�}z2|�|�|�|�r>||_W|jdurlt�	|�q|jdurjt�	|�0qdS)zAcquire the lock.N�)
r#r�openr
r�O_CREAT�O_WRONLY�	_try_lock�
_lock_success�close)r�fdrrrrjs



�
z_UnixLockMechanism.acquire)r,r	c
Csnzt�|tjtjB�WnPtyh}z8|jtjtjfvrRt�	d|j
�t�d���WYd}~n
d}~00dS)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�lockfZLOCK_EXZLOCK_NB�OSError�errno�EACCESZEAGAIN�logger�debugr
r�	LockError)rr,�errrrrr)xs
z_UnixLockMechanism._try_lockc
Cs�ddlm}ddlm}z||j�}Wn@tyf}z(|jtjkrPWYd}~dS�WYd}~n
d}~00||�}|j|jko�|j|jkS)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)	rr8r9r
r1r2�ENOENT�st_dev�st_ino)rr,r8r9Zstat1r7Zstat2rrrr*�s
z _UnixLockMechanism._lock_successcCs|zBt�|j�W|jdur"td��zt�|j�Wd|_qxd|_0n4|jdurVtd��zt�|j�Wd|_nd|_00dS)z)Remove, close, and release the lock file.NzError, self._fd is None.)r�remover
r#�	TypeErrorr+rrrrr�s
�
z_UnixLockMechanism.release)
rrrrr�intr)r!r*rrrrrrcs

rc@s,eZdZdZdd�dd�Zdd�dd�ZdS)r
a

    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
    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.
    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.
    Nrc
Cs�tjtjBtjB}d}z$t�|j|d�}t�|tj	d�WnXt
y�}z@|rXt�|�|jtj
krf�t�d|j�t�d��WYd}~n
d}~00||_dS)zAcquire the lockNr%�r-r.)r�O_RDWRr'�O_TRUNCrr&r
�msvcrt�lockingZLK_NBLCKr1r+r2r3r4r5rr6r#)rZ	open_moder,r7rrrr�s
 z_WindowsLockMechanism.acquirec
Cs�z||jst�d��t�|jtjd�t�|j�zt�|j	�Wn2t
yr}zt�t
|��WYd}~n
d}~00Wd|_nd|_0dS)zRelease the lock.z%The lock has not been acquired first.r@N)r#r�ErrorrCrDZLK_UNLCKrr+r=r
r1r4r5r )r�errrr�s
&z_WindowsLockMechanism.release)rrrrrrrrrrr
�sr
)�dir_pathr	cCsttj�|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)rGrrr�lock_dir�srI)rr2Zlogging�typingrZcertbotrZcertbot.compatrrr/�ImportErrorrCrZ	getLoggerrr4rr"rr
r rIrrrr�<module>s$

6U=
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&|ML0Zrm1[HXPlPR0'G=i2N+0e2]]9VTPO׮7h(F*癈'=QVZDF,d߬~TX G[`le69CR(!S2!P <0x<!1AQ "Raq02Br#SCTb ?Ζ"]mH5WR7k.ۛ!}Q~+yԏz|@T20S~Kek *zFf^2X*(@8r?CIuI|֓>^ExLgNUY+{.RѪ τV׸YTD I62'8Y27'\TP.6d&˦@Vqi|8-OΕ]ʔ U=TL8=;6c| !qfF3aů&~$l}'NWUs$Uk^SV:U# 6w++s&r+nڐ{@29 gL u"TÙM=6(^"7r}=6YݾlCuhquympǦ GjhsǜNlɻ}o7#S6aw4!OSrD57%|?x>L |/nD6?/8w#[)L7+6〼T ATg!%5MmZ/c-{1_Je"|^$'O&ޱմTrb$w)R$& N1EtdU3Uȉ1pM"N*(DNyd96.(jQ)X 5cQɎMyW?Q*!R>6=7)Xj5`J]e8%t!+'!1Q5 !1 AQaqё#2"0BRb?Gt^## .llQT $v,,m㵜5ubV =sY+@d{N! dnO<.-B;_wJt6;QJd.Qc%p{ 1,sNDdFHI0ГoXшe黅XۢF:)[FGXƹ/w_cMeD,ʡcc.WDtA$j@:) -# u c1<@ۗ9F)KJ-hpP]_x[qBlbpʖw q"LFGdƶ*s+ډ_Zc"?%t[IP 6J]#=ɺVvvCGsGh1 >)6|ey?Lӣm,4GWUi`]uJVoVDG< SB6ϏQ@ TiUlyOU0kfV~~}SZ@*WUUi##; s/[=!7}"WN]'(L! ~y5g9T̅JkbM' +s:S +B)v@Mj e Cf jE 0Y\QnzG1д~Wo{T9?`Rmyhsy3!HAD]mc1~2LSu7xT;j$`}4->L#vzŏILS ֭T{rjGKC;bpU=-`BsK.SFw4Mq]ZdHS0)tLg