Current File : //usr/lib64/python3.6/site-packages/borg/testsuite/__pycache__/archiver.cpython-36.pyc
3

up�de\�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZmZddlmZddlmZddlmZddlmZddlmZddlmZmZdd	lmZddlZyddl Z Wne!k
�rYnXddl"Z"ddl#Z"d
dl$m%Z%m&Z&m'Z'd
dl(m)Z)m*Z*m+Z+m,Z,d
d
l-m.Z.m/Z/m0Z0d
dl1m2Z2m3Z3d
dl4Td
dl5m6Z6m7Z7d
dl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>d
dl?m@Z@mAZAd
dlBmCZCd
dl&mDZDmEZEd
dl&mFZFmGZGmHZHd
dl&mIZImJZJmKZKd
dl&mLZLd
dl&mMZMd
dl&mNZNd
dlOmPZPmQZQd
dlRmSZSmTZTmUZUd
dlVmWZWd
dlXmYZYd
dlZm[Z[d
dl\m]Z]m^Z^d
d l_m`Z`d!d"l$maZambZbd!d#l$mcZcmdZdmeZemfZfd!d$l$mgZgmhZhmiZimjZjmkZkd!d%l'mlZld!d&lmmnZnd!d'l$moZoejpjqejpjrejpjset�d(��Zudd)dd*d)d+�d,d-�Zvd.d/�Zwyevd0d1d2d3�d4d5gZxWneyk
�rjd4gZxYnXejzexd6�d7d8��Z{d9d:�Z|d;Z}ej~jejpj�e}�d<e}d=�d>d?��Z�Gd@dA�dAec�Z�GdBdC�dCe��Z�ej�d5exkdD�GdEdF�dFe���Z�GdGdH�dHe��Z�GdIdJ�dJe��Z�GdKdL�dLe��Z�GdMdN�dNe��Z�GdOdP�dPe��Z�GdQdR�dRe��Z�dSdT�Z�dUdV�Z�GdWdX�dX�Z�GdYdZ�dZ�Z�d[d\�Z�d]d^�Z�ej~j�d_e�e��j����d`da��Z�ej~j�dbe�e.j�j����dcdd��Z�dS)e�N)�	unhexlify�
b2a_base64)�ConfigParser)�datetime)�timezone)�	timedelta)�sha256)�BytesIO�StringIO)�patch�)�xattr�helpers�platform)�Archive�ChunkBuffer�
flags_noatime�flags_normal)�Archiver�parse_storage_quota�PURE_PYTHON_MSGPACK_WARNING)�Cache�
LocalCache)�*)�
bytes_to_long�num_aes_blocks)�KeyfileKeyBase�RepoKey�
KeyfileKey�
Passphrase�TAMRequiredError�ArchiveTAMRequiredError)�RepoIdMismatch�NotABorgKeyFile)�FileIntegrityError)�Location�get_security_dir)�Manifest�MandatoryFeatureUnsupported�ArchiveInfo)�EXIT_SUCCESS�EXIT_WARNING�
EXIT_ERROR)�
bin_to_hex)�MAX_S)�msgpack)�
RstToTextLazy�rst_to_terminal)�	IECommand�PatternMatcher�
parse_pattern)�Item)�
LockFailed)�
setup_logging)�RemoteRepository�PathNotAllowed)�
Repository�)�has_lchflags�
has_llfuse)�BaseTestCase�	changedir�environment_variable�
no_selinux)�are_symlinks_supported�are_hardlinks_supported�are_fifos_supported�is_utime_fully_supported�is_birthtime_fully_supported)�fakeroot_detected)�make_attic_repo)�keyz..F�)�archiver�fork�exe�input�
binary_outputcOs�|r�yX|dkrtjddf}n$t|t�r.|f}nt|t�s@td��tj||tj|d�}d}	WnZtj	k
r�}
z|
j
}|
j}	WYdd}
~
Xn,tk
r�}
zd}|
j
}	WYdd}
~
XnX|r�|	|fS|	tj|�fS�ntjtjtj}}}
z�t|j��t_t|�tj_t�}tj|dd�}t_t_|dk�r8t�}d	d
�|_t|_tt_y|jt|��}WnFtk
�r�}
z(|j �|
j
|�r�|j!�n
|j!�j�fSd}
~
XnX|j"|�}	|j �|	|�r�|j!�n
|j!�j�fS|||
t_t_t_XdS)Nz-mz
borg.archiverz"exe must be None, a tuple or a str)�stderrrNr�zutf-8)�encodingcWsdS)N�)�argsrSrS� /usr/lib64/python3.6/archiver.py�<lambda>dszexec_cmd.<locals>.<lambda>)#�sys�
executable�
isinstance�str�tuple�
ValueError�
subprocessZcheck_outputZSTDOUTZCalledProcessError�output�
returncode�
SystemExit�code�os�fsdecode�stdin�stdoutrPr
�decoder	�buffer�io�
TextIOWrapperrZ
prerun_checksr*�	exit_coder�
parse_args�list�flush�getvalueZrun)rKrLrMrNrOrT�kw�borgr^�ret�erdrerPZoutput_textrSrSrU�exec_cmdEsN



,
rscCs6tjd�sdStjddgtjd�}|j�\}}d|kS)N�tarFz	--version)resGNU tar)�shutil�whichr]�Popen�PIPEZcommunicate)�popenrerPrSrSrU�have_gnutarvs

rz�helpzborg.exeT)rMrL�python�binary)Zparamscs8|jdkrd�n|jdkr d�ntd���fdd�}|S)Nr|r}zborg.exez"param must be 'python' or 'binary'cst|�dd�|��S)NT)rMrL)rs)rTro)rMrSrU�exec_fn�szcmd.<locals>.exec_fn)Zparamr\)Zrequestr~rS)rMrU�cmd�s

rcCs�|jd�}|jd�}|jd�}|jd�jd�|dddt|��\}}|tksRt�|d	d
|t|��\}}|tksvt�tt|���$|dd
|�\}}|tks�t�WdQRX|dd
|d�\}}|tks�t�|d	d
|t|��\}}|tks�t�dS)
N�reporNr^Z	test_file�content�initz--encryption=nonez%s�createz%s::archive�extractzdoes/not/match)	�mkdir�join�writerZr*�AssertionErrorr?r+r,)r�tmpdirr�rNr^�rc�outrSrSrU�test_return_codes�s


r�z/tmp/borg-mountzneeds a 16MB fs mounted on %s)�reasonc)Cs
ddd�}tdd����t}tjj|�s,t�tjj|d�}tjj|d�}tjj|d�}�x�td	�D�]�}tj	|dd
�tj	|dd
�||ddd
d�|d|�\}}|t
kr�td||�|t
ks�t�z�d\}	}
x�|	�r�|
d7}
y||dd�Wn6tk
�r"}z|j
t
jk�rP�WYdd}~XnXz6|dd||
f|�\}}|t
k}	|	�sXtd||�Wdtj	tjj|d�dd
�tjtjj|d��Xq�WWdtj	|dd
�X|d|�\}}|t
k�r�td||�|dd|�\}}|t
k�r�td||�|t
ksbt�qbWWdQRXdS)NTc
Ss�tj|dd�tj|�|r<tjd|�}|dkr<tjd|�}xLt|�D]@}tjj|d|�}t	|d��}tj
|�}|j|�WdQRXqFWdS)NT)�
ignore_errorsr;zfile%03d�wb)ru�rmtreerbr��randomZrandint�range�pathr��open�urandomr�)�dir�count�size�rnd�i�fn�f�datarSrSrU�
make_files�s

z"test_disk_full.<locals>.make_files�YES)�!BORG_CHECK_I_KNOW_WHAT_I_AM_DOINGr�rN�reserve�d)r��Pi��F)r�r�rr;�i@
r�z%s::test%03dzlock.exclusivezlock.rosterrl�checkz--repair)T)Tr)r@�DF_MOUNTrbr��existsr�r�r�rur�r*�print�OSError�errnoZENOSPC�remove)rr��mountr�rNr��jr�r��successr��errrSrSrU�test_disk_full�sP



r�c@sZeZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zddd�Zdd�Z
dS)�ArchiverTestCaseBaseNFrQcCs�dtjd<dtjd<dtjd<dtjd<|jr6t�p8d|_tj�|_tjj	|jd�|_
|j|j
|_tjj	|jd	�|_
tjj	|jd
�|_tjj	|jd�|_tjj	|jd�|_tjj	|jd
�|_tjj	|jd�|_|jtjd<|jtjd<tj|j
�tj|j
d�tj|j�tj|j�tj|j�t|jd��}|jd�WdQRXt|jd��}|jd�WdQRXtj�|_tj|j�dS)Nr�r��"BORG_DELETE_I_KNOW_WHAT_I_AM_DOINGZwaytooeasyonlyfortests�BORG_PASSPHRASEZdisabledZ
BORG_SELFTEST�
repositoryrNr^�keys�cacheZexcludes�patternsZ
BORG_KEYS_DIRZBORG_CACHE_DIRi�r�s1input/file2
# A comment line, then a blank line

sI+input/file_important
- input/file*
# A comment line, then a blank line

)rb�environ�FORK_DEFAULTrrK�tempfileZmkdtempr�r�r��repository_path�prefix�repository_location�
input_path�output_path�	keys_path�
cache_path�exclude_file_path�patterns_file_pathr��chmodr�r��getcwd�_old_wd�chdir)�self�fdrSrSrU�setUp�s6





zArchiverTestCaseBase.setUpcCs&tj|j�tj|jdd�t�dS)NT)r�)rbr�r�rur�r�r7)r�rSrSrU�tearDownszArchiverTestCaseBase.tearDownc	s�|jdd�}|jdd�}|jdd�}|dkr2|j}t|||j|jd�|��\}}||kr`t|�|j||�|rxtj	�nt�|r�dnd}|j
�fd	d
�|jdd�D��}|S)
NrjrrLrOF)rLrMrKrJrQc3s|]}�|kr|VqdS)NrS)�.0�line)�pp_msgrSrU�	<genexpr>,sz+ArchiverTestCaseBase.cmd.<locals>.<genexpr>T)�keepends)�pop�getr�rs�EXErKr��assert_equalr�encoder��
splitlines)	r�rTrorjrLrOrqr^�emptyrS)r�rUrs zArchiverTestCaseBase.cmdcCs|jdd|jd|t�dS)Nr�z--compression=lz4z::)rr��src_dir)r��namerSrSrU�create_src_archive0sz'ArchiverTestCaseBase.create_src_archivecCsFt|jdd�}|�&tj|tj�\}}t||||�}WdQRX||fS)NT)�	exclusive)r:r�r'�load�NO_OPERATION_CHECKr)r�r�r��manifestrI�archiverSrSrU�open_archive3s
z!ArchiverTestCaseBase.open_archivecCst|jdd�S)NT)r�)r:r�)r�rSrSrU�open_repository:sz$ArchiverTestCaseBase.open_repositoryrc	Cs�|dko|ot|�|ks"td��tjj|j|�}tjjtjj|��sXtjtjj|��t	|d�� }|dkrtd|}|j
|�WdQRXdS)Nrzsize and contents do not matchr��X)�lenr�rbr�r�r�r��dirname�makedirsr�r�)r�r�r��contents�filenamer�rSrSrU�create_regular_file=s"z(ArchiverTestCaseBase.create_regular_filecCs�|jdd#d�|jddd�|jdd$d�tjdd�t�r`tjtjj|jd�tjj|jd	��t�r~tj	d
tjj|jd��|jdd
d�t
jr�t
j|j�r�t
j
tjj|jd�dd�t
j
tjj|jd�dd�t�r�tjtjj|jd��t�rtjtjj|jd�tj�yZtjddtjBtjdd��tjddtjBtjdd��tjdd�tjddd�d}WnVtk
�r�d}Yn>tk
�r�}z |jtjtjfk�r��d}WYd d }~XnXtj d
�|jd!d"d�|S)%zFCreate a minimal test case including all supported file types
        �file1ir�)r��flagfilez
dir2/file2zinput/file1i�	�hardlink�	somewhere�link1�	fusexattrr;zuser.foosbarz
user.emptyrJ�fifo1z
input/bdevi��
r�z
input/cdev��(z
input/dir2imr���TFNr�ri@i@)!r�rbr�rC�linkr�r�r�rB�symlinkr
�XATTR_FAKEROOT�
is_enabled�setxattrrD�mkfifor<r�	set_flags�stat�	UF_NODUMP�mknod�S_IFBLK�makedev�S_IFCHR�chown�PermissionErrorr�r�ZEINVALZENOSYS�time�sleep)r��	have_rootrrrSrSrU�create_test_filesGs@
z&ArchiverTestCaseBase.create_test_files)rN)�__name__�
__module__�__qualname__r�r�r�r�r�rr�r�r�r�rrSrSrSrUr��s

r�c@s�eZdZejje�dd�Zdd�Zdd�Z	edd��Z
d	d
�Zdd�Zejje
�d
d�dd��Zejje�dd�dd��Zejje�dd�ejje�dd�dd���Zejje�dd�ejje�dd�dd���Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Z d2d3�Z!ee"j#e$d4�d5d6���Z%ed7d8��Z&ed9d:��Z'ed;d<��Z(d=d>�Z)d?d@�Z*dAdB�Z+dCdD�Z,dEdF�Z-dGdH�Z.dIdJ�Z/dKdL�Z0dMdN�Z1dOdP�Z2dQdR�Z3dSdT�Z4dUdV�Z5dWdX�Z6dYdZ�Z7d[d\�Z8d]d^�Z9d_d`�Z:dadb�Z;dcdd�Z<dedf�Z=dgdh�Z>didj�Z?dkdl�Z@dmdn�ZAdodp�ZBdqdr�ZCdsdt�ZDdudv�ZEejje�dd�dwdx��ZFejjeGjHdyd�dzd{��ZIejjeGjHd|d�d}d~��ZJdd��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_e"j#e$d4�d�d���Z`ejjd�eajbkd�d�d�d���Zcd�d��Zdd�d��Zed�d��Zfd�d��Zgd�d��Zhd�d��Zid�d��Zjd�d��Zkd�d��Zle"j#e$d4�d�d„�Zmejjnd�dĄ�Zod�dƄZpd�dȄZqd�dʄZrd�d̄Zsd�d΄Ztd�dЄZud�d҄Zvd�dԄZwd�dքZxd�d؄Zyd�dڄZzd�d܄Z{d�dބZ|d�d�Z}d�d�Z~d�d�Zd�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d��Z��d�d�d��Z�d�d��Z�d�d��Z�d�d��Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d	�Z��d
�d�Z��d�d
�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z�e"j#e$d4��d�d��Z�e"j#e$d4��d�d��Z�e"j#e$d4��d�d��Z�e"j#e$d4��d�d��Z��d�d�Z��d �d!�Z��d"�d#�Z��d$�d%�Z��d&�d'�Z��d(�d)�Z��d*�d+�Z��d,�d-�Z��d.�d/�Z��d0�d1�Z��d2�d3�Z��d4�d5�Z��d6�d7�Z��d8�d9�Z��d:�d;�Z�ejje�dd��d<�d=��Z��d>�d?�Z��d@�dA�Z��dB�dC�Z��dD�dE�Z��dF�dG�Z��dH�dI�Z��dJ�dK�Z��dL�dM�Z��dN�dO�Z��dP�dQ�Z��dR�dS�Z��dT�dU�Z��dV�dW�Z��dX�dY�Z��dZ�d[�Z��d\�d]�Z��d^�d_�Z��d`�da�Z��db�dc�Z��dd�de�Z��df�dg�Z�ejje���dhd�Z�ejje�jĐdi��djd�Z�edk�dl��Z�e�eŐdm�dn���Z�edo�dp��Z�eedq�dr���Z�eeds�dt���Zʐdu�dv�Z�ejjeGjHd|d��dw�dx��Z�ejjeGjHd|d��dy�dz��Z͐d{�d|�Zΐd}�d~�ZϐdS(��ArchiverTestCasezhardlinks not supported)r�cCst|j|j��}t|�S)N)r-�_extract_repository_idr�r&)r��
repository_idrSrSrUr&�sz!ArchiverTestCase.get_security_dirc
Cs�|j�}|jdddd|jdd�}|jd|�|jd|�|jd	d
|jdd�|jd	d
d
|jdd�}|jd|�|jd|�td��|jd|jd�WdQRX|jdd|j�}|jd|�|jd|�ddddddddg}t�r�|jd�t��r|jd�t��r|jd �|�s.|j	d�|j	d�t
�rR|j	d�tj	tjj
dd!��|jdd|jd�}x|D]}|j||��qlW|jdd"�|jd#|jd�}t
�r�d$nd%}|jd&||�tj|j�|jd#|jd�}d'd(�}	|j|	|�|	|��dS))Nr�z--encryption=repokeyz--show-versionz	--show-rcT)rLzborgbackup versionz%terminating with success status, rc 0r�z--exclude-nodumpz::testrNz--statsz::test.2zArchive name: test.2zThis archive: r^r�rlz--short�testztest.2z
input/bdevz
input/cdevz
input/dir2zinput/dir2/file2zinput/emptyzinput/file1zinput/flagfilezinput/fifo1zinput/link1zinput/hardlinkr�zoutput/input�info��zNumber of files: %dcSsRddddddg}g}x2|j�D]&}x |D]}|j|�r(|j|�q(WqWdj|�S)NzName:zFingerprint:zNumber of files:z
This archive:z
All archives:zChunk index:�
)r��
startswith�appendr�)r^�prefixes�resultr�r�rSrSrU�filter�s

z9ArchiverTestCase.test_basic_functionality.<locals>.filter)rrr��	assert_inr?rDrrBrCr�r<rbr�r��assert_dirs_equalrur�r�r�)
r�rr^Zlist_output�expectedr�Zinfo_outputZ
item_countZinfo_output2rrSrSrU�test_basic_functionality�sX







z)ArchiverTestCase.test_basic_functionalitycCs�tjj|jd�}tjj|jd�}tj|�tj|�tjj|d�}tjj|d�}|j|dd�tj||�|jdd|j�|jd|jd	d
d
�|jdd|jd	�}d
d�|j	d�D�}t
|�d
ddddgks�t�dS)N�a�br�s123456)r�r�z--encryption=noner�z::testrNrlz--json-linescSsg|]}|rtj|�d�qS)r�)�json�loads)r�r�rSrSrU�
<listcomp>�sz?ArchiverTestCase.test_create_duplicate_root.<locals>.<listcomp>rzinput/azinput/a/hardlinkzinput/bzinput/b/hardlink)rbr�r�r�r�r�r�rr��split�sortedr�)r��path_a�path_b�hl_a�hl_b�archive_list�pathsrSrSrU�test_create_duplicate_root�s

z+ArchiverTestCase.test_create_duplicate_rootcCsttjj|jdd�}tjj|d�}|j|}tjtj��|j	dd|�WdQRX|j	ddd|�tjj
|�spt�dS)NZparent1Zparent2r�r�z--encryption=nonez--make-parent-dirs)rbr�r�r�r��pytest�raisesr:ZParentPathDoesNotExistrr�r�)r��parent_pathr�r�rSrSrU�test_init_parent_dirs�s
z&ArchiverTestCase.test_init_parent_dirscCs�|jdd|j�y*tjtjtj�}|jtjj|j	d��WnPt
k
r�}z4|jtjkrdt
jd�n|jtjkrzt
jd�WYdd}~XnX|jd|jdd�|j�td	��*|jd
|jd�tjjd�s�t�WdQRXdS)Nr�z--encryption=repokeyzunix-socketz&unix sockets disabled or not supportedz(permission denied to create unix socketsr�z::testrNr^r�zinput/unix-socket)rr��socketZAF_UNIXZSOCK_STREAMZbindrbr�r�r�rr�ZEPERMr)�skip�EACCES�closer?r�r�)r�Zsockr�rSrSrU�test_unix_socket�s
z!ArchiverTestCase.test_unix_socketzsymlinks not supportedcCsh|j�|jdd|j�|jd|jdd�td��*|jd|jd�tjd�d	ksZt�WdQRXdS)
Nr�z--encryption=repokeyr�z::testrNr^r�zinput/link1r�)rrr�r?rb�readlinkr�)r�rSrSrU�test_symlink_extract�s
z%ArchiverTestCase.test_symlink_extractz4cannot properly setup and execute test without utimecCs�dd�}|j�d\}}|d�}tjd||f�|jdd|j�|jd|jd	d
�td��|jd|jd	�WdQRXtjd�}tjd
�}|j|jko�|dkns�t�|r�|j	|j	ko�|dkns�t�n|j	|dks�t�dS)NcSsntj|�j}y(ttj|t���}|j�WdQRXWntk
rHdSXtj|�j}ttk}|oh||kSdS)NF)rbr��st_atime_nsr�r�readrr)�	some_file�atime_before�file�atime_after�noatime_usedrSrSrU�has_noatimesz0ArchiverTestCase.test_atime.<locals>.has_noatime��[��8�
zinput/file1r�z--encryption=repokeyr�z::testrNr^r�zoutput/input/file1ge��A)r<r=)
rrb�utimerr�r?r��st_mtime_nsr�r4)r�r;�atime�mtime�have_noatime�sti�storSrSrU�
test_atime�s


$&zArchiverTestCase.test_atimez8cannot properly setup and execute test without birthtimecCs�|j�d\}}}tjd||f�tjd||f�|jdd|j�|jd|jdd	�td
��|jd|jd�WdQRXtjd�}tjd�}t|jd
�t|jd
�ko�|d
kns�t	�|j
|j
ko�|d
kns�t	�dS)N��k8�Cm8��n8zinput/file1r�z--encryption=repokeyr�z::testrNr^r�zoutput/input/file1ge��A)rFrGrH)rrbr>rr�r?r��int�st_birthtimer�r?)r��	birthtimerAr@rCrDrSrSrU�test_birthtimes



4zArchiverTestCase.test_birthtimecCs�|j�d\}}}tjd||f�tjd||f�|jdd|j�|jdd|jd	d
�td��|jd|jd	�WdQRXtjd�}tjd
�}t|jd�|dks�t	�t|jd�|dks�t	�|j
|j
ko�|dkns�t	�dS)N��k8�Cm8��n8zinput/file1r�z--encryption=repokeyr�z
--nobirthtimez::testrNr^r�zoutput/input/file1ge��A)rMrNrO)rrbr>rr�r?r�rIrJr�r?)r�rKrAr@rCrDrSrSrU�test_nobirthtime.s



z!ArchiverTestCase.test_nobirthtimec	Cst|j��}|jSQRXdS)N)r:r��id)r�r�r�rSrSrUr?sz'ArchiverTestCase._extract_repository_idcCsvtdd�}|jtjj|d��|jddt|��ttjj|d�d��}|j|�WdQRXt	|j
��}|jSQRXdS)N)�
interpolation�configr�rQ�w)rr5rbr�r��setr-r�r�r:r�rQ)r�r�rQrSr�r�rSrSrU�_set_repository_idCs
z#ArchiverTestCase._set_repository_idc	Csndd�}tjj|jd�}d}ddt>}|t|�|}t|d��:}|j|d�|j|�|j|d�|j	�}|j
|�WdQRX||||�}|�rj|jdd	|j�|jd
|jdd�t
|j��|jd
d|jd�WdQRX|jdd�tjj|jdd�}t|d��H}|j|j|�d|�|j|jt|��|�|j|j|�d|�WdQRX||||��sjt�dS)NcSs�tj|�}|j|kst�d}|r>t|d�r>|jd|jkr>d}|r�ttd�r�ttd�r�t|d��P}y0|jdtj�dkrzd}|jdtj	�|kr�d}Wnt
k
r�d}YnXWdQRX|S)	NT�	st_blocksiF�	SEEK_HOLE�	SEEK_DATA�rbr)rbr��st_sizer��hasattrrWr��seekrXrYr�)r��
total_size�	hole_size�st�sparser�rSrSrU�	is_sparseMs
z4ArchiverTestCase.test_sparse_file.<locals>.is_sparserasfoobarrr;r�r�z--encryption=repokeyr�z::testrNr�z--sparsezoutput/inputrZ�)rbr�r�r�Z
CHUNK_MAX_EXPr�r�r]r��tell�truncaterr�r?r�rr�r5r�)	r�rbr�r�r_r^r��posZsparse_supportrSrSrU�test_sparse_fileLs0
 z!ArchiverTestCase.test_sparse_filecCs�dddg}x2|D]*}tjj|j|�}t|d��WdQRXqW|jdd|j�|jd|jdd	�xZ|D]R}td
��$|jd|jdtjjd	|��WdQRXtjjtjjd
d	|��sht	�qhWdS)NZnormalzwith some blanksz
(with_parens)r�r�z--encryption=repokeyr�z::testrNr^r�)
rbr�r�r�r�rr�r?r�r�)r��	filenamesr�rSrSrU�test_unusual_filenamess



(z'ArchiverTestCase.test_unusual_filenamescCs�|j�dtjd<|jdd|j�|j|j�}|jd|jdd�tj|j�|jdd|j�|j	|j|�|j
||j|j��|jr�|jd|jd	dtd
�n,t
jtj��|jd|jd	d�WdQRXdS)N�
passphraser�r�z--encryption=repokeyr�z::testrNz--encryption=nonez::test.2)rj)rrbr�rr�rr�rur�rVr�r�r,r)r*r�EncryptionMethodMismatch)r�rrSrSrU�test_repository_swap_detection�s
z/ArchiverTestCase.test_repository_swap_detectioncCs�|j�|jdd|jd�dtjd<|jdd|jd�|jd|jd	d
�tj|jd�tj|jd|jd�|j	r�|jd|jdd
t
d�n,tjt
j��|jd|jdd
�WdQRXdS)
Nr�z--encryption=none�_unencryptedrjr�z--encryption=repokey�
_encryptedr�z_encrypted::testrNz_encrypted::test.2)rj)rrr�rbr�rur�r��renamer�r,r)r*r�RepositoryAccessAborted)r�rSrSrU�test_repository_swap_detection2�s
z0ArchiverTestCase.test_repository_swap_detection2cCs�|j�dtjd<|jdd|j�|j|j�}|jd|jdd�tj|j�|jdd|j�|j	|j|�|j
||j|j��|jd	d
|j�|jr�|jd|jddtd�n,t
jtj��|jd|jdd�WdQRXdS)
Nrjr�r�z--encryption=repokeyr�z::testrNz--encryption=none�deletez--cache-onlyz::test.2)rj)rrbr�rr�rr�rur�rVr�r�r,r)r*rrk)r�rrSrSrU�'test_repository_swap_detection_no_cache�s
z8ArchiverTestCase.test_repository_swap_detection_no_cachecCs�|j�|jdd|jd�dtjd<|jdd|jd�|jd|jd	d
�|jdd|jd�|jdd|jd�tj|jd�tj|jd|jd�|j	r�|jd|jd
d
t
d�n,tjt
j��|jd|jd
d
�WdQRXdS)Nr�z--encryption=nonermrjr�z--encryption=repokeyrnr�z_encrypted::testrNrrz--cache-onlyz_encrypted::test.2)rj)rrr�rbr�rur�r�ror�r,r)r*rrp)r�rSrSrU�(test_repository_swap_detection2_no_cache�s
z9ArchiverTestCase.test_repository_swap_detection2_no_cachecCs�|j�|jdd|j�|jd|jdd�tj|j�tdd��4|jdd|j�|jdd	|j�tj|j��WdQRXtdd��R|jr�|jd|jd
dt	d�n,t
jtj
��|jd|jd
d�WdQRXWdQRXdS)Nr�z--encryption=repokeyr�z::testrNrQ)r�rrz--cache-onlyz::test.2)rj)rrr�rur�r�r@r&r�r,r)r*r�CacheInitAbortedError)r�rSrSrU�7test_repository_swap_detection_repokey_blank_passphrase�szHArchiverTestCase.test_repository_swap_detection_repokey_blank_passphrasecCs|jdd|j�|j�}tj|j|jd�tdd��|jd|jd�WdQRXttjj	|d���(}|j
�}|t|jd�j�ks�t
�WdQRX|jd|jd�tj|j�|jd|jd�tj|�|jd|jd�x&d
D]}tjjtjj	||��s�t
�q�WdS)Nr�z--encryption=repokeyZ_new�yes)Z BORG_RELOCATED_REPO_ACCESS_IS_OKr�location�key-type�manifest-timestamp)rxryrz)rr�r&rbror�r@r�r�r�r5r%Zcanonical_pathr�rur�r�r�)r�Zsecurity_dirr�rxr8rSrSrU�test_repository_move�s$

z%ArchiverTestCase.test_repository_movec
CsP|jdd|j�ttjj|j�d�d��}|jd�WdQRX|jd|j�dS)Nr�z--encryption=repokeyrxrTzsomething outdatedr)rr�r�rbr�r�r&r�)r�r�rSrSrU�test_security_dir_compat�sz)ArchiverTestCase.test_security_dir_compatcCs�|jdd|j�|jd|j�tj|j�|jd|j�tj|j�tj|j��|jrl|jd|jtd�n&tj	t
j��|jd|j�WdQRXtdd��|jd|j�WdQRXdS)Nr�z--encryption=noner)rjrw)Z*BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK)
rr�rur�r�r&r�r,r)r*rrur@)r�rSrSrU�test_unknown_unencrypted�sz)ArchiverTestCase.test_unknown_unencryptedc!Cs�|jdd|j�|jd�|jd|jdd�td���|jd|jdd	d
�tjjd�s`t�|jd��|jd|jdd	d�WdQRX|jd��|jd|jdd	d
�WdQRX|jd��|jd|jdd	d�WdQRXWdQRXdS)Nr�z--encryption=repokeyzdir/filer�z::testrNr^r�z--strip-components�3r8�2�1zinput/dir/file�0)	rr�r�r?rbr�r�r��assert_creates_file)r�rSrSrU�test_strip_componentss

  z&ArchiverTestCase.test_strip_componentscCs�tjtjj|jd��tjtjj|jd��|jddd�tjtjj|jd�tjj|jd��tjtjj|jd�tjj|jd��tjtjj|jd�tjj|jd��|jd	�tjtjj|jd	�tjj|jd
��|jdd|j�|jd
|jdd�dS)NZdir1zdir1/subdir�sources123456)r�Zabbaz
dir1/hardlinkzdir1/subdir/hardlinkzdir1/source2z	dir1/aaaar�z--encryption=repokeyr�z::testrN)	rbr�r�r�r�r�r�rr�)r�rSrSrU�_extract_hardlinks_setups
z)ArchiverTestCase._extract_hardlinks_setupzllfuse not installedc-Cs*|j�tjj|jd�}tjdkr,ddg}nddg}|j|jd|df|����t	|��ltj
d�jd	ksnt�tj
d
�jd	ks�t�t
d
d�j�dks�t�tj
d
�jd	ks�t�tj
d�jd	ks�t�WdQRXWdQRX|j|jd|df|����t	|��vtj
d�jd	k�st�tj
d�jd	k�s&t�t
dd�j�dk�s>t�tj
d�jd	k�sTt�tj
d�jd	k�sjt�WdQRXWdQRX|j|jd|f|����t	|��vtj
d�jdk�s�t�tj
d�jdk�s�t�tj
d�jdk�s�t�tj
d�jdk�s�t�t
dd�j�dk�st�WdQRXWdQRXdS)N�
mountpoint�darwinz-oz$ignore_permissions,defer_permissionsZignore_permissionsz::testz--strip-components=2r�rzsubdir/hardlinkrZs123456�aaaa�source2z
input/dir1zinput/dir1/hardlinkzinput/dir1/subdir/hardlinkzinput/dir1/aaaazinput/dir1/source2zinput/sourcerz
input/abba)r�rbr�r�r�rWr�
fuse_mountr�r?r��st_nlinkr�r�r5)r�r�Zignore_permsrSrSrU�test_fuse_mount_hardlinks1s4


(
*
z*ArchiverTestCase.test_fuse_mount_hardlinkscCs�|j�td��~|jd|jd�tjd�jdks8t�tjd�jdksLt�tjd�jdks`t�tjd�jdkstt�tdd	�j	�d
ks�t�WdQRXdS)Nr^r�z::testzinput/sourcerz
input/abbazinput/dir1/hardlinkzinput/dir1/subdir/hardlinkrZs123456)
r�r?rr�rbr�r�r�r�r5)r�rSrSrU�test_extract_hardlinks1Ss
z(ArchiverTestCase.test_extract_hardlinks1cCs.|j�td���|jd|jddd�tjd�jdks<t�tjd�jdksPt�tdd	�j	�d
ksft�tjd�jdkszt�tjd�jdks�t�WdQRXtd���|jd|jdd
�tjd�jdks�t�tjd�jdks�t�tdd	�j	�d
ks�t�tjd�jdk�s
t�tjd�jdk�s t�WdQRXdS)Nr^r�z::testz--strip-componentsrr�rzsubdir/hardlinkrZs123456r�r�z
input/dir1zinput/dir1/hardlinkzinput/dir1/subdir/hardlinkzinput/dir1/aaaazinput/dir1/source2)
r�r?rr�rbr�r�r�r�r5)r�rSrSrU�test_extract_hardlinks2^s

z(ArchiverTestCase.test_extract_hardlinks2cCs�tjj|jd�}tjj|jd�}tj|�tj|�tjj|d�}tjj|d�}|j|dd�tj||�|jdd|j�|jd|jd	d
d
�t	d��@|jd|jd	�tj
d
�jdks�t�tj
d�jdks�t�WdQRXdS)Nrrr�s123456)r�r�z--encryption=noner�z::testrNr^r�zinput/a/hardlinkrzinput/b/hardlink)
rbr�r�r�r�r�r�rr�r?r�r�r�)r�r"r#r$r%rSrSrU�test_extract_hardlinks_twiceps


z-ArchiverTestCase.test_extract_hardlinks_twicecCs,|jdd|j�|jddd�|jddd�|jddd�|jd	dd�|jd
d|jdd
�td��|jd|jdd�WdQRX|jttjd��dg�td��|jdd|jd�WdQRX|jttjd��ddg�td�� |jdd|j|jd�WdQRX|jttjd��ddg�dS)Nr�z--encryption=repokeyr�ir�)r��file2�file3�file4r�z--exclude=input/file4z::testrNr^r�zinput/file1zoutput/inputz--exclude=input/file2z--exclude-from=i@i@i@i@)	rr�r�r?r�r!rb�listdirr�)r�rSrSrU�test_extract_include_exclude�s


$z-ArchiverTestCase.test_extract_include_excludec#Cs�|jdd|j�|jddd�|jddd�|jddd�|jd	dd�|jd
dd�|jdd|jd
d�td��|jd|jd
�WdQRX|jttjd��dddd
g�tj	d�td��|jdd|jd
�WdQRX|jttjd��ddg�tj	d�td��|jddd|jd
�WdQRX|jttjd��dd
g�tj	d�td��$|jdd|j
dd|jd
�WdQRX|jttjd��dg�dS)Nr�z--encryption=repokeyr�ir�)r�r�r�r��file333r�z--exclude=re:input/file4$z::testrNr^r�zoutput/inputz--exclude=re:file3+z--exclude=input/file2z--exclude=re:file[01]z--exclude-from=z--exclude=re:file1z--exclude=re:file(\d)\1\1$i@i@i@i@i@)rr�r�r?r�r!rbr�rur�r�)r�rSrSrU�"test_extract_include_exclude_regex�s.




 

z3ArchiverTestCase.test_extract_include_exclude_regexc/Cs�|jdd|j�|jddd�|jddd�|jddd�|jd	dd�|jd
dd�|jdd d�t|jd��}|jd
�|jd�WdQRX|jdd|j|jdd�td��|jd|jd�WdQRX|jtt	j
d��dddd
g�tjd�t|jd��}|jd�WdQRXtd�� |jdd|j|jd�WdQRX|jtt	j
d��ddg�tjd�t|jd��.}|jd�|jd�|jd�|jd�WdQRXtd�� |jdd|j|jd�WdQRX|jtt	j
d��dg�dS)!Nr�z--encryption=repokeyr�ir�)r�r�r�r�r�zaa:somethingr�sre:input/file4$
sfm:*aa:*thing
r�z--exclude-from=z::testrNr^r�zoutput/inputs
re:file3+
sre:file(\d)\1\1$
sfm:nothingwillmatchthis
s*/file1
s
re:file2$
i@i@i@i@i@i@)
rr�r�r�r�r�r?r�r!rbr�rur�)r�r�rSrSrU�,test_extract_include_exclude_regex_from_file�s:



$




$z=ArchiverTestCase.test_extract_include_exclude_regex_from_filec"Cs�|jdd|j�|jddd�|jddd�|jddd�|jd	dd�|jd
dd�|jd|jdd
�td��|jd|jdd�WdQRX|jttjd��dddd
d	g�tj	d�td��|jdd|jdd�WdQRX|jttjd��ddg�tj	d�td��|jdd|jdd�WdQRX|jttjd��dg�tj	d�td��|jd|jdddd�WdQRX|jttjd��ddd
g�dS)Nr�z--encryption=repokeyr�ir�)r�r�r�r�r�r�z::testrNr^r�zre:.*zoutput/inputz--exclude=re:file[34]$z
re:file\d$z--exclude=input/file1zre:file[12]$zfm:input/file1zfm:*file33*zinput/file2i@i@i@i@i@)
rr�r�r?r�r!rbr�rur�)r�rSrSrU�test_extract_with_pattern�s,
 

 

 

"z*ArchiverTestCase.test_extract_with_patternc"Cs$|jdd|j�|jddd�|jd|jdd	�td
��|jd|jd�}WdQRX|jd|�tjd
�td
��|jdd|jd�}WdQRX|jd|�tjd
�td
��|jdd|jd�}WdQRX|jd|�tjd
�td
��|jddd|jd�}WdQRX|jd|�dS)Nr�z--encryption=repokeyr8ir�)r�r�z::testrNr^r�z
input/filezoutput/inputz--infoz--listi@)rr�r�r?�
assert_not_inrur�r)r�r^rSrSrU�test_extract_list_outputs$






 z)ArchiverTestCase.test_extract_list_outputcCsj|jdd|j�|jddd�|jd|jdd	�td
��&|jd|jdd�}d
|ks\t�WdQRXdS)Nr�z--encryption=repokeyr8ir�)r�r�z::testrNr^r�z
--progresszExtracting:i@)rr�r�r?r�)r�r^rSrSrU�test_extract_progresss
z&ArchiverTestCase.test_extract_progresscCs�|jdd|j�|jddd�|jdttdd	�|jd
tdd	�tjd�t�rltjd
tdt�n|jdttdd	�dS)Nr�z--encryption=repokeyr�ir�)r�z	cache1/%ss extra stuff)r�z	cache2/%ssinvalid signaturezinput/cache3zinput/cache1/%szinput/cache3/%sz	cache3/%si@)	rr�r��CACHE_TAG_NAME�CACHE_TAG_CONTENTSrbr�rCr�)r�rSrSrU�_create_test_caches$s



z$ArchiverTestCase._create_test_cachescCs�|jdd|j�d}|jd|jdd|d�tj|jdd	|jd��}|d
dksVt�|ddksft�|d
t|�kszt�|ddks�t�|jdd|jddd�}||ks�t�dS)Nr�z--encryption=repokeysfoo

bar
   
r�z::test�-)rNrlz--json-lines�uidr�gidr�r�rdr�z--stdoutT)rO)rr�rrr�r�)r�Z
input_data�itemZextracted_datarSrSrU�test_create_stdin2sz"ArchiverTestCase.test_create_stdincCs*|jdd|j�|jd|jddd�dS)ztest create without a rootr�z--encryption=repokeyr�z::testr)rjN)rr�)r�rSrSrU�test_create_without_root>sz)ArchiverTestCase.test_create_without_rootcCs`|jdd|j�|jddd�|jddd�|jdd	d
d|jd�}|jd
|�|jd|�dS)z$test create with only a root patternr�z--encryption=repokeyr�ir�)r�r�r�z-vz--listz--pattern=R inputz::testz
A input/file1z
A input/file2Ni@i@)rr�r�r)r�r^rSrSrU�test_create_pattern_rootCsz)ArchiverTestCase.test_create_pattern_rootcCs~|jdd|j�|jddd�|jddd�|jddd�|jd	d
ddd
|jdd�}|jd|�|jd|�|jd|�dS)z test file patterns during creater�z--encryption=repokeyr�ir�)r�r��file_importantr�z-vz--listz--pattern=+input/file_importantz--pattern=-input/file*z::testrNzA input/file_importantz
x input/file1z
x input/file2Ni@i@i@)rr�r�r)r�r^rSrSrU�test_create_patternLs
z$ArchiverTestCase.test_create_patterncCs�|jdd|j�|jddd�|jddd�|jddd�|jd	dd�|jd
ddd
d|j|jdd�}|jd|�|jd|�|jd|�|jd|�dS)z test file patterns during creater�z--encryption=repokeyr�ir�)r�r�Z	otherfiler�r�z-vz--listz--pattern=-input/otherfilez--patterns-from=z::testrNzA input/file_importantz
x input/file1z
x input/file2zx input/otherfileNi@i@i@i@)rr�r�r�r)r�r^rSrSrU�test_create_pattern_fileYs

z)ArchiverTestCase.test_create_pattern_filecCs�tjj|jd�|_t|jd��}|jd�WdQRX|jdd|j�|j	ddd
�|j	ddd
�|j	ddd
�|jd
ddd|j|jdd�}|j
d|�|j
d|�|j
d|�dS)z?test when patterns exclude a parent folder, but include a child�	patterns2r�s+ input/x/b
- input/x*
Nr�z--encryption=repokeyz	x/a/foo_air�)r�z	x/b/foo_bzy/foo_yr�z-vz--listz--patterns-from=z::testrNzx input/x/a/foo_azA input/x/b/foo_bzA input/y/foo_yi@i@i@)rbr�r�r��patterns_file_path2r�r�rr�r�r)r�r�r^rSrSrU�.test_create_pattern_exclude_folder_but_recursehs
z?ArchiverTestCase.test_create_pattern_exclude_folder_but_recursecCs�tjj|jd�|_t|jd��}|jd�WdQRX|jdd|j�|j	ddd
�|j	ddd
�|j	ddd
�|jd
ddd|j|jdd�}|j
d|�|j
d|�|jd|�dS)zCtest when patterns exclude a parent folder and, but include a childr�r�s+ input/x/b
! input/x*
Nr�z--encryption=repokeyz	x/a/foo_air�)r�z	x/b/foo_bzy/foo_yr�z-vz--listz--patterns-from=z::testrNzinput/x/a/foo_az	input/x/azA input/y/foo_yi@i@i@)rbr�r�r�r�r�r�rr�r�r�r)r�r�r^rSrSrU�-test_create_pattern_exclude_folder_no_recurseys
z>ArchiverTestCase.test_create_pattern_exclude_folder_no_recursecCs�tjj|jd�|_t|jd��}|jd�WdQRX|jdd|j�|j	ddd
�|j	ddd
�t
d��"|jd
d|j|jdd�WdQRX|jddd|jd�}|j�}|jd|�|jd|�|j
d�|j
d�ks�t�|j
d�|j
d�ks�t�dS)zetest that intermediate folders appear first when patterns exclude a parent folder but include a childr�r�s#+ input/x/a
+ input/x/b
- input/x*
Nr�z--encryption=repokeyz	x/a/foo_air�)r�z	x/b/foo_brNr�z--patterns-from=z::test�.rlz--formatz{type} {path}{NL}zd x/azd x/bz- x/a/foo_az- x/b/foo_bi@i@)rbr�r�r�r�r�r�rr�r�r?r�r�indexr�)r�r�r�Zout_listrSrSrU�.test_create_pattern_intermediate_folders_first�s
z?ArchiverTestCase.test_create_pattern_intermediate_folders_firstcCs�|j�|jdd|j�|jdd|j�tj|jdd|jddd	d
��}tj|jd|jdd	d
��}|dd
}|dd
}||ks�t�|jdd|j�|jdd|jdd�|jd|j�|jd|j�dS)Nr�z--encryption=repokeyrrz--cache-onlyr�z--no-cache-syncz::testrNz--jsonz--errorrr��statsz::test2r�)rrr�rrr�)r��create_jsonZ	info_jsonZcreate_statsZ
info_statsrSrSrU�test_create_no_cache_sync�s
z*ArchiverTestCase.test_create_no_cache_syncc
Cs�|jdd|j�|jddd�|jddd�|jddd�|jd	|jd
d�td��|jd
dd|jd
�WdQRX|jttjd��dg�dS)Nr�z--encryption=repokeyr�ir�)r�r�r�r�z::testrNr^r�z--pattern=+input/file_importantz--pattern=-input/file*zoutput/inputi@i@i@)rr�r�r?r�r!rbr�)r�rSrSrU�test_extract_pattern_opt�s
z)ArchiverTestCase.test_extract_pattern_optcCs\td��|jd|jd�WdQRX|jttjd��ddg�|jttjd��tg�dS)Nr^r�z::testzoutput/inputZcache2r�zoutput/input/cache2)r?rr�r�r!rbr�r�)r�rSrSrU�_assert_test_caches�s
z$ArchiverTestCase._assert_test_cachescCs*|j�|jdd|jdd�|j�dS)Nr�z--exclude-cachesz::testrN)r�rr�r�)r�rSrSrU�test_exclude_caches�sz$ArchiverTestCase.test_exclude_cachescCs<|j�|jd|jdd�|jdd|jd�|j�dS)Nr�z::testrN�recreatez--exclude-caches)r�rr�r�)r�rSrSrU�test_recreate_exclude_caches�sz-ArchiverTestCase.test_recreate_exclude_cachescCsD|jdd|j�|jdd
d�|jd�|jd�|jd	dd�dS)Nr�z--encryption=repokeyr�ir�)r�ztagged1/.NOBACKUPztagged2/00-NOBACKUPztagged3/.NOBACKUP/file2i@)rr�r�)r�rSrSrU�_create_test_tagged�s


z$ArchiverTestCase._create_test_taggedcCsBtd��|jd|jd�WdQRX|jttjd��dg�dS)Nr^r�z::testzoutput/inputr�)r?rr�r�r!rbr�)r�rSrSrU�_assert_test_tagged�s
z$ArchiverTestCase._assert_test_taggedcCs0|j�|jddddd|jdd�|j�dS)Nr�z--exclude-if-presentz	.NOBACKUPz00-NOBACKUPz::testrN)r�rr�r�)r�rSrSrU�test_exclude_tagged�sz$ArchiverTestCase.test_exclude_taggedcCsB|j�|jd|jdd�|jddddd|jd�|j�dS)Nr�z::testrNr�z--exclude-if-presentz	.NOBACKUPz00-NOBACKUP)r�rr�r�)r�rSrSrU�test_recreate_exclude_tagged�s
z-ArchiverTestCase.test_recreate_exclude_taggedcCs�|jdd|j�|jddd�|jd�|jddd�|jddd�|jd	dd�|jd
ttdd�|jd
dd�|jd�|jddd�|jdttdd�|jddd�dS)Nr�z--encryption=repokey�file0i)r�ztagged1/.NOBACKUP1z
tagged1/file1ztagged2/.NOBACKUP2/subfile1z
tagged2/file2z
tagged3/%ss extra stuff)r�z
tagged3/file3ztaggedall/.NOBACKUP1ztaggedall/.NOBACKUP2/subfile1ztaggedall/%sztaggedall/file4)rr�r�r�r�)r�rSrSrU�_create_test_keep_tagged�s



z)ArchiverTestCase._create_test_keep_taggedcCs�td��|jd|jd�WdQRX|jttjd��ddddd	g�|jtjd
�dg�|jtjd�d
g�|jtjd�tg�|jttjd��dd
tg�dS)Nr^r�z::testzoutput/inputr�Ztagged1Ztagged2Ztagged3Z	taggedallzoutput/input/tagged1z
.NOBACKUP1zoutput/input/tagged2z
.NOBACKUP2zoutput/input/tagged3zoutput/input/taggedall)r?rr�r�r!rbr�r�)r�rSrSrU�_assert_test_keep_tagged�s
 z)ArchiverTestCase._assert_test_keep_taggedcCs8|jdd|j�|jddd|jdt�}|jd|�dS)Nr�z--encryption=repokeyr�z--exclude-cachesz--keep-tag-filesz::testz&--keep-tag-files" has been deprecated.)rr�r�r)r��output_warnrSrSrU�$test_exclude_keep_tagged_deprecationsz5ArchiverTestCase.test_exclude_keep_tagged_deprecationc
Cs4|j�|jddddddd|jdd�	|j�dS)	Nr�z--exclude-if-presentz
.NOBACKUP1z
.NOBACKUP2z--exclude-cachesz--keep-exclude-tagsz::testrN)r�rr�r�)r�rSrSrU�test_exclude_keep_taggedsz)ArchiverTestCase.test_exclude_keep_taggedc
CsF|j�|jd|jdd�|jddddddd	|jd�|j�dS)
Nr�z::testrNr�z--exclude-if-presentz
.NOBACKUP1z
.NOBACKUP2z--exclude-cachesz--keep-exclude-tags)r�rr�r�)r�rSrSrU�!test_recreate_exclude_keep_taggeds
z2ArchiverTestCase.test_recreate_exclude_keep_taggedcCs�|jdd|j�|jdtd�tjtjj|jd��tj	tjj|jd�tjj|jdt
��|jd|jdd�|jd	d
d|jd�dS)Nr�z--encryption=noner�)r�Zsubdirr�z::testrNr�z--exclude-cachesz--keep-exclude-tags)rr�r�r�rbr�r�r�r�r�r�)r�rSrSrU�test_recreate_hardlinked_tagssz.ArchiverTestCase.test_recreate_hardlinked_tagsz4Linux capabilities test, requires fakeroot >= 1.20.2cs�tj��fdd�}d}|jd�tjdd|�|jdd|j�|jd	|jd
d�td��Ftj	td
|��|jd|jd
�WdQRXtj
dd�|ks�t�WdQRXdS)Ncs"tj|dddd��|||�dS)Nzsecurity.capabilityF)�follow_symlinks)r
r�)r�r�r�)�fchownrSrU�patched_fchown'szBArchiverTestCase.test_extract_capabilities.<locals>.patched_fchowns r8z
input/filezsecurity.capabilityr�z--encryption=repokeyr�z::testrNr^r�r�)rbr�r�r
r�rr�r?r�object�getxattrr�)r�r�ZcapabilitiesrS)r�rU�test_extract_capabilities!s

z*ArchiverTestCase.test_extract_capabilitiesz@xattr not supported on this system or on this version offakerootc!Cs`dd�}dd�}dd�}|jd�tjdd	d
�|jd|jd�|jd
|jdd�td���tjjd�}t	j
td|��,|jd|jdtd�}||dks�t�WdQRXtj
|�t	j
td|��,|jd|jdtd�}||dks�t�WdQRXtj
|�t	j
td|��.|jd|jdtd�}||dk�s6t�WdQRXtjj|��sRt�WdQRXdS)Nc_sttjd��dS)N�E2BIG)r�r�r�)rT�kwargsrSrSrU�patched_setxattr_E2BIG9szKArchiverTestCase.test_extract_xattrs_errors.<locals>.patched_setxattr_E2BIGc_sttjd��dS)N�ENOTSUP)r�r�r�)rTr�rSrSrU�patched_setxattr_ENOTSUP<szMArchiverTestCase.test_extract_xattrs_errors.<locals>.patched_setxattr_ENOTSUPc_sttjd��dS)Nr/)r�r�r/)rTr�rSrSrU�patched_setxattr_EACCES?szLArchiverTestCase.test_extract_xattrs_errors.<locals>.patched_setxattr_EACCESr8z
input/filezuser.attribute�valuer�z-enoner�z::testrNr^r�r�)rjzN: when setting extended attribute user.attribute: too big for this filesystem
zZ: when setting extended attribute user.attribute: xattrs not supported on this filesystem
zD: when setting extended attribute user.attribute: Permission denied
)r�r
r�rr�r?rbr��abspathrr�r+r�r��isfile)r�r�r�r�Z
input_abspathr�rSrSrU�test_extract_xattrs_errors6s*



z+ArchiverTestCase.test_extract_xattrs_errorscCst|jdd|j�|jddd�td��|jd|jd	d
�WdQRX|jd|jd	�}|jd|�|jd
|�dS)Nr�z--encryption=repokeyzdir1/dir2/fileir�)r�zinput/dir1/dir2r�z::testz#../../../input/dir1/../dir1/dir2/..rlz..z input/dir1/dir2/filei@)rr�r�r?r�r)r�r^rSrSrU�test_path_normalizationUs
z(ArchiverTestCase.test_path_normalizationc'CsT|jdd|j�|jddd�|jddd�td��|jd	d
|jdd�WdQRXtd
��|jd|jd�WdQRX|jttjd
��dg�td��|jd	d|jdd�WdQRXtd
��|jd|jd�WdQRX|jttjd
��dg�|jd	d|jdd�td
��|jd|jd�WdQRX|jttjd��dg�dS)Nr�z--encryption=repokeyr�ir�)r�r�rNr�z--exclude=file1z::test1r�r^r�z--exclude=./file1z::test2z--exclude=input/./file1z::test3zoutput/inputi@i@)rr�r�r?r�r!rbr�)r�rSrSrU�test_exclude_normalization^s"
 

 

z+ArchiverTestCase.test_exclude_normalizationcCs8|jdd
d�|jdd|j�|jd|jdd	d	�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNi@)r�rr�)r�rSrSrU�test_repeated_filesqsz$ArchiverTestCase.test_repeated_filescCs�|jddd�|jddd�|jdd|j�|jd|jd	d
�tjd�tjd�tjd
�td��|jd|jd	�WdQRX|jd
d�tjd�tjd�tjd�td��|jd|jd	dd�WdQRXdS)Nr�ir�)r�z
dir2/file2r�z--encryption=repokeyr�z::testrNzoutput/inputzoutput/input/file1zoutput/input/dir2r^r�zoutput/input/file1/dirr;)rji@i@)r�rr�rbr�r?r�unlink)r�rSrSrU�test_overwritevs







zArchiverTestCase.test_overwritec
Cs:|jddd�|jddd�|jdd|j�|jd|jd	d
�|jd|jdd
�|jdd
|jd	�|jdd
|jd�|jd|jd	d�|jdd
|jd�|jd|jdd�|jdd
|jd�|jdd
|jd�t|j��}tj|tj�\}}WdQRX|jt	|j
�d�|jd|j
�|jd|j
�dS)Nr�ir�)r�z
dir2/file2r�z--encryption=repokeyr�z::testrNz::test.2r�z	--dry-runroztest.3ztest.4z::test.3z::test.4ri@i@)r�rr�r:r�r'r�r�r�r��archivesr)r�r�r�rIrSrSrU�test_rename�s"zArchiverTestCase.test_renamecCs�|jddd�|jdd|j�|jd|jdd	�|jd
|j�}d|ksLt�|jd
|jd�}d|ksjt�|jd
d
d|j�}d|ks�t�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrz
All archives:zArchive name: test
z--firstr�i@)r�rr�r�)r��	info_repo�info_archiverSrSrU�	test_info�szArchiverTestCase.test_infocs�|jdd(d�|jdd|j�|jd|jdd	�tj|jd
d|j��}|d}t|d
�dksdt�d|kspt�tj|dt	�s�t�|dddks�t�d|dks�t�|d}|d�t
dd��j�D��s�t�t
�fdd�d)D��s�t�tj|jd
d|jd��}|d|dk�st�|d|dk�s2t�|d}t|�d k�sLt�|d!}|d"d#k�sft�t|d$t
��szt�t|d%t��s�t�t|d
�dk�s�t�d|k�s�t�tj|d&t	��s�t�tj|d't	��s�t�dS)*Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrz--jsonr�rQ�@�
last_modified�
encryption�mode�repokey�keyfiler�r�css|]}t|t�VqdS)N)rYrI)r��orSrSrUr��sz2ArchiverTestCase.test_info_json.<locals>.<genexpr>c3s|]}|�kVqdS)NrS)r�rI)r�rSrUr��s�total_chunks�total_csizer^�total_unique_chunks�unique_csize�unique_sizer�r;rr�r
�command_line�duration�start�endi@)r�r�r^r�r�r�)r�rr�rrr�r�r�strptime�
ISO_FORMAT�all�valuesrYrl�float)r�r�r�r�r�r�r�rS)r�rU�test_info_json�s6zArchiverTestCase.test_info_jsoncCsd|jdd|j�tj|jddd|j��}|dgks8t�tj|jddd|j��}|dgks`t�dS)	z2See https://github.com/borgbackup/borg/issues/6120r�z--encryption=repokeyrz--jsonz	--first=1r�z--last=1N)rr�rrr�)r�r�rSrSrU�test_info_json_of_empty_archive�s
z0ArchiverTestCase.test_info_json_of_empty_archivecCsx|jddd�|jdd|j�|jd|jdd	�|jdd
d|jdd	�|jdd
d
|jdd	�|jdd
d|jdd	�d|jd|jd�ks�t�d|jd|jd�ks�t�|jd|jdd
d�|jd|jdd
d�|jd|jdd
d�|jd|jdd�d|jd|jd�k�s t�d|jd|jd�k�s<t�d|jd|jd�k�sXt�d|jd|jd�k�stt�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::test1rNz	--commentzthis is the commentz::test2z"deleted" commentz::test3zpreserved commentz::test4z
Comment: 
rzComment: this is the commentr�z
added commentzmodified commentrQZ12345zComment: added commentzComment: modified commentzComment: preserved commenti@)r�rr�r�)r�rSrSrU�test_comment�s zArchiverTestCase.test_commentc
CsL|jddd�|jddd�|jdd|j�|jd|jd	d
�|jd|jdd
�|jd|jdd
�|jd|jd
d
�|jd|jdd
�|jdd|jd	�|jdd|jd�|jddd|j�|jddd|j�|jd|jd	�|jdd|jd�|jdd|jd�}|jd|�t|j��}|jt|�d�WdQRXdS)Nr�ir�)r�z
dir2/file2r�z--encryption=repokeyr�z::testrNz::test.2z::test.3z::another_test.1z::another_test.2r�z	--dry-runrrz--prefixZanother_z--lastr�z--statsz
Deleted data:r;i@i@)r�rr�rr:r�r�r�)r�r^r�rSrSrU�test_delete�s$zArchiverTestCase.test_deletecCs�|jddd�|jdd|j�|jd|jdd	�|jd|jd
d	�|jd|jdd	�|jd|jdd
�|jdd|jd�|jd|jd�|jd|j�s�t�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::test1rNz::test2z::test3rr�test2r�z	--dry-runZtest3rli@)r�rr�r�)r�rSrSrU�test_delete_multiple�sz%ArchiverTestCase.test_delete_multiplecCs�|jddd�|jddd�|jdd|j�|jd|jd	d
�|jd|jdd
�dtjd
<|jd|jdd�tjj|j�s�t�dtjd
<|jd|j�|j	tjj|j��dS)Nr�ir�)r�z
dir2/file2r�z--encryption=repokeyr�z::testrNz::test.2�nor�rrr)rjr�i@i@)
r�rr�rbr�r�r�r�r�ZassertFalse)r�rSrSrU�test_delete_repos

z!ArchiverTestCase.test_delete_repocCs�|jdd|j�|jd�t|jdd��h}tj|tj�\}}t|||d�}x8|j	�D]$}|j
jd�rT|j|j
dj�PqTWds�t�|j�WdQRX|jd	d
|jd�}|jd|�|jd
d|j�|jd|j�}|jd|�dS)Nr�z--encryption=noner
T)r�ztestsuite/archiver.pyr;Frrz--forcez::testzdeleted archive was corruptedr�z--repairrl���)rr�r�r:r�r'r�r�r�
iter_itemsr��endswithrr�chunksrQr��commitrr�)r�r�r�rIr�r�r^rSrSrU�test_delete_forces 
z"ArchiverTestCase.test_delete_forcec
Cs�|jdd|j�|jd�t|jdd��F}tj|tj�\}}t|||d�}|j	j
d}|j|d�|j�WdQRX|jdd	d	|jd
�|jdd|j�|jd
|j�}|j
d|�dS)Nr�z--encryption=noner
T)r�rs%corrupted items metadata stream chunkrrz--forcez::testr�z--repairrl)rr�r�r:r�r'r�r�r�metadata�items�putr�r�)r�r�r�rIr�rQr^rSrSrU�test_delete_double_force"s
z)ArchiverTestCase.test_delete_double_forcec
Cs�|jdd|j�|jd�|jdd|jd�|jdd|j�}|jd	|�|jd
|�ttjtjj	|j
ddd
��dd�d}ttjj	|j
ddd
|�d��}|jd�|j
d�WdQRX|jdd|jdd�}|jd
|�dS)Nr�z--encryption=repokeyr
r�z	--dry-runz::testr�z--show-versionzborgbackup versionzStarting repository checkr�r�r�T)�reverser;zr+br�sXXXXz--info)rj)rr�r�rr�r!rbr�r�r�r�r�r]r�)r�r^r�r�rSrSrU�test_corrupted_repository0s
&
z*ArchiverTestCase.test_corrupted_repositorycCs�|jdd|j�|jd�|j|j��~|jrD|jdd|jtd�nJtjt	t
jf��}|jdd|j�WdQRXt|j
t
j�r�|j
jdks�t�|jdd|jd�WdQRXdS)	Nr�z--encryption=repokeyr
r�z
--verify-data)rjr6z
--bypass-lock)rr�r��	read_onlyr�r�r,r)r*r6r8�RPCErrorrYr��exception_classr�)r��excinforSrSrU�test_readonly_check?s
z$ArchiverTestCase.test_readonly_checkcCs�|jdd|j�|jd�|jd�|j|j���|jrR|jdd|jdtd�nNtjt	t
jf��}|jdd|jd�WdQRXt|j
t
j�r�|j
jdks�t�|jdd|jdd	�WdQRXdS)
Nr�z--encryption=repokeyrr�diffz%s::a)rjr6z
--bypass-lock)rr�r�rr�r�r,r)r*r6r8rrYr�r	r�)r�r
rSrSrU�test_readonly_diffNs

z#ArchiverTestCase.test_readonly_diffcCs�|jdd|j�|jd�|j|j���|jrH|jdd|jdtd�nNtjt	t
jf��}|jdd|jd�WdQRXt|j
t
j�r�|j
jdks�t�|jdd|jdd	�WdQRXdS)
Nr�z--encryption=repokeyr
z
export-tarz%s::testztest.tar)rjr6z
--bypass-lock)rr�r�rr�r�r,r)r*r6r8rrYr�r	r�)r�r
rSrSrU�test_readonly_export_tar^s
z)ArchiverTestCase.test_readonly_export_tarcCs�|jdd|j�|jd�|j|j���|jrF|jdd|jtd�nLtjt	t
jf��}|jdd|j�WdQRXt|j
t
j�r�|j
jdks�t�|jdd|jd�WdQRXdS)	Nr�z--encryption=repokeyr
r�z%s::test)rjr6z
--bypass-lock)rr�r�rr�r�r,r)r*r6r8rrYr�r	r�)r�r
rSrSrU�test_readonly_extractms
z&ArchiverTestCase.test_readonly_extractcCs�|jdd|j�|jd�|j|j��x|jrB|jd|jtd�nHtjt	t
jf��}|jd|j�WdQRXt|j
t
j�r�|j
jdks�t�|jd|jd�WdQRXdS)Nr�z--encryption=repokeyr
r)rjr6z
--bypass-lock)rr�r�rr�r�r,r)r*r6r8rrYr�r	r�)r�r
rSrSrU�test_readonly_info|s
z#ArchiverTestCase.test_readonly_infocCs�|jdd|j�|jd�|j|j��x|jrB|jd|jtd�nHtjt	t
jf��}|jd|j�WdQRXt|j
t
j�r�|j
jdks�t�|jd|jd�WdQRXdS)Nr�z--encryption=repokeyr
rl)rjr6z
--bypass-lock)rr�r�rr�r�r,r)r*r6r8rrYr�r	r�)r�r
rSrSrU�test_readonly_list�s
z#ArchiverTestCase.test_readonly_listcCs�|jdd|j�|jd�|j|j���|jrL|j|jtd��WdQRXnVtj	t
tjf��"}|j|jdd��WdQRXWdQRXt
|jtj�r�|jjdks�t�|j|jdd��WdQRXWdQRXdS)	Nr�z--encryption=repokeyr
)rjF)rLr6z
--bypass-lock)rr�r�rr�r�r�r,r)r*r6r8rrYr�r	r�)r�r
rSrSrU�test_readonly_mount�s
z$ArchiverTestCase.test_readonly_mount�BORG_TESTS_IGNORE_MODESzmodes unreliablecCsV|jddd�|jdd|j�|jd|jdd	�tj|j�j}|jtj|�d
�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNi�i@)	r�rr�rbr�r��st_mode�assertEqual�S_IMODE)r�r�rSrSrU�
test_umask�s
zArchiverTestCase.test_umaskc
Csd|jdd|j�|jdd|jdd�t|j��}tj|tj�\}}WdQRX|jt|j	�d�dS)Nr�z--encryption=repokeyr�z	--dry-runz::testrNr)
rr�r:r�r'r�r�r�r�r�)r�r�r�rIrSrSrU�test_create_dry_run�s
z$ArchiverTestCase.test_create_dry_runc
CsZt|jdd��B}tj|tj�\}}|jj�ddgii|jd<|j�|j	�WdQRXdS)NT)r�s	mandatorysunknown-features
feature_flags)
r:r�r'r�r�r�r�rSr�r�)r�Z	operationr�r�rIrSrSrU�add_unknown_feature�s
z$ArchiverTestCase.add_unknown_featurec	CsP|jr|j|dti�n4tjt��}|j|�WdQRX|jjdgfksLt�dS)Nrjzunknown-feature)	r�rr,r)r*r(r�rTr�)r�rTr
rSrSrU�cmd_raises_unknown_feature�s
z+ArchiverTestCase.cmd_raises_unknown_featurecCs<t|jdd|j��|jtjj�|jd|jddg�dS)Nr�z--encryption=repokeyr�z::testrN)r�rr�rr'�	OperationZWRITEr)r�rSrSrU�test_unknown_feature_on_create�sz/ArchiverTestCase.test_unknown_feature_on_createcCsH|jdd|j�|jdd|j�|jtjj�|jd|jddg�dS)Nr�z--encryption=repokeyrrz--cache-onlyr�z::testrN)rr�rr'r�READr)r�rSrSrU�"test_unknown_feature_on_cache_sync�sz3ArchiverTestCase.test_unknown_feature_on_cache_synccCs6t|jdd|j��|jtjj�|jd|jg�dS)Nr�z--encryption=repokeyzchange-passphrase)r�rr�rr'r�CHECKr)r�rSrSrU�)test_unknown_feature_on_change_passphrase�sz:ArchiverTestCase.test_unknown_feature_on_change_passphrasecCs�t|jdd|j��|jd|jdd�|jtjj�td��|jd|jdg�WdQRX|jd|jg�|jd	|jdg�dS)
Nr�z--encryption=repokeyr�z::testrNr^r�rlr)	r�rr�rr'rrr?r)r�rSrSrU�test_unknown_feature_on_read�s
z-ArchiverTestCase.test_unknown_feature_on_readcCsPt|jdd|j��|jd|jdd�|jtjj�|jd|jddg�dS)Nr�z--encryption=repokeyr�z::testrNro�other)r�rr�rr'rrr)r�rSrSrU�test_unknown_feature_on_rename�sz/ArchiverTestCase.test_unknown_feature_on_renamecCsnt|jdd|j��|jd|jdd�|jtjj�|jd|jdg�|jdd|jg�|jd|j�dS)	Nr�z--encryption=repokeyr�z::testrNrr�prunez--keep-daily=3)r�rr�rr'rZDELETEr)r�rSrSrU�test_unknown_feature_on_delete�sz/ArchiverTestCase.test_unknown_feature_on_deletecCsf|jdd|j�|jd|jdd�|jtjj�tjj|j	d�}tj
|�|jd|jd|g�dS)Nr�z--encryption=repokeyr�z::testrNr�r�)rr�rr'rrrbr�r�r�r�r)r�r�rSrSrU�test_unknown_feature_on_mount�s
z.ArchiverTestCase.test_unknown_feature_on_mountc&sr|jrd}nd}t|jdd|j��t|jdd��^}|rDt|j�|_tj	|tj
�\}}t|||��$}|j�t
dg�|j_|j�WdQRXWdQRX|jr�|jd|jd	d
�nPd�tj���fdd
�}tjtd|��|jd|jd	d
�WdQRX��st�t|jdd��X}|�r$t|j�|_tj	|tj
�\}}t|||��}|jjt
g�k�sZt�WdQRXWdQRXdS)Nzssh://__testsuite__rQr�z--encryption=repokeyT)r�zunknown-featurer�z::testrNFcsd��|�dS)NTrS)rT)�called�wipe_cache_saferSrU�wipe_wrapperszNArchiverTestCase.test_unknown_mandatory_feature_in_cache.<locals>.wipe_wrapper�
wipe_cache)r�r�rr�r:r�r%Z	_locationr'r�r�r�	begin_txnrUZcache_configZmandatory_featuresr�r�rr*rr�r�)r��path_prefixr�r�rIr�r)rS)r'r(rU�'test_unknown_mandatory_feature_in_caches4
z8ArchiverTestCase.test_unknown_mandatory_feature_in_cachecCsD|jddd�|jdd|j�|jdd|jd	d
�}|jd|�dS)
Nr�ir�)r�r�z--encryption=repokeyr�z
--progressz::test4rN�
i@)r�rr�r)r�r^rSrSrU�test_progress_on*sz!ArchiverTestCase.test_progress_oncCsB|jddd�|jdd|j�|jd|jdd	�}|jd
|�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::test5rNr.i@)r�rr�r�)r�r^rSrSrU�test_progress_off0sz"ArchiverTestCase.test_progress_offcCs�|jddd�tjd�|jddd�|jdd|j�|jd	d
|jdd�}|jd
|�|jd|�|jd	d
|jdd�}|jd|�|jd|�dS)z�test that various file status show expected results

        clearly incomplete: only tests for the weird "unchanged" status for nowr�ir�)r�r;r�r�z--encryption=repokeyr�z--listz::testrNz
A input/file1z
A input/file2z::test1z
U input/file1Ni@i@)r�rrrr�r)r�r^rSrSrU�test_file_status6s
z!ArchiverTestCase.test_file_statuscCs�|jddd�tjd�|jddd�|jdd	|j�|jd
dd|jd
d�}tjd�}|jddd�tjd|j|j	fd�|jd
dd|jdd�}|j
d|�dS)zbtest that a changed file with faked "previous" mtime still gets backed up in ctime,size cache_moder�s123)r�r;r�r�)r�r�z--encryption=repokeyr�z--listz--files-cache=ctime,sizez::test1rNzinput/file1s321)�nsz::test2z
M input/file1N)r�rrrr�rbr�r>r4r?r)r�r^r`rSrSrU�test_file_status_cs_cache_modeHs

z/ArchiverTestCase.test_file_status_cs_cache_modecCs�|jddd�tjd�|jddd�|jdd|j�|jdd	d
|jdd�}tjd
�}tjd
|jtj	A�|jdd	d
|jdd�}|j
d|�dS)zetest that a chmod'ed file with no content changes does not get chunked again in mtime,size cache_moder�r�)r�r;r�r�z--encryption=repokeyr�z--listz--files-cache=mtime,sizez::test1rNzinput/file1z::test2z
U input/file1N)r�rrrr�rbr�r�r�S_IRWXOr)r�r^r`rSrSrU�test_file_status_ms_cache_modeWs

z/ArchiverTestCase.test_file_status_ms_cache_modecCsv|jddd�tjd�|jddd�|jdd|j�|jdd	d
|jdd�}|jdd	d
|jd
d�}|jd|�dS)zItest that files get rechunked unconditionally in rechunk,ctime cache moder�r�)r�r;r�r�z--encryption=repokeyr�z--listz--files-cache=rechunk,ctimez::test1rNz::test2z
A input/file1N)r�rrrr�r)r�r^rSrSrU�test_file_status_rc_cache_modees
z/ArchiverTestCase.test_file_status_rc_cache_modecCs�|jddd�tjd�|jddd�trR|jddd�tjtjj|j	d�t
j�|jdd	|j
�|jd
dd|j
d
d�}|jd|�|jd|�tr�|jd|�|jd
dd|j
dddd�}|jd|�|jd|�tr�|jd|�dS)z#test that excluded paths are listedr�ir�)r�r;r�r�r�z--encryption=repokeyr�z--listz--exclude-nodumpz::testrNz
A input/file1z
A input/file2z
x input/file3z::test1z	--excludez*/file2z
U input/file1z
x input/file2Ni@i@i@)r�rrr<rr�rbr�r�r�r�r�rr�r)r�r^rSrSrU�test_file_status_excludedps"
z*ArchiverTestCase.test_file_status_excludedcCs�|jddd�|jdd|j�tj|jdd|jd	d
��}d|ksFt�d|ksRt�d
|ks^t�d|dksnt�|d}|ddks�t�t|dt�s�t�t|dt�s�t�t	|d�dks�t�d|ks�t�dS)Nr�ir�)r�r�z--encryption=repokeyr�z--jsonz::testrNr�r�r�r�r�r�r
r�r�rQr�r�i@)
r�rr�rrr�rYrlr�r�)r�Zcreate_infor�rSrSrU�test_create_json�sz!ArchiverTestCase.test_create_jsoncCs�|jddd�tjd�|jddd�|jdd|j�|jd	|jd
d�}|jd|�|jd	|jdd�}|jd|�|jd	d
d|jdd�}|jd|�|jd	d
d|jdd�}|jd|�|jddd�|jd	d
d|jdd�}|jd|�dS)Nr�ir�)r�r;r�r�z--encryption=repokeyr�z::testrNz::test0z--listz
--filter=Uz::test1z--filter=AMz::test2r�z::test3i@i@i�)r�rrrr�r�r)r�r^rSrSrU�test_create_topical�s
z$ArchiverTestCase.test_create_topicalcCs^tjdtjj|jd��|jdd|j�|jd}|jdd|d�|jd	|�}d
|ksZt�dS)Nzsomewhere does not existr�r�z--encryption=repokeyz::testr�z--read-specialrNrlz&input/link -> somewhere does not exist)rbr�r�r�r�rr�r�)r�r�r^rSrSrU�'test_create_read_special_broken_symlink�s
z8ArchiverTestCase.test_create_read_special_broken_symlinkcCs�|jdd|j�|jd|jdt�|jd|jdt�|jd|jdt�|jd|jdt�|jd|jdt�|jd	d
d|jd�}|jd
|�|jd|�|jd
|�|jd|�|jd|j�}|jd|�|jd|�|jd|�|jd|�|jd|�|jd	|jd�|jd|j�}|jd|�|jd|�|jd|�|jd|�|jd|�|jd|jdt�|jd	|jd�|jd|j�}|jd|�|jd|�dS)Nr�z--encryption=repokeyr�z::test1z::test2z::test3.checkpointz::test3.checkpoint.1z::test4.checkpointr$z--listz	--dry-runz--keep-daily=2zKeeping archive: test2zWould prune:     test1z!Keeping archive: test4.checkpointrl�test1r�ztest3.checkpointztest3.checkpoint.1ztest4.checkpointz::test5Z
checkpointZtest5)rr�r�rr�)r�r^rSrSrU�test_prune_repository�s:z&ArchiverTestCase.test_prune_repositorycCs�|jdd|j�|jd|jdt�|jd|jdt�|jddd|jd	�}|jd
|�|jd|�|jd|j�}|jd
|�|jd|�|jdd|jd	�|jd|j�}|jd
|�|jd|�dS)Nr�z--encryption=repokeyr�z::test1z::test2r$z--listz	--dry-runz--keep-daily=2zKeeping archive: test2zWould prune:     test1rlr;r�z--save-space)rr�r�rr�)r�r^rSrSrU� test_prune_repository_save_space�sz1ArchiverTestCase.test_prune_repository_save_spacecCs |jdd|j�|jd|jdt�|jd|jdt�|jd|jdt�|jd|jdt�|jdd	d
|jdd�}|jd
|�|jd|�|jd|j�}|jd|�|jd|�|jd|�|jd|�|jd|jdd�|jd|j�}|jd|�|jd|�|jd|�|jd|�dS)Nr�z--encryption=repokeyr�z::foo-2015-08-12-10:00z::foo-2015-08-12-20:00z::bar-2015-08-12-10:00z::bar-2015-08-12-20:00r$z--listz	--dry-runz--keep-daily=2z
--prefix=foo-z%Keeping archive: foo-2015-08-12-20:00z%Would prune:     foo-2015-08-12-10:00rlzfoo-2015-08-12-10:00zfoo-2015-08-12-20:00zbar-2015-08-12-10:00zbar-2015-08-12-20:00)rr�r�rr�)r�r^rSrSrU�test_prune_repository_prefix�s&z-ArchiverTestCase.test_prune_repository_prefixcCs |jdd|j�|jd|jdt�|jd|jdt�|jd|jdt�|jd|jdt�|jdd	d
|jdd�}|jd
|�|jd|�|jd|j�}|jd|�|jd|�|jd|�|jd|�|jd|jdd�|jd|j�}|jd|�|jd|�|jd|�|jd|�dS)Nr�z--encryption=repokeyr�z::2015-08-12-10:00-fooz::2015-08-12-20:00-fooz::2015-08-12-10:00-barz::2015-08-12-20:00-barr$z--listz	--dry-runz--keep-daily=2z--glob-archives=2015-*-fooz%Keeping archive: 2015-08-12-20:00-fooz%Would prune:     2015-08-12-10:00-foorlz2015-08-12-10:00-fooz2015-08-12-20:00-fooz2015-08-12-10:00-barz2015-08-12-20:00-bar)rr�r�rr�)r�r^rSrSrU�test_prune_repository_globs&z+ArchiverTestCase.test_prune_repository_globcCs�|jdd|j�|jd|jdt�|jd|jdt�|jd|jdt�|jdd|j�}|jd	|�|jd
|�|jd|�dS)Nr�z--encryption=repokeyr�z::test-1z::something-else-than-test-1z::test-2rlz--prefix=test-ztest-1ztest-2zsomething-else)rr�r�rr�)r�r^rSrSrU�test_list_prefixsz!ArchiverTestCase.test_list_prefixcCs�|jdd|j�|jd}|jd|t�|jddd|�}|jd|�|jd|�}|jdd	d
|�}|jdd	d|�}|j||�|j||�dS)Nr�z--encryption=repokeyz::testr�rlz
--list-formatr�z#--list-format" has been deprecated.z--formatzB{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}{NEWLINE}z{mtime:%s} {path}{NL})rr�r�rrZassertNotEqual)r��test_archiver��output_1�output_2�output_3rSrSrU�test_list_format's
z!ArchiverTestCase.test_list_formatcCs�|jdd|j�|jddd|jdt�|jddd|jdt�|jd	|j�}|jd	d
d|j�}|j||�|jd	d|j�}|j|d
�|jd	d
d|j�}|j|d�|jd	d
d|j�}|jd|�|jd|�dS)Nr�z--encryption=repokeyr�z	--commentz	comment 1z::test-1z	comment 2z::test-2rlz--formatz{archive:<36} {time} [{id}]{NL}z--shortztest-1
test-2
z{barchive}/ztest-1/test-2/z{name} {comment}{NL}ztest-1 comment 1
ztest-2 comment 2
)rr�r�rr)r�rBrCrDrSrSrU�test_list_repository_format3sz,ArchiverTestCase.test_list_repository_formatcCst|jddd�|jdddd�|jdd	|j�|jd
}|jd|d�|jd
dd|�}d|ksdt�d|kspt�dS)N�
empty_filer)r�Zamb�ai@B)r�r�z--encryption=repokeyz::testr�rNrlz--formatz{sha256} {path}{NL}zJcdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0 input/ambzQe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 input/empty_file)r�rr�r�)r�rAr^rSrSrU�test_list_hashBs
zArchiverTestCase.test_list_hashcCs�|jddd�|jd�ttjj|jd�d��"}|jdd�|jdd�WdQRX|jd	d
|j�|jd}|jd|d
�|jddd|�}d|ks�t	�d|ks�t	�dS)NrGr)r�Z
two_chunksr�sabbai��sbaabr�z--encryption=repokeyz::testr�rNrlz--formatz'{num_chunks} {unique_chunks} {path}{NL}z0 0 input/empty_filez2 2 input/two_chunks)
r�r�rbr�r�r�r�rr�r�)r�r�rAr^rSrSrU�test_list_chunk_countsLs

z'ArchiverTestCase.test_list_chunk_countscCs�|jddd�|jdd|j�|jd}|jddd	|d
�|jddd
|�}|jd�djd�\}}}}}t|�t|�ks|t�t|�t|�ks�t�t|�t|�ks�t�t|�t|�ks�t�dS)NZcompressible_filei')r�r�z--encryption=repokeyz::testr�z-C�lz4rNrlz--formatz*{size} {csize} {dsize} {dcsize} {path}{NL}rr;� )r�rr�r rIr�)r�rAr^r��csizeZdsizeZdcsizer�rSrSrU�test_list_sizeYs
zArchiverTestCase.test_list_sizecCs�|jdd%d�|jdd|j�|jd|jdd	�tj|jd
d|j��}|d}t|d
�dksdt�tj|dt	�sxt�|dddks�t�d|dks�t�|dd}tj|dt	�s�t�|jd
d|jd�}dd�|j
�D�}t|�dks�t�|d}|ddk�st�|ddk�st�tj|d t	��s4t�|jd
dd!|jd�}d"d�|j
�D�}t|�dk�snt�|d}|ddk�s�t�|d#d$k�s�t�dS)&Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrlz--jsonr�rQr�r�r�r�r�r�r�rrz--json-linescSsg|]}tj|��qSrS)rr)r��srSrSrUrssz3ArchiverTestCase.test_list_json.<locals>.<listcomp>rr;r�zinput/file1r�i@rAz--format={sha256}cSsg|]}tj|��qSrS)rr)r�rOrSrSrUr{srZ@b2915eb69f260d8d3c25249195f2c8f4f716ea82ec760ae929732c0262442b2bi@)r�rr�rrr�r�rr�r�r�)r�Z	list_repor�Zarchive0Zlist_archiverr�rSrSrU�test_list_jsones0zArchiverTestCase.test_list_jsoncCs@|jdd|j�|jdd|jdd�|jdd|jddd�dS)	Nr�z--encryption=repokeyrlz--json-linesr)rjz--jsonz	::archive)rr�)r�rSrSrU�test_list_json_args�sz$ArchiverTestCase.test_list_json_argscCs�|j�|jdd|j�|jdd|jdddd�}i}x&|j�D]}tj|�}|||d	<q@W|d
}d|ksrt�|djd�s�t�|d
}t|dt	�s�t�|ddks�t�t|dt
�s�t�dS)Nr�z--encryption=repokeyr�z
--log-jsonz::testrNz--listz--debug�type�file_statusZstatusr��log_messagerZ	levelname�DEBUG�message)rrr�r�rrr�rrYr�rZ)r��logZmessagesr��msgrSrTrSrSrU�
test_log_json�s
zArchiverTestCase.test_log_jsoncCs�|j�|jdd|j�|jd|jddd�|jddd	d
�tjd
�}|j�|jd�|jd|jddd
�tjd
�}|j�|jd�dS)Nr�z--encryption=repokeyr�z::testrNz--debug-profile=create.prof�debugzconvert-profilezcreate.profz
create.pyprofZcumtimez::test2z--debug-profile=create.pyprof)rrr��pstatsZStatsZ
strip_dirsZ
sort_stats)r�r�rSrSrU�test_debug_profile�s


z#ArchiverTestCase.test_debug_profilecCs>|j�|jdd|j�|jdd|jdd�}d|ks:t�dS)Nr�z--encryption=repokeyz--debugr�z::testrNz security: read previous location)rrr�r�)r�rWrSrSrU�test_common_options�sz$ArchiverTestCase.test_common_options�'c	Cs�|rd|}n
tj|�}|jd|d�|jdd|j�|jd}|jdd||d	�|jd
dd|�}|jd
�djd�\}}}t|�t|�fS)Nr�r8)r�r�z--encryption=nonez::testr�z-CrNrlz--formatz{size} {csize} {path}{NL}rr;rL)rbr�r�rr�r rI)	r�Zcompression�compressibler�r�r�r^rMr�rSrSrU�
_get_sizes�s


zArchiverTestCase._get_sizescCs2|jddd�\}}||kst�||dks.t�dS)N�noneT)r_�)r`r�)r�r�rMrSrSrU�"test_compression_none_compressible�sz3ArchiverTestCase.test_compression_none_compressiblecCs2|jddd�\}}||kst�||dks.t�dS)NraF)r_rb)r`r�)r�r�rMrSrSrU�$test_compression_none_uncompressible�sz5ArchiverTestCase.test_compression_none_uncompressiblecCs&|jddd�\}}||dks"t�dS)N�zlibT)r_g�������?)r`r�)r�r�rMrSrSrU�"test_compression_zlib_compressible�sz3ArchiverTestCase.test_compression_zlib_compressiblecCs"|jddd�\}}||kst�dS)NreF)r_)r`r�)r�r�rMrSrSrU�$test_compression_zlib_uncompressible�sz5ArchiverTestCase.test_compression_zlib_uncompressiblecCs&|jddd�\}}||dks"t�dS)NrKT)r_g�������?)r`r�)r�r�rMrSrSrU�!test_compression_lz4_compressible�sz2ArchiverTestCase.test_compression_lz4_compressiblecCs"|jddd�\}}||kst�dS)NrKF)r_)r`r�)r�r�rMrSrSrU�#test_compression_lz4_uncompressible�sz4ArchiverTestCase.test_compression_lz4_uncompressiblecCs&|jddd�\}}||dks"t�dS)N�lzmaT)r_g�������?)r`r�)r�r�rMrSrSrU�"test_compression_lzma_compressible�sz3ArchiverTestCase.test_compression_lzma_compressiblecCs"|jddd�\}}||kst�dS)NrjF)r_)r`r�)r�r�rMrSrSrU�$test_compression_lzma_uncompressible�sz5ArchiverTestCase.test_compression_lzma_uncompressiblecCs�|jddd�\}}|jd|j�|jddd�\}}|jd|j�|jddd�\}}||kod|knsnt�||dks~t�t||�}||ks�t�dS)Nz	auto,zlibT)r_rrrerKg�������?)r`rr�r��min)r�Z	auto_sizeZ
auto_csizeZ	zlib_sizeZ
zlib_csizeZlz4_sizeZ	lz4_csizeZsmallest_csizerSrSrU�"test_compression_auto_compressible�s
z3ArchiverTestCase.test_compression_auto_compressiblecCs2|jddd�\}}||kst�||dks.t�dS)Nz	auto,zlibF)r_rb)r`r�)r�r�rMrSrSrU�$test_compression_auto_uncompressible�sz5ArchiverTestCase.test_compression_auto_uncompressiblecCsD|jdd|j�dtjd<|jd|j�dtjd<|jd|j�dS)Nr�z--encryption=repokeyZ
newpassphraseZBORG_NEW_PASSPHRASEzchange-passphraser�rl)rr�rbr�)r�rSrSrU�test_change_passphrase�s


z'ArchiverTestCase.test_change_passphrasecCs"|jdd|j�|jd|j�dS)Nr�z--encryption=repokeyz
break-lock)rr�)r�rSrSrU�test_break_lock�sz ArchiverTestCase.test_break_lockcCs|j�|jd�dS)Nz-h)r)r�rSrSrU�
test_usage�szArchiverTestCase.test_usagecCsjd|jd�kst�d|jdd�ks&t�d|jdd�ks:t�d|jddd�ksPt�d|jddd	�ksft�dS)
NZBorgr{r�Z
Initializer�zpositional argumentsz
--epilog-onlyzThis command initializesz--usage-only)rr�)r�rSrSrU�	test_help	s
zArchiverTestCase.test_helpc2Cs�dd�}|jdd|j�|j�|d�}|jdd|jdd	�|jdd|jd
d	�trltjtjjd	d��tjj|jd�}|j	|j|��F|j
|jtjj|d
d	�ddd�|j
|jtjj|dd	�ddd�WdQRX|j	|jd|����|j
|jtjj|d	�ddd�d}tjj|d	d�}tj|�}tj|�}|j
|j
k�sDt�|j|jk�sVt�|j|jk�sht�|j|jk�szt�|�r�|j|jk�s�t�|j|jk�s�t�|j|jk�s�t�t��r�|j|jk�o�dkn�s�t�t|d��2}t|d��}	|j�|	j�k�st�WdQRXWdQRXt��r�d}tjj|d	d�}tj|�}
tj|�}|
j|jk�oldkn�sxt�|j|jk�s�t�t��r(d}tjj|d	d�}tj|dd�}tj|dd�}
|jtd�k�s�t�|
jtd�k�s�t�tj|j
��s�t�tj|
j
��st�tj|�tj|�k�s(t�t��r\tjj|d	d�}tj|�}
tj|
j
��s\t�y�d}tjj|d	d�}t j!�r�t j"|j��r�t#t$t j%|���ddgk�s�t�t j&|d�d k�s�t�t j&|d�dk�sFt�nnt$t j%|��gk�s�t�yt j&|d�Wn6t'k
�r6}z|j(t)j*k�s&t�WYdd}~XnXd�sFtd!��WnDt'k
�r�}z&t+j,j-d#��rz|j(t(j.k�rzn�WYdd}~XnXWdQRXdS)$NcSs\tj|�j}ytjtj|t��Wntk
r6dSXtj|�j}ttk}|oV||kSdS)NF)rbr�r4r0r�rrr)r6r7r9r:rSrSrUr;
	sz/ArchiverTestCase.test_fuse.<locals>.has_noatimer�z--encryption=repokeyzinput/file1r�z--exclude-nodumpz	::archiverNz
::archive2r�r�r�T)�ignore_bsdflags�
ignore_xattrs�archive2r�rrZzinput/hardlinkr�zinput/link1r�F)r�r�r�zinput/fusexattrr�z
user.emptyzuser.foosbarz2expected OSError(ENOATTR), but no error was raised�freebsd)rw)/rr�rr<rbr�r�r�r�r�rr�r�rr��st_uid�st_gidr[�st_atime�st_ctime�st_mtimerCr�r�r5�st_inorBr��S_ISLNKr2rD�S_ISFIFOr
r�r�r!rA�	listxattrr�r�r��llfuseZENOATTRrWrrr�)r�r;rBr�Zin_fnZout_fnZsti1Zsto1Zin_fZout_fZsti2Zsto2rCrDrrr�rSrSrU�	test_fuse	s�



$*

$
 $zArchiverTestCase.test_fusecs|jdd|j�|jddd�t�rJ|jddd�tjdd	�tjdd
�|jd|jdd
�|jddd�|jd|jdd
�tjj|jd�}|j	|j|dd���tjj|d
d��tj
��}tdd�|D��s�t�ddh�fdd�|D�ks�t�t��r�tjj|d
dd�}tjj|d
dd�}tjj|d
dd�}tj
|�jtj
|�jk�o\tj
|�jkn�sht�t|d�j�dk�s�t�WdQRX|j	|j|dddd��ht��rtjj|d
dd�}tjj|d
dd�}tj
|�jtj
|�jk�s�t�t|d�j�dk�st�WdQRXdS)Nr�z--encryption=repokeyr
sfirst)r�Z	hardlink1s123456zinput/hardlink1zinput/hardlink2zinput/hardlink3r�z
::archive1rNssecondz
::archive2r�z-oZversionscss|]}|jd�VqdS)ztest.N)r)r�r�rSrSrUr�~	sz;ArchiverTestCase.test_fuse_versions_view.<locals>.<genexpr>cs$h|]}ttjj�|�d�j��qS)rZ)r�rbr�r�r5)r�r�)r�rSrU�	<setcomp>	sz;ArchiverTestCase.test_fuse_versions_view.<locals>.<setcomp>zhardlink1.00001Z	hardlink2zhardlink2.00001Z	hardlink3zhardlink3.00001rZz-e)rr�r�rCrbr�r�r�r�r�r�r�r�r�r}r�r5)r�r��filesZhl1Zhl2Zhl3rS)r�rU�test_fuse_versions_viewn	s6
8"z(ArchiverTestCase.test_fuse_versions_viewc Cs8|jdd|j�|jd�|jd�\}}|�Nx>|j�D]*}|jjd�r8|j|jdj	�|j}Pq8Wdsnt
�|j�WdQRX|jdd|jd	d
�tjj
|jd�}|j|jd|��@tjt��}ttjj
||��WdQRX|jjtjks�t
�WdQRX|j|jd|d
d��ttjj
||��j�WdQRXdS)Nr�z--encryption=repokeyr�ztestsuite/archiver.pyr;Fr�z--repairr)rjr�z	::archivez-oZallow_damaged_filesr�)rr�r�r�r�r�r�rrr�rQr�r�rbr�r�r�r)r*r�r�r�r�ZEIOr0)r�r�r�r�r�r�r
rSrSrU�test_fuse_allow_damaged_files�	s&
z.ArchiverTestCase.test_fuse_allow_damaged_filesc.Cs�|jdd|j�|jd�|jd�|jd�|jd�tjj|jd�}|j|j|dd	��(ttj	tjj|���ddgks~t
�WdQRX|j|j|d
d	��(ttj	tjj|���ddgks�t
�WdQRX|j|j|d��(ttj	tjj|���ddgks�t
�WdQRX|j|j|d��*ttj	tjj|���ddgk�s<t
�WdQRX|j|j|d
��.ttj	tjj|���ddddgk�s�t
�WdQRX|j|j|d��&ttj	tjj|���gk�s�t
�WdQRXdS)Nr�z--encryption=repokeyZarch11Zarch12Zarch21Zarch22r�z	--first=2z--sort=namez--last=2z--prefix=arch1z--prefix=arch2z
--prefix=archz
--prefix=nope)rr�r�rbr�r�r�r�r!r�r�)r�r�rSrSrU�test_fuse_mount_options�	s$



,,,.2z(ArchiverTestCase.test_fuse_mount_optionscs�t��t�����fdd�}�j�dtjd<�jdd|�j�|��jd�jdd	�|��jd�jd
d	�|��jd�jd
�|�dS)Ncs�t�j���}x�|j|j��j�D]~\}}|j|�}t|�j�}|�kr �j|�t	t
|�d�}t|dd��}x,t|||�D]}�j
|���j|�q�Wq WWdQRXdS)N�)�!)r:r�Z
open_indexZget_transaction_id�	iteritemsr�rZdigest�addrr�rr�r�)r�rQ�_r��hashZ
num_blocks�nonceZcounter)�seenr��usedrSrU�verify_uniqueness�	s

zIArchiverTestCase.verify_aes_counter_uniqueness.<locals>.verify_uniquenessrjr�r�z
--encryption=r�z::testrNz::test.2rr)rUrrbr�rr�)r��methodr�rS)r�r�r�rU�verify_aes_counter_uniqueness�	s

z.ArchiverTestCase.verify_aes_counter_uniquenesscCs|jd�dS)Nr�)r�)r�rSrSrU�#test_aes_counter_uniqueness_keyfile�	sz4ArchiverTestCase.test_aes_counter_uniqueness_keyfilecCs|jd�dS)Nr�)r�)r�rSrSrU�&test_aes_counter_uniqueness_passphrase�	sz7ArchiverTestCase.test_aes_counter_uniqueness_passphrasecCs�|j�|jdd|j�|jd|jdd�td��|jdd|jd�}WdQRXttjd��}t|�d	kr||d	jd
�s�t	�d|ks�t	�dS)Nr�z--encryption=repokeyr�z::testrNr^rZzdump-archive-itemsrZ000000_zDone.)
rrr�r?r!rbr�r�rr�)r�r^�
output_dirrSrSrU�test_debug_dump_archive_items�	s
z.ArchiverTestCase.test_debug_dump_archive_itemscCs�|j�|jdd|j�|jd|jdd�td��|jdd|j�}WdQRXttjd��}t|�d	krx|d	jd
�s|t	�d|ks�t	�dS)Nr�z--encryption=repokeyr�z::testrNr^rZzdump-repo-objsrZ	00000000_zDone.)
rrr�r?r!rbr�r�rr�)r�r^r�rSrSrU�test_debug_dump_repo_objs�	s
z*ArchiverTestCase.test_debug_dump_repo_objscCs�|jdd|j�d}t|�j�}|jd|d�|jdd|jd�}||ksLt�|jdd	|j|d
�}||kslt�td
d��}|j�}WdQRX||ks�t�|jdd|j|�}d
|ks�t�|jdd|j|�}d|ks�t�|jdd|jd�}d|ks�t�dS)Nr�z--encryption=repokeys	some datar8)r�rZzput-objz
input/filezget-objzoutput/filerZz
delete-objZdeletedz	not foundZinvalidz
is invalid)rr�rZ	hexdigestr�r�r�r5)r�r�Zhexkeyr^r�Z	data_readrSrSrU�test_debug_put_get_delete_obj�	s"z.ArchiverTestCase.test_debug_put_get_delete_objc
CsNdd�}tjtd|��|jdd|jdd�WdQRXtjj|j�sJt�dS)NcWst�dS)N)�EOFError)rTrSrSrU�	raise_eof
sz7ArchiverTestCase.test_init_interrupt.<locals>.raise_eofr�r�z--encryption=repokeyr;)rj)	rr�rrr�rbr�r�r�)r�r�rSrSrU�test_init_interrupt
sz$ArchiverTestCase.test_init_interruptcCs|jd|jdd�dS)Nr�r)rj)rr�)r�rSrSrU�$test_init_requires_encryption_option
sz5ArchiverTestCase.test_init_requires_encryption_optioncCs`|jdd|j�|jr0|jdd|jddd�n,tjtj��|jdd|jd�WdQRXdS)Nr�z--encryption=repokeyz/nestedr)rj)rr�r�r)r*r:Z
AlreadyExists)r�rSrSrU�test_init_nested_repositories
s
z.ArchiverTestCase.test_init_nested_repositoriescCs�tjj|jd�}t|d���|jdd|jd�t|��}|j�}WdQRXdd|jdf}|j	rt|j|dd	i�n$t
jtj
j��|j|�WdQRXt|��}|j�}WdQRX||ks�t�WdQRXdS)
z�BORG_KEY_FILE=something borg init should quit if "something" already exists.

        See https://github.com/borgbackup/borg/pull/6046r�)Z
BORG_KEY_FILEr�z--encryption=keyfiler�Nr�rjr)rbr�r�r�r@rr�r�r5r�r)r*rpr�Errorr�)r�r�r8�before�arg�afterrSrSrU�%test_init_refuse_to_overwrite_keyfile
s

z6ArchiverTestCase.test_init_refuse_to_overwrite_keyfilecCs|jd|j�|j��b}tj|tj�\}}t|||dd��}|j}WdQRXtj|�t|||��}|j}WdQRXWdQRX||k	s�t	�t
�}xV|j�D]J\}\}	}
}||\}}
}|	|ks�t	�|
|
ks�t	�||ks�t	�|j|�q�Wx&|j�D]\}\}	}
}||ks�t	�q�WdS)Nr�F)�sync)
rr�r�r'r�r�rr�Zdestroyr�rUr�r�)r�r�r�rIr�Zoriginal_chunksZcorrect_chunksr�rQZrefcountr�rMZ
o_refcountZo_sizeZo_csizerSrSrU�check_cache,
s$

zArchiverTestCase.check_cachecCs�|jdd|j�|jd|jdd�|j��b}tj|tj�\}}t|||dd��4}|j�|jj	t
|jj��dd�|j�WdQRXWdQRXt
jt��|j�WdQRXdS)	Nr�z--encryption=repokeyr�z::testrNF)r�r)rr�r�r'r�r�rr+r�Zincrefrlr�r�r)r*r�r�)r�r�r�rIr�rSrSrU�test_check_cacheB
s
z!ArchiverTestCase.test_check_cachecCs4|jdd|j�|jd|jddd�}d|ks0t�dS)Nr�z--encryption=repokeyr�z
--target=asdfr)rjzNeed to specify single archive)rr�r�)r�r^rSrSrU�test_recreate_target_rcN
sz(ArchiverTestCase.test_recreate_target_rccCs�|j�|jdd|j�|j�|jd}|jd|d�|j�|jd|j�}|jd|dd	d
d�|j�|jd|j�}||ks�t�d|ks�t�|jd
}|jdd|�}d|ks�t�d|ks�t�d|ks�t�dS)Nr�z--encryption=repokeyz::test0r�rNrlr�z
input/dir2z-ezinput/dir2/file3z--target=new-archiveznew-archivez
::new-archivez--shortr�z
dir2/file2z
dir2/file3)rrr�r�r�)r�r�Zoriginal_archiver��listingrSrSrU�test_recreate_targetS
s"

z%ArchiverTestCase.test_recreate_targetcCs�|j�|jddd�|jdd|j�|jd}|jd|d	�|jd
|ddd
�|j�|jdd|�}d|ksrt�d|ks~t�d|ks�t�dS)Nz
dir2/file3ir�)r�r�z--encryption=repokeyz::test0r�rNr�z
input/dir2z-ezinput/dir2/file3rlz--shortr�z
dir2/file2i@)rr�rr�r�r�)r�r�r�rSrSrU�test_recreate_basicg
s
z$ArchiverTestCase.test_recreate_basiccCs�|j�|jd|jdd�|jd|jdd�|j�td��h|jd|jd�tjd	�jd
ksht�tjd�jd
ks|t�tjd�jd
ks�t�tjd
�jd
ks�t�WdQRXtd��,|jd|jd�tjd	�jdks�t�WdQRXdS)Nr�z::test2rNr�z::testz
input/dir1r^r�zinput/dir1/hardlinkrzinput/dir1/subdir/hardlinkzinput/dir1/aaaazinput/dir1/source2r)	r�rr�r�r?rbr�r�r�)r�rSrSrU�test_recreate_subtree_hardlinkst
s

z0ArchiverTestCase.test_recreate_subtree_hardlinkscCsttjj|jd�d��"}|jdd�|jdd�WdQRX|jdd|j�|jdd	d
|jdd�|jd|jd
dd�|jd|jdddd�}tt	|j
d��\}}||ks�t�|jd|jd	d�|j�t	|jd|jddd��s�t�t	|jd|jdddd���st�dS)NZ
large_filer�rHi�br�z--encryption=repokeyr�z--chunker-paramsz	7,9,8,128z::test1rNz::test2z--files-cache=disabledrlzinput/large_filez--formatz{num_chunks} {unique_chunks}rLr��defaultz--format={size}z{unique_chunks})
r�rbr�r�r�r�rr��maprIr r�r�)r�r�rlZ
num_chunksZ
unique_chunksrSrSrU�test_recreate_rechunkify�
sz)ArchiverTestCase.test_recreate_rechunkifycCs�|jddd�|jdd|j�|jd|jddd	d
�|jd|jddd
d�}|jd�\}}}t|�t|�ksrt�|jd|jd	dd�|j�|jd|jddd
d�}|jd�\}}}t|�t|�ks�t�||ks�t�dS)Nr_i')r�r�z--encryption=repokeyr�z::testrNz-Crarlzinput/compressiblez--formatz{size} {csize} {sha256}rLr�rKz--recompress)r�rr�r rIr�r�)r�Z	file_listr�rMZ
sha256_beforeZsha256_afterrSrSrU�test_recreate_recompress�
sz)ArchiverTestCase.test_recreate_recompresscs�tjttd���j�j}|j�|jdd|j�|jd}|jd|d�|jddd	d
d|�|jd|�j	�}td
dd�|j
d�}|jd��t�fdd�|D��s�t
�t�fdd�|D��s�t
�dS)Nrr�z--encryption=repokeyz::test0r�rNr�z--timestampz1970-01-02T00:00:00z	--commentr
ri�r;rz%Y-%m-%dcsg|]}tjd�|��qS)zTime \(start\).+ %s)�re�search)r�r�)�s_timerSrUr�
sz<ArchiverTestCase.test_recreate_timestamp.<locals>.<listcomp>csg|]}tjd�|��qS)zTime \(end\).+ %s)r�r�)r�r�)r�rSrUr�
s)r�nowrrZ
astimezoneZtzinforrr�r�Z	utcoffset�strftime�anyr�)r�Zlocal_timezoner�rZdtimerS)r�rU�test_recreate_timestamp�
s

z(ArchiverTestCase.test_recreate_timestampcCs�|jddd�|jdd|j�|jd|jdd�|jd	|jd�}|jd
|jddd
�|j�|jd	|jd�}||ks~t�dS)Nr_i')r�r�z--encryption=repokeyr�z::testrNrlr�z-nz-ezinput/compressible)r�rr�r�r�)r�Zarchives_beforeZarchives_afterrSrSrU�test_recreate_dry_run�
sz&ArchiverTestCase.test_recreate_dry_runcCs�|jddd�|jdd|j�|jd|jdd	�|jd
|jd�}|jd|jdd
�|j�|jd
|jd�}||ks|t�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrr�z--chunker-paramsr�i@)r�rr�r�r�)r�Zinfo_beforeZ
info_afterrSrSrU�!test_recreate_skips_nothing_to_do�
sz2ArchiverTestCase.test_recreate_skips_nothing_to_docCsN|jdd|j�tjj|jd�}ddd|f}|jd|jf|�dd	d
��dS)Nr�z--encryption=repokeyzlock.exclusiveZpython3z-cz<import os, sys; sys.exit(42 if os.path.exists("%s") else 23)z	with-lockT�*)rLrj)rr�rbr�r�r�)r�Z	lock_pathrrSrSrU�test_with_lock�
szArchiverTestCase.test_with_lockcCsN|jdd|j�|jddd�|jddd�|jddd�|jddd�|jd	dd�|jd
|jdd�|jd
dd|jddd�}|j�|jd|�|jd|�|jd
d|jddd�}|j�|jd|�|jd|�|jd
|jddd�}|j�|jd|�|jd|�|jd
d|jddd�}|j�|jd|�|jd|�dS)Nr�z--encryption=repokeyr�r)r�r�r�r�Zfile5r�z::testrNr�z--listz--infoz-ezinput/file2zinput/file1z
x input/file2zinput/file3z
x input/file3zinput/file4z
x input/file4zinput/file5z
x input/file5)rr�r�r�rr�)r�r^rSrSrU�test_recreate_list_output�
s.z*ArchiverTestCase.test_recreate_list_outputc
CsD|jdd|j�|jd|jdd�|jdddd	d|jd
dd�dS)
Nr�z--encryption=repokeyr�z::testrNrrz--firstr�z--lastTr)rLrj)rr�)r�rSrSrU�test_bad_filters�
sz!ArchiverTestCase.test_bad_filterscCs|jd}|jd|jdd�|j|j�}|jdd|j|�t|d��}|j�}WdQRX|jdt|�d	�srt	�|j
d
tj|j
�d}t|d��}|j�}WdQRX||ks�t	�tj
|�|jdd|j|�t|d��}|j�}WdQRX||ks�t	�dS)
Nz	/exportedr�z--encryptionr�rI�export�rz	BORG_KEY r�/r�import)r�rr�rr�r�r5rr-r�r�rbr�r�)r��export_file�repo_idr��export_contents�key_fileZkey_contentsZ
key_contents2rSrSrU�test_key_export_keyfile�
s 

z(ArchiverTestCase.test_key_export_keyfilec	CsD|jd}|jd|jdd�|j|j�}|jdd|j|�t|d��}|j�}WdQRX|jdt|�d	�srt	�t
|j��}t|�}|jdt
j��WdQRXttjj��}|j|t
j��|j|jks�t	�t
|j��}|jd
�WdQRX|jdd|j|�t
|j��}t|�}|jdt
j��WdQRX|j|jk�s@t	�dS)Nz	/exportedr�z--encryptionr�rIr�r�z	BORG_KEY rrJr�)r�rr�rr�r�r5rr-r�r:rr�rZenv_passphraserrIZTestKeyZMockRepositoryZenc_keyZsave_key)	r�r�r�r�r�r�Zrepo_keyZ
backup_keyZ	repo_key2rSrSrU�test_key_export_repokeys(
z(ArchiverTestCase.test_key_export_repokeyc	Cs�|jd}|jd|jdd�|j|j�}|jddd|j|�t|dd	d
��}|j�}WdQRXt|�|ksnt�|j	d�s|t�|j
d�s�t�dS)
Nz/exported.htmlr�z--encryptionr�rIr�z	--qr-htmlr�zutf-8)rRz<!doctype html>z</html>
)r�rr�rr�r�r5r-r�rr�)r�r�r�r�r�rSrSrU�test_key_export_qr-s
z#ArchiverTestCase.test_key_export_qrcCs@|jd}tj|�|jd|jdd�|jdd|j|td�dS)Nz	/exportedr�z--encryptionr�rIr�)rj)r�rbr�rr�r,)r�Zexport_directoryrSrSrU�test_key_export_directory:s

z*ArchiverTestCase.test_key_export_directoryc!Cs|jd}|jd|jdd�|jdd|j|td�t|d��}|jd	�WdQRX|jrp|jdd|j|d
d�n(tjt	��|jdd|j|�WdQRXt|d��}|jd�WdQRX|jr�|jdd|j|d
d�n(tjt
��|jdd|j|�WdQRXdS)Nz	/exportedr�z--encryptionr�rIr�)rjrTzsomething not a key
rzBORG_KEY a0a0a0
)r�rr�r,r�r�r�r)r*r#r")r�r�r�rSrSrU�test_key_import_errorsBs
z'ArchiverTestCase.test_key_import_errorscCs�d}|jd}|jd|jdd�|j|jt|��|jdtj|j�d}t	|d��0}|j
tjd	|d
�|j
t
d�j��WdQRX|jdd
d|j|�t	|d��}|j�}WdQRX|dks�t�dS)N�@e294423506da4e1ea76e8dcdf1a3919624ae3ae496fddf905610c351d3f09239z	/exportedr�z--encryptionr�r�rrTrLrsabcdefghijklmnopqrsturIr�z--paperr�z�To restore key use borg key import --paper /path/to/repo

BORG PAPER KEY v1
id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02
 1: 616263 646566 676869 6a6b6c 6d6e6f 707172 - 6d
 2: 737475 - 88
)r�rr�rVr�rr�rbr�r�r�r�FILE_IDrrfr5r�)r�r�r�r�r�r�rSrSrU�test_key_export_paperkeyZs
z)ArchiverTestCase.test_key_export_paperkeycCs�d}|jd|jdd�|j|jt|��|jdtj|j�d}t|d��0}|j	t
jd|d	�|j	td
�j
��WdQRXd}|jdd
d|j|d�d}|jdd
d|j|d�d}|jdd
d|j|d�dS)Nr�r�z--encryptionr�r�rrTrLrsabcdefghijklmnopqrstus�2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41  02
2 / e29442 3506da 4e1ea7  25f62a 5a3d41 - 02
2 / e29442 3506da 4e1ea7 / 25f62a 5a3d42 - 02
2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02
616263 646566 676869 6a6b6c 6d6e6f 707172 - 6d


737475 88
73747i - 88
73747 - 88
73 74 75  -  89
00a1 - 88
2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02
616263 646566 676869 6a6b6c 6d6e6f 707172 - 6d
73 74 75  -  88
rIr�z--paper)rNs
y
s12 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02

y
)rr�rVr�rr�rbr�r�r�rr�rrf)r�r�r�r�Ztyped_inputrSrSrU�test_key_import_paperkeytsz)ArchiverTestCase.test_key_import_paperkeyc	Cs�|jddd�|jdd|j�|jd|jdd	�|jd
}|jdd|j|�}|d
ksZt�t|d��}tj|�}WdQRXd|ks�t�d|ks�t�d|ks�t�d|ks�t�d|ks�t�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNz/dumprZz
dump-manifestrQr�r�rSZ	item_keys�	timestamp�versioni@)r�rr�r�r�r�rr�)r��	dump_filer^r�rrSrSrU�test_debug_dump_manifest�s
z)ArchiverTestCase.test_debug_dump_manifestc	Cs�|jddd�|jdd|j�|jd|jdd	�|jd
}|jdd|jd|�}|d
ks^t�t|d��}tj|�}WdQRXd|ks�t�d|ks�t�d|ks�t�d|ks�t�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNz/dumprZzdump-archiverQr��_nameZ_manifest_entryZ_metaZ_itemsi@)r�rr�r�r�r�rr�)r�r�r^r�rrSrSrU�test_debug_dump_archive�s
z(ArchiverTestCase.test_debug_dump_archivecCs�|jdd|j�|jdd|jdd�j�}|dks6t�tj|jdd	|jd
d��}|dd
}|jdd|j|�j�}|d|dks�t�|jdd|jdd�j�}|dks�t�dS)Nr�z--encryption=repokeyrZzrefcount-objr�r�zkobject 0000000000000000000000000000000000000000000000000000000000000000 not found [info from chunks cache].r�z--jsonz::testrNr�rQzobject z* has 1 referrers [info from chunks cache].Z124Zxyzaz4object id 124 is invalid.
object id xyza is invalid.)rr��stripr�rr)r�r^r��
archive_idrSrSrU�test_debug_refcount_obj�sz(ArchiverTestCase.test_debug_refcount_objcCs(|jdd�}d|kst�d|ks$t�dS)NrZrzCRC implementation�Python)rr�)r�r^rSrSrU�test_debug_info�sz ArchiverTestCase.test_debug_infocCs>|jdd|j�tdd��|jdd|j|j�WdQRXdS)Nr�z--encryption=repokeyr�)Z_BORG_BENCHMARK_CRUD_TESTZ	benchmarkZcrud)rr�r@r�)r�rSrSrU�test_benchmark_crud�sz$ArchiverTestCase.test_benchmark_crudcCsL|j�tjd�|jdd|j�|jdd|j�}|jd|�|jd|�|jd|�|jd	|�|jd
|�|jd|�|jd|�x�dD]|\}}|jd|j|�}|dks�t�|jd|j||�|jd|j|�}||dks�t�|jdd|j|�|jd|j|dd�q�W|jddd|jdd�|jd|jdd�|jd|jddd�dS)Nzinput/flagfiler�z--encryption=repokeyrSz--listz[repository]r�Zsegments_per_dirZ
storage_quota�append_only�additional_free_spacerQ�2G�repository.append_onlyr�r�rz--deleter;)rjrzinvalid-option�r�r��r�r�)r�r�z0
)rrbr�rr�rr�)r�r^Zcfg_keyZ	cfg_valuerSrSrU�test_config�s0
zArchiverTestCase.test_configz(GNU tar must be installed for this test.�gzipz%gzip must be installed for this test.cCs�|j�tjd�|jdd|j�|jd|jdd�|jd|jddd	�td
��tjddd
dg�WdQRX|jdddddd�dS)Nzinput/flagfiler�z--encryption=repokeyr�z::testrNz
export-tarz
simple.tarz
--progressr^rt�xpfz
../simple.tarz--warning=no-timestampzoutput/inputT)rtru�	ignore_ns)	rrbr�rr�r?r]�
check_callr)r�rSrSrU�test_export_tar�s

z ArchiverTestCase.test_export_tarcCs�tjd�stjd�|j�tjd�|jdd|j�|jd|jdd�|jd	|jdd
d�}d|kslt	�d
|ksxt	�t
d��tjddddg�WdQRX|j
dddddd�dS)Nr�zgzip is not installedzinput/flagfiler�z--encryption=repokeyr�z::testrNz
export-tarz
simple.tar.gzz--listzinput/file1
zinput/dir2
r^rtr�z../simple.tar.gzz--warning=no-timestampzoutput/inputT)rtrur�)rurvr)r.rrbr�rr�r�r?r]r�r)r�rlrSrSrU�test_export_tar_gzs



z#ArchiverTestCase.test_export_tar_gzcCs�tjd�stjd�|j�tjd�|jdd|j�|jd|jdd�|jd	|jdd
dd�}d
|ksnt	�d|kszt	�t
d��tjddddg�WdQRX|j
dddddd�dS)Nr�zgzip is not installedzinput/flagfiler�z--encryption=repokeyr�z::testrNz
export-tarz
simple.tarz--strip-components=1z--listzinput/file1
zinput/dir2
r^rtr�z
../simple.tarz--warning=no-timestampzoutput/T)rtrur�)rurvr)r.rrbr�rr�r�r?r]r�r)r�rlrSrSrU� test_export_tar_strip_componentss



z1ArchiverTestCase.test_export_tar_strip_componentscCs�|j�|jd|jddd�td��htjdddd	g�tjd
�jdksNt	�tjd�jdksbt	�tjd
�jdksvt	�tjd�jdks�t	�WdQRXdS)Nz
export-tarz::testz
output.tarz--strip-components=2r^rtr�z
../output.tarz--warning=no-timestampr�rzsubdir/hardlinkr�r�)
r�rr�r?r]r�rbr�r�r�)r�rSrSrU�&test_export_tar_strip_components_links s
z7ArchiverTestCase.test_export_tar_strip_components_linkscCs�|j�|jd|jddd�td��htjdddd	g�tjd
�jdksNt	�tjd�jdksbt	�tjd
�jdksvt	�tjd�jdks�t	�WdQRXdS)Nz
export-tarz::testz
output.tarz
input/dir1r^rtr�z
../output.tarz--warning=no-timestampzinput/dir1/hardlinkrzinput/dir1/subdir/hardlinkzinput/dir1/aaaazinput/dir1/source2)
r�rr�r?r]r�rbr�r�r�)r�rSrSrU�test_extract_hardlinks_tar,s
z+ArchiverTestCase.test_extract_hardlinks_tarc
Cs�t|j�}d|d|jgd|dgd|gd|ddgd|gd|gd	|gd
|dgdd|d
gdd|dgd|gd|gg}x*|D]"}|j|ddd��}d|kszt�qzWdS)Nr�z::testr�r�roZnewnamerlrrr$rrIr�Zexportedr�zchange-passphrasez
break-lockTr)rLrjzAttic repository detected.)rHr�r�rr�)r�r�ZcmdsrTr^rSrSrU�test_detect_attic_repo8s 






z'ArchiverTestCase.test_detect_attic_repocCs�dd�}|jd�tjddd�|jd|jd�|jd	|jd
d�td��6tjtd
|��|jd|jd
td�WdQRXWdQRXdS)z.https://github.com/borgbackup/borg/issues/6063c_sttjd��dS)Nr/)r�r�r/)rTr�rSrSrUr�Qsz`ArchiverTestCase.test_do_not_fail_when_percent_is_in_xattr_name.<locals>.patched_setxattr_EACCESr8s
input/filesuser.attribute%psvaluer�z-enoner�z::testrNr^r�r�)rjN)	r�r
r�rr�r?rr�r+)r�r�rSrSrU�.test_do_not_fail_when_percent_is_in_xattr_nameMs

z?ArchiverTestCase.test_do_not_fail_when_percent_is_in_xattr_namecCs�dd�}tjtjj|jd��tjddd�|jd|jd�|jd	|jd
d�t	d��6t
jtd
|��|jd|jd
td�WdQRXWdQRXdS)z.https://github.com/borgbackup/borg/issues/6063c_sttjd��dS)Nr/)r�r�r/)rTr�rSrSrUr�asz_ArchiverTestCase.test_do_not_fail_when_percent_is_in_file_name.<locals>.patched_setxattr_EACCESzdir%psinput/dir%psuser.attributesvaluer�z-enoner�z::testrNr^r�r�)rjN)
rbr�r�r�r�r
r�rr�r?rr�r+)r�r�rSrSrU�-test_do_not_fail_when_percent_is_in_file_name]s
z>ArchiverTestCase.test_do_not_fail_when_percent_is_in_file_namecCs|jddd�|jdd|j�|jd|jdd�tjtjj|jd	��tjtjj|j�d	��|jd
|j�}d|kszt	�|jd|j�}d
|ks�t	�|jd
|jd�}d|ks�t	�|jd|jd�}d|ks�t	�t
d��|jd|jd�WdQRX|jdd�dS)z�Nonce is only used for encrypting new data.

        It should be possible to retrieve the data from an archive even if
        both the client and the server forget the noncer�sHello, borg)r�r�z--encryption=repokeyr�z::testrNr�rz
All archives:rlr
zArchive name: test
r^r�Nzoutput/input)r�rr�rbr�r�r�r�r&r�r?r)r�Z	repo_infoZ	repo_listZarchive_infor&rSrSrU�+test_can_read_repo_even_if_nonce_is_deletedls 
z<ArchiverTestCase.test_can_read_repo_even_if_nonce_is_deletedcCst|jddd�|jdd|j�|jd|jdd�tjj|jd	�}tj|�|jd|jd
d�tjj|�spt	�dS)a We should be able to recover if path/to/repo/nonce is deleted.

        The nonce is stored in two places: in the repo and in $HOME.
        The nonce in the repo is only needed when multiple clients use the same
        repo. Otherwise we can just use our own copy of the nonce.
        r�sHello, borg)r�r�z--encryption=repokeyr�z::testrNr�z::test2N)
r�rr�rbr�r�r�r�r�r�)r�r�rSrSrU�%test_recovery_from_deleted_repo_nonce�s
z6ArchiverTestCase.test_recovery_from_deleted_repo_nonceN)r^)�rrr	r)�mark�skipifrCZrequires_hardlinksr&rr(r,r1rBr3rErErFrLrPrrVrgrirlrqrsrtrvr{r|r}r�r��unittest�
skipUnlessr=r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr
rrrrrrbr�rrrrrrr r!r#r%r&Zallow_cache_wiper-r/r0r1r3r5r6r7r8r9r:r<r=r>r?r@rErFrIrJrNrPrQrYr\r]r`rcrdrfrgrhrirkrlrnrorprqrrrsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rzZrequires_gnutarrurvZ
requires_gzipr�r�r�r�r�r�r�r�r�r�rSrSrSrUr
�s�?		3
!!(!		

	


)'



f 


 


-  r
zno borg.exe availablecs�eZdZdZdZejd�dd��Zejd�dd��Zejd�d	d
��Z	ejd�dd��Z
ejd
�dd��Zejd�dd��Z�fdd�Z
ejd�dd��Zejd�dd��Z�ZS)�ArchiverTestCaseBinaryzborg.exeTz(does not raise Exception, but sets rc==2cCsdS)NrS)r�rSrSrUr,�sz,ArchiverTestCaseBinary.test_init_parent_dirszpatches objectscCsdS)NrS)r�rSrSrUr��sz*ArchiverTestCaseBinary.test_init_interruptcCsdS)NrS)r�rSrSrUr��sz0ArchiverTestCaseBinary.test_extract_capabilitiescCsdS)NrS)r�rSrSrUr��sz1ArchiverTestCaseBinary.test_extract_xattrs_errorszLtest_basic_functionality seems incompatible with fakeroot and/or the binary.cCsdS)NrS)r�rSrSrUr�sz/ArchiverTestCaseBinary.test_basic_functionalityzBtest_overwrite seems incompatible with fakeroot and/or the binary.cCsdS)NrS)r�rSrSrUr��sz%ArchiverTestCaseBinary.test_overwritecs t�rtjd�n
t�j�dS)Nz9test_fuse with the binary is not compatible with fakeroot)rGr�r.�superr�)r�)�	__class__rSrUr��sz ArchiverTestCaseBinary.test_fusecCsdS)NrS)r�rSrSrUr��szEArchiverTestCaseBinary.test_do_not_fail_when_percent_is_in_xattr_namecCsdS)NrS)r�rSrSrUr��szDArchiverTestCaseBinary.test_do_not_fail_when_percent_is_in_file_name)rrr	r�r�r�r.r,r�r�r�rr�r�r�r��
__classcell__rSrS)r�rUr��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�Z�ZS)�ArchiverCheckTestCasecsLt�j�tjtdd��*|jdd|j�|jd�|jd�WdQRXdS)N�BUFFER_SIZEr�r�z--encryption=repokey�archive1rv)r�r�rr�rrr�r�)r�)r�rSrUr��s


zArchiverCheckTestCase.setUpcCs<|jddd|jdd�}|jd|�|jd|�|jd|�tjd	�jtj�|jddd
|jdd�}|jd|�|jd|�|jd|�|jddd|jdd�}|jd|�|jd|�|jdddd|jdd�}|jd
|�|jdddd|jdd�}|jd
|�|jd|�|jdddd|jdd�}|jd
|�|jd|�dS)Nr�z-vz
--progressr)rjzStarting repository checkz"Starting archive consistency checkzChecking segmentszborg.output.progressz--repository-onlyz--archives-onlyz--prefix=archive2r�z	--first=1rvz--last=1)rr�r�loggingZ	getLoggerZsetLevelZNOTSETr�)r�r^rSrSrU�test_check_usage�s(z&ArchiverCheckTestCase.test_check_usagecCs,|jd�\}}|�RxB|j�D],}|jjd�r|j}|d}|j|j�PqW|jd�|j�WdQRX|j	d|j
dd�|j	dd|j
dd�}|jd	|�|j	d|j
dd�|j	d
d|j
ddd�}|jd
|�xtdD]l}|j|�\}}|�PxH|j�D]2}|jjd��r�|j||j�|j
||j�P�q�W|jd�WdQRXq�Wtjtdd��|jd�WdQRX|j	ddd|j
dd�}|jd|�|jd|�xhdD]`}|j|�\}}|�Bx:|j�D]$}|jjd��r�|j||j�P�q�W|jd�WdQRX�q�W|j	d
d|j
ddd�}|j
d
|�dS)Nr�ztestsuite/archiver.pyr;zshould not happenr�)rjz--repairrzNew missing file chunk detectedrlz--format={health}#{path}{LF}z
::archive1zbroken#rvr�r�Zarchive3z-vz$Healed previously missing file chunkzAtestsuite/archiver.py: Completely healed previously damaged file!r�)r�rv)r�rv)r�r�r�r�r�rrrQZfailr�rr�rZassert_not_equalr�rr�rr�r�)r�r�r�r�Zvalid_chunksZkilled_chunkr^�archive_namerSrSrU�test_missing_file_chunk�sP


z-ArchiverCheckTestCase.test_missing_file_chunkc
Cst|jd�\}}|� |j|jjd�|j�WdQRX|jd|jdd�|jdd|jdd�|jd|jdd�dS)Nr�rr�r;)rjz--repair)r�rrrrr�rr�)r�r�r�rSrSrU�test_missing_archive_item_chunk
sz5ArchiverCheckTestCase.test_missing_archive_item_chunkc
Csn|jd�\}}|�|j|j�|j�WdQRX|jd|jdd�|jdd|jdd�|jd|jdd�dS)Nr�r�r;)rjz--repairr)r�rrrQr�rr�)r�r�r�rSrSrU�test_missing_archive_metadata#
sz3ArchiverCheckTestCase.test_missing_archive_metadatacCs�|jd�\}}|�|jtj�|j�WdQRX|jd|jdd�|jddd|jdd�}|jd|�|jd|�|jd|jdd�dS)	Nr�r�r;)rjz-vz--repairrrv)r�rrr'�MANIFEST_IDr�rr�r)r�r�r�r^rSrSrU�test_missing_manifest,
sz+ArchiverCheckTestCase.test_missing_manifestcCs�|jd�\}}|�0|jtj�}|d}|jtj|�|j�WdQRX|jd|jdd�|jddd|jdd�}|jd|�|jd	|�|jd|jdd�dS)
Nr�s
corrupted!r�r;)rjz-vz--repairrrv)	r�r�r'rrr�rr�r)r�r�r�r��corrupted_manifestr^rSrSrU�test_corrupted_manifest7
sz-ArchiverCheckTestCase.test_corrupted_manifestcCs�|jd�\}}|�R|jtj�}|d}|jtj|�|j|j�}|d}|j|j|�|j�WdQRX|jd|jdd�|jddd|jdd�}|j	d	|�|jd|jdd�dS)
Nr�s
corrupted!r�r;)rjz-vz--repairrrv)
r�r�r'rrrQr�rr�r)r�r�r�r�r�chunkZcorrupted_chunkr^rSrSrU�%test_manifest_rebuild_corrupted_chunkD
sz;ArchiverCheckTestCase.test_manifest_rebuild_corrupted_chunkc	Cs�|jd�\}}|j}|�n|jtj�}|d}|jtj|�ggdddddd�}|j|dd	�}|j|�}|j||j|��|j	�WdQRX|j
d
|jdd�|j
d
d|jd
d�|j
d|j�}|jd|�|jd|�|jd|�dS)Nr�s
corrupted!�foo�barz2016-12-15T18:49:51.849711r;)�cmdliner�hostname�usernamer�rr�sarchive)�contextr�)rjz--repairrrlz
archive1.1rv)
r�rIr�r'rrZpack_and_authenticate_metadata�id_hash�encryptr�rr�r)	r�r�r�rIr�rZarchive_dictr�r^rSrSrU�'test_manifest_rebuild_duplicate_archiveT
s.
z=ArchiverCheckTestCase.test_manifest_rebuild_duplicate_archivec
Cs�|jd|jdd�t|jdd��}|jdd�|j�WdQRX|jd|jdd�|jd|jdd�|jdd	|jdd�|jd|jdd�|jd
d|jddd�dS)
Nr�r)rjT)r�s 01234567890123456789012345678901sxxxxr;z--repairr�z	--dry-runz
::archive1)rr�r:rr�)r�r�rSrSrU�test_extra_chunksp
sz'ArchiverCheckTestCase.test_extra_chunkscGstj|j�|jd|jf|��|jd�|jd�\}}|�VxF|j�D]:}|jj	d�rH|j
d
}|j|j�d}|j
|j|�PqHW|j�WdQRX|jd|jdd�|jdd	|jdd�}t|j�d
|ks�t�|jddd	|jdd�}t|j�d
|k�st�d|k�st�dS)Nr�r�ztestsuite/archiver.pyr;s1234r�r)rjz
--verify-dataz, integrity errorz--repairz6testsuite/archiver.py: New missing file chunk detectedr�)rur�r�rr�r�r�r�r�r�r�r�rQrr�r-r�)r�Z	init_argsr�r�r�rr�r^rSrSrU�_test_verify_data{
s$

z'ArchiverCheckTestCase._test_verify_datacCs|jdd�dS)Nz--encryptionr�)r)r�rSrSrU�test_verify_data�
sz&ArchiverCheckTestCase.test_verify_datacCs|jdd�dS)Nz--encryptionra)r)r�rSrSrU�test_verify_data_unencrypted�
sz2ArchiverCheckTestCase.test_verify_data_unencryptedcCsTt|jdd��*}x|j�D]}|j|�qW|j�WdQRX|jd|jdd�dS)NT)r�r�r;)rj)r:r�rlrrr�r)r�r�Zid_rSrSrU�test_empty_repository�
s
z+ArchiverCheckTestCase.test_empty_repositorycCs�Gdd�d�}|jd�\}}|�Ztj|tj�\}}t|||��0}t|||d|dd�}|jj|��|j�WdQRXWdQRX|j	d|j
dd	�|j	d
|j
ddd	�dS)Nc@seZdZdd�ZdS)zAArchiverCheckTestCase.test_attic013_acl_bug.<locals>.Attic013Itemc	Ssddddddddd�S)NZ1234r�0)spathsmtimesmodesusersgroupsuidsgidsaclrS)r�rSrSrU�as_dict�
szIArchiverCheckTestCase.test_attic013_acl_bug.<locals>.Attic013Item.as_dictN)rrr	rrSrSrSrU�Attic013Item�
srr�z0.13T)r�r�r�r)rjrlz::0.13)r�r'r�r�rrZitems_bufferr�Zsaverr�)r�rr�r�r�rIr�rSrSrU�test_attic013_acl_bug�
sz+ArchiverCheckTestCase.test_attic013_acl_bug)rrr	r�r�r�r�rrrrrrrrrrrr�rSrS)r�rUr��s2		
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ManifestAuthenticationTestcCsf|�Xtj|tj�\}}|jtj|jtjdiitj	�t
dd�jt�d����|j
�WdQRXdS)Nr;)�days)r�r�rSr�)r'r�r�rrrr/�packbr�utcnowrr�r�r�)r�r�r�rIrSrSrU�spoof_manifest�
s"z)ManifestAuthenticationTest.spoof_manifestcCs�|jdd|j�t|jdd�}|�Vtj|tj�\}}|jtj|j	t
jditj
�tdd�jt�d����|j�WdQRXtjt��|jd|j�WdQRXdS)	Nr�z--encryption=repokeyT)r�r;)r)r�r�r�rl)rr�r:r�r'r�r�rrrr/rrrrr�r�r�r)r*r )r�r�r�rIrSrSrU�test_fresh_init_tam_required�
s"z7ManifestAuthenticationTest.test_fresh_init_tam_requiredcCsh|jdd|j�|jd�t|jdd�}|��tjtt|j	���t
j|t
j�\}}d|_
|j|j�tj|jd|jt
j���}|d=|jt
j|jtj|���|j�WdQRX|jdd	|j�}d|ks�t�d
|ks�t�|jdd|j�|jdd	|j�}d|k�st�d
|k�st�|j|�tjt��|jd|j�WdQRX|jddd|j�|jd|j�dS)Nr�z--encryption=repokey�archive1234T)r�Fstamrlz--debugz'Manifest TAM not found and not required�upgradez--tamzTAM-verified manifestz--force)rr�r�r:r�rur�r&r-rQr'r�r�Ztam_requiredZchange_passphraseZ_passphraser/ZunpackbZdecryptr�rrrrr�r�rr)r*r )r�r�r�rIr�r^rSrSrU�test_not_required�
s0

z,ManifestAuthenticationTest.test_not_requiredcCsZ|jdd|j�|jd�|jdd|j�t|jdd�}|j|�|jd|j�sVt�dS)	Nr�z--encryption=repokeyrr z
--disable-tamT)r�rl)rr�r�r:r�rr�)r�r�rSrSrU�test_disable�
s

z'ManifestAuthenticationTest.test_disablecCsZ|jdd|j�|jd�t|jdd�}|j|�|jdd|j�|jd|j�sVt�dS)	Nr�z--encryption=repokeyrT)r�r z
--disable-tamrl)rr�r�r:r�rr�)r�r�rSrSrU�
test_disable2�
s

z(ManifestAuthenticationTest.test_disable2N)rrr	rrr!r"r#rSrSrSrUr�
s
 rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ArchiveAuthenticationTestc	Csxtj|tj�\}}tjd|gdddtj�jt�d��}|j	|�}|j
||j|��|tj�f|j
|<|j�|j�dS)Nr;rQ)r�r�rr	r
rr)r'r�r�r/rrrr�r�r
rrr�r�r�r�)r�r�r�r�rIZarchive_datar�rSrSrU�write_archive_without_tam	s
z3ArchiveAuthenticationTest.write_archive_without_tamcCs�|jdd|j�|jd�t|jdd�}|�|j|d�WdQRX|jdd|j�}d	|ks`t�d
|kslt�|jdd|j�|jdd|j�}d	|ks�t�d
|ks�t�dS)Nr�z--encryption=repokey�archive_tamT)r��archive_no_tamrlz--format="{name} tam:{tam}{NL}"zarchive_tam tam:verifiedzarchive_no_tam tam:noner z--archives-tamzarchive_no_tam tam:verified)rr�r�r:r�r%r�)r�r�r^rSrSrU�test_upgrade_archives_tams
z3ArchiveAuthenticationTest.test_upgrade_archives_tamcCs�|jdd|j�|jd�t|jdd�}|�&|j|d�|jtj�|j	�WdQRX|jdd|j�|jd	d
|j�}d|ks�t
�d|ks�t
�dS)Nr�z--encryption=repokeyr&T)r�r'r�z--repairrlz--format="{name} tam:{tam}{NL}"zarchive_tam tam:verified)rr�r�r:r�r%rrr'rr�r�)r�r�r^rSrSrU�test_check_rebuild_manifest(s
z5ArchiveAuthenticationTest.test_check_rebuild_manifestcCs�|jdd|j�|jd�|jdd|j�}t|jdd�}|�|j|d�WdQRX|jdd	|j�}d
|kspt�d|ks|t�|jdd
|j�|jdd	|j�}d
|ks�t�d|ks�t�|jdd|j�}||ks�t�dS)Nr�z--encryption=repokeyr&rlz--format="{name} {id}{NL}"T)r�r'z--format="{name} tam:{tam}{NL}"zarchive_tam tam:verifiedzarchive_no_tam tam:noner�z--repair)rr�r�r:r�r%r�)r�Zarchive_id_pre_checkr�r^Zarchive_id_post_checkrSrSrU�test_check_rebuild_refcounts5s
z6ArchiveAuthenticationTest.test_check_rebuild_refcountsN)rrr	r%r(r)r*rSrSrSrUr$s
r$c@s\eZdZdZdd�Zdd�Zdd�Zejd�d	d
��Z	ejd�dd��Z
d
d�Zdd�ZdS)�RemoteArchiverTestCasez__testsuite__:cCstt|j��S)N)r8r%r�)r�rSrSrUr�Jsz&RemoteArchiverTestCase.open_repositoryc6Cs<tjtdd|jg��|jdd|j�WdQRXtjtdd|jg��0tjt��|jdd|jd�WdQRXWdQRXtjtdddg��0tjt��|jdd|jd�WdQRXWdQRXt	j
j|j�}tjtdd|g��|jdd|jd�WdQRXtjtdddd|g��|jdd|jd	�WdQRXdS)
N�extra_test_argsz--restrict-to-pathr�z--encryption=repokeyZ_0z/fooZ_1Z_2Z_3)rr�r8r�rr�r)r*r9rbr�r�)r�r,rSrSrU�!test_remote_repo_restrict_to_pathMs((z8RemoteArchiverTestCase.test_remote_repo_restrict_to_pathcCs�tjtdd|jg��|jdd|j�WdQRXtjj|jd�}tjtdd|g��,t	j
t��|jdd|j�WdQRXWdQRXdS)Nr,z--restrict-to-repositoryr�z--encryption=repokeyz..)rr�r8r�rr�rbr�r�r)r*r9)r�r+rSrSrU�'test_remote_repo_restrict_to_repositorybsz>RemoteArchiverTestCase.test_remote_repo_restrict_to_repositoryzonly works locallycCsdS)NrS)r�rSrSrUr�ksz4RemoteArchiverTestCase.test_debug_put_get_delete_objcCsdS)NrS)r�rSrSrUr�osz"RemoteArchiverTestCase.test_configc"Cs\|jdd|j�|jddd�|jddd�|jdd	d�|jd
dd�|jdd
d�|jd|jdd�d}td���|jdd|jddd�}||ks�t�|jd��*|jdd|jddd�}||ks�t�WdQRX|jd��,|jdd|jddd�}||k�st�WdQRX|jd��,|jdd|jddd�}||k�sDt�WdQRXWdQRXdS)Nr�z--encryption=repokeyzdir/filestest file contents 1)r�z	dir/file2stest file contents 2z
skipped-file1stest file contents 3z
skipped-file2stest file contents 4z
skipped-file3stest file contents 5r�z::testrNz)cached responses left in RemoteRepositoryr^r�z--debugz--strip-componentsr~r8rr�zinput/dir/filer�)rr�r�r?r�r�)r�Zmarker�resrSrSrU�!test_strip_components_doesnt_leakss(
z8RemoteArchiverTestCase.test_strip_components_doesnt_leakcCs<|jdd}|jd|ddd�}|jd|�|jd|�d	S)
z.https://github.com/borgbackup/borg/issues/6014z-this-repository-does-not-existz::testrrT)rjrLzthis-repository-does-not-existz$this-repository-does-not-exist::testN)r�rrr�)r�r�r^rSrSrU�4test_do_not_mention_archive_if_you_can_not_find_repo�szKRemoteArchiverTestCase.test_do_not_mention_archive_if_you_can_not_find_repoN)
rrr	r�r�r-r.r�r.r�r�r0r1rSrSrSrUr+Gs	r+csFeZdZ�fdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Z�Z	S)�ArchiverCorruptionTestCasecsFt�j�|j�|jdd|j�tj|jd|jd��dd|_dS)Nr�z--encryption=repokeyrz--jsonr�r�)r�r�rrr�rrr�)r�)r�rSrUr��s
z ArchiverCorruptionTestCase.setUpr;cCs\t|d��H}|j|tj�tdd�|j|�D��}|j|tj�|j|�WdQRXdS)Nzr+bcss|]}d|VqdS)�NrS)r��crSrSrUr��sz5ArchiverCorruptionTestCase.corrupt.<locals>.<genexpr>)r�r]rh�SEEK_END�bytesr5r�)r�r8Zamountr�Z	corruptedrSrSrU�corrupt�s
z"ArchiverCorruptionTestCase.corruptc
Csd|jtjj|jd��|jr<|jd|jdd�}d|ks`t�n$t	j
t��|jd|j�WdQRXdS)Nr�rr)rjzfailed integrity check)r7rbr�r�r�r�rr�r�r)r*r$)r�r�rSrSrU�test_cache_chunks�sz,ArchiverCorruptionTestCase.test_cache_chunkscCsN|jd|jdd�|jtjj|jd��|jd|jdd�}d|ksJt�dS)Nr�z::testrNr�z::test1zfiles cache is corrupted)rr�r7rbr�r�r�r�)r�r�rSrSrU�test_cache_files�sz+ArchiverCorruptionTestCase.test_cache_filescCs<|jd|jdd�|jd|jd�j�}|jd|jdd�|jdd|j�|jd	|jd
�tjj|jd�}ttj|��dks�t	�|j
tjj||d
��tjj|jd�}tdd�}|j|�|j
ddttd���t|d��}|j|�WdQRX|jdd|jdddd�}d|k�st	�d|k�s*t	�d|k�s8t	�dS)Nr�z::test1rNrlz--format={id}{LF}z::test2rrz--cache-onlyrz--jsonzchunks.archive.drz.compactrS)rRr�r�� rTz-vz::test3r;)rjz,Reading cached archive chunk index for test1z0Cached archive chunk index of test1 is corruptedz-Fetching and building archive index for test1)rr�r�rbr�r�r�r�r�r�r7rr5rUr-r6r�r�)r�Z	target_idZchunks_archive�config_pathrSr�r�rSrSrU�test_chunks_archive�s$

z.ArchiverCorruptionTestCase.test_chunks_archivec
Csxtjj|jd�}tdd�}|j|�|jddttd���t	|d��}|j
|�WdQRX|jd|j�}d|kstt
�dS)	NrS)rRr�r�r:rTrzHCache integrity data not available: old Borg version modified the cache.)rbr�r�r�rr5rUr-r6r�r�rr�r�)r�r;rSr�r�rSrSrU�test_old_version_interfered�s

z6ArchiverCorruptionTestCase.test_old_version_interfered)r;)
rrr	r�r7r8r9r<r=r�rSrS)r�rUr2�s

r2c@seZdZdd�Zdd�ZdS)�DiffArchiverTestCasecCs�|j�|jdd|j�|jddd�|jddd�|jdd	d�|jd
dd�tjd�tjdtjd
B�tjd�t	�r�tjd�tj
dd�tj
dd�tj
dd�tj
dd�tj
dd�t�r�tjdd�tjdd�tjdd�tjdd�|jd|jdd �|jd!d"d�|jd#d$d�tj
d�|jd
d%d&d'�tj
d�tj
d�tjd�|jd(d)d�tjdtjd
B�tjd*�tjd�t	��r�tjd�tj
d*d�tj
d�tj
d*d�tj
d*d+�tj
d�|jd,d-d�tj
d�t��rtj
d�tjd.d/�tdd0��}|jd1�WdQRX|jd|jd2d �|jdd3d4|jd5d �d6d7�}d8d9�}||jd:|jdd;�d<�||jd:|jdd=d>d?�d@�||jd:|jdd;dA�d<�dS)BNr�z--encryption=repokeyZfile_unchanged�)r�Zfile_removed�Z
file_removed2i�
file_replacedizinput/dir_replaced_with_filei�zinput/dir_removedzinput/dir_replaced_with_linkzinput/link_changedzinput/file_unchangedzinput/link_removedzinput/file_removed2zinput/link_target_removedzinput/emptyz"input/link_target_contents_changedzinput/link_replaced_by_filezinput/file_replacedzinput/hardlink_target_replacedzinput/hardlink_contents_changedzinput/file_removedzinput/hardlink_removedzinput/hardlink_target_removedr�z::test0rNZ
file_addediZfile_empty_addedrri)r�Zdir_replaced_with_filei zinput/dir_addedzinput/link_addedZlink_replaced_by_filei@zinput/file_addedzinput/hardlink_addedZabs
appended_dataz::test1az--chunker-paramsz
16,18,17,4095z::test1bcSs�|rdndjd�}d|kst�dj|�|ks0t�d|ks<t�dtjkrRd|ksRt�d	|ks^t�d
|ksjt�t�r�d|ks|t�d|ks�t�d
|ks�t�d|ks�t�d|ks�t�d|ks�t�|r�dndjd�}dj|�|ks�t�t�r�dj|�|ks�t�t��r
d|k�s
t�d|k�st�t��r.d|k�s.t�d|k�s<t�d|k�sJt�t��r`d|k�s`t�t��rvd|k�svt�t��r�d|k�s�t�dS)N�Bz{:<19}�modifiedrAz{} input/file_replacedzinput/file_unchangedrz7[drwxr-xr-x -> -rwxr-xr-x] input/dir_replaced_with_filez#added directory     input/dir_addedz%removed directory   input/dir_removedz&changed link        input/link_changedz$added link          input/link_addedz&removed link        input/link_removedz] input/dir_replaced_with_linkz] input/link_replaced_by_filezinput/link_target_removedz0 Bz{} input/emptyz"{} input/hardlink_contents_changedz"input/link_target_contents_changedz$added       2.05 kB input/file_addedz(added       2.05 kB input/hardlink_addedz*added           0 B input/file_empty_addedz&removed       256 B input/file_removedz*removed       256 B input/hardlink_removedzinput/hardlink_target_removedzinput/hardlink_target_replaced)�formatr�rbr�rBrC)r^�can_compare_idsZchangerSrSrU�
do_assertss@
zADiffArchiverTestCase.test_basic_functionality.<locals>.do_assertscSs�dd�}dd�|jd�D�}|r,dddd	�nd
di}||d|�ksFt�t|d|��sZt�d
tjkr~dddd�|d|�ks~t�d
di|d|�ks�t�d
di|d|�ks�t�t��rFd
di|d|�ks�t�d
di|d|�ks�t�d
di|d|�ks�t�tdd�|d|�D���st�td d�|d!|�D���s0t�t|d"|���sFt�|�rXdd#d$d	�nd
di}||d%|�k�stt�t��r�||d&|�k�s�t�t��r�t|d'|���s�t�d(d)d*�|d+|�k�s�t�t��r�d(d)d*�|d,|�k�s�t�d(d$d*�|d-|�k�st�d.d/d*�|d0|�k�st�t��r@d.d/d*�|d1|�k�s@t�t��r^t|d2|���s^t�t��r|t|d3|���s|t�dS)4Ncs0�fdd�|D�}t|�dks"t�dd�|D�S)Ncs g|]}|d�kr|d�qS)r�ZchangesrS)r�r�)r�rSrUr]szoDiffArchiverTestCase.test_basic_functionality.<locals>.do_json_asserts.<locals>.get_changes.<locals>.<listcomp>rcSsg|]}|D]}|�qqSrSrS)r�Zchgset�chgrSrSrUr`s)r�r�)r�r�ZchgsetsrS)r�rU�get_changes\sz[DiffArchiverTestCase.test_basic_functionality.<locals>.do_json_asserts.<locals>.get_changescSsg|]}|rtj|��qSrS)rr)r�r�rSrSrUrcszZDiffArchiverTestCase.test_basic_functionality.<locals>.do_json_asserts.<locals>.<listcomp>rrCii)rR�added�removedrRzinput/file_replacedzinput/file_unchangedrr�z
drwxr-xr-xz
-rwxr-xr-x)rR�old_mode�new_modezinput/dir_replaced_with_filezadded directoryzinput/dir_addedzremoved directoryzinput/dir_removedzchanged linkzinput/link_changedz
added linkzinput/link_addedzremoved linkzinput/link_removedcss(|] }|ddko|djd�VqdS)rRr�rL�lN)r)r�rGrSrSrUr�|szYDiffArchiverTestCase.test_basic_functionality.<locals>.do_json_asserts.<locals>.<genexpr>zinput/dir_replaced_with_linkcss(|] }|ddko|djd�VqdS)rRr�rKrMN)r)r�rGrSrSrUr�~szinput/link_replaced_by_filezinput/link_target_removed�
rzinput/emptyzinput/hardlink_contents_changedz"input/link_target_contents_changedrIi)rRr�zinput/file_addedzinput/hardlink_addedzinput/file_empty_addedrJr@zinput/file_removedzinput/hardlink_removedzinput/hardlink_target_removedzinput/hardlink_target_replaced)r r�r�rbr�rBrC)r^rErHZjoutputrrSrSrU�do_json_asserts[sH

zFDiffArchiverTestCase.test_basic_functionality.<locals>.do_json_assertsrZtest1aTZtest1br;)rjFz--json-lines)rrr�r�rbr�r�r��S_IFDIRrBr�rCr�r��rmdir�S_IFREGr�r�)r�r�rFrOrSrSrUr�sl













BMz-DiffArchiverTestCase.test_basic_functionalitycCs|jdd|j�|jddd�|jddd�|jdd	d�|jd
dd�|jd|jd
d�tjd�tjd�tjd�tjd�|jddd�|jd
dd�|jddd�|jddd�|jd|jdd�|jdd|jd
d�}ddddd
dg}tdd�t||j��D���st�dS)Nr�z--encryption=repokeyZa_file_removed�)r�Zf_file_removed�Zc_file_changedr:Ze_file_changedr�r�z::test0rNzinput/a_file_removedzinput/f_file_removedzinput/c_file_changedzinput/e_file_changediiZb_file_addedr?Zd_file_addedr@z::test1rz--sortr;css|]\}}||kVqdS)NrS)r��xr�rSrSrUr��sz8DiffArchiverTestCase.test_sort_option.<locals>.<genexpr>)	rr�r�rbr�r��zipr�r�)r�r^rrSrSrU�test_sort_option�s.



z%DiffArchiverTestCase.test_sort_optionN)rrr	rrWrSrSrSrUr>�sRr>cCs<t�}|jddddgd�}|j|jks*t�|jddgks<t�|jdksJt�|jd	ksXt�|jddd
dgd�}|jdd
gks~t�|jddddgd�}|jddgks�t�|jddd
dgd�}|jdd
gks�t�|jddd
dgd�}|jdd
gks�t�|jddddgd�}|j|jk�st�|jddgd�}|j|jk�s8t�dS)NrpZservez--restrict-to-path=/p1z--restrict-to-path=/p2zborg serve --info --umask=0027z/p1z/p2�rz--restrict-to-repository=/r1z--restrict-to-repository=/r2z/r1z/r2zborg serve --restrict-to-path=/z%borg serve --restrict-to-repository=/z-borg serve --restrict-to-repository=/r1/belowz borg init --encryption=repokey /z-BORG_HOSTNAME_IS_UNIQUE=yes borg serve --info)	rZget_args�funcZdo_server�Zrestrict_to_paths�umask�	log_levelZrestrict_to_repositories)rKrTrSrSrU�
test_get_args�s2
r\cCspdd�}|dddgdddd	d
g�s&t�|dgddg�s<t�|dd
gddg�sTt�|ddgddg�slt�dS)NcSsTdd�|D�}dd�|D�}tjt|�t|��}tjt|�t|��}||ksPt�|S)NcSsg|]}|�qSrSrS)r�r�rSrSrUr�sz<test_compare_chunk_contents.<locals>.ccc.<locals>.<listcomp>cSsg|]}|�qSrSrS)r�r�rSrSrUr�s)rZcompare_chunk_contents�iterr�)rrZchunks_aZchunks_bZcompare1Zcompare2rSrSrU�ccc�sz(test_compare_chunk_contents.<locals>.cccs1234s567AsbC�1s23s4567Ar��Cs12345s56s65s565)r�)r^rSrSrU�test_compare_chunk_contents�srac@s0eZdZedd��Zdd�Zdd�Zdd�Zd	S)
�TestBuildFiltercCsdS)NrS)r�ZmatchedrSrSrU�peek_and_store_hardlink_masterssz/TestBuildFilter.peek_and_store_hardlink_masterscCsft�}|jtd�gtj�tj||jd�}|tdd��s<t	�|tdd��sNt	�|tdd��sbt	�dS)NZincludedr)r�z
included/filezsomething else)
r3r�r4r2ZIncluder�build_filterrcr5r�)r��matcherrrSrSrU�
test_basicszTestBuildFilter.test_basiccCs0tdd�}tj||jd�}|tdd��s,t�dS)NT)�fallbackrZanything)r�)r3rrdrcr5r�)r�rerrSrSrU�
test_empty#s
zTestBuildFilter.test_emptycCsltdd�}tj||jdd�}|tdd��s0t�|tdd��sDt�|tdd��sVt�|td	d��sht�dS)
NT)rgr;)Zstrip_componentsZshallow)r�zshallow/zdeep enough/filezsomething/dir/file)r3rrdrcr5r�)r�rerrSrSrUr�(s
z%TestBuildFilter.test_strip_componentsN)rrr	�staticmethodrcrfrhr�rSrSrSrUrbsrbc@s�eZdZedd��Zejdd��Zejdd��Zejdd��Z	ejd	d
��Z
ejdd��Zd
d�Zej
jdd�ej
jdd �dd���ZdS)!�TestCommonOptionscCsv|ddddd�|dddd	d
dd�|d
ddd	ddd�|dddddgd�|dddddd�|ddtdddd�dS)Nz-hz--helpr{zshow this help message and exit)�actionr{z
--criticalr[r�store_const�critical�warning)�destr{rk�constr�z--error�errorz--appendrZTOPIC)ror{rk�metavarr�z-pz
--progress�progress�
store_true)rorkr{z--lock-wait�	lock_wait�Nr;z(default: %(default)d).)rorRrrr�r{)rI)Zadd_common_optionrSrSrU�define_common_options2sz'TestCommonOptions.define_common_optionscCs&tjdddd�}tj|jdd�|_|S)	Nr
ztest parserF)�prog�description�add_help�_level0�_level1)Zsuffix_precedence)r{r|)�argparse�ArgumentParserrZ
CommonOptionsrw�common_options)r��parserrSrSrU�basic_parser?s
zTestCommonOptions.basic_parsercCs|jddd�S)Nzrequired argumentsz	<command>)�titlerr)Zadd_subparsers)r�r�rSrSrU�
subparsersFszTestCommonOptions.subparserscCs|jj|ddd�|S)Nr{T)Zprovide_defaults)r�add_common_group)r�r�rSrSrUr�JszTestCommonOptions.parsercCs tjddd�}|jj|d�|S)NFr
)rzrxr|)r}r~rr�)r�r��
common_parserrSrSrUr�OszTestCommonOptions.common_parserc	sH|jd|gddddtjd�}|jdd�|jd	d
dd��fd
d�}|S)N�
subcommandFrr�baz)�parentsrzry�epilogr{Zformatter_classi�)rYz
--append-onlyr�rt)rorkcs&t|��j|�}�jj|�t|�S)N)r�rkrZresolve�vars)r�rT)r�rSrU�parse_vars_from_line]s
zDTestCommonOptions.parse_vars_from_line.<locals>.parse_vars_from_line)Z
add_parserr}ZRawDescriptionHelpFormatterZset_defaults�add_argument)r�r�r�r�Z	subparserr�rS)r�rUr�Us
z&TestCommonOptions.parse_vars_from_linecCs�|d�gdddd�kst�|ddd�gddddd	d
�ks<t�tjt��|dd�WdQRX|dd
ddd
d�dddgddddd	d
�ks�t�dS)Nz--errorr;rqF)rrur[rsr�z
--criticalrmi�)rrur[rsr�rYz
--append-onlyz--append=fooz--appendrr�rrn)r�r)r*r`)r�r�rSrSrU�test_simplees*
zTestCommonOptions.test_simple�positionr�r��bothzflag,args_key,args_value�-prsT�
--lock-wait=3rurbcCs`g}|d
kr|j|�|jd�|dkr2|j|�gdddddd	�}|||<||�|ks\t�dS)Nr�r�r�r�r;rnFi�)rrur[rsr�rY)r�r�)r�r�)rr�)r�r�r��flagZargs_keyZ
args_valuer�rrSrSrU�test_flag_position_independence�s


z1TestCommonOptions.test_flag_position_independenceN)r�r�r��r�rsT�r�rurb)r�r�)rrr	rirwr)�fixturer�r�r�r�r�r�r��parametrizer�rSrSrSrUrj1s
rjc	Cs4td�dkst�tjtj��td�WdQRXdS)NZ50M�2i�rZ5Mi@Bi��)rr�r)r*r}ZArgumentTypeErrorrSrSrSrU�test_parse_storage_quota�sr�csFtdd�j�}tdd�j�}i�d��fdd�	��d|td|i��S)	z0
    Return dict mapping command to parser.
    rp)rxZborgfsNcs�i}xJ|jD]@}|jdk	rdt|j�krx"|jj�D]\}}||||<q4WqW|dk	rb|j|�|rp|rpdSx0t|j��D] \}}�|d||�|�|<q~WdS)NZSubParsersActionrL)Z_actions�choicesrZr�r�updater!)r�r�rZ
extra_choicesr�rkr�command)�discover_level�parsersrSrUr��s

z'get_all_parsers.<locals>.discover_levelrQ)N)rZbuild_parser)r�Z
borgfs_parserrS)r�r�rU�get_all_parsers�sr�zcommand, parsercCst|jt�r|jjst�dS)N)rYr�r0Zrstr�)r�r�rSrSrU�test_help_formatting�sr�ztopic, helptextcCstt|��st�dS)N)rZr1r�)Ztopic�helptextrSrSrU�test_help_formatting_helptexts�sr�)�r}r�rhrr�rbr[r�rur-r�r]rWr�rr�r�ZbinasciirrZconfigparserrrrrZhashlibrr	r
Z
unittest.mockrr)r��ImportErrorrpZborg.helpersrQr
rrr�rrrrrKrrrr�rrZ	constantsZcrypto.low_levelrrZ
crypto.keyrrrrr r!Zcrypto.keymanagerr"r#Zcrypto.file_integrityr$r%r&r'r(r)r*r+r,r-r.r/Znanorstr0r1r�r2r3r4r�r5Zlockingr6Zloggerr7Zremoter8r9r�r:r<r=r>r?r@rArBrCrDrErFrGZupgraderrHrIr�r�r�r��__file__r�rsrzZ	BORG_EXES�FileNotFoundErrorr�rr�r�r�r�r�r�r�r
r�r�r�rr$r+r2r>r\rarbrjr�r�r�rlrr�r�r�rSrSrSrU�<module>s� 1	 &?
0+tL@JJs(!k