%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/duplicity/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/duplicity/__pycache__/tempdir.cpython-312.pyc

�

�2e�)���dZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ej�adaej�ad�ZGd�de�Zy)	z�
Provides temporary file handling cenetered around a single top-level
securely created temporary directory.

The public interface of this module is thread-safe.
�N)�config)�log)�utilc�4�tj�	t�tj��7t	t
j��atj�t_ttj�S#tj�wxYw)am
    Obtain the global default instance of TemporaryDirectory, creating
    it first if necessary. Failures are propagated to caller. Most
    callers are expected to use this function rather than
    instantiating TemporaryDirectory directly, unless they explicitly
    desdire to have their "own" directory for some reason.

    This function is thread-safe.
    )�temproot)
�_defaultLock�acquire�_defaultInstance�dir�TemporaryDirectoryrr�tempfile�tempdir�release���3/usr/lib/python3/dist-packages/duplicity/tempdir.py�defaultr0sf��������#�'7�';�';�'=�'E�1�6�?�?�K��/�3�3�5�H������������s�AB�Bc�B�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zy)ra5
    A temporary directory.

    An instance of this class is backed by a directory in the file
    system created securely by the use of tempfile.mkdtemp(). Said
    instance can be used to obtain unique filenames inside of this
    directory for cases where mktemp()-like semantics is desired, or
    (recommended) an fd,filename pair for mkstemp()-like semantics.

    See further below for the security implications of using it.

    Each instance will keep a list of all files ever created by it, to
    faciliate deletion of such files and rmdir() of the directory
    itself. It does this in order to be able to clean out the
    directory without resorting to a recursive delete (ala rm -rf),
    which would be risky. Calling code can optionally (recommended)
    notify an instance of the fact that a tempfile was deleted, and
    thus need not be kept track of anymore.

    This class serves two primary purposes:

    Firstly, it provides a convenient single top-level directory in
    which all the clutter ends up, rather than cluttering up the root
    of the system temp directory itself with many files.

    Secondly, it provides a way to get mktemp() style semantics for
    temporary file creation, with most of the risks
    gone. Specifically, since the directory itself is created
    securely, files in this directory can be (mostly) safely created
    non-atomically without the usual mktemp() security
    implications. However, in the presence of tmpwatch, tmpreaper, or
    similar mechanisms that will cause files in the system tempdir to
    expire, a security risk is still present because the removal of
    the TemporaryDirectory managed directory removes all protection it
    offers.

    For this reason, use of mkstemp() is greatly preferred above use
    of mktemp().

    In addition, since cleanup is in the form of deletion based on a
    list of filenames, completely independently of whether someone
    else already deleted the file, there exists a race here as
    well. The impact should however be limited to the removal of an
    'attackers' file.
    Nc�X�d�}|�'tjrtj}nt}t|dj�rtj|�}tj�jd�rB||�r:tjddg�}tj|�j�}tjdd|�|_t!j"t%d	�|jz�d
|_i|_t+j,�|_y)z�
        Create a new TemporaryDirectory backed by a unique and
        securely created file system directory.

        tempbase - The temp root directory, or None to use system
        default (recommended).
        c���tjjd�tjjd�g}tjj|�}|D]}|j|�s�yy)z-Determine if path point to a MAcOS system tmpz/tmpz/var/tmpTF)�os�path�realpath�
startswith)r�	sys_temps�	user_temp�sys_temps    r�defaults_to_tmpz4TemporaryDirectory.__init__.<locals>.defaults_to_tmp�sj����� � ��(���� � ��,��I�
���(�(��.�I�%�
 ���'�'��1��
 �rNr�Darwin�getconf�DARWIN_USER_TEMP_DIRz-tempdirz
duplicity-zUsing temporary directory %sr)rr�_initialSystemTempRoot�
isinstance�	__class__r�fsdecode�platform�systemr�
subprocess�check_output�rstripr
�mkdtemp�_TemporaryDirectory__dirr�Info�_�_TemporaryDirectory__tempcount�_TemporaryDirectory__pending�	threading�Lock�_TemporaryDirectory__lock)�selfrrs   r�__init__zTemporaryDirectory.__init__ws���	������!�?�?��2���h��
�
�.��{�{�8�,�H��?�?��'�'��1�o�h�6O�!�.�.�	�;Q�/R�S�H��{�{�8�,�3�3�5�H��%�%�j�,��I��
�����1�2�T�Z�Z�?�@��������n�n�&��rc��|jS)zC
        Returns the absolute pathname of the temp folder.
        )r,�r4s rrzTemporaryDirectory.dir�s���z�z�rc�2�t�|j�yy)z"
        Perform cleanup.
        N)r
�cleanupr7s r�__del__zTemporaryDirectory.__del__�s��
�'��L�L�N�(rc��d}|jj�	|jdz|_dt|j���}t	j
t
j|d|j��}tjtd�t	j|�z�d|j|<|jj�|S#|jj�wxYw)aN
        Return a unique filename suitable for use for a temporary
        file. The file is not created.

        Subsequent calls to this method are guaranteed to never return
        the same filename again. As a result, it is safe to use under
        concurrent conditions.

        NOTE: mkstemp() is greatly preferred.
        N��-zmktemp-z&Registering (mktemp) temporary file %s)r3r	r/�intr�fsencoder
�mktempr,r�Debugr.r%r0r)r4�filename�suffixs   rr@zTemporaryDirectory.mktemp�s�����������	"�#�/�/�!�3�D����T�-�-�.�/�0�F��{�{�8�?�?�6�9�d�j�j�#Q�R�H��I�I�a�@�A�B�K�K�PX�DY�Y�Z�'+�D�N�N�8�$��K�K���!����
�K�K���!�s�B#C�C9c��d}d}|jj�	|jdz|_dt|j���}t	j
|d|j�\}}tjtd�|z�d|j|<|jj�||fS#|jj�wxYw)z�
        Returns a filedescriptor and a filename, as per os.mkstemp(),
        but located in the temporary directory and subject to tracking
        and automatic cleanup.
        Nr<r=zmkstemp-z'Registering (mkstemp) temporary file %s)r3r	r/r>r
�mkstempr,rrAr.r0r)r4�fdrBrCs    rrEzTemporaryDirectory.mkstemp�s�������������	"�#�/�/�!�3�D����T�-�-�.�/�0�F�#�+�+����
�
��L�B��
�I�I�a�A�B�X�M�N�'+�D�N�N�8�$��K�K���!��8�|���
�K�K���!�s�BB>�>Cc�X�|j�\}}tj|d�|fS)zv
        Convenience wrapper around mkstemp(), with the file descriptor
        converted into a file object.
        zr+)rEr�fdopen)r4rFrBs   r�mkstemp_filezTemporaryDirectory.mkstemp_file�s)��
�|�|�~���H��y�y��T�"�H�,�,rc��|jj�	||jvrBtjtd�t
j|�z�|j|=n5tjtd�t
j|�z�	|jj�y#|jj�wxYw)a"
        Forget about the given filename previously obtained through
        mktemp() or mkstemp(). This should be called *after* the file
        has been deleted, to stop a future cleanup() from trying to
        delete it.

        Forgetting is only needed for scaling purposes; that is, to
        avoid n timefile creations from implying that n filenames are
        kept in memory. Typically this whould never matter in
        duplicity, but for niceness sake callers are recommended to
        use this method whenever possible.
        zForgetting temporary file %sz?Attempt to forget unknown tempfile %s - this is probably a bug.N)
r3r	r0rrAr.rr%�Warnr)r4�fnames  r�forgetzTemporaryDirectory.forget�s���	
������	"�����&��	�	�!�:�;�b�k�k�%�>P�P�Q��N�N�5�)�����\�]�`b�`k�`k�lq�`r�r�s���K�K���!��D�K�K���!�s�BB<�<Cc�B�|jj�	|j��t|jj��D][}	t
jtd�tj|�z�tjtj|��]	tj |j�d|_d|_|jj%�y#t$r7t
jtd�tj|�z�Y��wxYw#t$rAt
j"td�tj|j�z�Y��wxYw#|jj%�wxYw)z�
        Cleanup any files created in the temporary directory (that
        have not been forgotten), and clean up the temporary directory
        itself.

        On failure they are logged, but this method will not raise an
        exception.
        Nz+Removing still remembered temporary file %sz#Cleanup of temporary file %s failedzBCleanup of temporary directory %s failed - this is probably a bug.)r3r	r,�listr0�keysrrAr.rr%r�ignore_missing�unlink�	Exceptionr-�rmdirrKr)r4�files  rr9zTemporaryDirectory.cleanups=��	
������	"��z�z�%� ����!4�!4�!6�7��D���	�	�!�$Q�"R�UW�U`�U`�ae�Uf�"f�g��+�+�B�I�I�t�<����H�H�T�Z�Z�(�"&���!��
��K�K���!��%������#H�!I�B�K�K�X\�L]�!]�^����
!���H�H��a�b��+�+�d�j�j�1�2�����
�K�K���!�sU�2F�AC2�'F�*D5�	F�2=D2�/F�1D2�2F�5AE?�<F�>E?�?F�F)N)�__name__�
__module__�__qualname__�__doc__r5rr:r@rErIrMr9rrrrrHs1��,�\/'�b���4�4-�"�0"rr)rYrr&r(r
r1�	duplicityrrrr2rr
�
gettempdirr"r�objectrrrr�<module>r]s`��,�
���������y�~�~�����-��,�,�.���0a"��a"r

Zerion Mini Shell 1.0