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: //usr/lib64/python3.9/site-packages/borg/testsuite/__pycache__/repository.cpython-39.opt-1.pyc
a

HZ�h>��@s�ddlZddlZddlZddlZddlZddlZddlmZddlZddl	m
Z
ddlmZddlm
Z
ddlmZddlmZmZdd	lmZmZmZmZmZdd
lmZmZmZmZmZmZmZddl m!Z!dd
l	m"Z"e#�Z$Gdd�de!�Z%Gdd�de%�Z&Gdd�de%�Z'Gdd�de%�Z(Gdd�de%�Z)Gdd�de%�Z*Gdd�de%�Z+Gdd�de%�Z,Gdd�de%�Z-Gd d!�d!e%�Z.Gd"d#�d#e%�Z/Gd$d%�d%e&�Z0Gd&d'�d'e%�Z1Gd(d)�d)e.�Z2Gd*d+�d+e!�Z3dS),�N)�patch�)�NSIndex)�Location)�IntegrityError)�msgpack)�Lock�
LockFailed)�RemoteRepository�InvalidRPCMethod�PathNotAllowed�ConnectionClosedWithHint�handle_remote_line)�
Repository�LoggedIO�MAGIC�
MAX_DATA_SIZE�
TAG_DELETE�TAG_PUT�
TAG_COMMIT�)�BaseTestCase��Hc@sPeZdZdZdZdefdd�Zdd�Zdd	�Zefd
d�Z	dd
�Z
ddd�ZdS)�RepositoryTestCaseBase� TFcCs(|tur|j}ttj�|jd�||d�S)N�
repository��	exclusive�create)�UNSPECIFIEDrr�os�path�join�tmppath)�selfrr�r&�?/usr/lib64/python3.9/site-packages/borg/testsuite/repository.py�openszRepositoryTestCaseBase.opencCs&t��|_|jdd�|_|j��dS)NT)r)�tempfileZmkdtempr$r(r�	__enter__�r%r&r&r'�setUp"s
zRepositoryTestCaseBase.setUpcCs |j�ddd�t�|j�dS�N)r�__exit__�shutil�rmtreer$r+r&r&r'�tearDown'szRepositoryTestCaseBase.tearDowncCs,|j�ddd�|j|d�|_|j��dS)N�r)rr.r(r*)r%rr&r&r'�reopen+szRepositoryTestCaseBase.reopencCs||j�td�d�|j�td�d�|j�td�d�|jjdd�|j�td�d�|j�td	�d
�|j�td��dS)Nr�foor�bar�F��compactsbar2rsboo)r�putr�commit�deleter+r&r&r'�add_keys0szRepositoryTestCaseBase.add_keysNc

Cs�|dur|dnd}dd�td�D�}d|d<tdtdtd	i}|jj��D]D\}}|jj�|�D],\}}}}	td
||||||||	f�q`qJt�dS)Nz: �cSsi|]}t|�|�qSr&r)�.0�ir&r&r'�
<dictcomp>;�z4RepositoryTestCaseBase.repo_dump.<locals>.<dictcomp>�
���r9�delZcommz%s%s H(%d) -> %s[%d..+%d])	�rangerrrr�io�segment_iterator�iter_objects�print)
r%ZlabelZH_transZ	tag_trans�segment�fn�tag�key�offset�sizer&r&r'�	repo_dump9s$z RepositoryTestCaseBase.repo_dump)N)�__name__�
__module__�__qualname__Zkey_sizerr r(r,r1r3r<rPr&r&r&r'rs	rc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�RepositoryTestCasecs�td�D]}�j�t|�d�qtd�����j���d��j�����tj	��fdd���jj
dd��j������V���tj	��fdd��td�D]$}|dkr�q�����t|��d�q�Wd�n1s�0YdS)	N�d�SOMEDATA�2cs�j���Sr-)r�getr&)�key50r%r&r'�<lambda>LrAz*RepositoryTestCase.test1.<locals>.<lambda>Fr7cs
����Sr-)rXr&)rY�repository2r&r'rZPrA)
rErr9r�assert_equalrXr;�
assert_raisesr�ObjectNotFoundr:�closer()r%�xr&)rYr[r%r'�test1Fs

zRepositoryTestCase.test1cCs~|j�td�d�|j�td�d�|jjdd�|j�td��|j�td�d�|jjdd�|�|j�td��d�dS)z.Test multiple sequential transactions
        rr4rFr7r5N)rr9rr:r;r\rXr+r&r&r'�test2VszRepositoryTestCase.test2cs��j�td�d����j�td��d��j�td�d����j�td��d��j�td�d����j�td��d��j�td����tj�fdd��dS)zTest cache consistency
        rr4�foo2r5cs�j�td��S�Nr�rrXrr&r+r&r'rZkrAz5RepositoryTestCase.test_consistency.<locals>.<lambda>N)	rr9rr\rXr;r]rr^r+r&r+r'�test_consistencyasz#RepositoryTestCase.test_consistencycCs�|j�td�d�|�|j�td��d�|jjdd�|j�td�d�|�|j�td��d�|j��|�|j�td��d�dS)� Test cache consistency2
        rr4Fr7rcN)rr9rr\rXr:�rollbackr+r&r&r'�test_consistency2ms
z$RepositoryTestCase.test_consistency2cCsN|j�td�d�|j�td�d�|jjdd�|�|j�td��d�dS)rgrr4rcFr7N)rr9rr:r\rXr+r&r&r'�"test_overwrite_in_same_transactionxsz5RepositoryTestCase.test_overwrite_in_same_transactioncCs�|j�td�d�|jjdd�|j��|��|_|j�0|j�td�d�|jjdd�Wd�n1sp0Y|��|_|j�.|j�td��|jjdd�Wd�n1s�0YdS�Nrr4Fr7r5�rr9rr:r_r(r;r+r&r&r'�test_single_kind_transactions�s

,
z0RepositoryTestCase.test_single_kind_transactionscCs�td�D]}|j�t|�d�q|jjdd�|j��}|�t|�d�|jjdd�}|�t|�d�|�||dd��|jj|dd�}|�t|�d�|�||dd��|�t|jjdd��d�dS�	NrUrVFr7rW)�limitrC)Zmarker)rErr9rr:�listr\�len�r%r`�allZ
first_halfZsecond_halfr&r&r'�	test_list�s
zRepositoryTestCase.test_listcCsjtd�D]}|j�t|�d�q|jjdd�|j��}|jjdd�}|jj|dd�}td�D]}q`dSrn)rErr9rr:�scanrrr&r&r'�	test_scan�s
zRepositoryTestCase.test_scancsLdt��j�td������j�td������t��fdd��dS)N�xrcs�j�td��d�S)Nrrw)rr9rr&�Zmax_datar%r&r'rZ�rAz7RepositoryTestCase.test_max_data_size.<locals>.<lambda>)rrr9rr\rXr]rr+r&rxr'�test_max_data_size�s�z%RepositoryTestCase.test_max_data_sizeN)rQrRrSrarbrfrirjrmrtrvryr&r&r&r'rTDsrTc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�LocalRepositoryTestCasecCs|j�d�dSrd)r�_rebuild_sparser+r&r&r'�_assert_sparse�sz&LocalRepositoryTestCase._assert_sparsecCsP|j�td�d�|j�td�d�|jjdd�|j�td�d�|��dS)Nrr4r�	123456789Fr7r5)rr9rr:r|r+r&r&r'�test_sparse1�s
z$LocalRepositoryTestCase.test_sparse1cCsN|j�td�d�|j�td�d�|jjdd�|j�td��|��dS)Nrr4rr}Fr7)rr9rr:r;r|r+r&r&r'�test_sparse2�s
z$LocalRepositoryTestCase.test_sparse2cCsN|j�td�d�|j�td��|jjj��|j�d�|jjdd�dS)Nrs1245Tr7)	rr9rr;rFZ	_write_fd�syncr{r:r+r&r&r'�test_sparse_delete�sz*LocalRepositoryTestCase.test_sparse_deletecCs�|j�td�d�|jjdd�|jj��}t|jj�|d�d��}|�t	d�Wd�n1sh0Y|j�
�|��|_|j�0|j�td�d�|jjd	d�Wd�n1s�0YdS)
Nrr4Fr7r�wbscrapcrapcrapr5T)rr9rr:rF�get_latest_segmentr(Zsegment_filename�writerr_)r%�last_segment�fr&r&r'�test_uncommitted_garbage�s,

z0LocalRepositoryTestCase.test_uncommitted_garbageN)rQrRrSr|r~rr�r�r&r&r&r'rz�s

rzc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�RepositoryCommitTestCasecCsn|��t�|jj�D]&}|�d�rt�tj�|jj|��q|��|�	t
|j�d�|�	|j��d�dS)N�index.r6T)r<r!�listdirrr"�
startswith�unlinkr#r3r\rq�check)r%�namer&r&r'�test_replay_of_missing_index�s
z5RepositoryCommitTestCase.test_replay_of_missing_indexcCsf|��d|j_z|jjdd�Wnty4Yn0|��|�t|j�d�|�|j��d�dS)NTr7r6)	r<r�compact_segmentsr:�	TypeErrorr3r\rqr�r+r&r&r'�"test_crash_before_compact_segments�sz;RepositoryCommitTestCase.test_crash_before_compact_segmentscCsf|��d|j_z|jjdd�Wnty4Yn0|��|�t|j�d�|�|j��d�dS�NFr7r6T)	r<rZwrite_indexr:r�r3r\rqr�r+r&r&r'�test_crash_before_write_indexsz6RepositoryCommitTestCase.test_crash_before_write_indexc	s����t��jj�D]&}|�d�rt�tj��jj|��qtj	t
dtd��^}�jdd��j�,��
t�fdd��|��Wd�n1s�0YWd�n1s�0YdS)Nr��upgrade�Zside_effectr2cs
t�j�Sr-�rqrr&r+r&r'rZrAzGRepositoryCommitTestCase.test_replay_lock_upgrade_old.<locals>.<lambda>�r<r!r�rr"r�r�r#r�objectrr	r3r]�assert_called_once_with�r%r�r�r&r+r'�test_replay_lock_upgrade_olds
z5RepositoryCommitTestCase.test_replay_lock_upgrade_oldc	s����t��jj�D]&}|�d�rt�tj��jj|��qtj	t
dtd��^}�jdd��j�,��
t�fdd��|��Wd�n1s�0YWd�n1s�0YdS)Nr�r�r�Fr2cs
t�j�Sr-r�r&r+r&r'rZ*rAzCRepositoryCommitTestCase.test_replay_lock_upgrade.<locals>.<lambda>r�r�r&r+r'�test_replay_lock_upgrade s
z1RepositoryCommitTestCase.test_replay_lock_upgradecCsz|��d|jj_z|jjdd�Wnty6Yn0|��|�t|j�d�|�|j�	�d�|�t|j�d�dSr�)
r<rrF�delete_segmentr:r�r3r\rqr�r+r&r&r'�-test_crash_before_deleting_compacted_segments-s
zFRepositoryCommitTestCase.test_crash_before_deleting_compacted_segmentscCs(|j�td�tj�|��|jj}dSrd)rr9rrZCOMMITr3rF)r%rFr&r&r'�test_ignores_commit_tag_in_data9sz8RepositoryCommitTestCase.test_ignores_commit_tag_in_datac	Cs|j�td�d�|j�td�d�|jjdd�|�d�|j�td��|jjdd�|�d	�|jj��d}d
}|jj�|�D]\}}}}|t	kr�|d7}q�|j�td�d�|jjdd�|�d
�|jj�
�D]$\}}|jj�|�D]\}}}}q�q�dS)Nr�1r�2Fr7zp1 p2 cTzd1 ccrr6�3zp3 cc)rr9rr:rPr;rFr�rHrrG)	r%r�Znum_deletesrLrMrNrOrJ�_r&r&r'�test_moved_deletes_are_tracked?s&



z7RepositoryCommitTestCase.test_moved_deletes_are_trackedcCs�|jjj}|j�td�d�|�}|jjdd�|j�td��|j�td�d�|�}|jj|=|jj|=|jjdd�|j�td��|jjdd�t�	tj
�|jj
d|���dS�Nrr�Fr7rTzindex.%d�rrFr�r9rr:r;r8r!r�r"r#�r%r�Zput_segmentr�r&r&r'�$test_shadowed_entries_are_preserved1\s


z=RepositoryCommitTestCase.test_shadowed_entries_are_preserved1cCs�|jjj}|j�td�d�|�}|jjdd�|j�td�d�|j�td��|j�td�d�|�}|jj|=|jj|=|jjdd�|j�td��|jjdd�t�	tj
�|jj
d|���dSr�r�r�r&r&r'�$test_shadowed_entries_are_preserved2s


z=RepositoryCommitTestCase.test_shadowed_entries_are_preserved2cCs�|j�td�d�|j�td��|jjdd�|�d�|j�td�d�|j�td��|�d�|j��|�d�|j�td�d�dS)	Nrr�Tr7zp1 d1 cczp1 d1�rr)rr9rr;r:rPrhr+r&r&r'�test_shadow_index_rollback�s



z3RepositoryCommitTestCase.test_shadow_index_rollbackN)rQrRrSr�r�r�r�r�r�r�r�r�r�r�r&r&r&r'r��s	

#0r�c@s&eZdZd	dd�Zdd�Zdd�ZdS)
�RepositoryAppendOnlyTestCaseFcCsttj�|jd�d|dd�S)NrT)rr�append_only)rr!r"r#r$�r%rr&r&r'r(�sz!RepositoryAppendOnlyTestCase.opencCs8|�t��|j��Wd�n1s*0YdSr-)r]�
ValueErrorrZdestroyr+r&r&r'�test_destroy_append_only�s(z5RepositoryAppendOnlyTestCase.test_destroy_append_onlycs��fdd�}�j�td�d��jjdd�d�j_�j�td�d��jjdd�d�j_�j�td�d��jjdd�dS)Ncstt�jj����Sr-)rqrprrFrGr&r+r&r'�segments_in_repository�szMRepositoryAppendOnlyTestCase.test_append_only.<locals>.segments_in_repositoryrr4Fr7T)rr9rr:r�)r%r�r&r+r'�test_append_only�sz-RepositoryAppendOnlyTestCase.test_append_onlyN)F)rQrRrSr(r�r�r&r&r&r'r��s
r�c@seZdZdd�Zdd�ZdS)�RepositoryFreeSpaceTestCasecCs~|��|jj�ddd�|j�d�|��|j�td�d�t�	t
j��|jjdd�Wd�n1sp0YdS)	Nr�additional_free_spaceZ1000Tsshortcut to save_configr�foobarFr7)
r<rZconfig�setZsave_keyr3r9r�pytest�raisesr�InsufficientFreeSpaceErrorr:r+r&r&r'�test_additional_free_space�s,z6RepositoryFreeSpaceTestCase.test_additional_free_spacecCs@d|j_t�tj��|��Wd�n1s20YdS)Ng@��x�D)rr�r�r�rr�r<r+r&r&r'�test_create_free_space�s&z2RepositoryFreeSpaceTestCase.test_create_free_spaceN)rQrRrSr�r�r&r&r&r'r��s
r�c@seZdZdd�Zdd�ZdS)�
QuotaTestCasecCs�|j�td�td��|j�td�td��|j�td��|jjdd�|��|j�td�d�|j�td��|jjd	d�dS)
Nri�ri.Fr7r6rAT)rr9r�bytesr;r:r3r+r&r&r'�
test_tracking�szQuotaTestCase.test_trackingcCs�d|j_|j�td�d�|jjdd�t�tj��"|j�td�d�Wd�n1s\0Yt�tj��|jjdd�Wd�n1s�0Y|�	�d|j_|j�td�d�|jjdd�dS)	NrWrrAFr7rrUT)
r�
storage_quotar9rr:r�r�rZStorageQuotaExceededr3r+r&r&r'�test_exceed_quotas0,zQuotaTestCase.test_exceed_quotaN)rQrRrSr�r�r&r&r&r'r��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�NonceReservationc	Csj|jdd�t�t��@|j�|j��Wd�n1s>0YWd�n1s\0YdS)NFr2)r3r�r��AssertionErrorrZget_free_noncer+r&r&r'�test_get_free_nonce_assertssz,NonceReservation.test_get_free_nonce_assertsc	Cs�|j��ttj�|jjd�d��}|�d�Wd�n1s@0Yttj�|jjd�d��}|�d�Wd�n1s�0YWd�n1s�0YdS)N�nonce�wZ0000000000000000Z5000000000000000)rr(r!r"r#r��r%�fdr&r&r'�test_get_free_nonce#s((z$NonceReservation.test_get_free_noncec	Csn|jdd�t�t��D|j�|j�dd�Wd�n1sB0YWd�n1s`0YdS)NFr2��)r3r�r�r�r�commit_nonce_reservationr+r&r&r'�%test_commit_nonce_reservation_asserts/sz6NonceReservation.test_commit_nonce_reservation_assertsc	Cs&|j��t�t��|j�dd�Wd�n1s80Y|j�dd�ttj�|jjd���}Wd�n1s|0Yt�t��|j�dd�Wd�n1s�0Y|j�dd�ttj�|jjd���}Wd�n1s�0YWd�n1�s0YdS)Nr��r�i)	rr�r��	Exceptionr�r(r!r"r#r�r&r&r'�test_commit_nonce_reservation5s
,,z.NonceReservation.test_commit_nonce_reservationN)rQrRrSr�r�r�r�r&r&r&r'r�sr�cs�eZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Z�ZS)!�%RepositoryAuxiliaryCorruptionTestCasecs8t���|j�td�d�|jjdd�|j��dS)Nrr4Fr7)�superr,rr9rr:r_r+��	__class__r&r'r,Gs
z+RepositoryAuxiliaryCorruptionTestCase.setUpcCsJ|j�0|j�td�d�|jjdd�Wd�n1s<0YdS)NrsfoxFr7�rr9rr:r+r&r&r'�	do_commitMsz/RepositoryAuxiliaryCorruptionTestCase.do_commitcCsNttj�|jjd�d��}|�d�Wd�n1s80Y|��dS)N�hints.1�abr}�r(r!r"r#rr�r�r�r&r&r'�test_corrupted_hintsRs(z:RepositoryAuxiliaryCorruptionTestCase.test_corrupted_hintscCs$t�tj�|jjd��|��dS�Nr��r!r�r"r#rr�r+r&r&r'�test_deleted_hintsWsz8RepositoryAuxiliaryCorruptionTestCase.test_deleted_hintscCs$t�tj�|jjd��|��dS�N�index.1r�r+r&r&r'�test_deleted_index[sz8RepositoryAuxiliaryCorruptionTestCase.test_deleted_indexcCs\tj�|jjd�}t�|�t�|�|�t��|��Wd�n1sN0YdSr��	r!r"r#rr��mkdirr]�OSErrorr�)r%�hintsr&r&r'�test_unreadable_hints_s


z;RepositoryAuxiliaryCorruptionTestCase.test_unreadable_hintscCsNttj�|jjd�d��}|�d�Wd�n1s80Y|��dS�Nr�r�r}r�r�r&r&r'�
test_indexfs(z0RepositoryAuxiliaryCorruptionTestCase.test_indexcCslttj�|jjd�d��}|�d�Wd�n1s80Y|j�Wd�n1s^0YdSr�)r(r!r"r#rr�r�r&r&r'�test_index_outside_transactionks(zDRepositoryAuxiliaryCorruptionTestCase.test_index_outside_transactioncCs�tj�|jjd�}t|d��X}|��}t�td�d�dA�	dd�}|�
td�|�}|�d�|�|�Wd�n1sz0YdS)Nr��r+br�littlerr)
r!r"r#rr(�read�int�
from_bytesr�to_bytes�replace�seekr�)r%Z
index_pathr�Z
index_dataZ
corrupted_keyZcorrupted_index_datar&r&r'�_corrupt_indexqs
z4RepositoryAuxiliaryCorruptionTestCase._corrupt_indexcCs2|��|j�Wd�n1s$0YdSr-)r�rr+r&r&r'�test_index_corruptedsz:RepositoryAuxiliaryCorruptionTestCase.test_index_corruptedc	Cs�|��tj�|jjd�}t�|�|j�Lt�tj	�� |j�
td��Wd�n1s^0YWd�n1s|0YdS)N�integrity.1r)r�r!r"r#rr�r�r�rr^rXr)r%�integrity_pathr&r&r'�&test_index_corrupted_without_integrity�s
zLRepositoryAuxiliaryCorruptionTestCase.test_index_corrupted_without_integritycCs\tj�|jjd�}t�|�t�|�|�t��|��Wd�n1sN0YdSr�r�)r%�indexr&r&r'�test_unreadable_index�s


z;RepositoryAuxiliaryCorruptionTestCase.test_unreadable_indexcCs~tj�|jjd�}t|d��(}t�ddi|�|��Wd�n1sJ0Y|j�Wd�n1sp0YdS)Nr�r�sversiong������@)r!r"r#rr(r�pack�truncate)r%r�r�r&r&r'�test_unknown_integrity_version�s��&zDRepositoryAuxiliaryCorruptionTestCase.test_unknown_integrity_versioncCs�|j�jd|j_|j�td�d�|j�td�d�|jjdd�|j�td�d�|jjdd�Wd�n1sv0Ytj�|jjd	�}t|d
��D}t	�
|�}|�d�d|dd<t	�||�|�
�Wd�n1s�0YdS)
NTrr5rsbazFr7sbazzzhints.5r�rssegments)rr�r9rr:r!r"r#r(r�unpackr�r�r�)r%Z
hints_pathr�r�r&r&r'�_subtly_corrupted_hints_setup�s,

zCRepositoryAuxiliaryCorruptionTestCase._subtly_corrupted_hints_setupcCsZ|��|j�8d|j_|j�td�d�|jjdd�Wd�n1sL0YdS)NFr6�1234Tr7)r�rr�r9rr:r+r&r&r'�test_subtly_corrupted_hints�szARepositoryAuxiliaryCorruptionTestCase.test_subtly_corrupted_hintsc	Cs�|��tj�|jjd�}t�|�|j�bd|j_|j�td�d�t	�
t��}|jjdd�Wd�n1st0YWd�n1s�0YdS)Nzintegrity.5Fr6r�Tr7)
r�r!r"r#rr�r�r9rr�r�r�r:)r%r��exc_infor&r&r'�-test_subtly_corrupted_hints_without_integrity�s
,zSRepositoryAuxiliaryCorruptionTestCase.test_subtly_corrupted_hints_without_integrity)rQrRrSr,r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�
__classcell__r&r&r�r'r�Fs 

r�c@s�eZdZdd�Zd*dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)+�RepositoryCheckTestCasecCs dd�t�tj�|jd��D�S)NcSsg|]}|�d�r|�qS)r�)r��r>r�r&r&r'�
<listcomp>�rAz8RepositoryCheckTestCase.list_indices.<locals>.<listcomp>r)r!r�r"r#r$r+r&r&r'�list_indices�sz$RepositoryCheckTestCase.list_indicesFTc	CsD|�|jj|d�|�|�dd�t�tj�|jd��D�gd�dS)N��repaircSsg|]}d|vr|�qS)�tmpr&rr&r&r'r�rAz1RepositoryCheckTestCase.check.<locals>.<listcomp>rzFound tmp files)r\rr�r!r�r"r#r$)r%r�statusr&r&r'r��szRepositoryCheckTestCase.checkcGs|D]}|j�t|��qdSr-re)r%�ids�id_r&r&r'�get_objects�sz#RepositoryCheckTestCase.get_objectscCs8|D].}|D]}|j�t|�d�q|jjdd�qdS)N�dataFr7r�)r%�segmentsr
rr&r&r'�add_objects�sz#RepositoryCheckTestCase.add_objectsc
Cs,tdd�t�tj�|jddd��D��dS)Ncss|]}|��rt|�VqdSr-)�isdigitr�)r>�nr&r&r'�	<genexpr>�rAz3RepositoryCheckTestCase.get_head.<locals>.<genexpr>r�data�0rC)�sortedr!r�r"r#r$r+r&r&r'�get_head�sz RepositoryCheckTestCase.get_headc	Cs"t�tj�|jdd|������S�Nrr�)rr�r!r"r#r$rr+r&r&r'�
open_index�sz"RepositoryCheckTestCase.open_indexc	Csp|��}|t|�\}}ttj�|jdddt|��d��$}|�|�|�	d�Wd�n1sb0YdS)Nrrrr�sBOOM)
rrr(r!r"r#r$�strr�r�)r%r�idxrJrNr�r&r&r'�corrupt_object�s
"
z&RepositoryCheckTestCase.corrupt_objectcCs|jj�|�dSr-)rrFr�)r%rJr&r&r'r��sz&RepositoryCheckTestCase.delete_segmentc	Cs&t�tj�|jdd|������dSr)r!r�r"r#r$rr+r&r&r'�delete_index�sz$RepositoryCheckTestCase.delete_indexc	Cs6t�tj�|jdd|�����tj�|jd|��dSr)r!�renamer"r#r$r)r%�new_namer&r&r'�rename_indexs�z$RepositoryCheckTestCase.rename_indexcCsdd�|j��D�S)NcSsh|]}t|��qSr&)r�)r>rMr&r&r'�	<setcomp>rAz7RepositoryCheckTestCase.list_objects.<locals>.<setcomp>)rrpr+r&r&r'�list_objectssz$RepositoryCheckTestCase.list_objectscs���gd�ddgdgg���hd������jdd���d���t�fdd	���j���jd
d��jd
d��jddd���	d��jdd���hd�����dS)
N�rrr6����rrr6r#r$r%T�r	cs
��d�S)Nr$�rr&r+r&r'rZrAzGRepositoryCheckTestCase.test_repair_corrupted_segment.<locals>.<lambda>F�rr	>rrr6r#r%)
rr\r!r�rr]rrrhrr+r&r+r'�test_repair_corrupted_segments


z5RepositoryCheckTestCase.test_repair_corrupted_segmentcCsp|�gd�gd�g�|�hd�|���|jdd�|�d�|j��|jddd�|�hd�|���dS)	Nr"�r#r$r%r&Tr'rr)�rrr6)rr\r!r�r�rrhr+r&r&r'�test_repair_missing_segments

z3RepositoryCheckTestCase.test_repair_missing_segmentcsN��gd�gd�g���d���tj�fdd����hd�����dS)Nr"r+r6cs
��d�S�Nr#r(r&r+r&r'rZ#rAzLRepositoryCheckTestCase.test_repair_missing_commit_segment.<locals>.<lambda>r,)rr�r]rr^r\r!r+r&r+r'�"test_repair_missing_commit_segment s
z:RepositoryCheckTestCase.test_repair_missing_commit_segmentcs���gd�gd�g�ttj��jdddd�d��(}|�dtj�|�d	�Wd�n1s`0Y��	t
j�fd
d���jdd
���
d���hd�����dS)Nr"r+rrr�3r�rC�Xcs
��d�Sr.r(r&r+r&r'rZ+rAzNRepositoryCheckTestCase.test_repair_corrupted_commit_segment.<locals>.<lambda>Tr'r6r,)rr(r!r"r#r$r��SEEK_ENDr�r]rr^r�rr\r!r�r&r+r'�$test_repair_corrupted_commit_segment&s(
z<RepositoryCheckTestCase.test_repair_corrupted_commit_segmentcs���gd�g�ttj��jdddd�d��(}|�dtj�|�d�Wd�n1sZ0Y��	t
j�fd	d
���jdd��jdd���
���d
g��jddd���
���dg��jdd���d���
hd�����dS)Nr"rrr�1r�rCr1cs
��d�Sr.r(r&r+r&r'rZ5rAz@RepositoryCheckTestCase.test_repair_no_commits.<locals>.<lambda>Fr'r�Tr)zindex.2r6r,)rr(r!r"r#r$r�r2r�r]r�CheckNeededr�r\rrr!r�r&r+r'�test_repair_no_commits0s(
z.RepositoryCheckTestCase.test_repair_no_commitscCsL|�gd�gd�g�|��|jdd�|�d�|�hd�|���dS)Nr"r+Tr'r#r&)rrr�rr\r!r+r&r&r'�test_repair_missing_index?s

z1RepositoryCheckTestCase.test_repair_missing_indexcCsr|�gd�gd�g�|�|��dg�|�d�|jdd�|�|��dg�|�d�|�hd�|���dS)	Nr"r+zindex.3z	index.100Tr'r#r&)rr\rrr�rr!r+r&r&r'�test_repair_index_too_newFs

z1RepositoryCheckTestCase.test_repair_index_too_newcCs�|j�td�d�|j�td�d�t�td��(}|jjdd�|�d�Wd�n1s^0Y|��|j	dd�|�
|j�td��d�dS)	Nrr
sdata2r�Tr7g�������?r)rr9rrr�rr:r�r3r�r\rX)r%r8r&r&r'�test_crash_before_compactOs(z1RepositoryCheckTestCase.test_crash_before_compactN)FT)rQrRrSrr�rrrrrr�rrr!r*r-r/r3r6r7r8r9r&r&r&r'r�s&
	
	rc@seZdZdd�Zdd�ZdS)�RepositoryHintsTestCasecCs|j�td�d�|j�td��|jjdd�|jj}|jj}|jj}|��|j�td�d�|�	||jj�|�	||jj�|jjd=|�	||jj�|��|�	|jj
dd	�d�|��|j�td�d�|�	||jj�|jjd=|�	||jj�dS)
Nrr
Fr7�*r�rTr)rr9rr;r:�shadow_indexr8rr3r\r�)r%Zshadow_index_expectedZcompact_expectedZsegments_expectedr&r&r'�test_hints_persistence]s&

z.RepositoryHintsTestCase.test_hints_persistencecCs�|j�td�d�|�|jji�|j�td��|jjdd�|�td�|jj�|�t|jjtd��d�|�d|jj	�|j�td�d�|jjdd	d
�|�
td�|jj�|�
d|jj	�|�
d|jj�dS)Nrr
Fr7rr;r�Tg)r8Z	threshold)rr9rr\r<r;r:Z	assert_inrqr8Z
assert_not_inrr+r&r&r'�test_hints_behaviourxsz,RepositoryHintsTestCase.test_hints_behaviourN)rQrRrSr=r>r&r&r&r'r:[sr:c@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�RemoteRepositoryTestCaseNFcCs"ttdtj�|jd��d|d�S�N�__testsuite__:rTr�r
rr!r"r#r$r�r&r&r'r(�s�zRemoteRepositoryTestCase.opencCsGdd�d�}|�S)Nc@s$eZdZdZdZgZdZdd�ZdS)z9RemoteRepositoryTestCase._get_mock_args.<locals>.MockArgsZborg�?NcSs
t||�Sr-)�hasattr)r%�itemr&r&r'�__contains__�szFRemoteRepositoryTestCase._get_mock_args.<locals>.MockArgs.__contains__)rQrRrS�remote_path�umask�debug_topics�rshrFr&r&r&r'�MockArgs�s
rKr&)r%rKr&r&r'�_get_mock_args�s
z'RemoteRepositoryTestCase._get_mock_argscs��t�fdd��dS)Ncs�j�di�S)N�__init__)r�callr&r+r&r'rZ�rAz;RemoteRepositoryTestCase.test_invalid_rpc.<locals>.<lambda>)r]rr+r&r+r'�test_invalid_rpc�sz)RemoteRepositoryTestCase.test_invalid_rpcc
Cs�d}z|j�dddi�Wn&tjy@}zWYd}~n
d}~00z|j�dddi�Wn&tjy~}zWYd}~n
d}~00z|j�dddi�Wn&tjy�}zWYd}~n
d}~00z|j�dddi�Wn$ty�}zWYd}~n
d}~00z|j�dddi�Wn&t�y6}zWYd}~n
d}~00z|j�ddd	i�Wn(tj�yv}zWYd}~n
d}~00z|j�ddd
i�Wn&t	�y�}zWYd}~n
d}~00z|j�dddi�Wn(t
j�y�}zWYd}~n
d}~00dS)Nztest stringZinject_exception�kind�DoesNotExist�
AlreadyExistsr5rrr^rZdivide)rrNrrQrRr5rrr^rr
ZRPCError)r%�s1�er&r&r'�test_rpc_exception_transport�sBz5RemoteRepositoryTestCase.test_rpc_exception_transportcCs|��}||j_dtjd<dS)Nz	ssh --fooZBORG_RSH)rLr�_argsr!�environ�r%�argsr&r&r'�test_ssh_cmd�s
z%RemoteRepositoryTestCase.test_ssh_cmdcCsN|��}t���tj�d|_ddg|_|��}d|_d|_d|_||j	_
dS)Nzborg-0.28.2Zsomething_client_sideZrepository_compactionri���z
ssh -i foo)rL�logging�	getLogger�setLevel�INFOrGrIr�rJrrVrXr&r&r'�
test_borg_cmd�s
z&RemoteRepositoryTestCase.test_borg_cmd)F)
rQrRrSrr(rLrOrUrZr_r&r&r&r'r?�s

6
r?c@seZdZddd�Zdd�ZdS)�RemoteLegacyFreeFcCsTt�tdd��2ttdtj�|jd��d|d�Wd�S1sF0YdS)NZ
dictFormatTrArr)rr�r
rr!r"r#r$r�r&r&r'r(�s�zRemoteLegacyFree.opencCs�|j�td�d�|jjdd�|j��|��|_|j�0|j�td�d�|jjdd�Wd�n1sp0Y|��|_|j�.|j�td��|jjdd�Wd�n1s�0YdSrkrlr+r&r&r'�test_legacy_frees

,
z!RemoteLegacyFree.test_legacy_freeN)F)rQrRrSr(rar&r&r&r'r`�s
r`c@s.eZdZddd�Zdd�Zdd�Zdd	�Zd
S)�RemoteRepositoryCheckTestCaseFcCs"ttdtj�|jd��d|d�Sr@rBr�r&r&r'r(s�z"RemoteRepositoryCheckTestCase.opencCsdSr-r&r+r&r&r'r9sz7RemoteRepositoryCheckTestCase.test_crash_before_compactcCsdSr-r&r+r&r&r'r/sz@RemoteRepositoryCheckTestCase.test_repair_missing_commit_segmentcCsdSr-r&r+r&r&r'r- sz9RemoteRepositoryCheckTestCase.test_repair_missing_segmentN)F)rQrRrSr(r9r/r-r&r&r&r'rbs
rbc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�RemoteLoggerTestCasecCs|t��|_t�|j�|_|jgt��jdd�<gt�d�jdd�<gt�d�jdd�<tj	�
�tj	|_t��|_	t_	dS)N�borg.repository�borg.repository.foo)rF�StringIO�streamr[�
StreamHandler�handlerr\�handlers�sys�stderr�flush�
old_stderrr+r&r&r'r,&s

zRemoteLoggerTestCase.setUpcCs|jt_dSr-)rnrkrlr+r&r&r'r11szRemoteLoggerTestCase.tearDowncCs0td�|�|j��d�|�|j��d�dS)Nzunstructured stderr message
r=z$Remote: unstructured stderr message
�rr\rg�getvaluerlr+r&r&r'�test_stderr_messages4sz)RemoteLoggerTestCase.test_stderr_messagescCs0td�|�|j��d�|�|j��d�dS)Nz%unstructured stderr progress message
r=z-Remote: unstructured stderr progress message
ror+r&r&r'�test_stderr_progress_messages:sz2RemoteLoggerTestCase.test_stderr_progress_messagescCsN|j�tj�t���tj�td�|�|j��d�|�|j	��d�dS)Nz,$LOG INFO Remote: borg < 1.1 format message
z"Remote: borg < 1.1 format message
r=�
rir]r[�DEBUGr\rr\rgrprlr+r&r&r'�test_pre11_format_messages@s
z/RemoteLoggerTestCase.test_pre11_format_messagescCsN|j�tj�t���tj�td�|�|j��d�|�|j	��d�dS)Nz=$LOG INFO borg.repository Remote: borg >= 1.1 format message
z#Remote: borg >= 1.1 format message
r=rsr+r&r&r'�test_post11_format_messagesHs
z0RemoteLoggerTestCase.test_post11_format_messagescCsN|j�tj�t���tj�td�|�|j��d�|�|j	��d�dS)Nz:$LOG INFO borg.repository Remote: new format info message
r=)
rir]r[�WARNINGr\rr\rgrprlr+r&r&r'�test_remote_messages_screenedPs
z2RemoteLoggerTestCase.test_remote_messages_screenedcCs�t�d��tj�t�d��tj�|j�tj�t���tj�t��}t�|�}|�tj�|gt�d�j	dd�<t��}t�|�}|�tj�|gt�d�j	dd�<t
d�|�|��d�|�|��d�|�|j
��d�|�|j��d�dS)Nrdrez;$LOG INFO borg.repository Remote: new format child message
r=z!Remote: new format child message
)r[r\r]r^rirwrFrfrhrjrr\rprgrl)r%Zchild_streamZ
child_handlerZ
foo_streamZfoo_handlerr&r&r'� test_info_to_correct_local_childYs"

z5RemoteLoggerTestCase.test_info_to_correct_local_childN)rQrRrSr,r1rqrrrurvrxryr&r&r&r'rc%s	rc)4rFr[r!r/rkr)Z
unittest.mockrr�Z	hashindexrZhelpersrrrZlockingrr	Zremoter
rrr
rrrrrrrrrr=rrr�r rrTrzr�r�r�r�r�r�rr:r?r`rbrcr&r&r&r'�<module>sF$+s;R(*0n