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

�ie\�@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|��\}}|d	d
|t|��\}}tt|���|dd
|�\}}WdQRX|dd
|d�\}}|d	d
|t|��\}}dS)
N�reporNr^Z	test_file�content�initz--encryption=nonez%s�createz%s::archive�extractzdoes/not/match)�mkdir�join�writerZr?)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|d�}tjj|d�}tjj|d�}�x�td	�D�]x}tj|dd
�tj|dd
�||ddd
d�|d|�\}}|tkr�t	d||�z�d\}	}
x�|	�rn|
d7}
y||dd�Wn4t
k
�r}z|jtjkr�P�WYdd}~XnXz6|dd||
f|�\}}|tk}	|	�s:t	d||�Wdtjtjj|d�dd
�tj
tjj|d��Xq�WWdtj|dd
�X|d|�\}}|tk�r�t	d||�|dd|�\}}|tkrRt	d||�qRWWdQRXdS)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�r�r�rur�r*�print�OSError�errnoZENOSPC�remove)rr��mountr�rNr��jr�r��successr��errrSrSrU�test_disk_full�sL


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	Csjtjj|j|�}tjjtjj|��s6tjtjj|��t|d�� }|dkrRd|}|j|�WdQRXdS)Nr��X)	rbr�r�r��exists�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�	�hardlinkZ	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�}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>r)
rbr�r�r�r�r�r�rr��split)r��path_a�path_b�hl_a�hl_b�archive_list�pathsrSrSrU�test_create_duplicate_root�s

z+ArchiverTestCase.test_create_duplicate_rootcCsdtjj|jdd�}tjj|d�}|j|}tjtj��|j	dd|�WdQRX|j	ddd|�dS)NZparent1Zparent2r�r�z--encryption=nonez--make-parent-dirs)
rbr�r�r�r��pytest�raisesr:ZParentPathDoesNotExistr)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�WdQRXdS)Nr�z--encryption=repokeyzunix-socketz&unix sockets disabled or not supportedz(permission denied to create unix socketsr�z::testrNr^r�)rr��socketZAF_UNIXZSOCK_STREAMZbindrbr�r�r�r�r�ZEPERMr%�skip�EACCES�closer?)r�Zsockr�rSrSrU�test_unix_socket�s
z!ArchiverTestCase.test_unix_socketzsymlinks not supportedcCsV|j�|jdd|j�|jd|jdd�td��|jd|jd�WdQRXdS)Nr�z--encryption=repokeyr�z::testrNr^r�)rrr�r?)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
�}|r�ndS)NcSsntj|�j}y(ttj|t���}|j�WdQRXWntk
rHdSXtj|�j}ttk}|oh||kSdS)NF)rbr��st_atime_nsr�r�readr�r)�	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/file1)r7r8)rrb�utimerr�r?r�)r�r6�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�}dS)N��k8�Cm8��n8zinput/file1r�z--encryption=repokeyr�z::testrNr^r�zoutput/input/file1)r@rArB)rrbr9rr�r?r�)r��	birthtimer;r:r=r>rSrSrU�test_birthtimes



zArchiverTestCase.test_birthtimecCs�|j�d\}}}tjd||f�tjd||f�|jdd|j�|jdd|jd	d
�td��|jd|jd	�WdQRXtjd�}tjd
�}dS)N��k8�Cm8��n8zinput/file1r�z--encryption=repokeyr�z
--nobirthtimez::testrNr^r�zoutput/input/file1)rErFrG)rrbr9rr�r?r�)r�rCr;r:r=r>rSrSrU�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�rI�w)rr0rbr�r��setr-r�r�r:r�rI)r�r�rIrKr�r�rSrSrU�_set_repository_idCs
z#ArchiverTestCase._set_repository_idc	Cs\dd�}tjj|jd�}d}ddt>}|t|�|}t|d��:}|j|d�|j|�|j|d�|j	�}|j
|�WdQRX||||�}|�rX|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|�WdQRXdS)NcSs�tj|�}d}|r0t|d�r0|jd|jkr0d}|r�ttd�r�ttd�r�t|d��P}y0|jdtj�dkrld}|jdtj�|kr�d}Wnt	k
r�d}YnXWdQRX|S)	NT�	st_blocksiF�	SEEK_HOLE�	SEEK_DATA�rbr)
rbr��hasattrrO�st_sizer��seekrPrQr�)r��
total_size�	hole_size�st�sparser�rSrSrU�	is_sparseMs
z4ArchiverTestCase.test_sparse_file.<locals>.is_sparserYsfoobarr
r;r�r�z--encryption=repokeyr�z::testrNr�z--sparsezoutput/inputrR�)rbr�r�r�Z
CHUNK_MAX_EXP�lenr�rUr��tell�truncaterr�r?r�rr�r0)	r�rZr�r�rWrVr��posZsparse_supportrSrSrU�test_sparse_fileLs0
 z!ArchiverTestCase.test_sparse_filecCs�dddg}x2|D]*}tjj|j|�}t|d��WdQRXqW|jdd|j�|jd|jdd	�x>|D]6}td
��$|jd|jdtjjd	|��WdQRXqhWdS)NZnormalzwith some blanksz
(with_parens)r�r�z--encryption=repokeyr�z::testrNr^r�)rbr�r�r�r�rr�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�rNr�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�_unencryptedrcr�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)
Nrcr�r�z--encryption=repokeyr�z::testrNz--encryption=none�deletez--cache-onlyz::test.2)rj)rrbr�rr�rr�rur�rNr�r�r,r%r&rrd)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=nonerfrcr�z--encryption=repokeyrgr�z_encrypted::testrNrkz--cache-onlyz_encrypted::test.2)rj)rrr�rbr�rur�r�rhr�r,r%r&rri)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�rkz--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
�}WdQRX|jd|jd�tj|j
�|jd|jd�tj|�|jd|jd�xd
D]}q�WdS)Nr�z--encryption=repokeyZ_new�yes)Z BORG_RELOCATED_REPO_ACCESS_IS_OKr�location�key-type�manifest-timestamp)rqrrrs)rr�r&rbrhr�r@r�r�r�r0rur�r�)r�Zsecurity_dirr�rqr3rSrSrU�test_repository_move�s


z%ArchiverTestCase.test_repository_movec
CsP|jdd|j�ttjj|j�d�d��}|jd�WdQRX|jd|j�dS)Nr�z--encryption=repokeyrqrLzsomething 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)rjrp)Z*BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK)
rr�rur�r�r&r�r,r%r&rrnr@)r�rSrSrU�test_unknown_unencrypted�sz)ArchiverTestCase.test_unknown_unencryptedc!Cs�|jdd|j�|jd�|jd|jdd�td���|jd|jdd	d
�|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�3r3�2�1zinput/dir/file�0)rr�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	|��WdQRXWdQRX|j|jd|df|���t	|��WdQRXWdQRX|j|jd|f|���t	|��WdQRXWdQRXdS)	N�
mountpoint�darwinz-oz$ignore_permissions,defer_permissionsZignore_permissionsz::testz--strip-components=2z
input/dir1)
r~rbr�r�r�rWr�
fuse_mountr�r?)r�rZignore_permsrSrSrU�test_fuse_mount_hardlinks1s




z*ArchiverTestCase.test_fuse_mount_hardlinkscCs2|j�td��|jd|jd�WdQRXdS)Nr^r�z::test)r~r?rr�)r�rSrSrU�test_extract_hardlinks1Ss
z(ArchiverTestCase.test_extract_hardlinks1cCs^|j�td��|jd|jddd�WdQRXtd��|jd|jdd�WdQRXdS)Nr^r�z::testz--strip-componentsrxz
input/dir1)r~r?rr�)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	�WdQRXdS)
Nrrr�s123456)r�r�z--encryption=noner�z::testrNr^r�)
rbr�r�r�r�r�r�rr�r?)r�rrr 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��sortedrb�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=repokeyr3ir�)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_outputcCs^|jdd|j�|jdd
d�|jd|jdd	�td
��|jd|jdd�}WdQRXdS)Nr�z--encryption=repokeyr3ir�)r�r�z::testrNr^r�z
--progressi@)rr�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_cachescCsb|jdd|j�d}|jd|jdd|d�tj|jdd	|jd��}|jd
d|jddd
�}dS)Nr�z--encryption=repokeysfoo

bar
   
r�z::test�-)rNrlz--json-linesr�z--stdoutT)rO)rr�rr)r�Z
input_data�itemZextracted_datarSrSrU�test_create_stdin2sz"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|�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/bi@i@)
rbr�r�r�r�r�r�rr�r�r?r�r)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
}|jdd|j�|jdd|jdd�|jd|j�|jd|j�dS)Nr�z--encryption=repokeyrkz--cache-onlyr�z--no-cache-syncz::testrNz--jsonz--errorrr��statsz::test2r�)rrr�rr)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��2tj	td
|��|jd|jd
�WdQRXWdQRXdS)Ncs"tj|dddd��|||�dS)Nzsecurity.capabilityF)�follow_symlinks)r
r�)r�Zuid�gid)�fchownrSrU�patched_fchown'szBArchiverTestCase.test_extract_capabilities.<locals>.patched_fchowns r3z
input/filezsecurity.capabilityr�z--encryption=repokeyr�z::testrNr^r�r�)
rbr�r�r
r�rr�r?r�object)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!Csdd�}dd�}dd�}|jd�tjdd	d
�|jd|jd�|jd
|jdd�td���tjjd�}t	j
td|��|jd|jdtd�}WdQRXtj|�t	j
td|��|jd|jdtd�}WdQRXtj|�t	j
td|��|jd|jdtd�}WdQRXWdQRXdS)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_EACCESr3z
input/filezuser.attribute�valuer�z-enoner�z::testrNr^r�r�)rj)
r�r
r�rr�r?rbr��abspathrr�r+r�)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-runrhztest.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_renamecCsh|jdd
d�|jdd|j�|jd|jdd	�|jd
|j�}|jd
|jd�}|jd
dd|j�}dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrz--firstryi@)r�rr�)r��	info_repo�info_archiverSrSrU�	test_info�szArchiverTestCase.test_infocs�|jddd�|jdd|j�|jd|jdd	�tj|jd
d|j��}|d}|d
}|d�tj|jd
d|jd��}|d}|d}dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrz--jsonr�r�r�r�ri@)r�rr�rr)r�r�r�r�r�r�r�rS)r�rU�test_info_json�szArchiverTestCase.test_info_jsoncCsD|jdd|j�tj|jddd|j��}tj|jddd|j��}dS)z2See https://github.com/borgbackup/borg/issues/6120r�z--encryption=repokeyrz--jsonz	--first=1z--last=1N)rr�rr)r�r�rSrSrU�test_info_json_of_empty_archive�sz0ArchiverTestCase.test_info_json_of_empty_archivecCs�|jddd�|jdd|j�|jd|jdd	�|jdd
d|jdd	�|jdd
d
|jdd	�|jdd
d|jdd	�|jd|jdd
d�|jd|jdd
d�|jd|jdd
d�|jd|jdd�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::test1rNz	--commentzthis is the commentz::test2z"deleted" commentz::test3zpreserved commentz::test4r�z
added commentzmodified commentrQZ12345i@)r�rr�)r�rSrSrU�test_comment�szArchiverTestCase.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-runrkz--prefixZanother_z--lastryz--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�dS)Nr�ir�)r�r�z--encryption=repokeyr�z::test1rNz::test2z::test3rk�test2r�z	--dry-runZtest3i@)r�rr�)r�rSrSrU�test_delete_multiple�sz%ArchiverTestCase.test_delete_multiplecCs�|jddd�|jddd�|jdd|j�|jd|jd	d
�|jd|jdd
�dtjd
<|jd|jdd�dtjd
<|jd|j�|jtjj|j��dS)Nr�ir�)r�z
dir2/file2r�z--encryption=repokeyr�z::testrNz::test.2�nor�rkr)rjr�i@i@)	r�rr�rbr�ZassertFalser�r�r�)r�rSrSrU�test_delete_repos

z!ArchiverTestCase.test_delete_repocCs�|jdd|j�|jd�t|jdd��`}tj|tj�\}}t|||d�}x0|j	�D]$}|j
jd�rT|j|j
dj�PqTW|j�WdQRX|jdd	|jd
�}|jd|�|jdd
|j�|jd|j�}|jd|�dS)Nr�z--encryption=noner
T)r�ztestsuite/archiver.pyr;rkz--forcez::testzdeleted archive was corruptedr�z--repairrl���)rr�r�r:r�r'r�r�r�
iter_itemsr��endswithrk�chunksrI�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 chunkrkz--forcez::testr�z--repairrl)rr�r�r:r�r'r�r�r�metadata�items�putr�r�)r�r�r�rIr�rIr^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�rzT)�reverser;zr+br�sXXXXz--info)rj)rr�r�rr�r�rbr�r�r�r�r�rUr�)r�r^r�r�rSrSrU�test_corrupted_repository0s
&
z*ArchiverTestCase.test_corrupted_repositorycCs�|jdd|j�|jd�|j|j��n|jrD|jdd|jtd�n:tjt	t
jf��}|jdd|j�WdQRXt|j
t
j�r~|jdd|jd�WdQRXdS)Nr�z--encryption=repokeyr
r�z
--verify-data)rjz
--bypass-lock)rr�r��	read_onlyr�r�r,r%r&r6r8�RPCErrorrYr�)r��excinforSrSrU�test_readonly_check?s
z$ArchiverTestCase.test_readonly_checkcCs�|jdd|j�|jd�|jd�|j|j��z|jrR|jdd|jdtd�n>tjt	t
jf��}|jdd|jd�WdQRXt|j
t
j�r�|jdd|jdd�WdQRXdS)	Nr�z--encryption=repokeyrr�diffz%s::a)rjz
--bypass-lock)rr�r�r�r�r�r,r%r&r6r8r�rYr�)r�r�rSrSrU�test_readonly_diffNs

z#ArchiverTestCase.test_readonly_diffcCs�|jdd|j�|jd�|j|j��z|jrH|jdd|jdtd�n>tjt	t
jf��}|jdd|jd�WdQRXt|j
t
j�r�|jdd|jdd�WdQRXdS)	Nr�z--encryption=repokeyr
z
export-tarz%s::testztest.tar)rjz
--bypass-lock)rr�r�r�r�r�r,r%r&r6r8r�rYr�)r�r�rSrSrU�test_readonly_export_tar^s
z)ArchiverTestCase.test_readonly_export_tarcCs�|jdd|j�|jd�|j|j��t|jrF|jdd|jtd�n<tjt	t
jf��}|jdd|j�WdQRXt|j
t
j�r�|jdd|jd�WdQRXdS)Nr�z--encryption=repokeyr
r�z%s::test)rjz
--bypass-lock)rr�r�r�r�r�r,r%r&r6r8r�rYr�)r�r�rSrSrU�test_readonly_extractms
z&ArchiverTestCase.test_readonly_extractcCs�|jdd|j�|jd�|j|j��h|jrB|jd|jtd�n8tjt	t
jf��}|jd|j�WdQRXt|j
t
j�rz|jd|jd�WdQRXdS)Nr�z--encryption=repokeyr
r)rjz
--bypass-lock)rr�r�r�r�r�r,r%r&r6r8r�rYr�)r�r�rSrSrU�test_readonly_info|s
z#ArchiverTestCase.test_readonly_infocCs�|jdd|j�|jd�|j|j��h|jrB|jd|jtd�n8tjt	t
jf��}|jd|j�WdQRXt|j
t
j�rz|jd|jd�WdQRXdS)Nr�z--encryption=repokeyr
rl)rjz
--bypass-lock)rr�r�r�r�r�r,r%r&r6r8r�rYr�)r�r�rSrSrU�test_readonly_list�s
z#ArchiverTestCase.test_readonly_listcCs�|jdd|j�|jd�|j|j���|jrL|j|jtd��WdQRXnFtj	t
tjf��"}|j|jdd��WdQRXWdQRXt
|jtj�r�|j|jdd��WdQRXWdQRXdS)Nr�z--encryption=repokeyr
)rjF)rLz
--bypass-lock)rr�r�r�r�r�r�r,r%r&r6r8r�rYr�)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��moderSrSrU�
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�rKr�r�)r�Z	operationr�r�rIrSrSrU�add_unknown_feature�s
z$ArchiverTestCase.add_unknown_featurec	Cs<|jr|j|dti�n tjt��}|j|�WdQRXdS)Nrj)r�rr,r%r&r()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�r�r'�	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=repokeyrkz--cache-onlyr�z::testrN)rr�r�r'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�r�r'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�r�r'r�r�r?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::testrNrh�other)r�rr�r�r'r�r�r�)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::testrNrk�prunez--keep-daily=3)r�rr�r�r'r�ZDELETEr�)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::testrNrr�)rr�r�r'r�r�rbr�r�r�r�r�)r�rrSrSrU�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
�nFd�tj���fdd
�}tjtd|��|jd|jd	d
�WdQRXt|jdd��B}|�rt|j�|_tj	|tj
�\}}t|||��}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_txnrMZcache_configZmandatory_featuresr�r�rrrr�)r��path_prefixr�r�rIr�rrS)rrrU�'test_unknown_mandatory_feature_in_caches2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�r9r/�st_mtime_nsr)r�r^rXrSrSrU�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^rXrSrSrU�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_excludedcCsF|jddd�|jdd|j�tj|jdd|jd	d
��}|d}dS)
Nr�ir�)r�r�z--encryption=repokeyr�z--jsonz::testrNr�i@)r�rr�rr)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_topicalcCsRtjdtjj|jd��|jdd|j�|jd}|jdd|d�|jd	|�}dS)
Nzsomewhere does not existr�r�z--encryption=repokeyz::testr�z--read-specialrNrl)rbr�r�r�r�rr�)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.checkpointrz--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::test2rz--listz	--dry-runz--keep-daily=2zKeeping archive: test2zWould prune:     test1rlrr�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:00rz--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-barrz--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�rr�ZassertNotEqual)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�r�r)r�r!r"r#rSrSrU�test_list_repository_format3sz,ArchiverTestCase.test_list_repository_formatcCs\|jddd�|jdddd�|jdd	|j�|jd
}|jd|d�|jd
dd|�}dS)N�
empty_filer)r�Zamb�ai@B)r�r�z--encryption=repokeyz::testr�rNrlz--formatz{sha256} {path}{NL})r�rr�)r�r r^rSrSrU�test_list_hashBs
zArchiverTestCase.test_list_hashcCs�|jddd�|jd�ttjj|jd�d��"}|jdd�|jdd�WdQRX|jd	d
|j�|jd}|jd|d
�|jddd|�}dS)Nr&r)r�Z
two_chunksr�sabbai��sbaabr�z--encryption=repokeyz::testr�rNrlz--formatz'{num_chunks} {unique_chunks} {path}{NL})	r�r�rbr�r�r�r�rr�)r�r�r r^rSrSrU�test_list_chunk_countsLs

z'ArchiverTestCase.test_list_chunk_countscCsl|jddd�|jdd|j�|jd}|jddd	|d
�|jddd
|�}|jd�djd�\}}}}}dS)NZcompressible_filei')r�r�z--encryption=repokeyz::testr�z-C�lz4rNrlz--formatz*{size} {csize} {dsize} {dcsize} {path}{NL}rr;� )r�rr�r)r�r r^r��csizeZdsizeZdcsizer�rSrSrU�test_list_sizeYs
zArchiverTestCase.test_list_sizecCs�|jddd�|jdd|j�|jd|jdd	�tj|jd
d|j��}|d}|d
d}|jd
d|jd�}dd�|j�D�}|d}|jd
dd|jd�}dd�|j�D�}|d}dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrlz--jsonr�r�rz--json-linescSsg|]}tj|��qSrS)rr)r��srSrSrUrssz3ArchiverTestCase.test_list_json.<locals>.<listcomp>r;z--format={sha256}cSsg|]}tj|��qSrS)rr)r�r.rSrSrUr{si@)r�rr�rrr�)r�Z	list_repor�Zarchive0Zlist_archiver�r�rSrSrU�test_list_jsones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_argscCsr|j�|jdd|j�|jdd|jdddd�}i}x&|j�D]}tj|�}|||d	<q@W|d
}|d}dS)Nr�z--encryption=repokeyr�z
--log-jsonz::testrNz--listz--debug�type�file_status�log_message)rrr�r�rr)r��logZmessagesr��msgr2r3rSrSrU�
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_profilecCs2|j�|jdd|j�|jdd|jdd�}dS)Nr�z--encryption=repokeyz--debugr�z::testrN)rrr�)r�r4rSrSrU�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�r3)r�r�z--encryption=nonez::testr�z-CrNrlz--formatz{size} {csize} {path}{NL}rr;r+)rbr�r�rr�r�int)	r�Zcompression�compressibler�r�r�r^r,r�rSrSrU�
_get_sizes�s


zArchiverTestCase._get_sizescCs|jddd�\}}dS)N�noneT)r=)r>)r�r�r,rSrSrU�"test_compression_none_compressible�sz3ArchiverTestCase.test_compression_none_compressiblecCs|jddd�\}}dS)Nr?F)r=)r>)r�r�r,rSrSrU�$test_compression_none_uncompressible�sz5ArchiverTestCase.test_compression_none_uncompressiblecCs|jddd�\}}dS)N�zlibT)r=)r>)r�r�r,rSrSrU�"test_compression_zlib_compressible�sz3ArchiverTestCase.test_compression_zlib_compressiblecCs|jddd�\}}dS)NrBF)r=)r>)r�r�r,rSrSrU�$test_compression_zlib_uncompressible�sz5ArchiverTestCase.test_compression_zlib_uncompressiblecCs|jddd�\}}dS)Nr*T)r=)r>)r�r�r,rSrSrU�!test_compression_lz4_compressible�sz2ArchiverTestCase.test_compression_lz4_compressiblecCs|jddd�\}}dS)Nr*F)r=)r>)r�r�r,rSrSrU�#test_compression_lz4_uncompressible�sz4ArchiverTestCase.test_compression_lz4_uncompressiblecCs|jddd�\}}dS)N�lzmaT)r=)r>)r�r�r,rSrSrU�"test_compression_lzma_compressible�sz3ArchiverTestCase.test_compression_lzma_compressiblecCs|jddd�\}}dS)NrGF)r=)r>)r�r�r,rSrSrU�$test_compression_lzma_uncompressible�sz5ArchiverTestCase.test_compression_lzma_uncompressiblecCs`|jddd�\}}|jd|j�|jddd�\}}|jd|j�|jddd�\}}t||�}dS)Nz	auto,zlibT)r=rkrBr*)r>rr��min)r�Z	auto_sizeZ
auto_csizeZ	zlib_sizeZ
zlib_csizeZlz4_sizeZ	lz4_csizeZsmallest_csizerSrSrU�"test_compression_auto_compressible�s
z3ArchiverTestCase.test_compression_auto_compressiblecCs|jddd�\}}dS)Nz	auto,zlibF)r=)r>)r�r�r,rSrSrU�$test_compression_auto_uncompressible�sz5ArchiverTestCase.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_usagecCsdS)NrS)r�rSrSrU�	test_help	szArchiverTestCase.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|�}|�r8t
��r@t|d��}t|d��}	WdQRXWdQRXt
��r�d}tjj|d	d�}tj|�}
tj|�}t��r�d}tjj|d	d�}tj|dd�}tj|dd�}
t��r�tjj|d	d�}tj|�}
yhd}tjj|d	d�}tj�r&tj|j��r&n6ytj|d�Wn$tk
�rZ}zWYdd}~XnXWnDtk
�r�}z&tjjd��r�|jtjk�r�n�WYdd}~XnXWdQRXdS)NcSs\tj|�j}ytjtj|t��Wntk
r6dSXtj|�j}ttk}|oV||kSdS)NF)rbr�r/r,r�rr�r)r1r2r4r5rSrSrUr6
	sz/ArchiverTestCase.test_fuse.<locals>.has_noatimer�z--encryption=repokeyzinput/file1r�z--exclude-nodumpz	::archiverNz
::archive2r�rr�T)�ignore_bsdflags�
ignore_xattrs�archive2r�rRzinput/hardlinkr�zinput/link1r�F)r�r�zinput/fusexattrr�zuser.foo�freebsd)rT)rr�rr<rbr�r�r�r�r�rr�r�rCr�rBrDr
r�r��getxattrr�rWrrr�r�)r�r6r<rZin_fnZout_fnZsti1Zsto1Zin_fZout_fZsti2Zsto2r=r>rrr�rSrSrU�	test_fuse	sh






zArchiverTestCase.test_fusecsV|jdd|j�|jddd�t�rJ|jddd�tjdd	�tjdd
�|jd|jdd
�|jddd�|jd|jdd
�tjj|jd�}|j	|j|dd��\tjj|d
d��tj
��}t�r�tjj|d
dd�}tjj|d
dd�}tjj|d
dd�}WdQRX|j	|j|dddd��2t��rHtjj|d
dd�}tjj|d
dd�}WdQRXdS)Nr�z--encryption=repokeyr
sfirst)r�Z	hardlink1s123456zinput/hardlink1zinput/hardlink2zinput/hardlink3r�z
::archive1rNssecondz
::archive2rz-oZversionszhardlink1.00001Z	hardlink2zhardlink2.00001Z	hardlink3zhardlink3.00001z-e)rr�r�rCrbr�r�r�r�r�r�)r�r�filesZhl1Zhl2Zhl3rS)r�rU�test_fuse_versions_viewn	s.

z(ArchiverTestCase.test_fuse_versions_viewc Cs|jdd|j�|jd�|jd�\}}|�Fx6|j�D]*}|jjd�r8|j|jdj	�|j}Pq8W|j
�WdQRX|jdd|jdd	�tjj|j
d
�}|j|jd|��.tjt��}ttjj||��WdQRXWdQRX|j|jd|dd
��ttjj||��j�WdQRXdS)Nr�z--encryption=repokeyr�ztestsuite/archiver.pyr;r�z--repairr)rjrz	::archivez-oZallow_damaged_filesr�)rr�r�r�r�r�r�rkr�rIr�rbr�r�r�r%r&r�r�r,)r�r�r�r�r�rr�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	��WdQRX|j|j|d
d	��WdQRX|j|j|d��WdQRX|j|j|d��WdQRX|j|j|d
��WdQRX|j|j|d��WdQRXdS)Nr�z--encryption=repokeyZarch11Zarch12Zarch21Zarch22rz	--first=2z--sort=namez--last=2z--prefix=arch1z--prefix=arch2z
--prefix=archz
--prefix=nope)rr�r�rbr�r�r�r�)r�rrSrSrU�test_fuse_mount_options�	s$








z(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�rI�_r��hashZ
num_blocks�nonceZcounter)�seenr��usedrSrU�verify_uniqueness�	s

zIArchiverTestCase.verify_aes_counter_uniqueness.<locals>.verify_uniquenessrcr�r�z
--encryption=r�z::testrNz::test.2rk)rMrrbr�rr�)r��methodrdrS)rbr�rcrU�verify_aes_counter_uniqueness�	s

z.ArchiverTestCase.verify_aes_counter_uniquenesscCs|jd�dS)N�keyfile)rf)r�rSrSrU�#test_aes_counter_uniqueness_keyfile�	sz4ArchiverTestCase.test_aes_counter_uniqueness_keyfilecCs|jd�dS)N�repokey)rf)r�rSrSrU�&test_aes_counter_uniqueness_passphrase�	sz7ArchiverTestCase.test_aes_counter_uniqueness_passphrasecCsf|j�|jdd|j�|jd|jdd�td��|jdd|jd�}WdQRXttjd��}dS)	Nr�z--encryption=repokeyr�z::testrNr^r7zdump-archive-items)rrr�r?r�rbr�)r�r^�
output_dirrSrSrU�test_debug_dump_archive_items�	s
z.ArchiverTestCase.test_debug_dump_archive_itemscCsb|j�|jdd|j�|jd|jdd�td��|jdd|j�}WdQRXttjd��}dS)	Nr�z--encryption=repokeyr�z::testrNr^r7zdump-repo-objs)rrr�r?r�rbr�)r�r^rkrSrSrU�test_debug_dump_repo_objs�	s
z*ArchiverTestCase.test_debug_dump_repo_objscCs�|jdd|j�d}t|�j�}|jd|d�|jdd|jd�}|jdd	|j|d
�}td
d��}|j�}WdQRX|jdd|j|�}|jdd|j|�}|jdd|jd
�}dS)Nr�z--encryption=repokeys	some datar3)r�r7zput-objz
input/filezget-objzoutput/filerRz
delete-objZinvalid)rr�rZ	hexdigestr�r�r0)r�r�Zhexkeyr^r�Z	data_readrSrSrU�test_debug_put_get_delete_obj�	sz.ArchiverTestCase.test_debug_put_get_delete_objc
Cs:dd�}tjtd|��|jdd|jdd�WdQRXdS)NcWst�dS)N)�EOFError)rTrSrSrU�	raise_eof
sz7ArchiverTestCase.test_init_interrupt.<locals>.raise_eofr�r�z--encryption=repokeyr;)rj)rr�rrr�)r�rprSrSrU�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�}WdQRXWdQRXdS)
z�BORG_KEY_FILE=something borg init should quit if "something" already exists.

        See https://github.com/borgbackup/borg/pull/6046rg)Z
BORG_KEY_FILEr�z--encryption=keyfilerzNryrjr)rbr�r�r�r@rr�r�r0r�r%r&rpr�Error)r�rgr3�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}WdQRXWdQRXt	�}x2|j
�D]&\}\}	}
}||\}}
}|j|�q�Wx|j
�D]\}\}	}
}q�WdS)Nr�F)�sync)rr�r�r'r�r�rr�ZdestroyrMr]r^)r�r�r�rIr�Zoriginal_chunksZcorrect_chunksrbrIZrefcountr�r,Z
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)ryr)rr�r�r'r�r�rr	r�Zincrefrlr]r�r%r&�AssertionErrorrz)r�r�r�rIr�rSrSrU�test_check_cacheB
s
z!ArchiverTestCase.test_check_cachecCs(|jdd|j�|jd|jddd�}dS)Nr�z--encryption=repokeyr�z
--target=asdfr)rj)rr�)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�}|jd}|jdd
|�}dS)Nr�z--encryption=repokeyz::test0r�rNrlr�z
input/dir2z-ezinput/dir2/file3z--target=new-archivez
::new-archivez--short)rrr�rz)r�r�Zoriginal_archiver��listingrSrSrU�test_recreate_targetS
s

z%ArchiverTestCase.test_recreate_targetcCsj|j�|jddd�|jdd|j�|jd}|jd|d	�|jd
|ddd
�|j�|jdd|�}dS)Nz
dir2/file3ir�)r�r�z--encryption=repokeyz::test0r�rNr�z
input/dir2z-ezinput/dir2/file3rlz--shorti@)rr�rr�rz)r�r�r~rSrSrU�test_recreate_basicg
s
z$ArchiverTestCase.test_recreate_basiccCs�|j�|jd|jdd�|jd|jdd�|j�td��|jd|jd�WdQRXtd��|jd|jd�WdQRXdS)	Nr�z::test2rNr�z::testz
input/dir1r^r�)r~rr�rzr?)r�rSrSrU�test_recreate_subtree_hardlinkst
s


z0ArchiverTestCase.test_recreate_subtree_hardlinksc
Cs�ttjj|jd�d��"}|jdd�|jdd�WdQRX|jdd|j�|jdd	d
|jdd�|jd|jd
dd�|jd|jdddd�}tt	|j
d��\}}|jd|jd	d�|j�dS)NZ
large_filer�r'i�br�z--encryption=repokeyr�z--chunker-paramsz	7,9,8,128z::test1rNz::test2z--files-cache=disabledrlzinput/large_filez--formatz{num_chunks} {unique_chunks}r+r��default)r�rbr�r�r�r�rr��mapr<rrz)r�r�rlZ
num_chunksZ
unique_chunksrSrSrU�test_recreate_rechunkify�
sz)ArchiverTestCase.test_recreate_rechunkifycCs�|jddd�|jdd|j�|jd|jddd	d
�|jd|jddd
d�}|jd�\}}}|jd|jd	dd�|j�|jd|jddd
d�}|jd�\}}}dS)Nr=i')r�r�z--encryption=repokeyr�z::testrNz-Cr?rlzinput/compressiblez--formatz{size} {csize} {sha256}r+r�r*z--recompress)r�rr�rrz)r�Z	file_listr�r,Z
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��dS)Nrr�z--encryption=repokeyz::test0r�rNr�z--timestampz1970-01-02T00:00:00z	--commentr
ri�r;rz%Y-%m-%d)r�nowrrZ
astimezoneZtzinforrr�r�Z	utcoffset�strftime)r�Zlocal_timezoner�rZdtimerS)Zs_timerU�test_recreate_timestamp�
s

z(ArchiverTestCase.test_recreate_timestampcCsv|jddd�|jdd|j�|jd|jdd�|jd	|jd�}|jd
|jddd
�|j�|jd	|jd�}dS)Nr=i')r�r�z--encryption=repokeyr�z::testrNrlr�z-nz-ezinput/compressible)r�rr�rz)r�Zarchives_beforeZarchives_afterrSrSrU�test_recreate_dry_run�
sz&ArchiverTestCase.test_recreate_dry_runcCst|jddd�|jdd|j�|jd|jdd	�|jd
|jd�}|jd|jdd
�|j�|jd
|jd�}dS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNrr�z--chunker-paramsr�i@)r�rr�rz)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�rzrr�)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::testrNrkz--firstryz--lastTr)rLrj)rr�)r�rSrSrU�test_bad_filters�
sz!ArchiverTestCase.test_bad_filterscCs�|jd}|jd|jdd�|j|j�}|jdd|j|�t|d��}|j�}WdQRX|jdtj	|j�d	}t|d��}|j�}WdQRXtj
|�|jdd
|j|�t|d��}|j�}WdQRXdS)Nz	/exportedr�z--encryptionrgrI�export�r�/r�import)r�rr�rr�r�r0r�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	Cs|jd}|jd|jdd�|j|j�}|jdd|j|�t|d��}|j�}WdQRXt|j��}t|�}|j	dt
j��WdQRXtt
jj��}|j	|t
j��t|j��}|jd�WdQRX|jdd	|j|�t|j��}t|�}|j	dt
j��WdQRXdS)
Nz	/exportedr�z--encryptionrirIr�r�rJr�)r�rr�rr�r�r0r:rr�rZenv_passphraserrIZTestKeyZMockRepositoryZsave_key)	r�r�r�r�r�r�Zrepo_keyZ
backup_keyZ	repo_key2rSrSrU�test_key_export_repokeys$
z(ArchiverTestCase.test_key_export_repokeyc	Csb|jd}|jd|jdd�|j|j�}|jddd|j|�t|dd	d
��}|j�}WdQRXdS)Nz/exported.htmlr�z--encryptionrirIr�z	--qr-htmlr�zutf-8)rR)r�rr�rr�r�r0)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--encryptionrirIr�)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--encryptionrgrIr�)rjrLzsomething 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�}WdQRXdS)N�@e294423506da4e1ea76e8dcdf1a3919624ae3ae496fddf905610c351d3f09239z	/exportedr�z--encryptionrgr�rrLr+rsabcdefghijklmnopqrsturIr�z--paperr�)r�rr�rNr�rr�rbr�r�r�r�FILE_IDrrfr0)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--encryptionrgr�rrLr+rsabcdefghijklmnopqrstus�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�rNr�rr�rbr�r�r�rr�rrf)r�r�r�r�Ztyped_inputrSrSrU�test_key_import_paperkeytsz)ArchiverTestCase.test_key_import_paperkeyc	Csr|jddd�|jdd|j�|jd|jdd	�|jd
}|jdd|j|�}t|d
��}tj|�}WdQRXdS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNz/dumpr7z
dump-manifestr�i@)r�rr�r�r�rr�)r��	dump_filer^r�rrSrSrU�test_debug_dump_manifest�s
z)ArchiverTestCase.test_debug_dump_manifestc	Csv|jddd�|jdd|j�|jd|jdd	�|jd
}|jdd|jd|�}t|d
��}tj|�}WdQRXdS)Nr�ir�)r�r�z--encryption=repokeyr�z::testrNz/dumpr7zdump-archiver�i@)r�rr�r�r�rr�)r�r�r^r�rrSrSrU�test_debug_dump_archive�s
z(ArchiverTestCase.test_debug_dump_archivecCs�|jdd|j�|jdd|jdd�j�}tj|jdd|jd	d
��}|dd}|jdd|j|�j�}|jdd|jd
d�j�}dS)Nr�z--encryption=repokeyr7zrefcount-objrz�@r�z--jsonz::testrNr�rIZ124Zxyza)rr��striprr)r�r^r��
archive_idrSrSrU�test_debug_refcount_obj�sz(ArchiverTestCase.test_debug_refcount_objcCs|jdd�}dS)Nr7r)r)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_crudcCs0|j�tjd�|jdd|j�|jdd|j�}|jd|�|jd|�|jd|�|jd	|�|jd
|�|jd|�|jd|�xhdD]`\}}|jd|j|�}|jd|j||�|jd|j|�}|jdd|j|�|jd|j|dd�q�W|jddd|jdd�|jd|jdd�|jd|jddd�dS)Nzinput/flagfiler�z--encryption=repokeyrKz--listz[repository]�versionZsegments_per_dirZ
storage_quota�append_only�additional_free_spacerI�2G�repository.append_onlyryz--deleter;)rjrzinvalid-option�r�r��r�ry)r�r�)rrbr�rr�r)r�r^Zcfg_keyZ	cfg_valuerSrSrU�test_config�s,
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)rQrR�	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�}t	d��t
jd
dddg�WdQRX|jdddddd�dS)Nr�zgzip is not installedzinput/flagfiler�z--encryption=repokeyr�z::testrNz
export-tarz
simple.tar.gzz--listr^rtr�z../simple.tar.gzz--warning=no-timestampzoutput/inputT)rQrRr�)
rurvr%r*rrbr�rr�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�}t	d
��t
jddddg�WdQRX|jdddddd�dS)Nr�zgzip is not installedzinput/flagfiler�z--encryption=repokeyr�z::testrNz
export-tarz
simple.tarz--strip-components=1z--listr^rtr�z
../simple.tarz--warning=no-timestampzoutput/T)rQrRr�)
rurvr%r*rrbr�rr�r?r]r�r)r�rlrSrSrU� test_export_tar_strip_componentss



z1ArchiverTestCase.test_export_tar_strip_componentscCsH|j�|jd|jddd�td��tjdddd	g�WdQRXdS)
Nz
export-tarz::testz
output.tarz--strip-components=2r^rtr�z
../output.tarz--warning=no-timestamp)r~rr�r?r]r�)r�rSrSrU�&test_export_tar_strip_components_links s

z7ArchiverTestCase.test_export_tar_strip_components_linkscCsH|j�|jd|jddd�td��tjdddd	g�WdQRXdS)
Nz
export-tarz::testz
output.tarz
input/dir1r^rtr�z
../output.tarz--warning=no-timestamp)r~rr�r?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��}qzWdS)Nr�z::testr�r�rhZnewnamerlrkrrrIr�Zexportedr�zchange-passphrasez
break-lockTr)rLrj)rHr�r�r)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_EACCESr3s
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�}|jd|j�}|jd
|jd�}|jd|jd�}t	d��|jd
|jd�WdQRX|j
dd�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::testrNrarrlr^r�Nzoutput/input)r�rr�rbr�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_deletedcCsd|jddd�|jdd|j�|jd|jdd�tjj|jd	�}tj|�|jd|jd
d�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::testrNraz::test2N)r�rr�rbr�r�r�r�)r�rarSrSrU�%test_recovery_from_deleted_repo_nonce�s
z6ArchiverTestCase.test_recovery_from_deleted_repo_nonceN)r;)�rrrr%�mark�skipifrCZrequires_hardlinksr&rr$r(r-rBr.rEr?rFrDrHrrNr`rbrerjrlrmrortrurvr|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�r�r�r�r�r�r�r�r�r�r�rbr�r�r�r�r�r�r�r�r�rrrZallow_cache_wiperr
rrrrrrrrrrrrrrr$r%r(r)r-r/r0r6r9r:r>r@rArCrDrErFrHrIrKrLrMrNrOrPrVrXrYrZrfrhrjrlrmrnrqrrrsrxrzr|r}rr�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 


 


-  rzno 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�rSrSrUrq�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*�superrV)r�)�	__class__rSrUrV�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)rrrr�r�r�r*r(rqr�r�rr�rVr�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�archive1rS)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=1rSz--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#rSr�r�Zarchive3z-vz$Healed previously missing file chunkzAtestsuite/archiver.py: Completely healed previously damaged file!r�)r�rS)r�rS)r�r�r�r�r�rkrIZfailr�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�rkr�r�r�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�rkrIr�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--repairrrS)r�rkr'�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--repairrrS)	r�r�r'r�r�r�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--repairrrS)
r�r�r'r�r�rIr�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.1rS)
r�rIr�r'r�r�Zpack_and_authenticate_metadata�id_hash�encryptr�rr�r)	r�r�r�rIr�r�Z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:r�r�)r�r�rSrSrU�test_extra_chunksp
sz'ArchiverCheckTestCase.test_extra_chunkscGs�tj|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�}|jdd
d	|jdd�}dS)Nr�r�ztestsuite/archiver.pyr;s1234r�r)rjz
--verify-dataz--repairr�)rur�r�rr�r�r�r�r�r�r�r�rIr�r�)r�Z	init_argsr�r�r�r�r�r^rSrSrU�_test_verify_data{
s 

z'ArchiverCheckTestCase._test_verify_datacCs|jdd�dS)Nz--encryptionri)r�)r�rSrSrU�test_verify_data�
sz&ArchiverCheckTestCase.test_verify_datacCs|jdd�dS)Nz--encryptionr?)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�rlrkr�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)rrrr�rSrSrSrU�Attic013Item�
sr�r�z0.13T)r�r�r�r)rjrlz::0.13)r�r'r�r�rrZitems_bufferr^Zsaverr�)r�r�r�r�r�rIr�rSrSrU�test_attic013_acl_bug�
sz+ArchiverCheckTestCase.test_attic013_acl_bug)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�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�rK�	timestamp)r'r�r�r�r�r�r/�packbr�utcnowrr��
ISO_FORMATr�)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�r�r�r�r/r�rr�rr�r�r�r%r&r )r�r�r�rIrSrSrU�test_fresh_init_tam_required�
s"z7ManifestAuthenticationTest.test_fresh_init_tam_requiredcCs4|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�}|jd
d|j�|jdd	|j�}|j|�tjt��|jd|j�WdQRX|jd
dd|j�|jd|j�dS)
Nr�z--encryption=repokey�archive1234T)r�Fstamrlz--debug�upgradez--tamz--force)rr�r�r:r�rur�r&r-rIr'r�r�Ztam_requiredZchange_passphraseZ_passphraser/ZunpackbZdecryptr�r�r�r�r�r�r�r%r&r )r�r�r_rIr�r^rSrSrU�test_not_required�
s(

z,ManifestAuthenticationTest.test_not_requiredcCsF|jdd|j�|jd�|jdd|j�t|jdd�}|j|�dS)Nr�z--encryption=repokeyr�r�z
--disable-tamT)r�)rr�r�r:r�r�)r�r�rSrSrU�test_disable�
s

z'ManifestAuthenticationTest.test_disablecCsF|jdd|j�|jd�t|jdd�}|j|�|jdd|j�dS)Nr�z--encryption=repokeyr�T)r�r�z
--disable-tam)rr�r�r:r�r�)r�r�rSrSrU�
test_disable2�
s

z(ManifestAuthenticationTest.test_disable2N)rrrr�r�r�r�r�rSrSrSrUr��
s
 r�c@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�r�r�r�r�r)r'r�r�r/r�rr�r�r�r�r�r�r�r�r�r�)r�r�r�r�rIZarchive_datar�rSrSrU�write_archive_without_tam	s
z3ArchiveAuthenticationTest.write_archive_without_tamcCsx|jdd|j�|jd�t|jdd�}|�|j|d�WdQRX|jdd|j�}|jd	d
|j�|jdd|j�}dS)Nr�z--encryption=repokey�archive_tamT)r��archive_no_tamrlz--format="{name} tam:{tam}{NL}"r�z--archives-tam)rr�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�}dS)Nr�z--encryption=repokeyr�T)r�r�r�z--repairrlz--format="{name} tam:{tam}{NL}")
rr�r�r:r�r�rkr'r�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�}|jd
d|j�|jdd	|j�}|jdd|j�}dS)Nr�z--encryption=repokeyr�rlz--format="{name} {id}{NL}"T)r�r�z--format="{name} tam:{tam}{NL}"r�z--repair)rr�r�r:r�r�)r�Zarchive_id_pre_checkr�r^Zarchive_id_post_checkrSrSrU�test_check_rebuild_refcounts5s
z6ArchiveAuthenticationTest.test_check_rebuild_refcountsN)rrrr�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�rSrSrUrnksz4RemoteArchiverTestCase.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�}|jd��|jdd|jddd�}WdQRX|jd��|jdd|jddd�}WdQRX|jd��|jdd|jddd�}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-componentsrwr3rxryzinput/dir/filerz)rr�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)
rrrr�r�r�rr�r*rnr�rrrSrSrSrUr�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�rUrh�SEEK_END�bytesr0r�)r�r3Zamountr�Z	corruptedrSrSrU�corrupt�s
z"ArchiverCorruptionTestCase.corruptc
CsX|jtjj|jd��|jr0|jd|jdd�}n$tj	t
��|jd|j�WdQRXdS)Nr�rr)rj)r	rbr�r�r�r�rr�r%r&r$)r�r�rSrSrU�test_cache_chunks�sz,ArchiverCorruptionTestCase.test_cache_chunkscCsB|jd|jdd�|jtjj|jd��|jd|jdd�}dS)Nr�z::testrNrWz::test1)rr�r	rbr�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�}|jtjj||d��tjj|jd
�}tdd�}|j	|�|j
ddttd���t
|d��}|j|�WdQRX|jdd|jdddd�}dS)Nr�z::test1rNrlz--format={id}{LF}z::test2rkz--cache-onlyrz--jsonzchunks.archive.dz.compactrK)rJr�r�� rLz-vz::test3r;)rj)rr�r�rbr�r�r�r	rr0rMr-rr�r�)r�Z	target_idZchunks_archive�config_pathrKr�r�rSrSrU�test_chunks_archive�s

z.ArchiverCorruptionTestCase.test_chunks_archivec
Csltjj|jd�}tdd�}|j|�|jddttd���t	|d��}|j
|�WdQRX|jd|j�}dS)NrK)rJr�r�rrLr)
rbr�r�r�rr0rMr-rr�r�rr�)r�r
rKr�r�rSrSrU�test_old_version_interfered�s

z6ArchiverCorruptionTestCase.test_old_version_interfered)r;)
rrrr�r	r
rrrr�rSrS)r�rUr�s

rc@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_removed2iZ
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_addedrr�i)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�}dtjkrt�r"|r*dndjd�}t�r:t�r@t�rFt�rLt�rRt�rXdS)N�Bz{:<19}�modifiedr�z0 B)�formatrbr�rBrC)r^�can_compare_idsZchangerSrSrU�
do_assertss
	zADiffArchiverTestCase.test_basic_functionality.<locals>.do_assertscSs�dd�}dd�|jd�D�}|r,dddd	�nd
di}dtjkr>t�rD|rTddd
d	�nd
di}t�rbt�rht�rnt�rtt�rzt�r�dS)Ncs �fdd�|D�}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>cSsg|]}|D]}|�qqSrSrS)r�ZchgsetZchgrSrSrUr`srS)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>rrii)r1ZaddedZremovedr1r��
r)rrbr�rBrC)r^rrZjoutputrrSrSrU�do_json_asserts[s
	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�rrrSrSrUr�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}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_addedrZd_file_addedrz::test1r�z--sortr)rr�r�rbr�)r�r^rrSrSrU�test_sort_option�s.



z%DiffArchiverTestCase.test_sort_optionN)rrrrr rSrSrSrUr�sRrcCs�t�}|jddddgd�}|jddddgd�}|jddddgd�}|jddddgd	�}|jddddgd
�}|jddddgd�}|jddgd�}dS)
NrpZservez--restrict-to-path=/p1z--restrict-to-path=/p2zborg serve --info --umask=0027z--restrict-to-repository=/r1z--restrict-to-repository=/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)rKrTrSrSrU�
test_get_args�s 
r!cCsdd�}dS)NcSsHdd�|D�}dd�|D�}tjt|�t|��}tjt|�t|��}|S)NcSsg|]}|�qSrSrS)r�r�rSrSrUr�sz<test_compare_chunk_contents.<locals>.ccc.<locals>.<listcomp>cSsg|]}|�qSrSrS)r�r�rSrSrUr�s)rZcompare_chunk_contents�iter)rrZchunks_aZchunks_bZcompare1Zcompare2rSrSrU�ccc�s
z(test_compare_chunk_contents.<locals>.cccrS)r#rSrSrU�test_compare_chunk_contents�sr$c@s0eZdZedd��Zdd�Zdd�Zdd�Zd	S)
�TestBuildFiltercCsdS)NrS)r�ZmatchedrSrSrU�peek_and_store_hardlink_masterssz/TestBuildFilter.peek_and_store_hardlink_masterscCs.t�}|jtd�gtj�tj||jd�}dS)NZincludedr)r3r^r4r2ZIncluder�build_filterr&)r��matcherrrSrSrU�
test_basicszTestBuildFilter.test_basiccCstdd�}tj||jd�}dS)NT)�fallbackr)r3rr'r&)r�r(rrSrSrU�
test_empty#s
zTestBuildFilter.test_emptycCs tdd�}tj||jdd�}dS)NT)r*r;)Zstrip_components)r3rr'r&)r�r(rrSrSrUr|(s
z%TestBuildFilter.test_strip_componentsN)rrr�staticmethodr&r)r+r|rSrSrSrUr%sr%c@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
--critical�	log_levelr��store_constZcritical�warning)�destr{r.�constr�z--error�errorz--appendrZTOPIC)r2r{r.�metavarr�z-pz
--progress�progress�
store_true)r2r.r{z--lock-wait�	lock_wait�Nr;z(default: %(default)d).)r2r1r5r�r{)r<)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
CommonOptionsr:�common_options)r��parserrSrSrU�basic_parser?s
zTestCommonOptions.basic_parsercCs|jddd�S)Nzrequired argumentsz	<command>)�titler5)Zadd_subparsers)r�rDrSrSrU�
subparsersFszTestCommonOptions.subparserscCs|jj|ddd�|S)Nr>T)Zprovide_defaults)rB�add_common_group)r�rDrSrSrUrCJszTestCommonOptions.parsercCs tjddd�}|jj|d�|S)NFr
)r=r;r?)r@rArBrG)r�rC�
common_parserrSrSrUrHOszTestCommonOptions.common_parserc	sH|jd|gddddtjd�}|jdd�|jd	d
dd��fd
d�}|S)N�
subcommandFr�r�Zbaz)�parentsr=r<�epilogr{Zformatter_classi�)�funcz
--append-onlyr�r7)r2r.cs&t|��j|�}�jj|�t|�S)N)r�rkrBZresolve�vars)r�rT)rCrSrU�parse_vars_from_line]s
zDTestCommonOptions.parse_vars_from_line.<locals>.parse_vars_from_line)Z
add_parserr@ZRawDescriptionHelpFormatterZset_defaults�add_argument)r�rCrFrHZ	subparserrNrS)rCrUrNUs
z&TestCommonOptions.parse_vars_from_linec
Cs$tjt��|dd�WdQRXdS)Nz
--append-onlyrI)r%r&r`)r�rNrSrSrU�test_simpleeszTestCommonOptions.test_simple�positionrurw�bothzflag,args_key,args_value�-pr6T�
--lock-wait=3r8�cCsPg}|d
kr|j|�|jd�|dkr2|j|�gdddddd	�}|||<dS)NrurRrIrwr;r1Fi�)rr8r/r6r�rL)rurR)rwrR)r)r�rNrQ�flagZargs_keyZ
args_valuer�rrSrSrU�test_flag_position_independence�s


z1TestCommonOptions.test_flag_position_independenceN)rurwrR�rSr6T�rTr8rU)rXrY)rrrr,r:r%�fixturerDrFrCrHrNrPr��parametrizerWrSrSrSrUr-1s
r-c	Cs$tjtj��td�WdQRXdS)NZ5M)r%r&r@ZArgumentTypeErrorrrSrSrSrU�test_parse_storage_quota�sr\csFtdd�j�}tdd�j�}i�d��fdd�	��d|td|i��S)	z0
    Return dict mapping command to parser.
    rp)r;ZborgfsNcs�i}xJ|jD]@}|jdk	rdt|j�krx"|jj�D]\}}||||<q4WqW|dk	rb|j|�|rp|rpdSx0t|j��D] \}}�|d||�|�|<q~WdS)NZSubParsersActionr+)Z_actions�choicesrZr�r��updater�)r�rCrZ
extra_choicesr]r.r�command)�discover_level�parsersrSrUr`�s

z'get_all_parsers.<locals>.discover_levelrQ)N)rZbuild_parser)rCZ
borgfs_parserrS)r`rarU�get_all_parsers�srbzcommand, parsercCst|jt�rdS)N)rYrKr0)r_rCrSrSrU�test_help_formatting�srcztopic, helptextcCsdS)NrS)Ztopic�helptextrSrSrU�test_help_formatting_helptexts�sre)�r@r�rhrr�rbr8r�rur)r�r]rWr�r�rer�ZbinasciirrZconfigparserrrrrZhashlibrr	r
Z
unittest.mockrr%Zllfuse�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�FileNotFoundErrorrZrr�r�r�r�r�r�r�rr�r�r�r�r�r�rrr!r$r%r-r\rbr[rlr�rcrdrerSrSrSrU�<module>s� 1	 &?
0+tL@JJs(!k