§
    dô  ã                   ó@  — d dl Z d dlZd dlZddlT ddlmZ ddlmZmZ ddl	m
Z
 ddlmZ dd	lmZ e j                             e j                             e¦  «        d
¦  «        Zd„ Zd„ Zd„ Zd„ Z ej        ¦   «         d„ ¦   «         Z ej        ddg¬¦  «        d„ ¦   «         Zd„ Z ej        ¦   «         d„ ¦   «         Zd„ Zej                              e¦   «          d¬¦  «        d„ ¦   «         Z ej                              e¦   «          d¬¦  «        d„ ¦   «         Z!dS )é    Né   )Ú*)Ú
KeyfileKey)ÚAtticRepositoryUpgraderÚAtticKeyfileKey)Úget_keys_dir)Ú
Repositoryé   )Úare_hardlinks_supportedzattic.tar.gzc                 óè   ‡— ˆfd„}t          j        | d¦  «        5 }|                     | ||¦  «        ¬¦  «         ddd¦  «         n# 1 swxY w Y   t          j                             |‰¦  «        S )zo
    extract <tarfname> tar archive to <path>, all stuff starting with <what>.

    return path to <what>.
    c              3   óR   •K  — | D ] }|j                              ‰¦  «        r|V — Œ!d S ©N)ÚnameÚ
startswith)ÚmembersÚtarinfoÚwhats     €ú9/usr/lib/python3/dist-packages/borg/testsuite/upgrader.pyÚfileszuntar.<locals>.files   sB   øè è € Øð 	ð 	ˆGØŒ|×&Ò& tÑ,Ô,ð Ø���øð	ð 	ó    Úr)r   N)ÚtarfileÚopenÚ
extractallÚosÚpathÚjoin)Útarfnamer   r   r   Útfs     `  r   Úuntarr       s¸   ø€ ðð ð ð ð õ
 
Œ�h Ñ	$Ô	$ð /¨Ø
�Š�d E E¨"¡I¤IˆÑ.Ô.Ð.ð/ð /ð /ñ /ô /ð /ð /ð /ð /ð /ð /øøøð /ð /ð /ð /õ Œ7�<Š<˜˜dÑ#Ô#Ð#s   œ!A	Á	AÁAc                 óœ   — t          t          | ¦  «        dd¬¦  «        5 }|                     ¦   «         cddd¦  «         S # 1 swxY w Y   dS )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)Ú	exclusiveÚcreateN)r	   ÚstrÚcheck)r   Ú
repositorys     r   Ú
repo_validr'   $   s�   € õ 
•C˜‘I”I¨°eÐ	<Ñ	<Ô	<ð "À
à×ÒÑ!Ô!ð"ð "ð "ð "ñ "ô "ð "ð "ð "ð "ð "ð "øøøð "ð "ð "ð "ð "ð "s    AÁAÁAc                 óH  — t           j                             t          ¦   «         t           j                             | ¦  «        ¦  «        }t          |¦  «        5 }|                     ¦   «                              t          j	        ¦  «        cddd¦  «         S # 1 swxY w Y   dS )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)
r   r   r   r   Úbasenamer   Úreadr   r   ÚFILE_ID)r   ÚkeyfileÚfs      r   Ú	key_validr.   0   s»   € õ Œg�lŠl�<™>œ>Ýœ7×+Ò+¨DÑ1Ô1ñ3ô 3€Gå	ˆg‰Œð 7˜!Ø�vŠv‰xŒx×"Ò"¥:Ô#5Ñ6Ô6ð7ð 7ð 7ð 7ñ 7ô 7ð 7ð 7ð 7ð 7ð 7ð 7øøøð 7ð 7ð 7ð 7ð 7ð 7s   Á1BÂBÂBc                 óH   — t          t          t          | ¦  «        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$   )Údirs    r   Úmake_attic_repor3   =   s   € õ •�C ™HœH fÑ-Ô-Ð-r   c                 ó    — t          | ¦  «        S r   )r3   )Útmpdirs    r   Ú
attic_repor6   H   s   € å˜6Ñ"Ô"Ð"r   TF)Úparamsc                 ó   — | j         S r   )Úparam)Úrequests    r   Úinplacer;   M   s
   € àŒ=Ðr   c                 ó®  — | }t          j        t          j        ¦  «        5  t	          |¦  «         ddd¦  «         n# 1 swxY w Y   t          |d¬¦  «        }|5  d„ |j                             ¦   «         D ¦   «         }ddd¦  «         n# 1 swxY w Y   |                     |d|¬¦  «         | 	                    d¬¦  «         t	          |¦  «        sJ ‚dS )a  test 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©r#   c                 ó   — g | ]\  }}|‘ŒS © r?   )Ú.0ÚiÚfilenames      r   ú
<listcomp>z)test_convert_segments.<locals>.<listcomp>`   s   € ÐQÐQÐQ¡  H�HÐQÐQÐQr   ©Údryrunr;   ©rE   )
ÚpytestÚraisesr	   ÚAtticRepositoryr'   r   ÚioÚsegment_iteratorÚconvert_segmentsÚconvert_cache)r6   r;   Ú	repo_pathr&   Úsegmentss        r   Útest_convert_segmentsrP   R   sj  € ð €IÝ	Œ•zÔ1Ñ	2Ô	2ð ð Ý�9ÑÔÐðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð å(¨¸5ÐAÑAÔA€JØ	ð Rð RØQÐQ°
´×0NÒ0NÑ0PÔ0PÐQÑQÔQˆðRð Rð Rñ Rô Rð Rð Rð Rð Rð Rð Røøøð Rð Rð Rð Rà×Ò °ÀÐÑHÔHÐHØ×Ò EÐÑ*Ô*Ð*Ý�iÑ Ô Ð Ð Ð Ð Ð s!   ¡=½AÁAÁ$BÂBÂBc                 ó  — t          t          t          | ¦  «        d¦  «        }|                     d|¦  «         |                     d|¦  «         |                     dd¦  «         t          j                             |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
    ÚkeysÚATTIC_KEYS_DIRÚBORG_KEYS_DIRÚATTIC_PASSPHRASEÚtestr0   )r    r1   r$   Úsetenvr   r   r   )r5   ÚmonkeypatchÚkeys_dirs      r   Úattic_key_filerZ   f   sy   € õ •Y¥ F¡¤¨VÑ4Ô4€Hð ×ÒÐ'¨Ñ2Ô2Ð2ð
 ×Ò�¨Ñ1Ô1Ð1Ø×ÒÐ)¨6Ñ2Ô2Ð2åŒ7�<Š<˜ &Ñ)Ô)Ð)r   c                 óô   — |}t          |¦  «        rJ ‚t          | d¬¦  «        5 }t          j        |¦  «        }t          j        |d¬¦  «         ddd¦  «         n# 1 swxY w Y   t          |¦  «        sJ ‚dS )au  test 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=   rF   N)r.   r   r   Úfind_key_fileÚconvert_keyfiles)r6   rZ   Úkeyfile_pathr&   r,   s        r   Ú	test_keysr_   ~   sÔ   € ð "€LÝ˜Ñ&Ô&Ð&Ð&Ð&Ý	  °EÐ	:Ñ	:Ô	:ð H¸jÝ!Ô/°
Ñ;Ô;ˆÝÔ0°ÀÐGÑGÔGÐGðHð Hð Hñ Hô Hð Hð Hð Hð Hð Hð Høøøð Hð Hð Hð Hõ �\Ñ"Ô"Ð"Ð"Ð"Ð"Ð"s   ¥+AÁA Á#A zhardlinks not supported)Úreasonc                 óŠ  ‡— | }t          j        t          j        ¦  «        5  t	          |¦  «         ddd¦  «         n# 1 swxY w Y   d„ Šˆfd„} ||¦  «        }t          |d¬¦  «        5 }t          j        t          ¦  «         | 	                    d|¬¦  «        }|r|�J ‚ ||j
        ¦  «        |k    sJ ‚nO|sJ ‚ ||j
        ¦  «         ||¦  «        k    sJ ‚dt          j        vr ‰|¦  «        j        t          z  dk    sJ ‚ddd¦  «         n# 1 swxY w Y   t          |¦  «        sJ ‚t	          |¦  «        sJ ‚dS )	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)
    Nc                 ój   — t          j        t           j                             | ddd¦  «        ¦  «        S )NÚdataÚ0)r   Ústatr   r   )r   s    r   Ústat_segmentz&test_convert_all.<locals>.stat_segment    s&   € ÝŒw•r”w—|’| D¨&°#°sÑ;Ô;Ñ<Ô<Ð<r   c                 ó$   •—  ‰| ¦  «        j         S r   )Úst_ino)r   rf   s    €r   Úfirst_inodez%test_convert_all.<locals>.first_inode£   s   ø€ Øˆ|˜DÑ!Ô!Ô(Ð(r   Fr=   rD   ÚBORG_TESTS_IGNORE_MODESr   )rG   rH   r	   rI   r'   r   r   ÚumaskÚUMASK_DEFAULTÚupgrader   ÚenvironÚst_moder.   )	r6   rZ   r;   rN   ri   Ú
orig_inoder&   Úbackuprf   s	           @r   Útest_convert_allrr   �   s  ø€ ð €Iå	Œ•zÔ1Ñ	2Ô	2ð ð Ý�9ÑÔÐðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð=ð =ð =ð)ð )ð )ð )ð )ð �˜YÑ'Ô'€JÝ	  °5Ð	9Ñ	9Ô	9ð I¸Zå
Œ•ÑÔÐØ×#Ò#¨5¸'Ð#ÑBÔBˆØð 		IØ�>�>�>Ø�;˜zœÑ/Ô/°:Ò=Ð=Ð=Ð=Ð=àˆMˆMˆMØ�;˜zœÑ/Ô/°;°;¸vÑ3FÔ3FÒFÐFÐFÐFð )µ´
Ð:Ð:Ø#�| FÑ+Ô+Ô3µmÑCÀqÒHÐHÐHÐHðIð Ið Iñ Iô Ið Ið Ið Ið Ið Ið Iøøøð Ið Ið Ið Iõ �^Ñ$Ô$Ð$Ð$Ð$Ý�iÑ Ô Ð Ð Ð Ð Ð s"   ¢>¾AÁAÁ-BDÄDÄDc                 óÈ  — t          |                      d¦  «        ¦  «        }t          |d¦  «        5 }|                     d¦  «         ddd¦  «         n# 1 swxY w Y   t          |                      d¦  «        ¦  «        }t	          j        ||¦  «         t          j        |dd|¬¦  «         |s7t	          j        |¦  «        j	        t	          j        |¦  «        j	        k    sJ ‚n6t	          j        |¦  «        j	        t	          j        |¦  «        j	        k    sJ ‚t          |d	¦  «        5 }| 
                    ¦   «         d
k    sJ ‚	 ddd¦  «         dS # 1 swxY w Y   dS )ab  test 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Úwbs   aXXXNÚbó   aó   b)r;   Úrbs   bXXX)r$   r   r   Úwriter   Úlinkr   Úheader_replacere   rh   r*   )r5   r;   rt   Útmprv   s        r   Útest_hardlinkr~   º   sµ  € õ 	ˆF�KŠK˜ÑÔÑÔ€AÝ	ˆa�‰Œð ˜#Ø�	Š	�'ÑÔÐðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð åˆF�KŠK˜ÑÔÑÔ€AÝ„GˆAˆq�M„M€MÝÔ*¨1¨d°DÀ'ÐJÑJÔJÐJØð 6ÝŒw�q‰zŒzÔ ¥B¤G¨A¡J¤JÔ$5Ò5Ð5Ð5Ð5Ð5åŒw�q‰zŒzÔ ¥B¤G¨A¡J¤JÔ$5Ò5Ð5Ð5Ð5Ý	ˆa�‰Œð %˜#Ø�xŠx‰zŒz˜WÒ$Ð$Ð$Ð$Ð$ð%ð %ð %ñ %ô %ð %ð %ð %ð %ð %ð %ð %øøøð %ð %ð %ð %ð %ð %s#   ³AÁAÁAÄ.EÅEÅE)"r   r   rG   Ú	constantsÚ
crypto.keyr   Úupgraderr   r   Úhelpersr   r&   r	   Ú r   r   r   ÚdirnameÚ__file__r1   r    r'   r.   r3   Úfixturer6   r;   rP   rZ   r_   ÚmarkÚskipifrr   r~   r?   r   r   ú<module>r‰      s  ðØ 	€	€	€	Ø €€€à €€€à Ð Ð Ð Ø #Ð #Ð #Ð #Ð #Ð #Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø "Ð "Ð "Ð "Ð "Ð "Ø #Ð #Ð #Ð #Ð #Ð #Ø %Ð %Ð %Ð %Ð %Ð %ð ŒG�LŠL˜œŸš¨Ñ2Ô2°NÑCÔC€	ð$ð $ð $ð$	"ð 	"ð 	"ð
7ð 
7ð 
7ð.ð .ð .ð €„ÑÔð#ð #ñ Ôð#ð €„˜˜e�}Ð%Ñ%Ô%ðð ñ &Ô%ðð!ð !ð !ð( €„ÑÔð*ð *ñ Ôð*ð.#ð #ð #ð$ „×ÒÐ/Ð/Ñ1Ô1Ð1Ð:SÐÑTÔTð&!ð &!ñ UÔTð&!ðR „×ÒÐ/Ð/Ñ1Ô1Ð1Ð:SÐÑTÔTð%ð %ñ UÔTð%ð %ð %r   