HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/duplicity/backends/__pycache__/par2backend.cpython-310.pyc
o

�xa;$�@snddlZddlZddlmZddlmZddlmZddlmZddlmZGdd�dej	�Z
e�d	e
�dS)
�N)�backend)�BackendException)�log)�config)�utilc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�Par2Backendz�This backend wrap around other backends and create Par2 recovery files
    before the file and the Par2 files are transfered with the wrapped backend.

    If a received file is corrupt it will try to repair it on the fly.
    c	Cs�tj�||�zddlaWnty�w||_ztj|_Wnt	y+d|_Ynwztj
|_Wnt	y>d|_Ynwztjd|_
Wnt	ySd|_
Ynwt�|j�|_dD]}t|j|�rrt||t||dd���q]|j|_dS)Nr�
�z -q -qz-q -q)�_get�_put�_list�_delete�_delete_list�_query�_query_list�_retry_cleanup�_error_code�_move�_close)r�Backend�__init__�pexpect�ImportError�
parsed_urlr�par2_redundancy�
redundancy�AttributeError�par2_volumes�volumes�par2_options�common_options�get_backend_object�
url_string�wrapped_backend�hasattr�setattr�getattr�delete_listr)�selfr�attr�r*�@/usr/lib/python3/dist-packages/duplicity/backends/par2backend.pyr$s8�
�
�
��zPar2Backend.__init__cCsP|��}|��|�|�}|��}tj�|�s#tj�t�	t�
��|�}t�||���|��t
�d�d|j|j|jt�|���f}t�|dd�\}}	|	rrt
�d�d|j|jt�|���f}t�|dd�\}}	|	srt
�d�|��g}
|	s�|��D]
}|
�|�|��q~nt
�d|	�|||�|
D]	}|||���q�|��dS)	a3create Par2 files and transfer the given file and the Par2 files
        with the wrapped backend.

        Par2 must run on the real filename or it would restore the
        temp-filename later on. So first of all create a tempdir and symlink
        the soure_path with remote_filename into this.
        zCreate Par2 recovery fileszpar2 c -r%d -n%d %s "%s"NTzDFailed to create par2 file with requested options, retrying with -n1zpar2 c -r%d -n1 %s "%s"z'Successfully created par2 file with -n1z-FAILED to create par2 file with returncode %d)�get_temp_in_same_dir�mkdir�append�
get_canonical�os�path�isabs�joinr�fsencode�getcwd�symlink�setdatar�Inforrr �fsdecoder�run�Warn�delete�listdir�Error�get_filename�deltree)r(�method�source_path�remote_filename�par2temp�source_symlink�
source_target�
par2create�out�
returncode�files_to_transfer�filer*r*r+�transferIsB


�

�
�
zPar2Backend.transfercC�|�|jj||�dS�N)rLr#r�r(�local�remoter*r*r+�putv�zPar2Backend.putcCrMrN)rLr#rrOr*r*r+�moveyrSzPar2Backend.movec
	s�|��}|��|�|�}|j�||�z�z�|�|d�}|j�|��|�d|jt�|�	��t�|�	��f}t
�|dd�\}}|r�t�
d|�t�d|�����fdd�|j��D�}	|	D]}
|�|
�}|j�|
|�qad	|jt�|�	��t�|�	��f}t
�|dd�\}}|r�t�d
|�nt�
d|�Wn	ty�Yn
wW|�|�|��dSW|�|�|��dS|�|�|��w)atransfer remote_filename and the related .par2 file into
        a temp-dir. remote_filename will be renamed into local_path before
        finishing.

        If "par2 verify" detect an error transfer the Par2-volumes into the
        temp-dir and try to repair.
        s.par2zpar2 v %s %s "%s"NTz!File is corrupt. Try to repair %sz%s\.vol[\d+]*\.par2cs g|]}��t�|��r|�qSr*)�matchrr9)�.0�f��cr*r+�
<listcomp>�s z#Par2Backend.get.<locals>.<listcomp>zpar2 r %s %s "%s"zFailed to repair %szRepair successful %s)r,r-r.r#r
r?r rr9r/rr:rr;�re�compile�decoderr>r�renamer@)
r(rC�
local_pathrD�local_path_temp�par2file�
par2verifyrHrI�par2volumes�filenamerK�
par2repairr*rXr+�get|sN	
�
����
�

�
zPar2Backend.getcCsX|j�|�|��}t�dt�|��}|D]}|�t�|��r)|j�t�|��qdS)z2delete given filename and its .par2 files
        �%s(?:\.vol[\d+]*)?\.par2N)	r#r
�unfiltered_listr[r\rr9rUr4)r(rd�remote_listrYrCr*r*r+r<�s��zPar2Backend.deletecCs�|��}|dd�D]}t�dt�|��}|D]}|�t�|��r(|�d|�qq
t|jd�r6|j�	|�S|D]}|j�
|�q8dS)zKdelete given filename_list and all .par2 files that belong to them
        Nrgrr)rhr[r\rr9rU�insertr$r#rr
)r(�
filename_listrirdrYrCr*r*r+r'�s���zPar2Backend.delete_listcCs@|j��}t�d�}g}|D]}|�t�|��r|�|�q|S)z�
        Return list of filenames (byte strings) present in backend

        Files ending with ".par2" will be excluded from the list.
        z
(?!.*\.par2$))r#rr[r\rUrr9r.)r(rirY�
filtered_listrdr*r*r+�list�s


�zPar2Backend.listcCs
|j��SrN)r#r�r(r*r*r+rh�s
zPar2Backend.unfiltered_listcC�|j��dSrN)r#rrnr*r*r+�
retry_cleanup��zPar2Backend.retry_cleanupcCs|j�||�SrN)r#r)r(�	operation�er*r*r+�
error_code�rqzPar2Backend.error_codecC�|j�|�SrN�r#r)r(rdr*r*r+�query��zPar2Backend.querycCrurNrv)r(rkr*r*r+�
query_list�rxzPar2Backend.query_listcCrorN)r#rrnr*r*r+�close�rqzPar2Backend.closeN)�__name__�
__module__�__qualname__�__doc__rrLrRrTrfr<r'rmrhrprtrwryrzr*r*r*r+rs %-1r�par2)r0r[�	duplicityr�duplicity.errorsrrrrrr�register_backend_prefixr*r*r*r+�<module>sP