HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //lib64/python3.9/site-packages/borg/__pycache__/locking.cpython-39.opt-1.pyc
a

HZ�h1@�@sddlZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZd\ZZ
Zd\ZZee�Z
Gdd	�d	�ZGd
d�de�ZGdd
�d
e	�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�d�ZGdd�d�ZGdd�d�ZdS)�N�)�platform)�Error�ErrorWithTraceback)�
create_logger)�add�removeZremove2)Zshared�	exclusivec@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TimeoutTimerz�
    A timer for timeout checks (can also deal with "never timeout").
    It can also compute and optionally execute a reasonable sleep time (e.g. to avoid
    polling too often or to support thread/process rescheduling).
    NcCsX|dur|dkrtd��||_|durB|dur4d}ntd|d�}||_d|_d|_dS)ag
        Initialize a timer.

        :param timeout: time out interval [s] or None (never timeout, wait forever) [default]
        :param sleep: sleep interval [s] (>= 0: do sleep call, <0: don't call sleep)
                      or None (autocompute: use 10% of timeout [but not more than 60s],
                      or 1s for "never timeout" mode)
        Nrztimeout must be >= 0g�?gN@g$@)�
ValueError�timeout_interval�min�sleep_interval�
start_time�end_time)�self�timeout�sleep�r�2/usr/lib64/python3.9/site-packages/borg/locking.py�__init__s	zTimeoutTimer.__init__cCsd�|jj|j|j|j|j�S)Nz1<{}: start={!r} end={!r} timeout={!r} sleep={!r}>)�format�	__class__�__name__rrrr�rrrr�__repr__,s�zTimeoutTimer.__repr__cCs&t��|_|jdur"|j|j|_|S�N)�timerrrrrrr�start1s

zTimeoutTimer.startcCs|jdkrt�|j�dS�Nr)rrrrrrrr7s
zTimeoutTimer.sleepcCs|jduot��|jkSr)rrrrrr�	timed_out;szTimeoutTimer.timed_outcCs|��rdS|��dSdS)NTF)r rrrrr�timed_out_or_sleep>szTimeoutTimer.timed_out_or_sleep)NN)
r�
__module__�__qualname__�__doc__rrrrr r!rrrrr
s
r
c@seZdZdZdS)�	LockError�Failed to acquire the lock {}.N�rr"r#r$rrrrr%Fsr%c@seZdZdZdS)�
LockErrorTr&Nr'rrrrr(Jsr(c@seZdZdZdS)�LockTimeoutz/Failed to create/acquire the lock {} (timeout).Nr'rrrrr)Nsr)c@seZdZdZdS)�
LockFailedz*Failed to create/acquire the lock {} ({}).Nr'rrrrr*Rsr*c@seZdZdZdS)�	NotLockedz/Failed to release the lock {} (was not locked).Nr'rrrrr+Vsr+c@seZdZdZdS)�	NotMyLockz=Failed to release the lock {} (was/is locked, but not by me).Nr'rrrrr,Zsr,c@sleZdZdZddd�Zdd�Zdd�Zd	d
�Zddd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�
ExclusiveLocka/An exclusive Lock based on mkdir fs operation being atomic.

    If possible, try to use the contextmanager here like::

        with ExclusiveLock(...) as lock:
            ...

    This makes sure the lock is released again if the block is left, no
    matter how (e.g. if an exception occurred).
    NcCsP||_||_tj�|�|_|p$t��|_tj�|jd|j�|_	d|_
d|_dS)N�%s.%d-%xTF)rr�os�path�abspathr�get_process_id�id�join�unique_name�kill_stale_locks�stale_warning_printed)rr0rrr3rrrriszExclusiveLock.__init__cCs|��Sr��acquirerrrr�	__enter__rszExclusiveLock.__enter__cGs|��dSr��release�r�excrrr�__exit__uszExclusiveLock.__exit__cCsd|jj�d|j�d�S�N�<z: �>)rrr5rrrrrxszExclusiveLock.__repr__c
CsR|dur|j}|dur|j}tj�|j�\}}tj�|j�}d}�z�zNt�d|d|�}tj�	||�}t
|d��Wd�n1s�0YWn8ty�}z t|jt
|��d�WYd}~�nd}~00t||���}	zt�||j�Wn�t�yt|���rR|YW|du�rPzt�|�WnYn0zt�|�WSYS0S|��|	���rpt|j�d�Yq�0d}|W|du�r�zt�|�WnYn0zt�|�WSYS0Sq�W|du�rNzt�|�WnYn0zt�|�WnYn0nD|du�rLzt�|�WnYn0zt�|�WnYn00dS)Nz.tmp�.�wb)rrr/r0�split�basenamer5�tempfileZmkdtempr4�open�OSErrorr*�strr
r�replace�by_me�unlink�rmdir�kill_stale_lockr!r))
rrr�parent_path�	base_nameZunique_base_nameZ	temp_pathZtemp_unique_name�err�timerrrrr9{s~"*

�

�
�
zExclusiveLock.acquirec
Cs�|��st|j��|��s$t|j��t�|j�zt�|j�Wn>t	y~}z&|j
t
jt
jt
j
fvrj|�WYd}~n
d}~00dSr)�	is_lockedr+r0rLr,r/rMr5rNrI�errno�	ENOTEMPTY�EEXIST�ENOENT)rrRrrrr<�s

zExclusiveLock.releasecCstj�|j�Sr)r/r0�existsrrrrrT�szExclusiveLock.is_lockedcCstj�|j�Sr)r/r0rYr5rrrrrL�szExclusiveLock.by_mec
Cs�zt�|j�}Wnty$Y�n0|D�]}z6|�dd�\}}|�dd�\}}t|�}t|d�}Wn&ty�t�d||j�YdS0t	�
|||�r�dS|js�|js�t�
d|�d|_dSz&t�tj�|j|��t�
d	|�Wq*t�y6}	z0|j�st�d
|t|	��d|_WYd}	~	dSd}	~	00q*zt�|j�Wn^t�y�}	zD|	jtjtjtjfv�r�WYd}	~	dSt�dt|	��WYd}	~	dSd}	~	00dS)N�-rrC�z9Found malformed lock %s in %s. Please check/fix manually.FzLFound stale lock %s, but not deleting because self.kill_stale_locks = False.TzKilled stale lock %s.z0Found stale lock %s, but cannot delete due to %szFailed to remove lock dir: %s)r/�listdirr0�FileNotFoundError�rsplit�intr�logger�errorr�
process_aliver6r7�warningrMr4rIrJrNrUrVrWrX)
r�names�nameZhost_pidZ
thread_str�hostZpid_str�pid�threadrRrrrrO�sH

zExclusiveLock.kill_stale_lockcCs@|��r<t�|j�D]}t�tj�|j|��qt�|j�dSr)rTr/r\r0rMr4rN)rrerrr�
break_lock�szExclusiveLock.break_lockcCsltj�|jd|�}|��rZ|��rZt|d��Wd�n1sD0Yt�|j�|||_|_dS)�0migrate the lock ownership from old_id to new_idr.rDN)	r/r0r4rTrLrHrMr5r3)r�old_id�new_idZnew_unique_namerrr�migrate_lock�szExclusiveLock.migrate_lock)NNN)NN)rr"r#r$rr:r?rr9r<rTrLrOrirmrrrrr-^s

	
*1r-c@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�
LockRosterz�
    A Lock Roster to track shared/exclusive lockers.

    Note: you usually should call the methods with an exclusive lock held,
    to avoid conflicting access by multiple threads/processes/machines.
    NcCs||_|pt��|_d|_dS)NT)r0rr2r3r6)rr0r3rrrrszLockRoster.__init__c		Cs�z�t|j��}t�|�}Wd�n1s,0Y|jr�ttfD]|}z||}WntyjYqDYn0t�}|D]<\}}}t	�
|||�r�|�|||f�qvt�
d||||�qvt|�||<qDWnttfy�i}Yn0|S)Nz:Removed stale %s roster lock for host %s pid %d thread %d.)rHr0�json�loadr6�SHARED�	EXCLUSIVE�KeyError�setrrbrr`rc�listr]r)	r�f�data�key�entries�elementsrfrgrhrrrrp	s((
�
zLockRoster.loadcCs<t|jd��}t�||�Wd�n1s.0YdS)N�w)rHr0ro�dump)rrwrvrrr�save"szLockRoster.savecCs(zt�|j�Wnty"Yn0dSr)r/rMr0r]rrrrr&szLockRoster.removecCs|��}dd�|�|g�D�S)NcSsh|]}t|��qSr��tuple��.0�errr�	<setcomp>.�z!LockRoster.get.<locals>.<setcomp>)rp�get)rrx�rosterrrrr�,szLockRoster.getcst�fdd�|D��S)Nc3s|]}��|�VqdSr)r�)r�rxrrr�	<genexpr>1r�z#LockRoster.empty.<locals>.<genexpr>)�all)r�keysrrr�empty0szLockRoster.emptycCs�|��}zdd�||D�}Wnty6t�}Yn0|tkrN|�|j�n8|tkrd|�|j�n"|tkrz|�	|j�nt
d|��tdd�|D��||<|�|�dS)NcSsh|]}t|��qSrr~r�rrrr�6r�z$LockRoster.modify.<locals>.<setcomp>zUnknown LockRoster op %rcss|]}t|�VqdSr)rur�rrrr�Dr�z$LockRoster.modify.<locals>.<genexpr>)
rprsrt�ADDrr3�REMOVE�discard�REMOVE2rrrur})rrx�opr�rzrrr�modify3szLockRoster.modifycCsb|jd}|_zFz|�|t�Wnty8||_Yn0||_|�|t�W||_n||_0dS)rjFN)r6r�r�rsr3r�)rrxrkrlZkillingrrrrmGszLockRoster.migrate_lock)N)rr"r#r$rrpr}rr�r�r�rmrrrrrn�s
rnc@steZdZdZddd�Zdd�Zdd	�Zd
d�Zddd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�Locka�
    A Lock for a resource that can be accessed in a shared or exclusive way.
    Typically, write access to a resource needs an exclusive lock (1 writer,
    no one is allowed reading) and read access to a resource needs a shared
    lock (multiple readers are allowed).

    If possible, try to use the contextmanager here like::

        with Lock(...) as lock:
            ...

    This makes sure the lock is released again if the block is left, no
    matter how (e.g. if an exception occurred).
    FNcCsP||_||_||_||_|p"t��|_t|d|d�|_t	|d||d�|_
dS)Nz.roster)r3z
.exclusive)r3r)r0�is_exclusiverrrr2r3rn�_rosterr-�_lock)rr0r	rrr3rrrrjsz
Lock.__init__cCs|��Srr8rrrrr:wszLock.__enter__cGs|��dSrr;r=rrrr?zsz
Lock.__exit__cCsd|jj�d|j�d�Sr@)rrr3rrrrr}sz
Lock.__repr__cCs�|dur|j}|p|jpd}|r<|�||�|j�tt�nJ|j�4|durZ|j�|t�|j�t	t�Wd�n1s|0Y||_|S)Ng�������?)
r�r�_wait_for_readers_finishingr�r�rrr�r�r�rq)rr	rrrrrr9�s,zLock.acquirecCs�t|j|���}|j��zJ|dur2|j�|t�t|j�	t
��dkrLWdS|durb|j�|t�Wn|j���Yn0|j��|�
�rt|j��qdSr)r
rrr�r9r�r�r��lenr�rqr�r<r!r)r0)rrrrSrrrr��s


z Lock._wait_for_readers_finishingcCs�|jr8|j�tt�|j�tt�r,|j��|j�	�nL|j�6|j�tt�|j�tt�rf|j��Wd�n1sz0YdSr)
r�r�r�rrr�r�rqrr�r<rrrrr<�s
zLock.releasecCs|js|jdtd�dS)NT�r	r)r�r9rqrrrr�upgrade�szLock.upgradecCs|jr|jdtd�dS)NFr�)r�r9rrrrrr�	downgrade�szLock.downgradecCs|jo|j��o|j��Sr)r�r�rTrLrrrr�got_exclusive_lock�szLock.got_exclusive_lockcCs|j��|j��dSr)r�rr�rirrrrri�s
zLock.break_lockcCst||_|jr,|j�||�|j�t||�nD|j�.|j�||�|j�t||�Wd�n1sf0YdSr)r3r�r�rmr�rrrq)rrkrlrrrrm�szLock.migrate_lock)FNNN)NNN)rr"r#r$rr:r?rr9r�r<r�r�r�rirmrrrrr�[s


r�)rUror/rGr�rZhelpersrrr`rr�r�r�rqrrrr
r%r(r)r*r+r,r-rnr�rrrr�<module>s*
5 ^