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__/svnfs.cpython-310.pyc
o

�N�g2d�@s�dZddlZddlZddlZddlZddlZddlZddlZddlmZddl	Z
ddlZ
ddlZ
ddl
Z
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlmZddlmZddlmZdZdZzddlZd	Ze��ZWn	eysYnwe�e �Z!d
Z"dZ#dd
�Z$dd�Z%dd�Z&dd�Z'dd�Z(dd�Z)d3dd�Z*d3dd�Z+dd�Z,dd�Z-d4d d!�Z.d"d#�Z/d5d%d&�Z0d'd(�Z1d)d*�Z2d+d,�Z3d-d.�Z4d/d0�Z5d1d2�Z6dS)6a
Subversion Fileserver Backend

After enabling this backend, branches and tags in a remote subversion
repository are exposed to salt as different environments. To enable this
backend, add ``svnfs`` to the :conf_master:`fileserver_backend` option in the
Master config file.

.. code-block:: yaml

    fileserver_backend:
      - svnfs

.. note::
    ``svn`` also works here. Prior to the 2018.3.0 release, *only* ``svn``
    would work.

This backend assumes a standard svn layout with directories for ``branches``,
``tags``, and ``trunk``, at the repository root.

:depends:   - subversion
            - pysvn

.. versionchanged:: 2014.7.0
    The paths to the trunk, branches, and tags have been made configurable, via
    the config options :conf_master:`svnfs_trunk`,
    :conf_master:`svnfs_branches`, and :conf_master:`svnfs_tags`.
    :conf_master:`svnfs_mountpoint` was also added. Finally, support for
    per-remote configuration parameters was added. See the
    :conf_master:`documentation <svnfs_remotes>` for more information.
�N)�datetime)�DEFAULT_HASH_TYPE��FileserverConfigError)�tagify)�
mountpoint�root�trunk�branches�tagsFT�svnfs)�svncCs�ttdvrdStst�d�dSg}dD]}tj�t|�r*|�d�	|t|��q|r>|D]}t�|�q/t�d�dStS)z.
    Only load if subversion is available
    Zfileserver_backendFzfSubversion fileserver backend is enabled in configuration but could not be loaded, is pysvn installed?)Zsvnfs_trunkZsvnfs_branchesZ
svnfs_tagszJMaster configuration parameter '{}' (value: {}) cannot be an absolute pathz-Subversion fileserver backed will be disabled)
�__virtualname__�__opts__�HAS_SVN�log�error�os�path�isabs�append�format)�errors�paramr�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/svnfs.py�__virtual__Ms*���
rcCspz
tt�|d����}Wn%tjjttt	fy2}zt
�d|d|d|�WYd}~dSd}~ww|djS)z%
    Returns revision ID of repo
    �repozCError retrieving revision ID for svnfs remote %s (cachedir: %s): %s�urlN�revision)
�dict�CLIENT�info�items�pysvn�_pysvn�ClientError�	TypeError�KeyError�AttributeErrorrr�number)rZ	repo_info�excrrr�_revhs���
r,cCstd��)zB
    Fatal fileserver configuration issue, raise an exception
    z%Failed to load svn fileserver backendrrrrr�	_failhardzsr-cCs tj�tdd�}d}g}i}tD]
}ttd|���||<qtdD�]}t�|�}t|t	�rut
t|��}dd�tj
j�||���D�}|sQt�d|�t�d}	d	d
�|D�D]}t�d||d�t��d
}	qZ|	rot�|�|�n|}t|t�s�t�d|�t�z
tj
j�|d�|d<Wn	ty�Ynwttt�dt��}
|
|���}tj�||�}tj�|�s�t�|�t�|�s�zt �!||�|�"|�d
}WnEt#j$j%y�}
zt�d||
�t�WYd}
~
n,d}
~
wwzt �&|�Wnt#j$j%�y}
zt�d||�t�WYd}
~
nd}
~
ww|�||||tj�|d�d��|�"|�q#|�r�tj�tdd�}zCtj
j'�(|d��0}t)�*��+d�}|�,d|�d��|D]}|�,tj
j-�.d�/|d|d����qUWd�n	1�svwYWnt0�y�Y|Swt�1d|�|S)zL
    Return the list of svn remotes and their configuration information
    �cachedirrFZsvnfs_Z
svnfs_remotescSsi|]	\}}|t|��qSr)�str)�.0�key�valrrr�
<dictcomp>�s��zinit.<locals>.<dictcomp>z�Invalid per-remote configuration for remote %s. If no per-remote parameters are being specified, there may be a trailing colon after the URL, which should be removed. Check the master configuration file.css�|]	}|tvr|VqdS�N)�PER_REMOTE_OVERRIDES�r0�xrrr�	<genexpr>�s�zinit.<locals>.<genexpr>z|Invalid configuration parameter '%s' for remote %s. Valid parameters are: %s. See the documentation for further information.z, Tz[Invalid svnfs remote %s. Remotes must be strings, you may need to enclose the URL in quotesr�	hash_typez*Failed to initialize svnfs remote '%s': %sNz�Cache path %s (corresponding remote: %s) exists but is not a valid subversion checkout. You will need to manually delete this directory on the master to continue to use this svnfs remote.z	update.lk)rr�hashr.�lockfilezsvnfs/remote_map.txt�w+z%d %b %Y %H:%M:%S.%fz# svnfs_remote map as of �
z{} = {}
r:rz Wrote new svnfs_remote map to %s)2rr�joinrr5r/�copy�deepcopy�
isinstancer �next�iter�salt�utils�dataZrepack_dictlistr#rrr-�updaterZstrip_protor'�getattr�hashlib�getr�	hexdigest�isdir�makedirs�listdirr!Zcheckoutrr$r%r&�status�files�fopenr�now�strftime�write�stringutilsZto_strr�OSErrorr")�bp_Z
new_remote�reposZper_remote_defaultsr�remoteZ	repo_confZrepo_urlZper_remote_confZper_remote_errorsr9Z	repo_hashZrp_r+Z
remote_map�fp_�	timestamprrr�init�s�

����
���


�������	�����	�r\cCs2tj�tdd�}zt�|�}Wntyg}Ynwt�}|D]}z	|�|d�Wq!ty5Yq!wg}|D]}|dvrAq:tj�||�}tj�	|�rS|�
|�q:g}|r�|D].}zt�|�Wnty�}	zt
�d||	�|�
|�WYd}	~	qZd}	~	wwt
�d|�qZ|D]}
|�|
�q�t|�|fS)zC
    Remove cache directories for remotes no longer configured
    r.rr:)r:Zrefsz1Unable to remove old svnfs remote cachedir %s: %sNzsvnfs removed old cachedir %s)rrr>rrNrVr\�remove�
ValueErrorrLr�shutil�rmtreerr�debug�bool)rWZcachedir_lsrXr�	to_remove�itemr�failed�rdirr+Zfdirrrr�_clear_old_remotessJ��
����rgcCs�tj�tdd�}tj�tdd�}g}||fD]-}tj�|�rEzt�|�WqtyD}z|�d|�d|���WYd}~qd}~wwq|S)z&
    Completely clear svnfs cache
    r.r�file_lists/svnfszUnable to delete z: N)	rrr>r�existsr_r`rVr)Zfsb_cachedir�
list_cachedirrrfr+rrr�clear_cache)s"���rkc	Cs�dd�}t|t�r
||�Sg}g}t�D]2}|r6z
||dvr!WqWnty5t|�|dvr3YqYnw||�\}}|�|�|�|�q||fS)z�
    Clear update.lk

    ``remote`` can either be a dictionary containing repo configuration
    information, or a pattern. If the latter, then remotes for which the URL
    matches the pattern will be locked.
    c
Ssdd�}g}g}tj�|d�r�z	t�|d�WnUtyn}zI|jtjkrIz	t�|d�Wn'tyH}z||||�WYd}~nd}~ww||||�WYd}~||fSWYd}~||fSWYd}~||fSd}~wwd�	|d�}t
�|�|�|�||fS)NcSs.d�|d|d|�}t�|�|�|�dS)Nz-Unable to remove update lock for {} ({}): {} rr;)rrrar)Zerrlistrr+�msgrrr�
_add_errorCs
�
z6clear_lock.<locals>._do_clear_lock.<locals>._add_errorr;zRemoved lock for {}r)
rrrir]rV�errnoZEISDIRr_r`rrrar)rrm�successrer+rlrrr�_do_clear_lockBs4��
�	
���

z"clear_lock.<locals>._do_clear_lockr)rAr r\r'r/�extend)rYrpZclearedrrrorerrr�
clear_lock9s(	

���
rrc	Cs�dd�}t|t�r
||�Sg}g}t�D]6}|r:zt�|d|�s#WqWnty9t�|dt|��s7YqYnw||�\}}|�|�|�|�q||fS)z�
    Place an update.lk

    ``remote`` can either be a dictionary containing repo configuration
    information, or a pattern. If the latter, then remotes for which the URL
    matches the pattern will be locked.
    c
Ss�g}g}tj�|d�siz!tjj�|dd��
}|�d�Wd�n1s'wYWn*tyW}zd�	|d|d|�}t
�|�|�|�WYd}~||fSd}~wwd�	|d�}t
�|�|�|�||fS)Nr;r<�z*Unable to set update lock for {} ({}): {} rzSet lock for {})
rrrirDrErPrQrTrVrrrar)rrorerZr+rlrrr�_do_lock}s*���
��

zlock.<locals>._do_lockr)rAr r\�fnmatchr'r/rq)rYrt�lockedrrrorerrr�lockts(	

���
rwc
CsTddd�}t�\|d<}|D]y}tj�|d�r$t�d|d|d�qt|�\}}|r5t�d|d�qt�d	|d�t	|�}z	t
�|d
�Wn tj
jyj}zt�d|d|d|�WYd
}~nd
}~wwt	|�}tdd�||fD��r{q||kr�d|d<t|�qtj�tdd�}|�dd�dus�tj�|�s�tj�|�}	tj�|	�s�t�|	�tdd�}
tjj�|d��}|�tj�|
��t�d|�Wd
�n1s�wYt�dd��r
tjj j!dtdtdd��}|�"|t#ddgdd��Wd
�n	1�swYztj$�%tj�tdd�t&�Wd
St'�y)Yd
Sw)z3
    Execute an svn update on all of the repos
    Fr)�changedZbackendrxr;z�Update lockfile is present for svnfs remote %s, skipping. If this warning persists, it is possible that the update process was interrupted. Removing %s or running 'salt-run fileserver.clear_lock svnfs' will allow updates to continue for this remote.rz8Unable to set update lock for svnfs remote %s, skipping.zsvnfs is fetching from %srz1Error updating svnfs remote %s (cachedir: %s): %sr.Ncss�|]}|duVqdSr4rr6rrrr8���zupdate.<locals>.<genexpr>T�svnfs/envs.p)�ignore_cachezwb+zWrote env cache data to %sZfileserver_eventsZmasterZsock_dir)�opts�listenrG�
fileserver)�prefixz
svnfs/hash)(rgrrrir�warningrwrrar,r!rGr$r%r&�anyrrr>rrJ�isfile�dirnamerM�envsrDrErPrQrT�payload�dumpsZtrace�eventZ	get_eventZ
fire_eventrr~Zreap_fileserver_cache_dir�	find_filerV)
rFrXr�_rZold_revr+Znew_rev�	env_cacheZenv_cachedirZnew_envsrZr�rrrrG�s|
�	����


���
��rGcCstjjj|tdtdd�S)zc
    Check if an environment is exposed by comparing it against a whitelist and
    blacklist.
    Zsvnfs_saltenv_whitelistZsvnfs_saltenv_blacklist)Z	whitelistZ	blacklist)rDrErUZcheck_whitelist_blacklistr)�envrrr�_env_is_exposed�s
�r�cCs,|stj�tdd�}tj�t|�}|dur|St�}t�D]n}tj�|d|d�}tj�	|�r7|�
d�nt�d|d|d�tj�|d|d	�}tj�	|�r\|�
t�|��nt�d
|d	|d�tj�|d|d�}tj�	|�r�|�
t�|��qt�d|d|d�qd
d�t|�D�S)z@
    Return a list of refs that can be used as environments
    r.rzNrr	�basezdsvnfs trunk path '%s' does not exist in repo %s, no base environment will be provided by this remoterr
z2svnfs branches path '%s' does not exist in repo %srz.svnfs tags path '%s' does not exist in repo %scSsg|]}t|�r|�qSr)r�r6rrr�
<listcomp>'szenvs.<locals>.<listcomp>)rrr>rrDr~Zcheck_env_cache�setr\rL�addrrrGrN�sorted)r{r��cache_match�retrr	r
rrrrr��s@
���r�cCs�|dkrtj�|d|d�}tj�|�r|SdStj�|d|d�}tj�|�r8|t�|�vr8tj�||�Stj�|d|d�}tj�|�rW|t�|�vrWtj�||�SdS)z�
    Return the root of the directory corresponding to the desired environment,
    or None if the environment was not found.
    r�rr	Nr
r)rrr>rLrN)r�saltenvr	r
rrrr�	_env_root*sr�r�c	Ksddd�}tj�|�s|t�vr|St�D]h}t||�}|dur!q|dr1|�|dtjj�s1q|t|d�d��	tjj�}|drMtj�
|d|�}tj�
||�}tj�|�r}||d<||d<ztt�
|��|d<W|Sty|Y|Swq|S)	z�
    Find the first file to match the path and ref. This operates similarly to
    the roots file sever but with assumptions of the directory structure
    based on svn standard practices.
    rs)r�relNrrr�r�stat)rrrr�r\r��
startswith�sep�len�lstripr>r��listr��	Exception)rZtgt_env�kwargs�fndr�env_rootZ	repo_path�fullrrrr�Ds2



���r�csd�vr	��d�ddd�}t�fdd�dD��s|S|ds!|S|d|d	<��d
d�}tj�|d�}tjj�	|d��9}|�
�d
�|�td�}|rZtjj�
|�sZ|�t�}|rj|rjtjj�||�}||d
<||d<Wd�|S1sywY|S)z?
    Return a chunk from a file based on the data received
    r�rs)rF�destc3��|]}|�vVqdSr4rr6��loadrrr8zryzserve_file.<locals>.<genexpr>)r�locr�rr�r��gzipN�rbr�Zfile_buffer_sizerF)�pop�allrJrr�normpathrDrErPrQ�seek�readrZ	is_binary�decodeZ__salt_system_encoding__Z	gzip_util�compress)r�r�r�r�ZfpathrZrFrr�r�
serve_fileqs.




�	�	r�cs�d�vr	��d�t�fdd�dD��sdS�d}|dkr d}i}|d	}|d
}|r2tj�|�s4|Std|d<tj�tdd
d|d�|td��}tj�|�r�t	j
j�|d��&}|�
��d�\}}	tj�|�|	kry||d<|Wd�SWd�n1s�wYt	j
j�|td�|d<tj�|�}
tj�|
�s�t�|
�t	j
j�|d��}|�d�|dtj�|���Wd�|S1s�wY|S)zL
    Return a file hash, the hash type is set in the master config file
    r�c3r�r4rr6r�rrr8�ryzfile_hash.<locals>.<genexpr>)rr�rsr�r�r	r�rr9r.rr:z
{}.hash.{}r��:�hsumN�wz{}:{})r�r�rrr�rr>rrirDrErPrQr��split�getmtimeZ	hashutilsZget_hashr�rMrT)r�r�r�r��relpathr�
cache_pathrZr��mtimeZ	cache_dirrr�r�	file_hash�sN
���
 
��r�c	Cs@d|vr	|�d�d|vs|dt�vrgStj�tdd�}tj�|�s>zt�|�Wnty=t	�
d|�gYSwtj�|d�|d��}tj�|d�|d��}tj
�t|||�\}}}|durh|S|�rt�t�t�d	�}t�D]y}	t|	|d�}
|
dur�qw|	d
r�tj�|
|	d
��tjj�}
tj�|
�s�qwtjj�|
�D]J\}}}
tj�||
�}tj�|	d|�}|dkr�|d
�|�|s�|
s�|d�|�|
D]}tj�tj�||�|
�}|d�tj�|	d|��q�q�qw|	dr�|d
�|	d�|D]}t||�||<�q|�rtj
�t|||�|�|g�SgS)zY
    Return a dict containing the file lists for files, dirs, emptydirs and symlinks
    r�r�r.rhzUnable to make cachedir %sz{}.pz.{}.wN)rP�dirs�
empty_dirsrr�.r�r�rP)r�r�rrr>rrLrMrVr�criticalrrDr~Zcheck_file_list_cacher�r\r��rstripr�rEZos_walkr�r�r�Zwrite_file_list_cacherJ)r�ZformrjZ
list_cacheZw_lockr�Z
refresh_cacheZ
save_cacher�rr�rr�rPr�Z
dir_rel_fn�fnameZrel_fnr1rrr�_file_lists�sb
�
�
��
r�cC�
t|d�S)zV
    Return a list of all files on the file server in a specified
    environment
    rP�r�r�rrr�	file_lists
r�cCr�)z>
    Return a list of all empty directories on the master
    r�r�r�rrr�file_list_emptydirs�
r�cCr�)z8
    Return a list of all directories on the master
    r�r�r�rrr�dir_listr�r�r4)F)r�)7�__doc__r?rnrurI�loggingrr_rZsalt.fileserverrDZsalt.utils.dataZsalt.utils.filesZsalt.utils.gzip_utilZsalt.utils.hashutilsZsalt.utils.pathZsalt.utils.stringutilsZsalt.utils.urlZsalt.utils.versionsZsalt.configrZsalt.exceptionsrZsalt.utils.eventrr5rr$ZClientr!�ImportError�	getLogger�__name__rrZ__virtual_aliases__rr,r-r\rgrkrrrwrGr�r�r�r�r�r�r�r�r�r�rrrr�<module>sj �
(

;1L
-
-7<