Server : Apache System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64 User : dh_edsupp ( 6597262) PHP Version : 8.2.26 Disable Function : NONE Directory : /lib/python3/dist-packages/duplicity/__pycache__/ |
Upload File : |
o �~�_<* � @ s� d Z ddlmZ ddlmZ e�� ddlmZ ddlZddl Z ddl Z ddlZddlZddl mZ ddl mZ ddl mZ e�� adae�� ad d � ZG dd� de�ZdS ) z� Provides temporary file handling cenetered around a single top-level securely created temporary directory. The public interface of this module is thread-safe. � )�print_function)�standard_library)�objectN)�config)�log)�utilc C sL t �� ztdu st�� du rttjd�at�� t_tW t � � S t � � w )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. N)�temproot) �_defaultLock�acquire�_defaultInstance�dir�TemporaryDirectoryr r �tempfile�tempdir�release� r r �3/usr/lib/python3/dist-packages/duplicity/tempdir.py�default5 s r c @ sR e Zd ZdZddd�Zdd� Zdd� Zd d � Zdd� Zd d� Z dd� Z dd� ZdS )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 C s� dd� }|du rt jrt j}nt}t|dj�rt�|�}t�� � d�r5||�r5t �ddg�}t�|��� }t �dd |�| _t�td �| j � d| _i | _t�� | _dS )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 S sB t j�d�t j�d�g}t j�| �}|D ] }|�|�r dS qdS )z-Determine if path point to a MAcOS system tmpz/tmpz/var/tmpTF)�os�path�realpath� startswith)r � sys_temps� user_temp�sys_tempr r r �defaults_to_tmp� s � �z4TemporaryDirectory.__init__.<locals>.defaults_to_tmpN� �Darwin�getconf�DARWIN_USER_TEMP_DIRz-tempdirz duplicity-zUsing temporary directory %sr )r r �_initialSystemTempRoot� isinstance� __class__r �fsdecode�platform�systemr � subprocess�check_output�rstripr �mkdtemp�_TemporaryDirectory__dirr �Info�_�_TemporaryDirectory__tempcount�_TemporaryDirectory__pending� threading�Lock�_TemporaryDirectory__lock)�selfr r r r r �__init__{ s zTemporaryDirectory.__init__c C s | j S )zC Returns the absolute pathname of the temp folder. )r* �r2 r r r r � s zTemporaryDirectory.dirc C s t dur | �� dS dS )z" Perform cleanup. N)r �cleanupr4 r r r �__del__� s �zTemporaryDirectory.__del__c C s| d}| j �� z0| jd | _d| jf }t�t�|d| j��}t� t d�t�|� � d| j|<