HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/borg/testsuite/__pycache__/upgrader.cpython-39.opt-1.pyc
a

HZ�h��@sddlZddlZddlZddlTddlmZddlmZmZddl	m
Z
ddlmZdd	l
mZej�ej�e�d
�Zdd�Zd
d�Zdd�Zdd�Ze��dd��Zejddgd�dd��Zdd�Ze��dd��Zdd�Zejje�d d!�d"d#��Z ejje�d d!�d$d%��Z!dS)&�N�)�*)�
KeyfileKey)�AtticRepositoryUpgrader�AtticKeyfileKey)�get_keys_dir)�
Repository�)�are_hardlinks_supportedzattic.tar.gzcsX�fdd�}t�|d��"}|j|||�d�Wd�n1s@0Ytj�|��S)zo
    extract <tarfname> tar archive to <path>, all stuff starting with <what>.

    return path to <what>.
    c3s |D]}|j���r|VqdS�N)�name�
startswith)�members�tarinfo��what��=/usr/lib64/python3.9/site-packages/borg/testsuite/upgrader.py�filesszuntar.<locals>.files�r)rN)�tarfile�open�
extractall�os�path�join)ZtarfnamerrrZtfrrr�untars0rcCs>tt|�ddd��}|��Wd�S1s00YdS)z�
    utility function to check if borg can open a repository

    :param path: the path to the repository
    :returns: if borg can check the repository
    TF)Z	exclusive�createN)r�str�check)r�
repositoryrrr�
repo_valid$sr!cCsTtj�t�tj�|��}t|�� }|���tj	�Wd�S1sF0YdS)z�
    check that the new keyfile is alright

    :param path: the path to the key file
    :returns: if the file starts with the borg magic string
    N)
rrrr�basenamer�readr
rZFILE_ID)r�keyfile�frrr�	key_valid0s


�
r&cCsttt|�d�S)z�
    create an attic repo with some stuff in it

    :param dir: path to the repository to be created
    :returns: path to attic repository
    �repo)r�	ATTIC_TARr)�dirrrr�make_attic_repo=sr*cCst|�Sr)r*)�tmpdirrrr�
attic_repoHsr,TF)�paramscCs|jSr)Zparam)Zrequestrrr�inplaceMsr.cCs�|}t�tj��t|�Wd�n1s.0Yt|dd�}|�$dd�|j��D�}Wd�n1sr0Y|j|d|d�|j	dd�dS)atest segment conversion

    this will load the given attic repository, list all the segments
    then convert them one at a time. we need to close the repo before
    conversion otherwise we have errors from borg

    :param attic_repo: a populated attic repository (fixture)
    NF�rcSsg|]\}}|�qSrr)�.0�i�filenamerrr�
<listcomp>`�z)test_convert_segments.<locals>.<listcomp>��dryrunr.�r6)
�pytest�raisesr�AtticRepositoryr!r�ioZsegment_iteratorZconvert_segmentsZ
convert_cache)r,r.�	repo_pathr �segmentsrrr�test_convert_segmentsRs	&2r>cCsBttt|�d�}|�d|�|�d|�|�dd�tj�|d�S)z�
    create an attic key file from the given repo, in the keys
    subdirectory of the given tmpdir

    :param tmpdir: a temporary directory (a builtin fixture)
    :returns: path to key file
    �keysZATTIC_KEYS_DIRZ
BORG_KEYS_DIRZATTIC_PASSPHRASE�testr')rr(rZsetenvrrr)r+ZmonkeypatchZkeys_dirrrr�attic_key_filefs
	rAcCsL|}t|dd��(}t�|�}tj|dd�Wd�n1s>0YdS)autest key conversion

    test that we can convert the given key to a properly formatted
    borg key. assumes that the ATTIC_KEYS_DIR and BORG_KEYS_DIR have
    been properly populated by the attic_key_file fixture.

    :param attic_repo: path to an attic repository (fixture defined above)
    :param attic_key_file: path to an attic key file (fixture defined above)
    Fr/r7N)rrZ
find_key_fileZconvert_keyfiles)r,rAZkeyfile_pathr r$rrr�	test_keys~s


,rBzhardlinks not supported)�reasoncs�|}t�tj��t|�Wd�n1s.0Ydd���fdd�}||�}t|dd��8}t�t�|j	d|d�}|r�n
d	tj
vr�Wd�n1s�0YdS)
a[test all conversion steps

    this runs everything. mostly redundant test, since everything is
    done above. yet we expect a NotImplementedError because we do not
    convert caches yet.

    :param attic_repo: path to an attic repository (fixture defined above)
    :param attic_key_file: path to an attic key file (fixture defined above)
    NcSst�tj�|ddd��S)N�data�0)r�statrr�rrrr�stat_segment�sz&test_convert_all.<locals>.stat_segmentcs
�|�jSr)�st_inorG�rHrr�first_inode�sz%test_convert_all.<locals>.first_inodeFr/r5ZBORG_TESTS_IGNORE_MODES)r8r9rr:r!rr�umaskZ
UMASK_DEFAULTZupgrade�environ)r,rAr.r<rKZ
orig_inoder ZbackuprrJr�test_convert_all�s&

rNcCs�t|�d��}t|d��}|�d�Wd�n1s80Yt|�d��}t�||�tj|dd|d�|stnt|d	��}Wd�n1s�0YdS)
abtest that we handle hard links properly

    that is, if we are in "inplace" mode, hardlinks should *not*
    change (ie. we write to the file directly, so we do not rewrite the
    whole file, and we do not re-create the file).

    if we are *not* in inplace mode, then the inode should change, as
    we are supposed to leave the original inode alone.�a�wbsaXXXN�b�a�b)r.�rb)rrr�writer�linkrZheader_replace)r+r.rO�tmprQrrr�
test_hardlink�s
(rX)"rrr8Z	constantsZ
crypto.keyrZupgraderrrZhelpersrr r�r
rr�dirname�__file__r(rr!r&r*Zfixturer,r.r>rArBZmarkZskipifrNrXrrrr�<module>s2




)