HEX
Server: LiteSpeed
System: Linux s3.sitechai.com 4.18.0-553.51.1.lve.1.el8.x86_64 #1 SMP Wed May 14 14:34:57 UTC 2025 x86_64
User: workzeni (2217)
PHP: 8.1.32
Disabled: mail, show_source, system, shell_exec, passthru, exec, eval, shell
Upload Files
File: //usr/lib64/python3.6/site-packages/borg/testsuite/__pycache__/repository.cpython-36.opt-1.pyc
3

y��b��@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(|tkr|j}ttjj|jd�||d�S)N�
repository)�	exclusive�create)�UNSPECIFIEDrr�os�path�join�tmppath)�selfrr�r$�"/usr/lib64/python3.6/repository.py�openszRepositoryTestCaseBase.opencCs&tj�|_|jdd�|_|jj�dS)NT)r)�tempfileZmkdtempr"r&r�	__enter__)r#r$r$r%�setUp"s
zRepositoryTestCaseBase.setUpcCs|jj�tj|j�dS)N)r�close�shutilZrmtreer")r#r$r$r%�tearDown's
zRepositoryTestCaseBase.tearDowncCs"|jr|jj�|j|d�|_dS)N)r)rr*r&)r#rr$r$r%�reopen+s
zRepositoryTestCaseBase.reopencCsx|jjtd�d�|jjtd�d�|jjtd�d�|jj�|jjtd�d�|jjtd�d�|jjtd��dS)	Nrsfoorsbar�sbar2rsboo)r�putr�commit�delete)r#r$r$r%�add_keys0s
zRepositoryTestCaseBase.add_keysNc

Cs�|dk	r|dnd}dd�td�D�}d|d<tdtdtd	i}xX|jjj�D]H\}}x>|jjj|�D],\}}}}	td
||||||||	f�qdWqLWt�dS)Nz: �cSsi|]}|t|��qSr$)r)�.0�ir$r$r%�
<dictcomp>;sz4RepositoryTestCaseBase.repo_dump.<locals>.<dictcomp>�
rr/�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_sizerrr&r)r,r-r2rEr$r$r$r%rs	rc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�RepositoryTestCasecs�x"td�D]}�jjt|�d�q
Wtd���j�jj��d��jj���jtj	��fdd���jj
��jj��j��P��jtj	��fdd��x0td�D]$}|dkr�q��j�jt|��d�q�WWdQRXdS)N�dsSOMEDATA�2cs�jj��S)N)r�getr$)�key50r#r$r%�<lambda>Lsz*RepositoryTestCase.test1.<locals>.<lambda>cs
�j��S)N)rLr$)rM�repository2r$r%rNPs)
r:rr/r�assert_equalrLr1�
assert_raisesr�ObjectNotFoundr0r*r&)r#�xr$)rMrOr#r%�test1Fs


zRepositoryTestCase.test1cCsv|jjtd�d�|jjtd�d�|jj�|jjtd��|jjtd�d�|jj�|j|jjtd��d�dS)z.Test multiple sequential transactions
        rsfoorsbarN)rr/rr0r1rPrL)r#r$r$r%�test2Vs

zRepositoryTestCase.test2cs��jjtd�d��j�jjtd��d��jjtd�d��j�jjtd��d��jjtd�d��j�jjtd��d��jjtd���jtj�fdd��dS)zTest cache consistency
        rsfoosfoo2sbarcs�jjtd��S)Nr)rrLrr$)r#r$r%rNksz5RepositoryTestCase.test_consistency.<locals>.<lambda>N)	rr/rrPrLr1rQrrR)r#r$)r#r%�test_consistencyasz#RepositoryTestCase.test_consistencycCs�|jjtd�d�|j|jjtd��d�|jj�|jjtd�d�|j|jjtd��d�|jj�|j|jjtd��d�dS)z Test cache consistency2
        rsfoosfoo2N)rr/rrPrLr0�rollback)r#r$r$r%�test_consistency2ms

z$RepositoryTestCase.test_consistency2cCsJ|jjtd�d�|jjtd�d�|jj�|j|jjtd��d�dS)z Test cache consistency2
        rsfoosfoo2N)rr/rr0rPrL)r#r$r$r%�"test_overwrite_in_same_transactionxs
z5RepositoryTestCase.test_overwrite_in_same_transactioncCs�|jjtd�d�|jj�|jj�|j�|_|j�"|jjtd�d�|jj�WdQRX|j�|_|j� |jjtd��|jj�WdQRXdS)Nrsfoosbar)rr/rr0r*r&r1)r#r$r$r%�test_single_kind_transactions�s



z0RepositoryTestCase.test_single_kind_transactionscCs�x"td�D]}|jjt|�d�q
W|jj�|jj�}|jt|�d�|jjdd�}|jt|�d�|j||dd��|jj|dd�}|jt|�d�|j||dd��|jt|jjdd��d�dS)NrJsSOMEDATArK)�limitr)�markerr9)r:rr/rr0�listrP�len)r#rS�all�
first_half�second_halfr$r$r%�	test_list�s

zRepositoryTestCase.test_listcCsnx"td�D]}|jjt|�d�q
W|jj�|jj�}|jjdd�}|jj|dd�}xtd�D]}qbWdS)NrJsSOMEDATArK)r[r)r\r9)r:rr/rr0�scan)r#rSr_r`rar$r$r%�	test_scan�s

zRepositoryTestCase.test_scancsLdt��jjtd����j�jjtd�����jt��fdd��dS)N�xrcs�jjtd��d�S)Nrre)rr/rr$)�max_datar#r$r%rN�sz7RepositoryTestCase.test_max_data_size.<locals>.<lambda>)rrr/rrPrLrQr)r#r$)rfr#r%�test_max_data_size�s
z%RepositoryTestCase.test_max_data_sizeN)rFrGrHrTrUrVrXrYrZrbrdrgr$r$r$r%rIDsrIc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�LocalRepositoryTestCasecCs|jjd�dS)Nr)r�_rebuild_sparse)r#r$r$r%�_assert_sparse�sz&LocalRepositoryTestCase._assert_sparsecCsL|jjtd�d�|jjtd�d�|jj�|jjtd�d�|j�dS)Nrsfoors	123456789sbar)rr/rr0rj)r#r$r$r%�test_sparse1�s

z$LocalRepositoryTestCase.test_sparse1cCsJ|jjtd�d�|jjtd�d�|jj�|jjtd��|j�dS)Nrsfoors	123456789)rr/rr0r1rj)r#r$r$r%�test_sparse2�s

z$LocalRepositoryTestCase.test_sparse2cCsJ|jjtd�d�|jjtd��|jjjj�|jjd�|jj�dS)Nrs1245)	rr/rr1r;Z	_write_fd�syncrir0)r#r$r$r%�test_sparse_delete�s
z*LocalRepositoryTestCase.test_sparse_deletecCs�|jjtd�d�|jj�|jjj�}t|jjj|d�d��}|jt	d�WdQRX|jj
�|j�|_|j�"|jjtd�d�|jj�WdQRXdS)Nrsfoor�wbscrapcrapcrapsbar)rr/rr0r;�get_latest_segmentr&Zsegment_filename�writerr*)r#�last_segment�fr$r$r%�test_uncommitted_garbage�s


z0LocalRepositoryTestCase.test_uncommitted_garbageN)rFrGrHrjrkrlrnrtr$r$r$r%rh�s
rhc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�RepositoryCommitTestCasec
Cs�|j�x8tj|jj�D]&}|jd�rtjtjj|jj|��qW|j�|j�*|j	t
|j�d�|j	|jj�d�WdQRXdS)Nzindex.r.T)r2r�listdirrr �
startswith�unlinkr!r-rPr^�check)r#�namer$r$r%�test_replay_of_missing_index�s
z5RepositoryCommitTestCase.test_replay_of_missing_indexcCsv|j�d|j_y|jj�Wntk
r2YnX|j�|j�*|jt|j�d�|j|jj�d�WdQRXdS)Nr.T)	r2r�compact_segmentsr0�	TypeErrorr-rPr^ry)r#r$r$r%�"test_crash_before_compact_segments�sz;RepositoryCommitTestCase.test_crash_before_compact_segmentscCsv|j�d|j_y|jj�Wntk
r2YnX|j�|j�*|jt|j�d�|j|jj�d�WdQRXdS)Nr.T)	r2rZwrite_indexr0r}r-rPr^ry)r#r$r$r%�test_crash_before_write_indexsz6RepositoryCommitTestCase.test_crash_before_write_indexcs��j�x8tj�jj�D]&}|jd�rtjtjj�jj|��qWtj	t
dtd��@}�jdd��j�"�j
t�fdd��|j�WdQRXWdQRXdS)Nzindex.�upgrade)�side_effect)rcs
t�j�S)N)r^rr$)r#r$r%rNszGRepositoryCommitTestCase.test_replay_lock_upgrade_old.<locals>.<lambda>)r2rrvrr rwrxr!r�objectrr	r-rQ�assert_called_once_with)r#rzr�r$)r#r%�test_replay_lock_upgrade_olds
z5RepositoryCommitTestCase.test_replay_lock_upgrade_oldcs��j�x8tj�jj�D]&}|jd�rtjtjj�jj|��qWtj	t
dtd��@}�jdd��j�"�j
t�fdd��|j�WdQRXWdQRXdS)Nzindex.r�)r�F)rcs
t�j�S)N)r^rr$)r#r$r%rN+szCRepositoryCommitTestCase.test_replay_lock_upgrade.<locals>.<lambda>)r2rrvrr rwrxr!rr�rr	r-rQr�)r#rzr�r$)r#r%�test_replay_lock_upgrade!s
z1RepositoryCommitTestCase.test_replay_lock_upgradecCs�|j�d|jj_y|jj�Wntk
r4YnX|j�|j�<|jt|j�d�|j|jj	�d�|jt|j�d�WdQRXdS)Nr.T)
r2rr;�delete_segmentr0r}r-rPr^ry)r#r$r$r%�-test_crash_before_deleting_compacted_segments.s
zFRepositoryCommitTestCase.test_crash_before_deleting_compacted_segmentsc	Cs:|jjtd�tj�|j�|j�|jj}WdQRXdS)Nr)rr/rrZCOMMITr-r;)r#r;r$r$r%�test_ignores_commit_tag_in_data;s
z8RepositoryCommitTestCase.test_ignores_commit_tag_in_datac	Cs|jjtd�d�|jjtd�d�|jj�|jd�|jjtd��|jj�|jd�|jjj�d}d}x.|jjj|�D]\}}}}|t	kr�|d7}q�W|jjtd�d	�|jj�|jd
�x8|jjj
�D](\}}x|jjj|�D]\}}}}q�Wq�WdS)Nr�1r�2zp1 p2 cczd1 ccrr.�3zp3 cc)rr/rr0rEr1r;rpr=rr<)	r#rrZnum_deletesrArBrCrDr?�_r$r$r%�test_moved_deletes_are_trackedBs&





z7RepositoryCommitTestCase.test_moved_deletes_are_trackedcCs�|jjj}|jjtd�d�|�}|jj�|jjtd��|jjtd�d�|�}|jj|=|jj|=|jj�|jjtd��|jj�tj	tj
j|jj
d|���dS)Nrr�rzindex.%d)rr;rpr/rr0r1�compactrrxr r!)r#rpZput_segmentr�r$r$r%�#test_shadowed_entries_are_preserved_s





z<RepositoryCommitTestCase.test_shadowed_entries_are_preservedcCs�|jjtd�d�|jjtd��|jj�|jd�|jjtd�d�|jjtd��|jd�|jj�|jd�|jjtd�d�dS)Nrr�zp1 d1 cczp1 d1�rr)rr/rr1r0rErW)r#r$r$r%�test_shadow_index_rollback�s




z3RepositoryCommitTestCase.test_shadow_index_rollbackN)
rFrGrHr{r~rr�r�r�r�r�r�r�r$r$r$r%ru�s



"ruc@s&eZdZd	dd�Zdd�Zdd�ZdS)
�RepositoryAppendOnlyTestCaseFcCsttjj|jd�d|dd�S)NrT)rr�append_only)rrr r!r")r#rr$r$r%r&�sz!RepositoryAppendOnlyTestCase.openc	Cs$|jt��|jj�WdQRXdS)N)rQ�
ValueErrorrZdestroy)r#r$r$r%�test_destroy_append_only�sz5RepositoryAppendOnlyTestCase.test_destroy_append_onlycst�fdd�}�jjtd�d��jj�d�j_�jjtd�d��jj�d�j_�jjtd�d��jj�dS)Ncstt�jjj���S)N)r^r]rr;r<r$)r#r$r%�segments_in_repository�szMRepositoryAppendOnlyTestCase.test_append_only.<locals>.segments_in_repositoryrsfooFT)rr/rr0r�)r#r�r$)r#r%�test_append_only�s


z-RepositoryAppendOnlyTestCase.test_append_onlyN)F)rFrGrHr&r�r�r$r$r$r%r��s
r�c@seZdZdd�Zdd�ZdS)�RepositoryFreeSpaceTestCasecCsx|j�|jjjddd�|jjd�|j�|j�:|jjtd�d�tj	t
j��|jj�WdQRXWdQRXdS)Nr�additional_free_spaceZ1000Tsshortcut to save_configrsfoobar)
r2r�config�setZsave_keyr-r/r�pytest�raisesr�InsufficientFreeSpaceErrorr0)r#r$r$r%�test_additional_free_space�sz6RepositoryFreeSpaceTestCase.test_additional_free_spacec	Cs,d|j_tjtj��|j�WdQRXdS)Ng@��x�D)rr�r�r�rr�r2)r#r$r$r%�test_create_free_space�sz2RepositoryFreeSpaceTestCase.test_create_free_spaceN)rFrGrHr�r�r$r$r$r%r��sr�c@seZdZdd�Zdd�ZdS)�
QuotaTestCasec
Cs�|jjtd�td��|jjtd�td��|jjtd��|jj�|j�|j�2|jjtd�d�|jjtd��|jj�WdQRXdS)Nri�ri.r.�)rr/r�bytesr1r0r-)r#r$r$r%�
test_tracking�s

zQuotaTestCase.test_trackingcCs�d|j_|jjtd�d�|jj�tjtj��|jjtd�d�WdQRXtjtj��|jj�WdQRX|j	�|j�*d|j_|jjtd�d�|jj�WdQRXdS)NrKrr�rrJ)
r�
storage_quotar/rr0r�r�rZStorageQuotaExceededr-)r#r$r$r%�test_exceed_quota�s

zQuotaTestCase.test_exceed_quotaN)rFrGrHr�r�r$r$r$r%r��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�NonceReservationcCsB|jdd�tjt��"|j�|jj�WdQRXWdQRXdS)NF)r)r-r�r��AssertionErrorrZget_free_nonce)r#r$r$r%�test_get_free_nonce_asserts�sz,NonceReservation.test_get_free_nonce_assertscCsr|j�bttjj|jjd�d��}|jd�WdQRXttjj|jjd�d��}|jd�WdQRXWdQRXdS)N�nonce�wZ0000000000000000Z5000000000000000)rr&rr r!rq)r#�fdr$r$r%�test_get_free_nonce�sz$NonceReservation.test_get_free_noncecCsF|jdd�tjt��&|j�|jjdd�WdQRXWdQRXdS)NF)ri�)r-r�r�r�r�commit_nonce_reservation)r#r$r$r%�%test_commit_nonce_reservation_assertssz6NonceReservation.test_commit_nonce_reservation_assertsc%Cs�|j��tjt��|jjdd�WdQRX|jjdd�ttjj|jjd�d��}WdQRXtjt��|jjdd�WdQRX|jjdd�ttjj|jjd�d��}WdQRXWdQRXdS)Ni�r�r�i)	rr�r��	Exceptionr�r&rr r!)r#r�r$r$r%�test_commit_nonce_reservations
z.NonceReservation.test_commit_nonce_reservationN)rFrGrHr�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)!�%RepositoryAuxiliaryCorruptionTestCasecs4t�j�|jjtd�d�|jj�|jj�dS)Nrsfoo)�superr)rr/rr0r*)r#)�	__class__r$r%r)s

z+RepositoryAuxiliaryCorruptionTestCase.setUpc
Cs2|j�"|jjtd�d�|jj�WdQRXdS)Nrsfox)rr/rr0)r#r$r$r%�	do_commit#sz/RepositoryAuxiliaryCorruptionTestCase.do_commitc	Cs:ttjj|jjd�d��}|jd�WdQRX|j�dS)Nzhints.1Zabs	123456789)r&rr r!rrqr�)r#r�r$r$r%�test_corrupted_hints(sz:RepositoryAuxiliaryCorruptionTestCase.test_corrupted_hintscCs$tjtjj|jjd��|j�dS)Nzhints.1)rrxr r!rr�)r#r$r$r%�test_deleted_hints-sz8RepositoryAuxiliaryCorruptionTestCase.test_deleted_hintscCs$tjtjj|jjd��|j�dS)Nzindex.1)rrxr r!rr�)r#r$r$r%�test_deleted_index1sz8RepositoryAuxiliaryCorruptionTestCase.test_deleted_indexc	CsHtjj|jjd�}tj|�tj|�|jt��|j�WdQRXdS)Nzhints.1)	rr r!rrx�mkdirrQ�OSErrorr�)r#�hintsr$r$r%�test_unreadable_hints5s


z;RepositoryAuxiliaryCorruptionTestCase.test_unreadable_hintsc	Cs:ttjj|jjd�d��}|jd�WdQRX|j�dS)Nzindex.1ros	123456789)r&rr r!rrqr�)r#r�r$r$r%�
test_index<sz0RepositoryAuxiliaryCorruptionTestCase.test_indexcCsDttjj|jjd�d��}|jd�WdQRX|j�WdQRXdS)Nzindex.1ros	123456789)r&rr r!rrq)r#r�r$r$r%�test_index_outside_transactionAszDRepositoryAuxiliaryCorruptionTestCase.test_index_outside_transactionc
Csttjj|jjd�}t|d��N}|j�}tjtd�d�dAj	dd�}|j
td�|�}|jd�|j|�WdQRXdS)Nzindex.1zr+br�littlerr)
rr r!rr&�read�int�
from_bytesr�to_bytes�replace�seekrq)r#Z
index_pathr�Z
index_dataZ
corrupted_keyZcorrupted_index_datar$r$r%�_corrupt_indexGs
z4RepositoryAuxiliaryCorruptionTestCase._corrupt_indexc	Cs|j�|j�WdQRXdS)N)r�r)r#r$r$r%�test_index_corruptedUsz:RepositoryAuxiliaryCorruptionTestCase.test_index_corruptedcCsb|j�tjj|jjd�}tj|�|j�.tjtj	��|jj
td��WdQRXWdQRXdS)Nzintegrity.1r)r�rr r!rrxr�r�rrRrLr)r#�integrity_pathr$r$r%�&test_index_corrupted_without_integrity_s
zLRepositoryAuxiliaryCorruptionTestCase.test_index_corrupted_without_integrityc	CsHtjj|jjd�}tj|�tj|�|jt��|j�WdQRXdS)Nzindex.1)	rr r!rrxr�rQr�r�)r#�indexr$r$r%�test_unreadable_indexks


z;RepositoryAuxiliaryCorruptionTestCase.test_unreadable_indexcCsVtjj|jjd�}t|d��}tjddi|�|j�WdQRX|j�WdQRXdS)Nzintegrity.1zr+bsversiong������@)rr r!rr&r�pack�truncate)r#r�r�r$r$r%�test_unknown_integrity_versionrszDRepositoryAuxiliaryCorruptionTestCase.test_unknown_integrity_versioncCs�|j�Xd|j_|jjtd�d�|jjtd�d�|jj�|jjtd�d�|jj�WdQRXtjj|jjd�}t|d��:}t	j
|�}|jd	�d	|d
d<t	j||�|j
�WdQRXdS)NTrsbarrsbazsbazzzhints.5zr+brssegments)rr�r/rr0rr r!r&r�unpackr�r�r�)r#Z
hints_pathr�r�r$r$r%�_subtly_corrupted_hints_setup�s


zCRepositoryAuxiliaryCorruptionTestCase._subtly_corrupted_hints_setupc
CsB|j�|j�*d|j_|jjtd�d�|jj�WdQRXdS)NFr.s1234)r�rr�r/rr0)r#r$r$r%�test_subtly_corrupted_hints�s
zARepositoryAuxiliaryCorruptionTestCase.test_subtly_corrupted_hintscCst|j�tjj|jjd�}tj|�|j�@d|j_|jjtd�d�t	j
t��}|jj�WdQRXWdQRXdS)Nzintegrity.5Fr.s1234)
r�rr r!rrxr�r/rr�r�r�r0)r#r��exc_infor$r$r%�-test_subtly_corrupted_hints_without_integrity�s
zSRepositoryAuxiliaryCorruptionTestCase.test_subtly_corrupted_hints_without_integrity)rFrGrHr)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__r$r$)r�r%r�s 

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�tjtjj|jd��D�S)NcSsg|]}|jd�r|�qS)zindex.)rw)r4rzr$r$r%�
<listcomp>�sz8RepositoryCheckTestCase.list_indices.<locals>.<listcomp>r)rrvr r!r")r#r$r$r%�list_indices�sz$RepositoryCheckTestCase.list_indicesFTcCsD|j|jj|d�|�|jdd�tjtjj|jd��D�gd�dS)N)�repaircSsg|]}d|kr|�qS)Ztmpr$)r4rzr$r$r%r��sz1RepositoryCheckTestCase.check.<locals>.<listcomp>rzFound tmp files)rPrryrrvr r!r")r#r��statusr$r$r%ry�szRepositoryCheckTestCase.checkcGs"x|D]}|jjt|��qWdS)N)rrLr)r#�ids�id_r$r$r%�get_objects�s
z#RepositoryCheckTestCase.get_objectscCs<x6|D].}x|D]}|jjt|�d�qW|jj�qWdS)Nsdata)rr/rr0)r#�segmentsr�r�r$r$r%�add_objects�s

z#RepositoryCheckTestCase.add_objectscCs,tdd�tjtjj|jddd��D��dS)Ncss|]}|j�rt|�VqdS)N)�isdigitr�)r4�nr$r$r%�	<genexpr>�sz3RepositoryCheckTestCase.get_head.<locals>.<genexpr>r�data�0rr9)�sortedrrvr r!r")r#r$r$r%�get_head�sz RepositoryCheckTestCase.get_headcCs"tjtjj|jddj|j����S)Nrzindex.{})rr�rr r!r"�formatr�)r#r$r$r%�
open_index�sz"RepositoryCheckTestCase.open_indexc	Cs\|j�}|t|�\}}ttjj|jdddt|��d��}|j|�|j	d�WdQRXdS)Nrr�r�zr+bsBOOM)
r�rr&rr r!r"�strr�rq)r#r��idxr?rCr�r$r$r%�corrupt_object�s
"
z&RepositoryCheckTestCase.corrupt_objectcCs$tjtjj|jdddt|���dS)Nrr�r�)rrxr r!r"r�)r#r?r$r$r%r��sz&RepositoryCheckTestCase.delete_segmentcCs&tjtjj|jddj|j����dS)Nrzindex.{})rrxr r!r"r�r�)r#r$r$r%�delete_index�sz$RepositoryCheckTestCase.delete_indexcCs6tjtjj|jddj|j���tjj|jd|��dS)Nrzindex.{})r�renamer r!r"r�r�)r#�new_namer$r$r%�rename_index�sz$RepositoryCheckTestCase.rename_indexcCstdd�|jj�D��S)Ncss|]}t|�VqdS)N)r�)r4rBr$r$r%r��sz7RepositoryCheckTestCase.list_objects.<locals>.<genexpr>)r�rr])r#r$r$r%�list_objects�sz$RepositoryCheckTestCase.list_objectscs��jdddgddgdgg��jtddddddg��j���jdd��jd��jt�fd	d
���jj	��jdd��jdd��jddd��j
d��jdd��jtdddddg��j��dS)
Nrrr.���T)r�cs
�jd�S)Nr�)r�r$)r#r$r%rN�szGRepositoryCheckTestCase.test_repair_corrupted_segment.<locals>.<lambda>F)r�r�)r�rPr�r�ryr�rQrrrWr�)r#r$)r#r%�test_repair_corrupted_segment�s 


z5RepositoryCheckTestCase.test_repair_corrupted_segmentcCs�|jdddgdddgg�|jtddddddg�|j��|jdd�|jd�|jj�|jddd	�|jtdddg�|j��dS)
Nrrr.r�r�r�T)r�)r�r�)r�rPr�r�ryr�rrW)r#r$r$r%�test_repair_missing_segment�s 

z3RepositoryCheckTestCase.test_repair_missing_segmentcsX�jdddgdddgg��jd��jtj�fdd���jtdddg��j��dS)	Nrrr.r�r�r�cs
�jd�S)Nr�)r�r$)r#r$r%rN�szLRepositoryCheckTestCase.test_repair_missing_commit_segment.<locals>.<lambda>)r�r�rQrrRrPr�r�)r#r$)r#r%�"test_repair_missing_commit_segment�s
z:RepositoryCheckTestCase.test_repair_missing_commit_segmentcs��jdddgdddgg�ttjj�jddd	d
�d��}|jdtj�|jd�WdQRX�j	t
j�fd
d���jdd��j
d��jtdddg��j��dS)Nrrr.r�r�r�rr�r��3zr+b�Xcs
�jd�S)Nr�)r�r$)r#r$r%rNszNRepositoryCheckTestCase.test_repair_corrupted_commit_segment.<locals>.<lambda>T)r�r9)r�r&rr r!r"r��SEEK_ENDrqrQrrRryr�rPr�r�)r#r�r$)r#r%�$test_repair_corrupted_commit_segment�s
z<RepositoryCheckTestCase.test_repair_corrupted_commit_segmentcs��jdddgg�ttjj�jdddd�d��}|jdtj�|jd	�WdQRX�j	t
j�fd
d���jdd
��jdd
��j
�j�dg��jddd��j
�j�dg��jdd
��jd��j
tdddg��j��dS)Nrrr.rr�r��1zr+br�cs
�jd�S)Nr�)r�r$)r#r$r%rNsz@RepositoryCheckTestCase.test_repair_no_commits.<locals>.<lambda>F)r�zindex.1T)r�r�zindex.3r9)r�r&rr r!r"r�r�rqrQr�CheckNeededryrPr�r�r�r�)r#r�r$)r#r%�test_repair_no_commitss
z.RepositoryCheckTestCase.test_repair_no_commitscCs\|jdddgdddgg�|j�|jdd�|jd�|jtddddddg�|j��dS)	Nrrr.r�r�r�T)r�)r�r�ryr�rPr�r�)r#r$r$r%�test_repair_missing_indexs

z1RepositoryCheckTestCase.test_repair_missing_indexcCs�|jdddgdddgg�|j|j�dg�|jd�|jd	d
�|j|j�dg�|jd�|jtddddddg�|j��dS)Nrrr.r�r�r�zindex.3z	index.100T)r�)r�rPr�r�ryr�r�r�)r#r$r$r%�test_repair_index_too_news

z1RepositoryCheckTestCase.test_repair_index_too_newcCs�|jjtd�d�|jjtd�d�tjtd��}|jj�|j�WdQRX|j�|j�*|j	dd�|j
|jjtd��d�WdQRXdS)Nrsdatasdata2r|T)r�)rr/rrr�rr0r�r-ryrPrL)r#r�r$r$r%�test_crash_before_compact%s
z1RepositoryCheckTestCase.test_crash_before_compactN)FT)rFrGrHr�ryr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr$r$r$r%r��s&
	
	r�c@seZdZdd�ZdS)�RepositoryHintsTestCasecCs�|jjtd�d�|j|jji�|jjtd��|jj�|jjtd�d�|jj�|jtd�|jj�|jd|jj�|jd|jj	�dS)Nrsdatar)
rr/rrPZshadow_indexr1r0Z
assert_not_inr�r�)r#r$r$r%�test_hints_behaviour4s

z,RepositoryHintsTestCase.test_hints_behaviourN)rFrGrHrr$r$r$r%r2src@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�RemoteRepositoryTestCaseNFcCs"ttdtjj|jd��d|d�S)Nz__testsuite__:rT)rr)r
rrr r!r")r#rr$r$r%r&HszRemoteRepositoryTestCase.opencCsGdd�d�}|�S)Nc@s$eZdZdZdZgZdZdd�ZdS)z9RemoteRepositoryTestCase._get_mock_args.<locals>.MockArgsZborg�?NcSs
t||�S)N)�hasattr)r#�itemr$r$r%�__contains__SszFRemoteRepositoryTestCase._get_mock_args.<locals>.MockArgs.__contains__)rFrGrH�remote_path�umask�debug_topics�rshrr$r$r$r%�MockArgsMs
r
r$)r#r
r$r$r%�_get_mock_argsLs
z'RemoteRepositoryTestCase._get_mock_argscs�jt�fdd��dS)Ncs�jjdi�S)N�__init__)r�callr$)r#r$r%rNZsz;RemoteRepositoryTestCase.test_invalid_rpc.<locals>.<lambda>)rQr)r#r$)r#r%�test_invalid_rpcYsz)RemoteRepositoryTestCase.test_invalid_rpccrCs�d}y|jjdddi�Wn$tjk
r>}zWYdd}~XnXy|jjdddi�Wn$tjk
rz}zWYdd}~XnXy|jjdddi�Wn$tjk
r�}zWYdd}~XnXy|jjdddi�Wn"tk
r�}zWYdd}~XnXy|jjdddi�Wn$tk
�r,}zWYdd}~XnXy|jjddd	i�Wn&tjk
�rj}zWYdd}~XnXy|jjddd
i�Wn$t	k
�r�}zWYdd}~XnXy|jjdddi�Wn&t
jk
�r�}zWYdd}~XnXdS)Nztest stringZinject_exceptionZkind�DoesNotExist�
AlreadyExistsr�rrrRrZdivide)rrrrrr�rrrRrr
ZRPCError)r#�s1�er$r$r%�test_rpc_exception_transport\sBz5RemoteRepositoryTestCase.test_rpc_exception_transportcCs|j�}||j_dtjd<dS)Nz	ssh --fooZBORG_RSH)rr�_argsr�environ)r#�argsr$r$r%�test_ssh_cmd�s
z%RemoteRepositoryTestCase.test_ssh_cmdcCsN|j�}tj�jtj�d|_ddg|_|j�}d|_d|_d|_||j	_
dS)Nzborg-0.28.2Zsomething_client_sideZrepository_compactionri���z
ssh -i foo)r�logging�	getLogger�setLevel�INFOr	rr�rrr)r#rr$r$r%�
test_borg_cmd�s
z&RemoteRepositoryTestCase.test_borg_cmd)F)
rFrGrHrr&rrrrrr$r$r$r%rEs

6
rc@seZdZddd�Zdd�ZdS)�RemoteLegacyFreeFc
Cs<tjtdd��$ttdtjj|jd��d|d�SQRXdS)NZ
dictFormatTz__testsuite__:r)rr)rr�r
rrr r!r")r#rr$r$r%r&�szRemoteLegacyFree.opencCs�|jjtd�d�|jj�|jj�|j�|_|j�"|jjtd�d�|jj�WdQRX|j�|_|j� |jjtd��|jj�WdQRXdS)Nrsfoosbar)rr/rr0r*r&r1)r#r$r$r%�test_legacy_free�s



z!RemoteLegacyFree.test_legacy_freeN)F)rFrGrHr&r!r$r$r$r%r �s
r c@seZdZddd�Zdd�ZdS)�RemoteRepositoryCheckTestCaseFcCs"ttdtjj|jd��d|d�S)Nz__testsuite__:rT)rr)r
rrr r!r")r#rr$r$r%r&�sz"RemoteRepositoryCheckTestCase.opencCsdS)Nr$)r#r$r$r%r�sz7RemoteRepositoryCheckTestCase.test_crash_before_compactN)F)rFrGrHr&rr$r$r$r%r"�s
r"c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�RemoteLoggerTestCasecCs|tj�|_tj|j�|_|jgtj�jdd�<gtjd�jdd�<gtjd�jdd�<tj	j
�tj	|_tj�|_	t_	dS)Nzborg.repositoryzborg.repository.foo)r;�StringIO�streamr�
StreamHandler�handlerr�handlers�sys�stderr�flush�
old_stderr)r#r$r$r%r)�s

zRemoteLoggerTestCase.setUpcCs|jt_dS)N)r,r)r*)r#r$r$r%r,�szRemoteLoggerTestCase.tearDowncCs0td�|j|jj�d�|j|jj�d�dS)Nzunstructured stderr message
r3z$Remote: unstructured stderr message
)rrPr%�getvaluer*)r#r$r$r%�test_stderr_messages�sz)RemoteLoggerTestCase.test_stderr_messagescCs0td�|j|jj�d�|j|jj�d�dS)Nz%unstructured stderr progress message
r3z-Remote: unstructured stderr progress message
)rrPr%r-r*)r#r$r$r%�test_stderr_progress_messages�sz2RemoteLoggerTestCase.test_stderr_progress_messagescCsN|jjtj�tj�jtj�td�|j|jj�d�|j|j	j�d�dS)Nz,$LOG INFO Remote: borg < 1.1 format message
z"Remote: borg < 1.1 format message
r3)
r'rr�DEBUGrrrPr%r-r*)r#r$r$r%�test_pre11_format_messages�s
z/RemoteLoggerTestCase.test_pre11_format_messagescCsN|jjtj�tj�jtj�td�|j|jj�d�|j|j	j�d�dS)Nz=$LOG INFO borg.repository Remote: borg >= 1.1 format message
z#Remote: borg >= 1.1 format message
r3)
r'rrr0rrrPr%r-r*)r#r$r$r%�test_post11_format_messages�s
z0RemoteLoggerTestCase.test_post11_format_messagescCsN|jjtj�tj�jtj�td�|j|jj�d�|j|j	j�d�dS)Nz:$LOG INFO borg.repository Remote: new format info message
r3)
r'rr�WARNINGrrrPr%r-r*)r#r$r$r%�test_remote_messages_screeneds
z2RemoteLoggerTestCase.test_remote_messages_screenedcCs�tjd�jtj�tjd�jtj�|jjtj�tj�jtj�tj�}tj|�}|jtj�|gtjd�j	dd�<tj�}tj|�}|jtj�|gtjd�j	dd�<t
d�|j|j�d�|j|j�d�|j|j
j�d�|j|jj�d�dS)Nzborg.repositoryzborg.repository.fooz;$LOG INFO borg.repository Remote: new format child message
r3z!Remote: new format child message
)rrrrr'r3r;r$r&r(rrPr-r%r*)r#Zchild_streamZ
child_handlerZ
foo_streamZfoo_handlerr$r$r%� test_info_to_correct_local_childs"

z5RemoteLoggerTestCase.test_info_to_correct_local_childN)rFrGrHr)r,r.r/r1r2r4r5r$r$r$r%r#�s	r#)4r;rrr+r)r'Z
unittest.mockrr�Z	hashindexrZhelpersrrrZlockingrr	Zremoter
rrr
rrrrrrrrrr3rrr�rrrIrhrur�r�r�r�r�r�rrr r"r#r$r$r$r%�<module>sF$+s9&**n