§
    dT=  ã                   ó\  — d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZddlm	Z	 ddl
mZ ddlmZ ddlT ddlmZ  e¦   «         Zej        ej        z  ej        z  d	fd
„Zd„ Zd„ Zd-d„Zd„ Zd„ Zd„ Zd„ Z ej        d¦  «        Zd„ Zd„ Zd„ Z ddœd„Z!d„ Z"d„ Z#d„ Z$d„ Z% e%ddd¦  «        Z&e& e%d¦  «        z  Z'e&Z(e& e%d d¦  «        z  Z)e) e%d!¦  «        z  Z* e%d¦  «        Z+ e%d"dd¦  «        Z,dddd#d$œd%„Z-dddd#d&œd'„Z.d(„ Z/d dlZ0d dlZ1d dl Z2d d)l3m4Z4m5Z5m6Z6m7Z7m8Z8 d.d+„Z9d/d,„Z:dS )0é    Né   )ÚError)Úprepare_subprocess_envé   )Úis_win32)Ú*)Úcreate_loggerTc                 ó˜   — 	 t          j        | |d¬¦  «         dS # t          $ r$}|rt          t	          |¦  «        ¦  «        ‚‚ d}~ww xY w)a  
    Ensures that the dir exists with the right permissions.
    1) Make sure the directory exists in a race-free operation
    2) If mode is not None and the directory has been created, give the right
    permissions to the leaf directory. The current umask value is masked out first.
    3) If pretty_deadly is True, catch exceptions, reraise them with a pretty
    message.
    Returns if the directory has been created and has the right permissions,
    An exception otherwise. If a deadly exception happened it is reraised.
    T)ÚmodeÚexist_okN)ÚosÚmakedirsÚOSErrorr   Ústr)Úpathr   Úpretty_deadlyÚes       ú1/usr/lib/python3/dist-packages/borg/helpers/fs.pyÚ
ensure_dirr      s`   € ðÝ
Œ�D˜t¨dÐ3Ñ3Ô3Ð3Ð3Ð3øÝð ð ð Øð 	Ý�˜A™œ‘-”-Ðàøøøøð	øøøs   ‚ ›
A	¥AÁA	c                  ó  — t           j                             d¦  «        pt           j                             d¦  «        } | s@t           j                             dt           j                             dd¦  «        z  ¦  «        } | S )z‡Get home directory / base directory for borg:

    - BORG_BASE_DIR, if set
    - HOME, if set
    - ~$USER, if USER is set
    - ~
    ÚBORG_BASE_DIRÚHOMEz~%sÚUSERÚ )r   ÚenvironÚgetr   Ú
expanduser)Úbase_dirs    r   Úget_base_dirr   )   sd   € õ Œz�~Š~˜oÑ.Ô.ÐHµ"´*·.².ÀÑ2HÔ2H€Hð
 ð JÝ”7×%Ò% e­b¬j¯nªn¸VÀRÑ.HÔ.HÑ&HÑIÔIˆØ€Oó    c                  ó¾   — t           j                             d¦  «        } | €,t           j                             t          ¦   «         d¦  «        } t          | ¦  «         | S )ú,Determine where to repository keys and cacheÚBORG_KEYS_DIRNÚkeys©r   r   r   r   ÚjoinÚget_config_dirr   )Úkeys_dirs    r   Úget_keys_dirr)   ;   sI   € åŒz�~Š~˜oÑ.Ô.€HØÐå”7—<’<¥Ñ 0Ô 0°&Ñ9Ô9ˆÝˆxÑÔÐØ€Or    c                 ó  — t           j                             d¦  «        }|€,t           j                             t          ¦   «         d¦  «        }| r t           j                             || ¦  «        }t          |¦  «         |S )z4Determine where to store local security information.ÚBORG_SECURITY_DIRNÚsecurityr%   )Úrepository_idÚsecurity_dirs     r   Úget_security_dirr/   E   si   € å”:—>’>Ð"5Ñ6Ô6€LØÐå”w—|’|¥NÑ$4Ô$4°jÑAÔAˆØð AÝ”w—|’| L°-Ñ@Ô@ˆÝˆ|ÑÔÐØÐr    c                  óÜ  — t           j                             t          ¦   «         d¦  «        } t           j                             d¦  «        s t           j                             d| ¦  «        } t           j                             dt           j                             | d¦  «        ¦  «        }t          |¦  «         t           j                             |t          ¦  «        }t           j                             |¦  «        sot          t          j        d¦  «                             d¦  «        z   }dd	lm}  ||d
¬¦  «        5 }|                     |¦  «         ddd¦  «         n# 1 swxY w Y   |S )r"   z.cacher   ÚXDG_CACHE_HOMEÚBORG_CACHE_DIRÚborgz»
        # This file is a cache directory tag created by Borg.
        # For information about cache directory tags, see:
        #       http://www.bford.info/cachedir/spec.html
        Úasciir   )ÚSaveFileT)ÚbinaryN)r   r   r&   r   r   r   r   ÚCACHE_TAG_NAMEÚexistsÚCACHE_TAG_CONTENTSÚtextwrapÚdedentÚencodeÚplatformr5   Úwrite)Ú
cache_homeÚ	cache_dirÚcache_tag_fnÚcache_tag_contentsr5   Úfds         r   Úget_cache_dirrD   Q   si  € õ ”—’�l™nœn¨hÑ7Ô7€JåŒ:�>Š>˜/Ñ*Ô*ð BÝ”Z—^’^Ð$4°jÑAÔAˆ
å”
—’Ð/µ´·²¸jÈ&Ñ1QÔ1QÑRÔR€IåˆyÑÔÐÝ”7—<’< 	­>Ñ:Ô:€LÝŒ7�>Š>˜,Ñ'Ô'ð )Ý/µ(´/ð Cñ 3ô 3÷ ŠV�G‰_Œ_ñ	Ðð
 	(Ð'Ð'Ð'Ð'Ð'ØˆX�l¨4Ð0Ñ0Ô0ð 	)°BØ�HŠHÐ'Ñ(Ô(Ð(ð	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)àÐs   Ä?E!Å!E%Å(E%c                  óv  — t           j                             t          ¦   «         d¦  «        } t           j                             d¦  «        s t           j                             d| ¦  «        } t           j                             dt           j                             | d¦  «        ¦  «        }t          |¦  «         |S )z%Determine where to store whole configz.configr   ÚXDG_CONFIG_HOMEÚBORG_CONFIG_DIRr3   )r   r   r&   r   r   r   r   )Úconfig_homeÚ
config_dirs     r   r'   r'   i   s„   € õ ”'—,’,�|™~œ~¨yÑ9Ô9€KåŒ:�>Š>˜/Ñ*Ô*ð EÝ”j—n’nÐ%6¸ÑDÔDˆå”—’Ð 1µ2´7·<²<ÀÈVÑ3TÔ3TÑUÔU€JåˆzÑÔÐØÐr    c                 ó„  — t           j                             | t          ¦  «        }	 t           j                             |¦  «        rit          |d¦  «        5 }|                     t          t          ¦  «        ¦  «        }|t          k    r	 ddd¦  «         dS 	 ddd¦  «         n# 1 swxY w Y   n# t          $ r Y nw xY wdS )zÝDetermines whether the specified path is a cache directory (and
    therefore should potentially be excluded from the backup) according to
    the CACHEDIR.TAG protocol
    (http://www.bford.info/cachedir/spec.html).
    ÚrbNTF)
r   r   r&   r7   r8   ÚopenÚreadÚlenr9   r   )r   Útag_pathÚtag_fileÚtag_datas       r   Údir_is_cachedirrR   w   s  € õ Œw�|Š|˜D¥.Ñ1Ô1€HðÝŒ7�>Š>˜(Ñ#Ô#ð 	 Ý�h Ñ%Ô%ð  ¨Ø#Ÿ=š=­Õ-?Ñ)@Ô)@ÑAÔA�ØÕ1Ò1Ð1Øð ð  ð  ñ  ô  ð  ð  ð  à1ð ð  ð  ñ  ô  ð  ð  ð  ð  ð  ð  øøøð  ð  ð  ð  øøõ ð ð ð Øˆðøøøàˆ5s;   §/B0 Á4B$Â
B0 ÂB0 Â$B(Â(B0 Â+B(Â,B0 Â0
B=Â<B=c                 ó  — g }|r)t          | ¦  «        r|                     t          ¦  «         |�Y|D ]V}t          j                             | |¦  «        }t          j                             |¦  «        r|                     |¦  «         ŒW|S )a  Determines whether the specified path is excluded by being a cache
    directory or containing user-specified tag files/directories. Returns a
    list of the names of the tag files/directories (either CACHEDIR.TAG or the
    matching user-specified files/directories).
    )rR   Úappendr7   r   r   r&   r8   )r   Úexclude_cachesÚexclude_if_presentÚ	tag_namesÚtagrO   s         r   Údir_is_taggedrY   Š   s�   € ð €IØð )�/¨$Ñ/Ô/ð )Ø×Ò�Ñ(Ô(Ð(ØÐ%Ø%ð 	&ð 	&ˆCÝ”w—|’| D¨#Ñ.Ô.ˆHÝŒw�~Š~˜hÑ'Ô'ð &Ø× Ò  Ñ%Ô%Ð%øØÐr    z^((\.\.)?/+)+c                 ó<   — t                                d| ¦  «        pdS )z3Make path safe by making it relative and local
    r   ú.)Ú_safe_reÚsub)r   s    r   Úmake_path_safer^   Ÿ   s   € õ �<Š<˜˜DÑ!Ô!Ð( SÐ(r    c                 ó¢   — t          j        | ¦  «        p;t          j        | ¦  «        p't          j        | ¦  «        pt          j        | ¦  «        S )z7return True if we support hardlinked items of this type)ÚstatÚS_ISREGÚS_ISBLKÚS_ISCHRÚS_ISFIFO)r   s    r   Úhardlinkablere   ¥   s@   € åŒ<˜ÑÔÐ`¥¤¨dÑ!3Ô!3Ð`µt´|ÀDÑ7IÔ7IÐ`ÍTÌ]Ð[_ÑM`ÔM`Ð`r    c                 ó²   — 	 d|                       ¦   «         fS # t          $ r4}t                               d| j        |¦  «         d| j        fcY d }~S d }~ww xY w)Nr   z&scandir_inorder: Unable to stat %s: %sr   )Úinoder   ÚloggerÚdebugr   Úname)Údirentr   s     r   Úscandir_keyfuncrl   ª   sp   € ð	 Ø�6—<’<‘>”>Ð"Ð"øÝð  ð  ð  å�ŠÐ=¸v¼{ÈAÑNÔNÐNð
 �6”;ÐÐÐÐÐÐÐøøøøð øøøs   ‚ ˜
A¢)AÁAÁA)rC   c                 ó^   — |�|n| }t          t          j        |¦  «        t          ¬¦  «        S )N)Úkey)Úsortedr   Úscandirrl   )r   rC   Úargs      r   Úscandir_inorderrr   ·   s*   € Ø�ˆ"ˆ" D€CÝ•"”*˜S‘/”/¥Ð7Ñ7Ô7Ð7r    c                ó°  — t          | d¦  «        5 }t          j        |                     ¦   «         ¦  «        }|j        dk    r|sf|                     t          j        |j        ¦  «        ¦  «         |                     ¦   «          t          j	        |                     ¦   «         ¦  «         ddd¦  «         n# 1 swxY w Y   t          j
        | ¦  «         dS )a�  Attempt to securely erase a file by writing random data over it before deleting it.

    If avoid_collateral_damage is True, we only secure erase if the total link count is 1,
    otherwise we just do a normal "delete" (unlink) without first overwriting it with random.
    This avoids other hardlinks pointing to same inode as <path> getting damaged, but might be less secure.
    A typical scenario where this is useful are quick "hardlink copies" of bigger directories.

    If avoid_collateral_damage is False, we always secure erase.
    If there are hardlinks pointing to the same inode as <path>, they will contain random garbage afterwards.
    úr+br   N)rL   r   r`   ÚfilenoÚst_nlinkr>   ÚurandomÚst_sizeÚflushÚfsyncÚunlink)r   Úavoid_collateral_damagerC   Ústs       r   Úsecure_eraser~   ¼   sã   € õ 
ˆd�EÑ	Ô	ð "˜bÝŒW�R—Y’Y‘[”[Ñ!Ô!ˆØ”˜a’�Ð$;�Ø�HŠH•R”Z ¤
Ñ+Ô+Ñ,Ô,Ð,Ø�HŠH‰JŒJˆJÝŒH�R—Y’Y‘[”[Ñ!Ô!Ð!ð"ð "ð "ñ "ô "ð "ð "ð "ð "ð "ð "øøøð "ð "ð "ð "õ „Iˆd�O„O€O€O€Os   ‘BB7Â7B;Â>B;c                 ó�  — 	 t          j        | ¦  «         dS # t          $ r£}|j        t          j        k    r‚ t          j        | ¦  «        }|j        dk    r‚ 	 t          | d¦  «        5 }|                     ¦   «          ddd¦  «         n# 1 swxY w Y   t          j        | ¦  «         n# t          $ r |‚w xY wY d}~dS d}~ww xY w)a½  
    Safely unlink (delete) *path*.

    If we run out of space while deleting the file, we try truncating it first.
    BUT we truncate only if path is the only hardlink referring to this content.

    Use this when deleting potentially large files when recovering
    from a VFS error such as ENOSPC. It can help a full file system
    recover. Refer to the "File system interaction" section
    in repository.py for further explanations.
    r   rt   N)	r   r{   r   ÚerrnoÚENOSPCr`   rv   rL   Útruncate)r   Ú
unlink_errr}   rC   s       r   Úsafe_unlinkr„   Ð   s  € ðÝ
Œ	�$‰ŒˆˆˆøÝð ð ð ØÔ�uœ|Ò+Ð+àåŒW�T‰]Œ]ˆØŒ;˜Š?ˆ?àð		å�d˜EÑ"Ô"ð  bØ—’‘”�ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð õ ŒI�d‰OŒOˆOˆOøõ ð 	ð 	ð 	àÐð	øøøð
 ˆOˆOˆOˆOˆOøøøøð'øøøsP   ‚ ˜
C¢6C ÁB*Á)B
Á>B*Â
B	ÂB*ÂB	ÂB*ÂC Â*B7Â7C Ã Cc                 óŒ   — d|vsJ ‚| dk    r)d|v rt           j        nt           j        }d|v r|j        n|S t	          | |¦  «        S )Nú+ú-ÚrÚb)ÚsysÚstdinÚstdoutÚbufferrL   )r   r   Ústreams      r   Ú	dash_openr�   ô   sQ   € Ø�dˆ?ˆ?ˆ?ˆ?Øˆs‚{€{Ø! T˜k˜k•”�­s¬zˆØ # t  ˆvŒ}ˆ}°Ð7å�D˜$ÑÔÐr    c                  óL   — d}| D ]}|t          t          d|z   d¦  «        z  }Œ|S )Nr   ÚO_)Úgetattrr   )ÚflagsÚresultÚflags      r   r‘   r‘   ý   s7   € Ø€FØð .ð .ˆØ•'�"˜d T™k¨1Ñ-Ô-Ñ-ˆˆØ€Mr    ÚBINARYÚNOCTTYÚRDONLYÚNOFOLLOWÚNONBLOCKÚNOATIMEÚ	DIRECTORYF)r   Ú	parent_fdrj   Únoatimec                 óô  — |r|�|}n|d}}t           r!t          j                             |¦  «        rdS | }|r©|t	          d¦  «        z  }	 t          j        |||¬¦  «        }n•# t          $ r! ||k    r‚ t          j        |||¬¦  «        }Y nkt          $ rH}	ddlm	}
 d|
v r3|	j
        t          j        k    r||k    rt          j        |||¬¦  «        }n‚ Y d}	~	nd}	~	ww xY wt          j        |||¬¦  «        }|S )aÂ  
    Use os.open to open a fs item.

    If parent_fd and name are given, they are preferred and openat will be used,
    path is not used in this case.

    :param path: full (but not necessarily absolute) path
    :param parent_fd: open directory file descriptor
    :param name: name relative to parent_fd
    :param flags: open flags for os.open() (int)
    :param noatime: True if access time shall be preserved
    :return: file descriptor
    Nr›   )Údir_fdr   )ÚworkaroundsÚretry_erofs)r   r   r   Úisdirr‘   rL   ÚPermissionErrorr   r   r¡   r€   ÚEROFS)r“   r   r�   rj   rž   ÚfnameÚ_flags_normalÚ_flags_noatimerC   Úexcr¡   s              r   Úos_openrª     sT  € ð ð &�	Ð%àˆˆà ˆyˆÝð •B”G—M’M %Ñ(Ô(ð àˆtØ€MØð =Ø&­¨I©¬Ñ6ˆð	å”˜ °yÐAÑAÔAˆBˆBøÝð 	Að 	Að 	AØ Ò.Ð.àå”˜ °iÐ@Ñ@Ô@ˆBˆBˆBÝð 	ð 	ð 	à%Ð%Ð%Ð%Ð%Ð%Ø Ð+Ð+°´	½U¼[Ò0HÐ0HÈ^Ð_lÒMlÐMlÝ”W˜U M¸)ÐDÑDÔD��àð ����øøøøð		øøøõ ŒW�U˜M°)Ð<Ñ<Ô<ˆØ€Is   ÁA# Á#(CÂ	CÂ>CÃC)r   r�   rj   Úfollow_symlinksc                 óF   — |r|�|}n| d}}t          j        |||¬¦  «        S )aP  
    Use os.stat to open a fs item.

    If parent_fd and name are given, they are preferred and statat will be used,
    path is not used in this case.

    :param path: full (but not necessarily absolute) path
    :param parent_fd: open directory file descriptor
    :param name: name relative to parent_fd
    :return: stat info
    N)r    r«   )r   r`   )r   r�   rj   r«   r¦   s        r   Úos_statr­   ;  s8   € ð ð &�	Ð%àˆˆà ˆyˆÝŒ7�5 ¸OÐLÑLÔLÐLr    c                 ó¦   — t          d¬¦  «        }	 t          j        dd| g|¬¦  «        S # t          $ r t          j        d| g|¬¦  «        cY S w xY w)NT)ÚsystemÚ
fusermountz-u)ÚenvÚumount)r   Ú
subprocessÚcallÚFileNotFoundError)Ú
mountpointr±   s     r   r²   r²   O  ss   € Ý
 ¨Ð
-Ñ
-Ô
-€Cð@ÝŒ ¨d°JÐ?ÀSÐIÑIÔIÐIøÝð @ð @ð @ÝŒ ¨*Ð5¸3Ð?Ñ?Ô?Ð?Ð?Ð?ð@øøøs   ’+ «"AÁA)Ú_sanitize_paramsÚ_get_candidate_namesÚTMP_MAXÚ_text_openflagsÚ_bin_openflagsé€  c                 ó¦  — t           j                             | ¦  «        } t          ¦   «         }|t          u rt          t           j        |¦  «        }t          t          ¦  «        D ]Ó}t          |¦  «        }t           j         
                    | ||z   |z   ¦  «        }	t          j        d|	¦  «         	 t          j        |	||¦  «        }
nj# t          $ r Y Œpt          $ rR t           j        dk    r@t           j                             | ¦  «        r!t          j        | t           j        ¦  «        rY ŒÉ‚ w xY w|
|	fc S t          t(          j        d¦  «        ‚)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstempÚntz#No usable temporary file name found)Ú_osr   Úabspathr¸   ÚbytesÚmapÚfsencodeÚranger¹   Únextr&   Ú_sysÚauditrL   ÚFileExistsErrorr¤   rj   r£   ÚaccessÚW_OKÚ_errnoÚEEXIST)ÚdirÚpreÚsufr“   Úoutput_typer   ÚnamesÚseqrj   ÚfilerC   s              r   Ú_mkstemp_innerrÔ   `  s<  € õ Œ(×
Ò
˜3Ñ
Ô
€CÝ Ñ"Ô"€EØ•eÐÐÝ•C”L %Ñ(Ô(ˆå•W‰~Œ~ð ð ˆÝ�E‰{Œ{ˆÝŒx�}Š}˜S #¨¡*¨sÑ"2Ñ3Ô3ˆÝŒ
Ð% tÑ,Ô,Ð,ð
	Ý”˜$  tÑ,Ô,ˆBˆBøÝð 	ð 	ð 	ØˆHÝð 	ð 	ð 	õ Œx˜4ÒÐ¥C¤H§N¢N°3Ñ$7Ô$7Ð½C¼JÀsÍCÌHÑ<UÔ<UÐØ�àð	øøøð �4ˆxˆˆˆå
�&œ-Ð)NÑ
OÔ
OÐOs   Â2C	Ã	
D0ÃAD0Ä.D0c                 óx   — t          || |¦  «        \  }} }}|rt          }nt          }t          ||| |||¦  «        S )a…  User-callable function to create and return a unique temporary
    file.  The return value is a pair (fd, name) where fd is the
    file descriptor returned by os.open, and name is the filename.
    If 'suffix' is not None, the file name will end with that suffix,
    otherwise there will be no suffix.
    If 'prefix' is not None, the file name will begin with that prefix,
    otherwise a default prefix is used.
    If 'dir' is not None, the file will be created in that directory,
    otherwise a default directory is used.
    If 'text' is specified and true, the file is opened in text
    mode.  Else (the default) the file is opened in binary mode.
    If any of 'suffix', 'prefix' and 'dir' are not None, they must be the
    same type.  If they are bytes, the returned name will be bytes; str
    otherwise.
    The file is readable and writable only by the creating user ID.
    If the operating system uses permission bits to indicate whether a
    file is executable, the file is executable by no one. The file
    descriptor is not inherited by children of this process.
    Caller is responsible for deleting the file when done with it.
    )r·   rº   r»   rÔ   )ÚsuffixÚprefixrÍ   Útextr   rÐ   r“   s          r   Úmkstemp_moderÙ   |  sJ   € õ, (8¸ÀÈÑ'LÔ'LÑ$€FˆF�C˜àð Ýˆˆåˆå˜#˜v v¨u°kÀ4ÑHÔHÐHr    )N)r¼   )NNNFr¼   );r€   r   Úos.pathÚrer`   r³   rŠ   r:   Úerrorsr   Úprocessr   Úplatformflagsr   Ú	constantsrh   r	   ÚS_IRWXUÚS_IRWXGÚS_IRWXOr   r   r)   r/   rD   r'   rR   rY   Úcompiler\   r^   re   rl   rr   r~   r„   r�   r‘   Ú
flags_baseÚflags_specialÚflags_special_followÚflags_normalÚflags_noatimeÚ
flags_rootÚ	flags_dirrª   r­   r²   r¿   rÆ   rË   Útempfiler·   r¸   r¹   rº   r»   rÔ   rÙ   © r    r   ú<module>rí      sI  ðØ €€€Ø 	€	€	€	Ø €€€Ø 	€	€	€	Ø €€€Ø Ð Ð Ð Ø 
€
€
€
Ø €€€à Ð Ð Ð Ð Ð à +Ð +Ð +Ð +Ð +Ð +Ø $Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð à "Ð "Ð "Ð "Ð "Ð "Ø	ˆ‰Œ€ð œ,¨¬Ñ5¸¼ÑDÐTXð ð ð ð ð(ð ð ð$ð ð ð	ð 	ð 	ð 	ðð ð ð0ð ð ðð ð ð&ð ð ð$ ˆ2Œ:Ð&Ñ'Ô'€ð)ð )ð )ðað að að

 ð 
 ð 
 ð !%ð 8ð 8ð 8ð 8ð 8ð
ð ð ð(!ð !ð !ðH ð  ð  ðð ð ð ˆR�˜( HÑ-Ô-€
Ø˜R˜R 
™^œ^Ñ+€Ø!Ð Ø˜B˜B˜z¨:Ñ6Ô6Ñ6€Ø˜r˜r )™}œ}Ñ,€ØˆR�‰\Œ\€
ØˆBˆ{˜H jÑ1Ô1€	ð  ¨4°dÀEð +ð +ð +ð +ð +ð\  D¨tÀUð Mð Mð Mð Mð Mð(@ð @ð @ð Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð Ø eÐ eÐ eÐ eÐ eÐ eÐ eÐ eÐ eÐ eÐ eÐ eÐ eÐ eðPð Pð Pð Pð8Ið Ið Ið Ið Ið Ir    