HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/__pycache__/roots.cpython-310.pyc
o

�N�gnD�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlZe�e�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)a�
The default file server backend

This fileserver backend serves files from the Master's local filesystem. If
:conf_master:`fileserver_backend` is not defined in the Master config file,
then this backend is enabled by default. If it *is* defined then ``roots`` must
be in the :conf_master:`fileserver_backend` list to enable this backend.

.. code-block:: yaml

    fileserver_backend:
      - roots

Fileserver environments are defined using the :conf_master:`file_roots`
configuration option.
�N�basecKs�|}d|vr|�d�tj�|�}ddd�}tj�|�r|S|tdvr5dtdvr3t�d|�d}n|Sdd�}d	|vr�ztd|t|d	�}Wnt	yV|YSt
y`|YSwtj�||�}tj�|�r�t
j�t|�s�||d
<||d<||�S|Std|D]=}|dkr�|�d|�}tj�||�}t
jjj||dtd
d�s�q�tj�|�r�t
j�t|�s�||d
<||d<||�Sq�|S)z7
    Search the environment for the relative path.
    �env�)�path�rel�
file_roots�__env__�:salt environment '%s' maps to __env__ file_roots directoryc
SsPztt�|d��|d<W|Sty'}z
t�d|�WYd}~|Sd}~ww)a0
        Stat the file and, assuming no errors were found, convert the stat
        result to a list of values and add to the return dict.

        Converting the stat result to a list, the elements of the list
        correspond to the following stat_result params:

        0 => st_mode=33188
        1 => st_ino=10227377
        2 => st_dev=65026
        3 => st_nlink=1
        4 => st_uid=1000
        5 => st_gid=1000
        6 => st_size=1056233
        7 => st_atime=1468284229
        8 => st_mtime=1456338235
        9 => st_ctime=1456338235
        r�statzUnable to stat file: %sN)�list�osr
�	Exception�log�error)�fnd�exc�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/roots.py�_add_file_stat:s���z!find_file.<locals>._add_file_stat�indexrrT�fileserver_followsymlinks�Zsubdir�realpath)�poprr�normpath�isabs�__opts__r�debug�int�
IndexError�
ValueError�join�isfile�salt�
fileserver�is_file_ignored�replace�utils�verify�
clean_path)r�saltenv�kwargs�actual_saltenvrr�root�fullrrr�	find_file$sV

����r/cCsttd�S)z-
    Return the file server environments
    r)�sortedrrrrr�envstsr1cCsrd|vr	|�d�ddd�}d|vsd|vsd|vr|S|ds"|S|d|d<|�d	d
�}tj�|d�}|d}}|tdvrSdtdvrQt�d
|�d}n|Sd}td|D]}|dkrg|�d|�}t	j
jj||dtdd�rwd}q[|s||St	j
j
�|d��+}	|	�|d�|	�td�}
|r�|
r�t	j
j�|
|�}
||d	<|
|d<Wd
�|S1s�wY|S)z?
    Return a chunk from a file based on the data received
    rr)�data�destr�locr*rr3�gzipNrrr	FTrr�rbZfile_buffer_sizer2)r�getrrrrrrr&r#r'r(r)�files�fopen�seek�readZ	gzip_util�compress)�loadr�retr5Zfpathr,r*Zfile_in_rootr-�fp_r2rrr�
serve_file{sP

���

��r@c
Csnztj�tj�tddd�t�Wn	tyYnwtj�tddd�}ddgidd�}tj�	ttd�}i}zUtj
jj|d	d
��B}|D]7}z%|�
��dd�\}}t|�}|||<||�||�krk|d
d�|�WqEty|t�d||�YqEwWd�n1s�wYWnttfy�Ynwtj�||�|d<t|�}t|�}	t||	�|d
d<t|	|�|d
d<tj�|�}
tj�|
�s�t�|
�tj
j�|d��!}|��D]\}}|�tj
j�|�d|�d���q�Wd�n1s�wYt�dd��r5tj
j j!dtdtdd��}|�"|tj
j j#ddgdd��Wd�|S1�s0wY|S)zL
    When we are asked to update (regular interval) lets reap the cache
    �cachedir�roots�hashZ	mtime_mapF�changed)rDr8Zbackendr�utf-8��encoding�:�r8z+Skipped invalid cache mtime entry in %s: %sNZremovedZadded�wb�
Zfileserver_eventsZmasterZsock_dir)�opts�listen�updater$��prefix)$r#r$Zreap_fileserver_cache_dirrrr!rr/�OSErrorZgenerate_mtime_mapr'r8r9�strip�rsplit�floatr7�appendr r�warning�UnicodeDecodeErrorZdiff_mtime_map�setr�dirname�exists�makedirs�items�writeZstringutils�to_bytes�eventZ	get_eventZ
fire_eventZtagify)Zmtime_map_pathr2Z
new_mtime_mapZ
old_mtime_mapr?�lineZ	file_path�mtimeZ	old_filesZ	new_filesZmtime_map_path_dirr_rrrrN�s|���������
"����
��rNcCs�d|vr	|�d�d|vsd|vrdS|d}|d}|tdvr)dtdvr)d}i}|r3tj�|�s5|Std|d<tj�tdd	d
|d�|dtd��}tj�|�r�zktj	j
j|d
d��X}z|���
d�\}}Wn,ty�t�d�zt�|�Wn	ty�Ynwt||�YWd�WSwttj�|��|kr�||d<|Wd�WSWd�n1s�wYWn$ty�t�d�zt�|�Wn	ty�Ynwt||�YSwtj	j�|td�|d<tj�|�}	tj�|	��s"zt�|	�Wnt�y!}
z|
jtjk�rn�WYd}
~
nd}
~
wwd�|dtj�|��}tj	j
�|d��}|�|�Wd�|S1�sHwY|S)zL
    Return a file hash, the hash type is set in the master config file
    rrr*rrrZ	hash_typerArBrCz
{}.hash.{}rrErFrHz=Fileserver attempted to read incomplete cache file. Retrying.N�hsumz>Fileserver encountered lock when reading cache file. Retrying.z{}:{}�w)rrrrr"r!�formatrZr#r'r8r9r;�splitr rr�unlinkrQ�	file_hash�str�getmtimeZ	hashutilsZget_hashrYr[�errnoZEEXISTZflopenr])r=rrr*r>�
cache_pathr?rbraZ	cache_dir�errZcache_objectrrrrg�s�
����
�
��
��
���
��rgcs�d|vr	|�d�|d}|}|tdvr&dtdvr$t�d|�d}ngStj�tddd�}tj�|�sOzt�|�Wnt	yNt�
d	|�gYSwtj�|tjj
�|��d
��}tj�|dtjj
�|��d��}tj�t|||�\}}}	|d
ur�|S|r�t�t�t�id���fdd�}
td|D]/}|dkr�|�d|�}tjjj|tdd�D]\}}
}|
�d|||
�|
�d|||�q�q�t�d��d<t�d��d<t�d��d<|	r�ztj�t�||�Wn	ty�Ynw��|g�SgS)zZ
    Return a dict containing the file lists for files, dirs, empty dirs and symlinks
    rr*rrr	rAZ
file_listsrBzUnable to make cachedir %sz.p�.z.wN)r8�dirs�
empty_dirs�linksc	s�dd�}|D]�}tj�||�}t�d|�tjj�|�}t�d||s$dnd�|r.tdr.q|tj�	||��}t�d||�tj
�t|�rFq|�|�tj�
|�rozt�|�s^�d	�|�Wntynt�d
|�Ynw|r�tjj�|�}	t�d||	�tjj��r�|	�d�r�t�d
|	|�|}	|	�d�r�tj�||	�}
ntj�tj�|�|	�}
|tj�	tj�tj�|
��tj�|���}t�d||�|�d�s�|	�d|<qtds�|	�d|<qdS)z9
            Add the files to the target set
            cSstjjdkr|�dd�S|S)zZ
                Translate path separators for Windows masterless minions
                �\�/)rr�sepr&)rrrr�_translate_sepusz4_file_lists.<locals>._add_to.<locals>._translate_sepzroots: Processing %szroots: %s is %sa linkznot rZfileserver_ignoresymlinkszroots: %s relative path is %srozUnable to list dir: %sz#roots: %s symlink destination is %sz\\z)roots: %s is a UNC path, using %s insteadz..rprN)rrr!rZtracer#r'�islinkr�relpathr$r%�add�isdir�listdirrQr�readlink�platformZ
is_windows�
startswithrYrr)ZtgtZfs_rootZ
parent_dirr\rt�itemZabs_path�is_linkZrel_pathZ	link_destZjoinedZrel_dest�r>rr�_add_topsj�

�����

��
��z_file_lists.<locals>._add_tor)�followlinksrnr8ro)rrrrrrr!rxr[rQ�criticalr#r'r8Zsafe_filename_leafr$Zcheck_file_list_cacherXr&Zos_walkr0Zwrite_file_list_cache�	NameErrorr7)r=Zformr*r,Z
list_cachedirZ
list_cacheZw_lockZcache_matchZ
refresh_cacheZ
save_cacher�rr-rnr8rrr�_file_listsFsn
����
�D���r�cC�
t|d�S)zV
    Return a list of all files on the file server in a specified
    environment
    r8�r��r=rrr�	file_list�s
r�cCr�)z>
    Return a list of all empty directories on the master
    ror�r�rrr�file_list_emptydirs��
r�cCr�)z8
    Return a list of all directories on the master
    rnr�r�rrr�dir_list�r�r�csrd|vr	|�d�i}|dtdvrdtdvr|Sd|vr'|d�d��nd�t|d�}�fd	d
�|��D�S)zK
    Return a dict of all symlinks based on a given path on the Master
    rr*rrrPrrrrpcs i|]\}}|���r||�qSr)r|)�.0�key�valrOrr�
<dictcomp>�s z symlink_list.<locals>.<dictcomp>)rrrRr�r\)r=r>�symlinksrrOr�symlink_list�s

r�)r)�__doc__rj�loggingrZsalt.fileserverr#Zsalt.utils.eventZsalt.utils.filesZsalt.utils.gzip_utilZsalt.utils.hashutilsZsalt.utils.pathZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.verifyZsalt.utils.versions�	getLogger�__name__rr/r1r@rNrgr�r�r�r�r�rrrr�<module>s4

P0IR