HEX
Server: Apache
System: Linux nc-ph-4101.simplemoneygoals.com 5.14.0-503.21.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jan 12 09:45:05 EST 2025 x86_64
User: dailygoldindex (1004)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/sos/__pycache__/archive.cpython-39.opt-1.pyc
a

\��h3r�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZzddlZWney�Yn0dZdZdZd	ZGd
d�d�ZGdd
�d
e�ZGdd�de�ZdS)�N)�datetime)�Lock)�	find_spec)�sos_get_command_output�file�linkZnode�dirc@s�eZdZdZedd��Ze�d�ZdZ	dZ
e�Zdd�Z
d	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zd-dd�Zd.dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdS)/�Archivez!Abstract base class for archives.cCs|jS)z6Returns the archive class's name as a string.
        )�__name__)�cls�r�//usr/lib/python3.9/site-packages/sos/archive.py�archive_type+szArchive.archive_typeZsosZunsetFcCsd|���d|��S)Nz	[archive:z] )r��self�msgrrr
�_format_msg8szArchive._format_msgcCs
||_dS�N)�_debug)r�debugrrr
�	set_debug;szArchive.set_debugcCs|j�|�|��dSr)�log�errorrrrrr
�	log_error>szArchive.log_errorcCs|j�|�|��dSr)rZwarningrrrrr
�log_warnAszArchive.log_warncCs|j�|�|��dSr)r�inforrrrr
�log_infoDszArchive.log_infocCs |js
dS|j�|�|��dSr)rrrrrrrr
�	log_debugGszArchive.log_debugcCs|jSr)�_name�rrrr
�nameLszArchive.nameNcCst�dSr��NotImplementedError)r�src�dest�forcerrr
�add_fileRszArchive.add_file�wcCst�dSrr!)r�contentr$�moderrr
�
add_stringUszArchive.add_stringcCst�dSrr!)rr(r$rrr
�
add_binaryXszArchive.add_binarycCst�dSrr!)r�source�	link_namerrr
�add_link[szArchive.add_linkcCst�dSrr!�r�pathrrr
�add_dir^szArchive.add_dircCst�dSrr!)rr0r)�devicerrr
�add_nodeaszArchive.add_nodecCst�dS)z�Return a temporary directory that clients of the archive may
        use to write content to. The content of the path is guaranteed
        to be included in the generated archive.Nr!rrrr
�get_tmp_dirdszArchive.get_tmp_dircCst�dS)z�Return the maximum file name length this archive can support.
        This is the lesser of the name length limit of the archive
        format and any temporary file system based cache.Nr!rrrr
�name_maxjszArchive.name_maxcCst�dS)aTReturn a string representing the path to the temporary
        archive. For archive classes that implement in-line handling
        this will be the archive file itself. Archives that use a
        directory based cache prior to packaging should return the
        path to the temporary directory where the report content is
        locatedNr!rrrr
�get_archive_pathpszArchive.get_archive_pathcCst�dS)z:Clean up any temporary resources used by an Archive class.Nr!rrrr
�cleanupyszArchive.cleanupcCst�dS)aFinalize an archive object via method. This may involve creating
        An archive that is subsequently compressed or simply closing an
        archive that supports in-line handling. If method is automatic then
        the following methods are tried in order: xz, gzipNr!�r�methodrrr
�finalize}szArchive.finalize)NF)r')r
�
__module__�__qualname__�__doc__�classmethodr�loggingZ	getLoggerrrrr�
_path_lockrrrrrrr r&r*r+r.r1r3r4r5r6r7r:rrrr
r	(s2



	r	c@s�eZdZdZdZdZdZd7dd�Zdd�Zdd	�Z	d8dd�Z
d9dd�Zdd�Zd:dd�Z
d;dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd<d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�ZdS)=�FileCacheArchivezd Abstract superclass for archive types that use a temporary cache
    directory in the file system. �NcCs�||_tj�|j|g�|kr,tj�||�|_||_||_||_||_|pJd|_	||_
tj�||�|_|j
�t�|jd�Wd�n1s�0Y|�d|j�d��dS)N�/�z'initialised empty FileCacheArchive at '�')r�osr0�commonprefix�relpath�_tmp_dirZ_policyZ_threads�enc_opts�sysroot�manifest�join�
_archive_rootr@�makedirsr�rr ZtmpdirZpolicy�threadsrJrKrLrrr
�__init__�s
,�zFileCacheArchive.__init__cCs(tj�|�r|�tj�}tj�|j|�Sr)rFr0�isabs�lstrip�seprMrN)rr rrr
�	dest_path�szFileCacheArchive.dest_pathcCs@|jr|�|j�r|S|dtjkr0|dd�}tj�|j|�S)Nr�)rK�
startswithrFrUr0rMr/rrr
�join_sysroot�s
zFileCacheArchive.join_sysrootrDcs�|�d|���|j�|}�fdd�}|�d�s6|}n&tj�|�|��rL|ntj�|�d}|}g}|dvr�tj�|�\}}	|�|	�|}qd|�	��}
d}|D�]}tj�
|
|�}
||
�s�q�tj�
||�}tj�|
�s�|�d|
���tj�|��r�tj�|��r�t�
|�}
tj�|�d}tj�
||
�}|j||d�}tj�|�}tj�|
��rbtj�|
|�}
|�d	|
�d
|
�d��t�|
|
�q�|�d|
���t�|
|�|}q�|S)
a�Create leading path components

            The standard python `os.makedirs` is insufficient for our
            needs: it will only create directories, and ignores the fact
            that some path components may be symbolic links.

            :param src: The source path in the host file system for which
                        leading components should be created, or the path
                        to an sos_* virtual directory inside the archive.

                        Host paths must be absolute (initial '/'), and
                        sos_* directory paths must be a path relative to
                        the root of the archive.

            :param mode: An optional mode to be used when creating path
                         components.
            :returns: A rewritten destination path in the case that one
                      or more symbolic links in intermediate components
                      of the path have altered the path destination.
        zMaking leading paths for cs|�tj��d��S)z>Test whether path ``path`` is inside the archive.
            rB)rXrFr0rM)r0��rootrr
�
in_archive�sz8FileCacheArchive._make_leading_paths.<locals>.in_archiverCr)rCrBzMaking path �r)zMaking symlink '�' -> 'rEzMaking directory )rrNrXrFr0�isdirrY�split�append�reverserM�exists�islink�readlink�_make_leading_paths�normpathrSrH�symlink�mkdir)rr#r)r$r\�src_dirr0Z
path_comps�head�tailZabs_pathZsrc_path�comp�targetZ
target_dirZ
target_srcrrZr
rf�sR
�


�
z$FileCacheArchive._make_leading_pathsFc
Cs\|p|�|�}|tkr|}ntj�|�d}|s4|Stj�|�r\tj�|�s\td|�d���tj�|�s�|tkrt|ntj�|�d}|�|�dd�}|r�|Stj�|��rXt�	|�}d}	|t
kr�t�|j
�s�t|	|df��|tk�rt�|j
��st|	|df��|tk�r,||j
��s,t|	|d	f��|tk�rTt�|j
��sTt|	|d
f��dS|S)a4Check a new destination path in the archive.

            Since it is possible for multiple plugins to collect the same
            paths, and since plugins can now run concurrently, it is possible
            for two threads to race in archive methods: historically the
            archive class only needed to test for the actual presence of a
            path, since it was impossible for another `Archive` client to
            enter the class while another method invocation was being
            dispatched.

            Deal with this by implementing a locking scheme for operations
            that modify the path structure of the archive, and by testing
            explicitly for conflicts with any existing content at the
            specified destination path.

            It is not an error to attempt to create a path that already
            exists in the archive so long as the type of the object to be
            added matches the type of object already found at the path.

            It is an error to attempt to re-create an existing path with
            a different path type (for example, creating a symbolic link
            at a path already occupied by a regular file).

            :param src: the source path to be copied to the archive
            :param path_type: the type of object to be copied
            :param dest: an optional destination path
            :param force: force file creation even if the path exists
            :returns: An absolute destination path if the path should be
                      copied now or `None` otherwise
        rzpath 'z' exists and is not a directorycSs(tt�|�t�|�t�|�t�|�g�Sr)�any�stat�S_ISBLK�S_ISCHR�S_ISFIFO�S_ISSOCKr]rrr
�
is_special7s�z/FileCacheArchive.check_path.<locals>.is_specialz path '%s' exists and is not a %szregular filez
symbolic linkzspecial fileZ	directoryN)rV�P_DIRrFr0r`rcr_�
ValueErrorrf�lstat�P_FILErp�S_ISREG�st_mode�P_LINK�S_ISLNK�P_NODE�S_ISDIR)
rr#�	path_typer$r%�dest_dirrjru�stZve_msgrrr
�
check_paths6

zFileCacheArchive.check_pathc
Cs�zdt�|�}|�d�s |�d�rDt�||�tj||j|jfd�nt�||�t�	||j
|j�Wn<ty�}z$|�
d|�d|�d��WYd}~n
d}~00dS)N�/sys/�/proc/)�nszcaught 'z' setting attributes of 'rE)rFrprX�shutil�copymode�utime�st_atime_ns�st_mtime_ns�copystat�chown�st_uid�st_gid�	Exceptionr)rr#r$�_stat�errr
�_copy_attributesSs
z!FileCacheArchive._copy_attributescCsP|j��2|s|}|j|t|d�}|s6Wd�dSt|dd�s�zt�||�WnRty�}z:|�d�s�|�d�rxn|�d|�d|�d��WYd}~n
d}~00|�	||�d|�d�}nR|�
d�t|d	d
d��$}|D]}|�|�q�Wd�n1�s0Yd}|�
d
|�d|j�d��Wd�n1�sB0YdS)N�r%�readr�r�zFile z not collected: 'rErr'�utf-8��encodingz	open filezadded z to FileCacheArchive ')r@r�ry�getattrr��copy�OSErrorrXrr��seek�open�writerrN)rr#r$r%r��	file_name�f�linerrr
r&`s.
.
,�zFileCacheArchive.add_filer'c	Cs�|j��|}|j|tdd�}tj||dd��b}t|t�rD|�dd�}|�|�t	j
�|�rf|�||�|�
d|�d|j�d	��Wd�n1s�0YWd�n1s�0YdS)
NTr�r�r��utf8�ignorezadded string at 'z' to FileCacheArchive 'rE)r@r�ry�codecsr��
isinstance�bytes�decoder�rFr0rcr�rrN)rr(r$r)r#r�rrr
r*�s

�zFileCacheArchive.add_stringc	Cs�|j��|�|t�}|s(Wd�dStj|ddd��}|�|�Wd�n1sX0Y|�d|�d|j�d��Wd�n1s�0YdS)N�wbr�zadded binary content at 'z' to archive 'rE)r@r�ryr�r�r�rrN)rr(r$r�rrr
r+�s(�zFileCacheArchive.add_binaryc	
Cs�|�d|�d|�d��|j�h|�|t�}|s@Wd�dStj�|�sxt�||�|�d|�d|�d|j�d��Wd�n1s�0Y|�d|�d|�d	|���tj�	|�}tj�
tj�||��}|�|�}d
d�}tj�
|��s�tj�|��r�|}tj�	|�}tj�|t�|��}tj�||�}|||��r\|�d|�d
|�d��dS|�d|�d|�d��|�||�nntj�|��r�|�d|�d��|�|�nBtj�|��r�|�d|�d��|�|�n|�d|�d|���dS)Nzadding symlink at 'r^rEzadded symlink at 'z' to 'z' in archive 'zLink follow up: source=z link_name=z dest=c
Ss�tj�|�}tj�|�s.tj�tj�||��}tj�|�}||krFdSzt�|�Wn>ty�}z&|jdkr|WYd}~dS�WYd}~n
d}~00dS)z�Return ``True`` if the symbolic link ``link_name`` is part
                of a file system loop, or ``False`` otherwise.
            T�(NF)	rFr0�dirnamerS�realpathrMrpr��errno)r-r,Zlink_dirr�rrr
�is_loop�s
z*FileCacheArchive.add_link.<locals>.is_loopzLink 'z' - 'z' loops: skipping...zAdding link z -> z for link follow upzAdding dir zAdding file zNo link follow up: source=)rr@r�r|rFr0�lexistsrhrNr�r�rMrVrcrdrerHr.r_r1�isfiler&)	rr,r-r$Z
source_dirZhost_path_nameZdest_path_namer�r�rrr
r.�sJ�(�
�zFileCacheArchive.add_linkcCs6|j�|�|t�Wd�n1s(0YdS)zmCreate a directory in the archive.

            :param path: the path in the host file system to add
        N)r@r�rvr/rrr
r1�szFileCacheArchive.add_dirc
Cs�|�|t�}|sdStj�|�s�zt�|||�Wn^ty�}zF|jtjkrxd}|�	d|�d|�d��WYd}~dS|�WYd}~n
d}~00|�
||�dS)NzOperation not permittedz
add_node: z
 - mknod 'rE)r�r~rFr0rc�mknodr�r��EPERMrr�)rr0r)r2r$r�rrrr
r3�szFileCacheArchive.add_nodecCs&dtjvr"tjd}t�|j|�SdS)N�PC_NAME_MAX�)rF�pathconf_names�pathconfrN)rZpc_name_maxrrr
r5s

zFileCacheArchive.name_maxcCs|jSr�rNrrrr
r4	szFileCacheArchive.get_tmp_dircCs|jSrr�rrrr
r6sz!FileCacheArchive.get_archive_pathcCs8tjtj�|j|�|d�|�d|�d|j�d��dS)zsCreate path, including leading components.

            Used by sos.sosreport to set up sos_* directories.
        r]zcreated directory at 'z' in FileCacheArchive 'rEN)rFrOr0rMrNr)rr0r)rrr
rOs�zFileCacheArchive.makedirscCs|�|�}tj|dddd�S)N�rr�r�)r��errors)rVr�r�r/rrr
�	open_files
zFileCacheArchive.open_filecCstj�|j�rt�|j�dSr)rFr0r_rNr��rmtreerrrr
r7szFileCacheArchive.cleanupcCsft��}|jj}||}|j�d|�|j�d|�|j�d|�|�|jjdd�tj�	dd��dS)	z�Adds component-agnostic data to the manifest so that individual
        SoSComponents do not need to redundantly add these manually
        Zend_time�run_time�compression�)�indent�sos_reportsz
manifest.jsonN)
rZnowrLZ
start_timeZ	add_fieldr*Zget_jsonrFr0rM)rr9�end�startr�rrr
�add_final_manifest_data s�z(FileCacheArchive.add_final_manifest_datacCsN|�|j�|_tj�|j|j�}t�|j|�||_tj�|j|���|_	dS)zeRename the archive to an obfuscated version using an initialized
        SoSCleaner instance
        N)
Zobfuscate_stringrrFr0rMrI�renamerNr �
_archive_name)rZcleanerZ	_new_rootrrr
�rename_archive_root-s
z$FileCacheArchive.rename_archive_rootcCs�tjtjB}t|d�r(|j}|j|B}n|}|}d}|�|��}|��}Wd�n1s\0Yt|t	�s||�
dd�}tj||||d�\}	}
|
r�|�|	|�nd}
|
S)a�Apply a regexp substitution to a file in the archive.

        :param path: Path in the archive where the file can be found
        :type path: ``str``

        :param regexp:  A regex to match the contents of the file
        :type regexp: ``str`` or compiled ``re`` object

        :param subst: The substitution string to be used to replace matches
                      within the file
        :type subst: ``str``

        :returns: Number of replacements made
        :rtype: ``int``
        �patternrBNr�r�)�flagsr)
�re�
IGNORECASE�	MULTILINE�hasattrr�r�r�r�r��strr��subnr*)rr0Zregexp�substZcommon_flagsr�r�r(�readable�resultZreplacementsrrr
�do_file_sub7s$
&

�
zFileCacheArchive.do_file_subc
Cs�|�d|j�d|�d��z|�|�}Wn<tyd}z$|�d|���|��WYd}~Sd}~00|��|�d|j�dt�	|j�j
�d��|jd�r�z|�|�WSt�y�}z(d	}|�|�d
|���|WYd}~Sd}~00n|SdS)Nzfinalizing archive 'z' using method 'rEz+An error occurred compressing the archive: zbuilt archive at 'z' (size=�)Zencryptz)An error occurred encrypting the archive:� )
rrN�_build_archiver�rr r7r�rFrp�st_sizerJ�_encrypt)rr9�res�errr�Zexp_msgrrr
r:\s(�
�
zFileCacheArchive.finalizecCs�|�dd�}|d7}d|�d�}d}|jdrL|d|jd�d�7}||7}|jd	r�|jd	�d
d�}d|i}|d
7}d|�d�}||7}t|d|dd�}|ddkr�|S|ddkr�|jdr�d}q�d}nd|d�d|d��}t|��dS)a�Encrypts the compressed archive using GPG.

        If encryption fails for any reason, it should be logged by sos but not
        cause execution to stop. The assumption is that the unencrypted archive
        would still be of use to the user, and/or that the end user has another
        means of securing the archive.

        Returns the name of the encrypted archive, or raises an exception to
        signal that encryption failed and the unencrypted archive name should
        be used.
        z
sosreport-zsecured-sosreport-z.gpgzgpg --batch -o r�N�keyz--trust-model always -e -r �passwordz'"rBZsos_gpgz-c --passphrase-fd 0 z/bin/bash -c "echo $sos_gpg | �"rT)�timeout�env�stderr�status�zSpecified key not in keyringzCould not read passphrasezgpg exited with code z and error �output)�replacerJrr�)r�archiveZarc_nameZenc_cmdr��passwdr�rrrr
r�ss,


zFileCacheArchive._encryptcCs|��Sr)r r8rrr
r��szFileCacheArchive._build_archive)N)rD)NF)NF)r')rD)r
r;r<r=rIrNr�rRrVrYrfr�r�r&r*r+r.r1r3r5r4r6rOr�r7r�r�r�r:r�r�rrrr
rA�s:�

]
K
$
G	
	

%)rAcsTeZdZdZdZdZd�fdd�	Zddd�Zdd	�Zd
d�Z	dd
�Z
dd�Z�ZS)�TarFileArchivez: archive class using python TarFile to create tar archivesNFc	s6t��|||||||�d|_tj�||���|_dS)N�tar)�superrR�_suffixrFr0rMr r�rP��	__class__rr
rR�s��zTarFileArchive.__init__cCsP|j|_|jd�|jd<|jd�|jd<|r4||_n|j|_|j|_|j	|_
dS)Nz.9fZatime�ctime)�st_mtime�mtime�st_atime�pax_headers�st_ctimer)r{r��uidr��gid)rZtar_info�fstatr)rrr
�set_tarinfo_from_stat�sz$TarFileArchive.set_tarinfo_from_statcs�|jttj�|j�d�d���s*|j�gd�}t�fdd�|D��rLdSzt���}Wntyp|YS0|j	r�|�
��}|r�||jd<|�||�|S)N���)z
/version.txt$z/sos_logs(/.*)?z/sos_reports(/.*)?c3s|]}t�|��VqdSr)r��match)�.0�skip��	orig_pathrr
�	<genexpr>��z9TarFileArchive.copy_permissions_filter.<locals>.<genexpr>zRHT.security.selinux)
r �lenrFr0r`rNrorpr��_with_selinux_context�get_selinux_contextr�r�)r�tarinfoZskipsr��contextrr�r
�copy_permissions_filter�s  


z&TarFileArchive.copy_permissions_filtercCs.zt�|�\}}|WSty(YdS0dSr)�selinuxZ
getfileconr�)rr0�_�crrr
r��s
z"TarFileArchive.get_selinux_contextcCs|j�d|j��S)N�.)rNr�rrrr
r �szTarFileArchive.namecCsd}|dkr td�durdnd}|durb|�d�}|j�d|��|_|jd|��7_d|��}id	d
iddid
�}tj|jfd|i||���n}dD]B}tj�tj�	|j
|��r�|jtj�	|j
|�|j�d|��d�q�|j|j
|j|j
d�Wd�n1�s0Y|��S)Nr'�auto�lzma�xz�gzip�iprzw:�
compresslevel��preset�)Nr
r	r))zversion.txtr�Zsos_logsrC)�arcname)r�filter)r�stripr�r��tarfiler�rFr0rcrMrN�addrrr )rr9�_modeZ
_comp_mode�kwargsr�Z_contentrrr
r��s8

�����&zTarFileArchive._build_archive)N)N)
r
r;r<r=r9r�rRr�rr�r r��
__classcell__rrr�r
r��s�	

r�)rFrr�r?r�r�rpr�r�	threadingr�importlib.utilrZ
sos.utilitiesrr�ImportErrorryr|r~rvr	rAr�rrrr
�<module>s4]