HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/borg/helpers/__pycache__/fs.cpython-39.opt-1.pyc
a

HZ�h:=�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlTddlmZe�ZejejBejBd	fd
d�Zdd
�Zdd�ZdBdd�Zdd�Zdd�Zdd�Zdd�Ze�d�Zdd�Zdd�Zdd �Z dd!�d"d#�Z!d$d%�Z"d&d'�Z#d(d)�Z$d*d+�Z%e%d,d-d.�Z&e&e%d/�BZ'e&Z(e&e%d0d/�BZ)e)e%d1�BZ*e%d2d.d/�Z+dddd3d4�d5d6�Z,dddd3d7�d8d9�Z-d:d;�Z.ddlZ/ddlZ0ddlZ1dd<l2m3Z3m4Z4m5Z5m6Z6m7Z7dCd>d?�Z8dDd@dA�Z9dS)E�N�)�Error)�prepare_subprocess_env�)�is_win32)�*)�
create_loggerTc
CsRztj||dd�Wn8tyL}z |r6tt|���n�WYd}~n
d}~00dS)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	Z
pretty_deadly�e�r�5/usr/lib64/python3.9/site-packages/borg/helpers/fs.py�
ensure_dirsrcCs:tj�d�ptj�d�}|s6tj�dtj�dd��}|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~%sZUSER�)r�environ�getr�
expanduser)�base_dirrrr�get_base_dir)srcCs0tj�d�}|dur$tj�t�d�}t|�|S)�,Determine where to repository keys and cacheZ
BORG_KEYS_DIRN�keys�rrrr�join�get_config_dirr)Zkeys_dirrrr�get_keys_dir;s
r!cCsBtj�d�}|dur$tj�t�d�}|r6tj�||�}t|�|S)z4Determine where to store local security information.ZBORG_SECURITY_DIRNZsecurityr)Z
repository_idZsecurity_dirrrr�get_security_dirEsr"cCs�tj�t�d�}tj�d�s*tj�d|�}tj�dtj�|d��}t|�tj�|t�}tj�|�s�t	t
�d��d�}dd	l
m}||d
d��}|�|�Wd�n1s�0Y|S)
rz.cacherZXDG_CACHE_HOMEZBORG_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)ZbinaryN)rrrrrrr�CACHE_TAG_NAME�exists�CACHE_TAG_CONTENTS�textwrap�dedent�encode�platformr%�write)Z
cache_homeZ	cache_dirZcache_tag_fnZcache_tag_contentsr%�fdrrr�
get_cache_dirQs�(r/cCsNtj�t�d�}tj�d�s*tj�d|�}tj�dtj�|d��}t|�|S)z%Determine where to store whole configz.configrZXDG_CONFIG_HOMEZBORG_CONFIG_DIRr#)rrrrrrr)Zconfig_homeZ
config_dirrrrr isr cCs�tj�|t�}zbtj�|�rnt|d��8}|�tt��}|tkrPWd�WdSWd�n1sd0YWnt	y�Yn0dS)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)
rrrr&r'�open�read�lenr(r
)r�tag_pathZtag_fileZtag_datarrr�dir_is_cachedirws4r5cCsTg}|rt|�r|�t�|durP|D](}tj�||�}tj�|�r&|�|�q&|S)aDetermines 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).
    N)r5�appendr&rrrr')rZexclude_cachesZexclude_if_presentZ	tag_names�tagr4rrr�
dir_is_tagged�s
r8z
^((\.\.)?/+)+cCst�d|�pdS)z3Make path safe by making it relative and local
    r�.)�_safe_re�sub)rrrr�make_path_safe�sr<cCs(t�|�p&t�|�p&t�|�p&t�|�S)z7return True if we support hardlinked items of this type)�stat�S_ISREG�S_ISBLK�S_ISCHR�S_ISFIFO)r	rrr�hardlinkable�srBc
CsRzd|��fWStyL}z&t�d|j|�d|jfWYd}~Sd}~00dS)Nrz&scandir_inorder: Unable to stat %s: %sr)�inoder
�logger�debugr�name)Zdirentrrrr�scandir_keyfunc�s
rG)r.cCs"|dur|n|}tt�|�td�S)N)�key)�sortedr�scandirrG)rr.�argrrr�scandir_inorder�srLcCs|t|d��T}t�|���}|jdkr(|sP|�t�|j��|��t�	|���Wd�n1sd0Yt�
|�dS)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+brN)r1rr=�fileno�st_nlinkr-�urandom�st_size�flush�fsync�unlink)rZavoid_collateral_damager.�strrr�secure_erase�s,rVcCs�zt�|�Wn�ty�}z�|jtjkr,�t�|�}|jdkrB�z6t|d��}|��Wd�n1sl0YWnty�|�Yn0t�|�WYd}~n
d}~00dS)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.
    rrMN)	rrTr
�errno�ENOSPCr=rOr1�truncate)rZ
unlink_errrUr.rrr�safe_unlink�s

*
rZcCs<|dkr.d|vrtjntj}d|vr*|jS|St||�SdS)N�-�r�b)�sys�stdin�stdout�bufferr1)rr	�streamrrr�	dash_open�srccGs&d}|D]}|ttd|d�O}q|S)Nr�O_)�getattrr)�flags�result�flagrrrrd�srdZBINARYZNOCTTYZRDONLYZNOFOLLOWZNONBLOCK�NOATIMEZ	DIRECTORYF)r�	parent_fdrF�noatimec
Cs�|r|dur|}n
|d}}tr0tj�|�r0dS|}|r�|td�B}ztj|||d�}Wq�ty�||krp�tj|||d�}Yq�ty�}	zHddlm	}
d|
vr�|	j
t
jkr�||kr�tj|||d�}n�WYd}	~	q�d}	~	00ntj|||d�}|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
    Nri)�dir_fdr)�workaroundsZretry_erofs)rrr�isdirrdr1�PermissionErrorr
rrmrWZEROFS)rfrrjrFrk�fnameZ
_flags_normalZ_flags_noatimer.�excrmrrr�os_opens*
rr)rrjrF�follow_symlinkscCs,|r|dur|}n
|d}}tj|||d�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)rlrs)rr=)rrjrFrsrprrr�os_stat:s
rtcCsJtdd�}ztjdd|g|d�WStyDtjd|g|d�YS0dS)NT)�systemZ
fusermountz-u)�env�umount)r�
subprocess�call�FileNotFoundError)Z
mountpointrvrrrrwNs

rw)�_sanitize_params�_get_candidate_names�TMP_MAX�_text_openflags�_bin_openflags�c	Cs�tj�|�}t�}|tur&ttj|�}tt�D]�}t	|�}tj�
||||�}	t�d|	�zt�
|	||�}
WnRty�Yq.Yn>ty�tjdkr�tj�|�r�t�|tj�r�Yq.n�Yn0|
|	fSttjd��dS)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstemp�ntz#No usable temporary file name foundN)�_osr�abspathr|�bytes�map�fsencode�ranger}�nextr�_sys�auditr1�FileExistsErrorrorFrn�access�W_OK�_errnoZEEXIST)�dirZpreZsufrf�output_typer	�names�seqrF�filer.rrr�_mkstemp_inner_s$$r�cCs4t|||�\}}}}|rt}nt}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~rr�)�suffix�prefixr��textr	r�rfrrr�mkstemp_mode{s
r�)N)r�)NNNFr�):rWrZos.path�rer=rxr^r)�errorsrZprocessrZ
platformflagsrZ	constantsrDr�S_IRWXU�S_IRWXG�S_IRWXOrrr!r"r/r r5r8�compiler:r<rBrGrLrVrZrcrdZ
flags_baseZ
flags_specialZflags_special_followZflags_normalZ
flags_noatimeZ	flags_dirrrrtrwr�r�r�Ztempfiler{r|r}r~rr�r�rrrr�<module>sZ



$	.