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.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_listcCs�td�D]}|j�t|�d�q|jjdd�|j��}t|�dksHJ�|jjdd�}t|�dksfJ�||dd�kszJ�|jj|dd�}t|�dks�J�||dd�ks�J�t|jjdd��dks�J�td�D]}||t|�ks�J�q�dSrn)rErr9rr:�scanrqrrr&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`|jjddksJ�|jjddks(J�|jjddks<J�|j�d�|jjddks\J�dS)NrrWr�	r�))rr8�_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)Nrr4rrFr7)rr9rr:r;r~r+r&r&r'�test_sparse2�s
z$LocalRepositoryTestCase.test_sparse2cCs�|j�td�d�|j�td��|jjj��|jjddksDJ�|j�d�|jjddt	t
�kslJ�|jjdd�ddd�|jj��D�vs�J�dS)Nrs1245�VTr7cSsg|]\}}|�qSr&r&)r>rJ�_r&r&r'�
<listcomp>�rAz>LocalRepositoryTestCase.test_sparse_delete.<locals>.<listcomp>)
rr9rr;rFZ	_write_fd�syncr8r}rqrr:rGr+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�r�r�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}|�|���r6J�dSrd)	rr9rrZCOMMITr3rFZis_committed_segmentr�)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�|td�ks�J�|d7}q�|dks�J�||jj
vs�J�|j�td�d�|jjdd�|�d
�||jj
v�sJ�|jj�|��r J�|jj��D]H\}}|jj�|�D].\}}}}|t	k�s\J�|td�k�sBJ��qB�q,td�|jj
v�s�J�dS)Nr�1r�2Fr7zp1 p2 cTzd1 ccrr6�3zp3 cc)rr9rr:rPr;rFr�rHrr8�segment_existsrG�shadow_index)	r%r�Znum_deletesrLrMrNrOrJr�r&r&r'�test_moved_deletes_are_tracked?s2



z7RepositoryCommitTestCase.test_moved_deletes_are_trackedcCs|jjj}|j�td�d�|�}|jjdd�|j�td��|j�td�d�|�}|jj|=|jj|=|jjdd�|j�td��|jjdd�|jj�|�s�J�|jj�|�r�J�td�|jvs�J�t	�
t	j�|jjd|���td�|jvs�J�dS�Nrr�Fr7rTzindex.%d�
rrFr�r9rr:r;r8r�r!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�|jj�|�s�J�|jj�|�r�J�td�|jvs�J�t	�
t	j�|jjd|���td�|jv�sJ�dSr�r�r�r&r&r'�$test_shadowed_entries_are_preserved2s$


z=RepositoryCommitTestCase.test_shadowed_entries_are_preserved2cCs�|j�td�d�|j�td��|jjtd�dgks<J�|jjdd�|�d�|jjtd�gkslJ�|j�td�d�|j�td��|�d�|jjtd�dgks�J�|j��|�d	�|j�td
�d�|jjtd�gks�J�dS)Nrr�rTr7zp1 d1 cczp1 d1��rr)rr9rr;r�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.opencCsD|�t��|j��Wd�n1s*0Y|jjs@J�dSr-)r]�
ValueErrorrZdestroyr�r+r&r&r'�test_destroy_append_only�s(z5RepositoryAppendOnlyTestCase.test_destroy_append_onlycs��fdd�}�j�td�d��jjdd�d�j_|�dksBJ��j�td�d��jjdd�|�dkspJ�d�j_|�dks�J��j�td�d��jjdd�|�d	ks�J�dS)
Ncstt�jj����Sr-)rqrprrFrGr&r+r&r'�segments_in_repository�szMRepositoryAppendOnlyTestCase.test_append_only.<locals>.segments_in_repositoryrr4Fr7rTr�)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�n1sp0Yt
j�|jj�s�J�dS)	Nr�additional_free_spaceZ1000Tsshortcut to save_configr�foobarFr7)r<rZconfig�setZsave_keyr3r9r�pytest�raisesr�InsufficientFreeSpaceErrorr:r!r"�existsr+r&r&r'�test_additional_free_space�s,z6RepositoryFreeSpaceTestCase.test_additional_free_spacecCsTd|j_t�tj��|��Wd�n1s20Ytj�	|jj�rPJ�dS)Ng@��x�D)
rr�r�r�rr�r<r!r"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�|jjdksJ�|j�td�td��|jjdks6J�|j�td�td��|jjdks\J�|j�td��|jjdks|J�|jjdd	�|jjdks�J�|��|j�td
�d�|j�td
��|jjdks�J�|jjd
d	�|jjdks�J�dS)Nrri�i�ri.iRFr7r6rAi{TiW)r�storage_quota_user9r�bytesr;r:r3r+r&r&r'�
test_tracking�szQuotaTestCase.test_trackingcCs8|jjdksJ�d|j_|j�td�d�|jjdks:J�|jjdd�t�tj	��"|j�td�d�Wd�n1s|0Y|jjd	ks�J�t�tj	��|jjdd�Wd�n1s�0Y|jjd	ks�J�|�
�d
|j_|j�td�d�|jjd	k�sJ�|jjdd�|jjdk�s4J�dS)NrrWrrAr|Fr7r�RrUT)rr��
storage_quotar9rr:r�r�rZStorageQuotaExceededr3r+r&r&r'�test_exceed_quotas"0,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��AssertionErrorr�get_free_noncer+r&r&r'�test_get_free_nonce_assertssz,NonceReservation.test_get_free_nonce_assertsc	Cs�|j��|j��dusJ�ttj�|jjd�d��}|�d�Wd�n1sR0Y|j��dksnJ�ttj�|jjd�d��}|�d�Wd�n1s�0Y|j��dks�J�Wd�n1s�0YdS)N�nonce�wZ0000000000000000rZ5000000000000000l)rr�r(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	CsJ|j��,t�t��|j�dd�Wd�n1s80Y|j�dd�ttj�|jjd��� }|�	�dksxJ�Wd�n1s�0Yt�t��|j�dd�Wd�n1s�0Y|j�dd�ttj�|jjd���"}|�	�dk�sJ�Wd�n1�s0YWd�n1�s<0YdS)Nr��r�Z0000000000000200iZ0000000000000400)
rr�r��	Exceptionr�r(r!r"r#�readr�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�rr�r�r&r&r'�
test_indexfs(z0RepositoryAuxiliaryCorruptionTestCase.test_indexcCs~ttj�|jjd�d��}|�d�Wd�n1s80Y|j�"t|j�dks\J�Wd�n1sp0YdS)Nr�r�rr)r(r!r"r#rr�rqr�r&r&r'�test_index_outside_transactionks(zDRepositoryAuxiliaryCorruptionTestCase.test_index_outside_transactioncCs�tj�|jjd�}t|d��x}|��}t�td�d�dA�	dd�}|�
td�|�}||ks^J�t|�t|�ksrJ�|�d�|�
|�Wd�n1s�0YdS)Nr��r+br�littlerr)r!r"r#rr(r��int�
from_bytesr�to_bytes�replacerq�seekr�)r%Z
index_pathr�Z
index_dataZ
corrupted_keyZcorrupted_index_datar&r&r'�_corrupt_indexqs
z4RepositoryAuxiliaryCorruptionTestCase._corrupt_indexcCs\|��|j�:t|j�dks"J�|j�td��dks:J�Wd�n1sN0YdS)Nrrr4)r�rrqrXrr+r&r&r'�test_index_corruptedsz:RepositoryAuxiliaryCorruptionTestCase.test_index_corruptedc	Cs�|��tj�|jjd�}t�|�|j�^t|j�dks>J�t�t	j
�� |j�td��Wd�n1sp0YWd�n1s�0YdS)N�integrity.1rr)
r�r!r"r#rr�rqr�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�:t|j�dksnJ�|j�	t
d��dks�J�Wd�n1s�0YdS)Nr�r�sversiong������@rrr4)r!r"r#rr(r�pack�truncaterqrXr)r%r�r�r&r&r'�test_unknown_integrity_version�s��&zDRepositoryAuxiliaryCorruptionTestCase.test_unknown_integrity_versioncCs4|j��d|j_t|j�dks"J�|j�td��dks:J�|j�td�d�|j�td�d�|jjdd	�|j�td�d
�|jjdd	�Wd�n1s�0Ytj�	|jjd�}t
|d��X}t�|�}|�
d�|d
ddks�J�d|d
d<t�||�|��Wd�n1�s&0YdS)NTrrr4r5rsbazFr7�bazzzhints.5r�ssegments)rr�rqrXrr9r:r!r"r#r(r�unpackr�rr)r%Z
hints_pathr�r�r&r&r'�_subtly_corrupted_hints_setup�s",

zCRepositoryAuxiliaryCorruptionTestCase._subtly_corrupted_hints_setupcCs�|��|j��d|j_|j�td�d�|jjdd�t|j�dksJJ�|j�td��dksbJ�|j�td	��d
kszJ�|j�td��dks�J�Wd�n1s�0YdS)
NFr6�1234Tr7r�rr4rr5rr)rrr�r9rr:rqrXr+r&r&r'�test_subtly_corrupted_hints�szARepositoryAuxiliaryCorruptionTestCase.test_subtly_corrupted_hintsc	Cs�|��tj�|jjd�}t�|�|j�td|j_|j�td�d�t	�
t��}|jjdd�Wd�n1st0Ydt
|j�vs�J�Wd�n1s�0YdS)Nzintegrity.5Fr6rTr7z!Corrupted segment reference count)rr!r"r#rr�r�r9rr�r�r�r:�str�value)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�rrrr	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'r��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%�segmentsrrr&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$r"r+r&r&r'�
open_index�sz"RepositoryCheckTestCase.open_indexc	Csp|��}|t|�\}}ttj�|jdddt|��d��$}|�|�|�	d�Wd�n1sb0YdS)Nrrr r�sBOOM)
r$rr(r!r"r#r$r
r�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$r"r+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�rrr6r����rrr6r�r.r/T�rcs
��d�S)Nr.�rr&r+r&r'rZrAzGRepositoryCheckTestCase.test_repair_corrupted_segment.<locals>.<lambda>F�rr>rrr6r�r/)
rr\r,r�r&r]rrrhrr+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/r0Tr1rr3�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-r5r6cs
��d�S�Nr�r2r&r+r&r'rZ#rAzLRepositoryCheckTestCase.test_repair_missing_commit_segment.<locals>.<lambda>r6)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-r5rrr �3r�rC�Xcs
��d�Sr8r2r&r+r&r'rZ+rAzNRepositoryCheckTestCase.test_repair_corrupted_commit_segment.<locals>.<lambda>Tr1r6r6)rr(r!r"r#r$r��SEEK_ENDr�r]rr^r�rr\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�rCr;cs
��d�Sr8r2r&r+r&r'rZ5rAz@RepositoryCheckTestCase.test_repair_no_commits.<locals>.<lambda>Fr1r�Tr3zindex.2r6r6)rr(r!r"r#r$r�r<r�r]r�CheckNeededr�r\rrr,r�r&r+r'�test_repair_no_commits0s(
z.RepositoryCheckTestCase.test_repair_no_commitscCsL|�gd�gd�g�|��|jdd�|�d�|�hd�|���dS)Nr-r5Tr1r�r0)rr'r�rr\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-r5zindex.3z	index.100Tr1r�r0)rr\rr*r�rr,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)	Nrrsdata2r�Tr7g�������?r)rr9rrr�rr:r�r3r�r\rX)r%r8r&r&r'�test_crash_before_compactOs(z1RepositoryCheckTestCase.test_crash_before_compactN)FT)rQrRrSrr�rrr"r$r&r�r'r*r,r4r7r9r=r@rArBrCr&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)
NrrFr7�*r�rTr)rr9rr;r:r�r8rr3r\r�)r%Zshadow_index_expectedZcompact_expectedZsegments_expectedr&r&r'�test_hints_persistence]s&

z.RepositoryHintsTestCase.test_hints_persistencecCs�|j�td�d�|�|jji�t|jj�dks6J�|j�td��|jjdd�|�	td�|jj�|�t|jjtd��d�|�	d|jj�|j�td�d�|jjdd	d
�|�
td�|jj�|�
d|jj�|�
d|jj�dS)NrrFr7rrEr�Tg)r8Z	threshold)rr9rr\r�rqr8r;r:Z	assert_inZ
assert_not_inrr+r&r&r'�test_hints_behaviourxsz,RepositoryHintsTestCase.test_hints_behaviourN)rQrRrSrFrGr&r&r&r'rD[srDc@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>.MockArgs�borg�?NcSs
t||�Sr-)�hasattr)r%�itemr&r&r'�__contains__�szFRemoteRepositoryTestCase._get_mock_args.<locals>.MockArgs.__contains__)rQrRrS�remote_path�umask�debug_topics�rshrPr&r&r&r'�MockArgs�s
rUr&)r%rUr&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�WnPtjyj}z6t|j�dks>J�|jd|jjjksVJ�WYd}~n
d}~00z|j�dddi�WnPtjy�}z6t|j�dks�J�|jd|jjjks�J�WYd}~n
d}~00z|j�dddi�WnVtj	�y@}z:t|j�dk�sJ�|jd|jjjk�s,J�WYd}~n
d}~00z|j�ddd	i�WnNt
�y�}z4t|j�dk�s~J�|jd|k�s�J�WYd}~n
d}~00z|j�ddd
i�WnNt�y}z4t|j�dk�s�J�|jddk�s�J�WYd}~n
d}~00z|j�dddi�Wnjtj�y�}zNt|j�d
k�sLJ�|jd|k�s`J�|jd|jjjk�szJ�WYd}~n
d}~00z|j�dddi�WnNt
�y�}z4t|j�dk�s�J�|jd|k�s�J�WYd}~n
d}~00z|j�dddi�Wnjtj�yv}zN|j�s,J�|��dk�s>J�|jdk�sNJ�t|j�dk�sbJ�WYd}~n
d}~00dS)Nztest stringZinject_exception�kind�DoesNotExistrr�
AlreadyExistsr?rr�foor^rrZdividez6ZeroDivisionError: integer division or modulo by zero
�ZeroDivisionError)rrXrr[rq�args�locationZ	processedr\r?rrr^rr
ZRPCErrorZunpackedZget_messageZexception_classZexception_full)r%�s1�er&r&r'�test_rpc_exception_transport�sX..0**0*z5RemoteRepositoryTestCase.test_rpc_exception_transportcCs�|��}||j_|j�td��ddgks,J�|j�td��ddgksHJ�|j�td��ddgksdJ�|j�td��gd�ks�J�d	tjd
<|j�td��gd�ks�J�dS)N�example.com:foo�ssh�example.comzssh://example.com/foozssh://user@example.com/foo�user@example.comzssh://user@example.com:1234/foo)rez-pZ1234rgz	ssh --fooZBORG_RSH)rez--foorf)rVr�_args�ssh_cmdrr!�environ�r%r_r&r&r'�test_ssh_cmd�s
z%RemoteRepositoryTestCase.test_ssh_cmdcCs|jjddd�tjdddgks"J�|��}t���tj�|jj|dd�gd�ksVJ�d|_	|jj|dd�gd	�ksxJ�d
dg|_
|jj|dd�gd�ks�J�|��}d
|_|jj|dd�gd�ks�J�d|_|jj|dd�gd�ks�J�d|_||j_
|j�td��gd�k�sJ�dS)NT)Ztestingz-mz
borg.archiver�serveF)rLrm�--info�borg-0.28.2)rormrnZsomething_client_sideZrepository_compaction)rormrnz.--debug-topic=borg.debug.repository_compactionri���)rLrmrnz--storage-quota=314159265z
ssh -i foord)rez-ir]rf)rZborg_cmd�sys�
executablerV�logging�	getLogger�setLevel�INFOrQrSr�rTrhrirrkr&r&r'�
test_borg_cmd�s "
z&RemoteRepositoryTestCase.test_borg_cmd)F)
rQrRrSrr(rVrYrcrlrvr&r&r&r'rH�s

6
rHc@seZdZddd�Zdd�ZdS)�RemoteLegacyFreeFcCsTt�tdd��2ttdtj�|jd��d|d�Wd�S1sF0YdS)NZ
dictFormatTrJrr)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(rxr&r&r&r'rw�s
rwc@s.eZdZddd�Zdd�Zdd�Zdd	�Zd
S)�RemoteRepositoryCheckTestCaseFcCs"ttdtj�|jd��d|d�SrIrKr�r&r&r'r(s�z"RemoteRepositoryCheckTestCase.opencCsdSr-r&r+r&r&r'rCsz7RemoteRepositoryCheckTestCase.test_crash_before_compactcCsdSr-r&r+r&r&r'r9sz@RemoteRepositoryCheckTestCase.test_repair_missing_commit_segmentcCsdSr-r&r+r&r&r'r7 sz9RemoteRepositoryCheckTestCase.test_repair_missing_segmentN)F)rQrRrSr(rCr9r7r&r&r&r'rys
ryc@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�streamrr�
StreamHandler�handlerrs�handlersrp�stderr�flush�
old_stderrr+r&r&r'r,&s

zRemoteLoggerTestCase.setUpcCs|jt_dSr-)r�rpr�r+r&r&r'r11szRemoteLoggerTestCase.tearDowncCs0td�|�|j��d�|�|j��d�dS)Nzunstructured stderr message
r=z$Remote: unstructured stderr message
�rr\r~�getvaluer�r+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
r�r+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=�
r�rtrr�DEBUGrsrr\r~r�r�r+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=r�r+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=)
r�rtrr�WARNINGrsrr\r~r�r�r+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)Nr{r|z;$LOG INFO borg.repository Remote: new format child message
r=z!Remote: new format child message
)rrrsrtrur�r�rFr}rr�rr\r�r~r�)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,r1r�r�r�r�r�r�r&r&r&r'rz%s	rz)4rFrrr!r/rpr)Z
unittest.mockrr�Z	hashindexrZhelpersrrrZlockingrr	Zremoter
rrr
rrrrrrrrrr=rrr�r rrTrzr�r�r�r�r�r�rrDrHrwryrzr&r&r&r'�<module>sF$+s;R(*0n