/usr/lib/python3/dist-packages/sos/__pycache__
NameSizeModeActions
archive.cpython-310.pyc235540644editdlrm
component.cpython-310.pyc161280644editdlrm
missing.cpython-310.pyc27590644editdlrm
options.cpython-310.pyc115130644editdlrm
utilities.cpython-310.pyc232920644editdlrm
__init__.cpython-310.pyc52530644editdlrm
Edit: /usr/lib/python3/dist-packages/sos/__pycache__/archive.cpython-310.pyc (23554B)
o G%@i3r@sddlZddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZzddlZWn eyGYnwdZdZdZd ZGd d d ZGd d d eZGdddeZdS)N)datetime)Lock) find_spec)sos_get_command_outputfilelinknodedirc@seZdZdZeddZedZdZ dZ e Z ddZ d d Zd d Zd dZddZddZddZd-ddZd.ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,ZdS)/Archivez!Abstract base class for archives.cC|jS)z6Returns the archive class's name as a string. )__name__)clsr-/usr/lib/python3/dist-packages/sos/archive.py archive_type+szArchive.archive_typesosunsetFcCsd|d|S)Nz [archive:z] )rselfmsgrrr _format_msg8szArchive._format_msgcCs ||_dSN)_debug)rdebugrrr set_debug;s zArchive.set_debugcC|j||dSr)logerrorrrrrr log_error>zArchive.log_errorcCrr)rwarningrrrrrlog_warnArzArchive.log_warncCrr)rinforrrrrlog_infoDrzArchive.log_infocCs |jsdS|j||dSr)rrrrrrrr log_debugGszArchive.log_debugcCr r)_namerrrrnameLz Archive.nameNcCtrNotImplementedError)rsrcdestforcerrradd_fileRzArchive.add_filewcCr)rr*)rcontentr-moderrr add_stringUr0zArchive.add_stringcCr)rr*)rr2r-rrr add_binaryXr0zArchive.add_binarycCr)rr*)rsource link_namerrradd_link[r0zArchive.add_linkcCr)rr*rpathrrradd_dir^r0zArchive.add_dircCr)rr*)rr:r3devicerrradd_nodear0zArchive.add_nodecCr))zReturn 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.r*r&rrr get_tmp_dirdzArchive.get_tmp_dircCr))zReturn 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.r*r&rrrname_maxjr?zArchive.name_maxcCr))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 locatedr*r&rrrget_archive_pathpszArchive.get_archive_pathcCr))z:Clean up any temporary resources used by an Archive class.r*r&rrrcleanupyszArchive.cleanupcCr))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, gzipr*rmethodrrrfinalize}szArchive.finalizeNFr1)r __module__ __qualname____doc__ classmethodrlogging getLoggerrr%rr _path_lockrrrr!r#r$r'r/r4r5r8r;r=r>r@rArBrErrrrr (s4     r c@seZdZdZdZdZdZ d7ddZddZdd Z d8d d Z d9ddZ ddZ d9ddZ d:ddZddZddZddZddZdd Zd!d"Zd#d$Zd8d%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6ZdS);FileCacheArchivezd Abstract superclass for archive types that use a temporary cache directory in the file system. NcCs||_tj|j|g|krtj|||_||_||_||_||_|p%d|_ ||_ tj |||_ |j t|j dWdn1sGwY|d|j ddS)N/z'initialised empty FileCacheArchive at '')r%osr: commonprefixrelpath_tmp_dir_policy_threadsenc_optssysrootmanifestjoin _archive_rootrNmakedirsr#rr'tmpdirpolicythreadsrZr[r\rrr__init__s  zFileCacheArchive.__init__cCs(tj|r |tj}tj|j|Sr)rTr:isabslstripsepr]r^)rr'rrr dest_paths  zFileCacheArchive.dest_pathcCs@|jr ||jr |S|dtjkr|dd}tj|j|S)Nr)r[ startswithrTrgr:r]r9rrr join_sysroots  zFileCacheArchive.join_sysrootrRcs|d||j|}fdd}|ds|}ntj||r&|ntj|d}|}g}|dvrItj|\}} || |}|dvs6| } d} |D]} tj | | } || saqStj | | } tj | s|d| tj | rtj| rt | } tj| d}tj || }|j||d}tj|}tj| rtj| |} |d | d | d t| | qS|d | t| || }qS|S) aCreate 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|tjdS)z>Test whether path ``path`` is inside the archive. rP)rjrTr:r])r:rootrr in_archivesz8FileCacheArchive._make_leading_paths..in_archiverQr)rQrPz Making path r3zMaking symlink '' -> 'rSzMaking directory )r$r^rjrTr:isdirrksplitappendreverser]existsislinkreadlink_make_leading_pathsnormpathrerVsymlinkmkdir)rr,r3r-rnsrc_dirr: path_compsheadtailabs_pathsrc_pathcomptarget target_dir target_srcrrlrrxsV          z$FileCacheArchive._make_leading_pathsFc CsN|p||}|tkr|}ntj|d}|s|Stj|r.tj|s.td|dtj|sG|tkr:|ntj|d}||dd}|rO|Stj|rt |}d} |t krnt |j snt| |df|tkrt |j st| |df|tkr||j st| |d f|tkrt |j st| |d fd S|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|gSr)anystatS_ISBLKS_ISCHRS_ISFIFOS_ISSOCKrorrr is_special7s z/FileCacheArchive.check_path..is_specialz path '%s' exists and is not a %sz regular filez symbolic linkz special file directoryN)rhP_DIRrTr:rrrurq ValueErrorrxlstatP_FILErS_ISREGst_modeP_LINKS_ISLNKP_NODES_ISDIR) rr, path_typer-r.dest_dirr|rstve_msgrrr check_paths6    zFileCacheArchive.check_pathc Csz3t|}|ds|dr"t||tj||j|jfdnt||t ||j |j WdSt yR}z| d|d|dWYd}~dSd}~ww)N/sys//proc/)nszcaught 'z' setting attributes of 'rS)rTrrjshutilcopymodeutime st_atime_ns st_mtime_nscopystatchownst_uidst_gid Exceptionr$)rr,r-_staterrr_copy_attributesSs   &z!FileCacheArchive._copy_attributesc CsN|j|s|}|j|t|d}|s WddSt|dds`zt||Wn)tyR}z|ds;|dr.is_loopzLink 'z' - 'z' loops: skipping...z Adding link z -> z for link follow upz Adding dir z Adding file zNo link follow up: source=)r$rNrrrTr:lexistsrzr^rrr]rhrurvrwrVr8rqr;isfiler/) rr6r7r- source_dirhost_path_namedest_path_namerrrrrr8sR               zFileCacheArchive.add_linkcCs8|j||tWddS1swYdS)zmCreate a directory in the archive. :param path: the path in the host file system to add N)rNrrr9rrrr;s"zFileCacheArchive.add_dirc Cs||t}|s dStj|sKz t|||Wn)tyB}z|jtjkr r(zFileCacheArchive.get_tmp_dircCr rrr&rrrrA r(z!FileCacheArchive.get_archive_pathcCs8tjtj|j||d|d|d|jddS)zsCreate path, including leading components. Used by sos.sosreport to set up sos_* directories. rozcreated directory at 'z' in FileCacheArchive 'rSN)rTr_r:r]r^r$)rr:r3rrrr_s zFileCacheArchive.makedirscCs||}tj|ddddS)Nrrr)rerrors)rhrrr9rrr open_files zFileCacheArchive.open_filecCs"tj|jrt|jdSdSr)rTr:rqr^rrmtreer&rrrrBszFileCacheArchive.cleanupcCsft}|jj}||}|jd||jd||jd|||jjddtj dddS) zAdds component-agnostic data to the manifest so that individual SoSComponents do not need to redundantly add these manually end_timerun_time compression)indent sos_reportsz manifest.jsonN) rnowr\ start_time add_fieldr4get_jsonrTr:r])rrDendstartrrrradd_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) obfuscate_stringr%rTr:r]rWrenamer^r' _archive_name)rcleaner _new_rootrrrrename_archive_root-s z$FileCacheArchive.rename_archive_rootc CstjtjB}t|dr|j}|j|B}n|}|}d}|| }|}Wdn1s.wYt|t s>| dd}tj ||||d\} } | rS| | || Sd} | S)aApply 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`` patternrPNrr)flagsr) re IGNORECASE MULTILINEhasattrrrrrrstrrsubnr4) rr:regexpsubst common_flagsrrr2readableresult replacementsrrr do_file_sub7s(          zFileCacheArchive.do_file_subc Cs|d|jd|dz||}Wnty2}z|d||WYd}~Sd}~ww||d|jdt |jj d|j druz| |WStyt}zd }||d ||WYd}~Sd}~ww|S) Nzfinalizing archive 'z' using method 'rSz+An error occurred compressing the archive: zbuilt archive at 'z' (size=)encryptz)An error occurred encrypting the archive: ) r#r^_build_archiverrr'rBrrTrst_sizerZ_encrypt)rrDreserrrexp_msgrrrrE\s0    zFileCacheArchive.finalizecCs|dd}|d7}d|d}d}|jdr&|d|jdd7}||7}|jd rF|jd d d }d |i}|d 7}d|d}||7}t|d|dd}|ddkrV|S|ddkrm|jdrgd}t|d}t|d|dd|d}t|)aEncrypts 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 rNkeyz--trust-model always -e -r passwordz'"rPsos_gpgz-c --passphrase-fd 0 z/bin/bash -c "echo $sos_gpg | "rT)timeoutenvstderrstatuszSpecified key not in keyringzCould not read passphrasezgpg exited with code z and error output)replacerZrr)rarchivearc_nameenc_cmdr passwdrrrrrrss0        zFileCacheArchive._encryptcCs|Sr)r'rCrrrrszFileCacheArchive._build_archiver)rRrFrG)r rHrIrJrWr^rrdrhrkrxrrr/r4r5r8r;r=r@r>rAr_rrBrrrrErrrrrrrOs<   ]K $ G     % )rOcsVeZdZdZdZdZ dfdd ZdddZdd Zd d Z d d Z ddZ Z S)TarFileArchivez: archive class using python TarFile to create tar archivesNFc s6t|||||||d|_tj|||_dS)Ntar)superrd_suffixrTr:r]r'rr` __class__rrrds zTarFileArchive.__init__cCsP|j|_|jd|jd<|jd|jd<|r||_n|j|_|j|_|j |_ dS)Nz.9fatimectime) st_mtimemtimest_atime pax_headersst_ctimer3rruidrgid)rtar_infofstatr3rrrset_tarinfo_from_stats z$TarFileArchive.set_tarinfo_from_statcs|jttj|jdds|jgd}tfdd|Dr&dSzt}Wn ty8|YSw|j rH| }|rH||j d<| |||S)N)z /version.txt$z/sos_logs(/.*)?z/sos_reports(/.*)?c3s|] }t|VqdSr)rmatch).0skip orig_pathrr sz9TarFileArchive.copy_permissions_filter..zRHT.security.selinux) r'lenrTr:rrr^rrr_with_selinux_contextget_selinux_contextrr$)rtarinfoskipsr#contextrr)rcopy_permissions_filters"     z&TarFileArchive.copy_permissions_filtercCs*z t|\}}|WStyYdSwr)selinux getfileconr)rr:_crrrr.s  z"TarFileArchive.get_selinux_contextcCs|jd|jS)N.)r^rr&rrrr'szTarFileArchive.namecCsd}|dkrtddurdnd}|dur1|d}|jd||_|jd|7_d|}id d id d id }tj|jfd|i||:}dD]!}tjtj |j |rm|j tj |j ||j d|dqL|j |j |j |j dWd|S1swY|S)Nr1autolzmaxzgzipipr7zw: compresslevelpreset)Nr;r:r3)z version.txtrsos_logsrQ)arcname)rBfilter)rstriprrtarfilerrTr:rur]r^addr%r2r')rrD_mode _comp_modekwargsr_contentrrrrs@     zTarFileArchive._build_archiver) r rHrIrJrDr-rdr$r2r.r'r __classcell__rrrrrs  r)rTrErrLrrrrr threadingrimportlib.utilr sos.utilitiesrr3 ImportErrorrrrrr rOrrrrrs8       ]