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__/upgrader.cpython-36.opt-1.pyc
3

y��b��@sddlZddlZddlZddlTddlmZddlmZmZddl	m
Z
ddlmZdd	l
mZejjejje�d
�Zdd�Zd
d�Zdd�Zdd�Zej�dd��Zejddgd�dd��Zdd�Zej�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.gzcsD�fdd�}tj|d��}|j|||�d�WdQRXtjj|��S)zo
    extract <tarfname> tar archive to <path>, all stuff starting with <what>.

    return path to <what>.
    c3s$x|D]}|jj��r|VqWdS)N)�name�
startswith)�membersZtarinfo)�what�� /usr/lib64/python3.6/upgrader.py�filess
zuntar.<locals>.files�r)r
N)�tarfile�openZ
extractall�os�path�join)ZtarfnamerrrZtfr)rr�untarsrc	Cs&tt|�ddd��
}|j�SQRXdS)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�strZcheck)r�
repositoryrrr�
repo_valid$src	Cs>tjjt�tjj|��}t|d��}|j�jtj	�SQRXdS)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
    rN)
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|�S)N)r%)�tmpdirrrr�
attic_repoHsr'TF)ZparamscCs|jS)N)Zparam)Zrequestrrr�inplaceMsr(cCst|}tjtj��t|�WdQRXt|dd�}|�dd�|jj�D�}WdQRX|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>`sz)test_convert_segments.<locals>.<listcomp>)�dryrunr()r-)
�pytest�raisesr�AtticRepositoryrr�ioZsegment_iteratorZconvert_segmentsZ
convert_cache)r'r(�	repo_pathrZsegmentsrrr�test_convert_segmentsRs	r3cCsBttt|�d�}|jd|�|jd|�|jdd�tjj|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_PASSPHRASEZtestr")rr#rZsetenvrrr)r&ZmonkeypatchZkeys_dirrrr�attic_key_filefs
	r5cCs8|}t|dd��}tj|�}tj|dd�WdQRXdS)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)
    F)r)r-N)rrZ
find_key_fileZconvert_keyfiles)r'r5Zkeyfile_pathrrrrr�	test_keys~s


r6zhardlinks not supported)�reasoncs�|}tjtj��t|�WdQRXdd���fdd�}||�}t|dd��.}tjt�|j	d|d�}|rln
d	tj
krvWdQRXdS)
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)
    NcSstjtjj|ddd��S)N�data�0)r�statrr)rrrr�stat_segment�sz&test_convert_all.<locals>.stat_segmentcs
�|�jS)N)�st_ino)r)r;rr�first_inode�sz%test_convert_all.<locals>.first_inodeF)r)r-r(ZBORG_TESTS_IGNORE_MODES)r.r/rr0rrr�umaskZ
UMASK_DEFAULTZupgrade�environ)r'r5r(r2r=Z
orig_inoderZbackupr)r;r�test_convert_all�s


r@cCszt|jd��}t|d��}|jd�WdQRXt|jd��}tj||�tj|dd|d�|s`nt|d	��}WdQRXdS)
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(rAZtmprCrrr�
test_hardlink�s
rI)"rrr.Z	constantsZ
crypto.keyrZupgraderrrZhelpersrrr�r
rr�dirname�__file__r#rrr!r%Zfixturer'r(r3r5r6ZmarkZskipifr@rIrrrr�<module>s(
*