HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/cli/__pycache__/cp.cpython-310.pyc
o

�N�g1$�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlZddlZddlZddlZe�e�ZGdd�dejjj�ZGdd�d�ZdS)z�
The cp module is used to execute the logic used by the salt-cp command
line application, salt-cp is NOT intended to broadcast large files, it is
intended to handle text files.
Salt-cp can be used to distribute configuration files
�Nc@seZdZdZdd�ZdS)�	SaltCPCliz-
    Run the salt-cp command line client
    cCs|��t|j�}|��dS)z!
        Execute salt-cp
        N)�
parse_args�SaltCPZconfig�run)�selfZcp_�r�?/opt/saltstack/salt/lib/python3.10/site-packages/salt/cli/cp.pyr"s
z
SaltCPCli.runN)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)rzL
    Create a salt cp object, used to distribute simple files with salt
    cCs||_tjj��|_dS)N)�opts�salt�utils�platform�
is_windows)rr
rrr�__init__0szSaltCP.__init__c
CsF|jrdSzttt�|�j�dd�d�WStttfy"YdSw)N����)	r�int�oct�os�stat�st_mode�	TypeError�
IndexError�
ValueError)r�pathrrr�_mode4s �zSaltCP._modec	
Cs�i}g}zt�|�}WnLtyW}z@|jtjkr(tj�|�d��t�d�n"|jtj	tj
fvrA|�|�||<WYd}~||fSWYd}~||fSWYd}~||fSd}~ww|s_|�|�|D]}|�
tj�||��\}}|�|�|�|�qa||fS)z3
        Get a list of all specified files
        z does not exist
�*N)r�listdir�OSError�errno�ENOENT�sys�stderr�write�exit�EINVAL�ENOTDIRr�append�_recurser�join�update�extend)	rr�files�
empty_dirsZ	sub_paths�exc�fn_�files_�empty_dirs_rrrr+<s0	
�
���	

zSaltCP._recursecCsHi}t�}|jdD]}|�|�\}}|�|�|�|�q
|t|�fS)N�src)�setr
r+r-�sorted)rr/r0r2r3r4rrr�_list_filesVs
zSaltCP._list_filescCsxtj�|�sd|�d�}tj�|d�t�d�tjj	�
|d��}|��}Wd�||iS1s3wY||iS)zM
        Take a path and return the contents of the file as a string
        zThe referenced file, z is not available.�
r�rN)rr�isfiler$r%r&r'rrr/Zfopen�read)rr2�errZfp_�datarrr�
_file_dict_s


��zSaltCP._file_dictcCs`i}|jdD]&}tj�|�r|�|�|��qtj�|�r-tjj	�
d�|��t�
d�q|S)zs
        Parse the files indicated in opts['src'] and load them into a python
        object for transport
        r5zg{} is a directory, only files are supported in non-chunked mode. Use "--chunked" command line argument.�)r
rrr;r-r?�isdirrr�stringutilsZ	print_cli�formatr$r')rr/r2rrr�_load_filesks�
�zSaltCP._load_filescCs<|jdr
|��}n|��}tj�||j�dd�|j�dS)z+
        Make the salt client call
        �chunked�output�nestedN)r
�run_chunked�run_oldstylerrFZdisplay_output�get)r�retrrrr}s

 z
SaltCP.runcCs�|��|jdg}|jdd||jdg}|j�dd�}|dur%|�|�tj�|jd��
}|j|�Wd�S1s>wYdS)zO
        Make the salt client call in old-style all-in-one call method
        �dest�tgtzcp.recv�timeout�selected_target_optionN�	conf_file)rDr
rJr*r�client�get_local_client�cmd)r�arg�argsrO�localrrrrI�s�
$�zSaltCP.run_oldstylec
s����\}}�jd��jd}�jd}�jd}�j�d�}t|�p1t|�dkp1tt�d����|r9tjj	j
ntjjj}tjj
��j�j||pJdd	�}|d
}	����fdd�}
i}d
tj�tj��jd���}|��D]�\}
}|
|
�}d}i}||
�jdd�D]�}t�tjj�|��}|dk}t�d|
|r�|�d�nd|||r�d|�d�nd�|d|||||g|g}|dur�|�|�|j|�}|s�d�|dkr�dnd�jd�}|	D]
}||�|i�|<q�n$|��D]\}}||�|i�|<|du�r||v�r|||<q�|d7}q�|��D]\}}||||<�qqo|D]>}|
|�}t�d||�r/|�d�nd|�|d|dg|g}|du�rE|�|�|j|���D]
\}}||�|i�|<�qL�q|Wd�S1�siwYdS)zT
        Make the salt client call in the new fasion chunked multi-call way
        rL�gziprMrNrOr@z[\\/]$�glob)Ztgt_type�minionscs�|�jdvr�rtj��tj�|��S�S�jdD]}tj�||tj�}|���r-qtj��tj�|�|�St�	d|�dS)Nr5z!Failed to find remote path for %s)
r
rrr,�basename�relpath�sep�
startswith�log�error)r2rr[�rLZdest_is_dir�parentrrr�_get_remote_path�s��
z,SaltCP.run_chunked.<locals>._get_remote_pathz..rPZsalt_cp_chunk_size)Z
chunk_sizez#Copying %s to %starget '%s' as %s%s� �z	 (chunk #�)zcp.recv_chunkedNzXPublish failed.{} It may be necessary to decrease salt_cp_chunk_size (current value: {})z File partially transferred.Tz&Creating empty dir %s on %starget '%s')r8r
rJ�bool�len�re�searchrrZ	gzip_utilZ
compress_file�	itertoolsZ	read_filerYZ	CkMinionsZ
check_minionsrr\rQrR�items�base64�	b64encoderB�to_bytesr^�debugr*rSrC�
setdefault)rr/r0rWrMrNrO�readerZ_resrYrbrKrVr2�modeZremote_path�indexZfailed�chunkr*rU�result�msgZminionZ	minion_idZ
minion_ret�dirnamerr`rrH�s�



"����
�	�

���
��

�&�zSaltCP.run_chunkedN)
r	r
rrrrr+r8r?rDrrIrHrrrrr+s	r)rrlr"�loggingrrhr$Zsalt.clientrZsalt.outputZsalt.utils.filesZsalt.utils.gzip_utilZsalt.utils.itertoolsZsalt.utils.minionsZsalt.utils.parsersZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.verify�	getLoggerr	r^r�parsersZSaltCPOptionParserrrrrrr�<module>s(