a ì)gÞjã@sèddlmZmZmZeZddlZddlZddlZddl Z ddl Z ddl Z ddl m ZddlmZmZddlmZddlmZmZmZddlmZddlmZdd lmZee ¡ƒ  d ¡Z!d d „Z"d d„Z#ddd„Z$Gdd„deƒZ%dS)é)Úabsolute_importÚdivisionÚprint_functionN)Ú constants)Ú AnsibleErrorÚAnsibleFileNotFound)ÚFILE_COMMON_ARGUMENTS)Úto_bytesÚ to_nativeÚto_text)Úboolean)Ú ActionBase)Úchecksum)ÚstateÚpathÚ_original_basenameÚrecurseÚforceZ _diff_peekÚsrccCstdd„| ¡DƒƒS)z)remove keys that are not relevant to filecss"|]\}}|tvr||fVqdS©N)ÚREAL_FILE_ARGS©Ú.0ÚkÚv©rú?/usr/lib/python3.9/site-packages/ansible/plugins/action/copy.pyÚ /óz+_create_remote_file_args..©ÚdictÚitems©Ú module_argsrrrÚ_create_remote_file_args-sr$cCstdd„| ¡DƒƒS)zremove action plugin only keyscss"|]\}}|dvr||fVqdS))ÚcontentÚdecryptNrrrrrr4rz+_create_remote_copy_args..rr"rrrÚ_create_remote_copy_args2sr'Fcsògggdœ‰d ‡‡‡fdd„ ‰d}|r0||ƒ}n| tjj¡}|durJ|}|sZtj |¡}| |¡rlt|ƒ}|r‚||ƒs‚|d7}n| tjj¡s˜|d7}tj |¡rƈsÆt |¡tj  |¡fˆd<ˆSt  |¡}t |j |j ffƒ}ˆ|||ƒˆS) aD Walk a filesystem tree returning enough information to copy the files :arg topdir: The directory that the filesystem tree is rooted at :kwarg base_path: The initial directory structure to strip off of the files for the destination directory. If this is None (the default), the base_path is set to ``top_dir``. :kwarg local_follow: Whether to follow symlinks on the source. When set to False, no symlinks are dereferenced. When set to True (the default), the code will dereference most symlinks. However, symlinks can still be present if needed to break a circular link. :kwarg trailing_slash_detector: Function to determine if a path has a trailing directory separator. Only needed when dealing with paths on a remote machine (in which case, pass in a function that is aware of the directory separator conventions on the remote machine). :returns: dictionary of tuples. All of the path elements in the structure are text strings. This separates all the files, directories, and symlinks along with important information about each:: { 'files': [('/absolute/path/to/copy/from', 'relative/path/to/copy/to'), ...], 'directories': [('/absolute/path/to/copy/from', 'relative/path/to/copy/to'), ...], 'symlinks': [('/symlink/target/path', 'relative/path/to/copy/to'), ...], } The ``symlinks`` field is only populated if ``local_follow`` is set to False *or* a circular symlink cannot be dereferenced. ©ÚfilesÚ directoriesÚsymlinksÚc s<t |¡D]*\}}}|D]}tj ||¡}tj |||d…¡} tj |¡r˜tj |¡} ˆr~tj | ¡r~ˆd | | f¡qªˆd t |¡| f¡qˆd || f¡q|D]‚} tj || ¡} tj || |d…¡} tj | ¡}t  |¡}tj | ¡r"ˆr|j |j f|vr0ˆd t | ¡| f¡nÖt ƒ}tj  | ¡ tjj¡}tt|ƒddƒD]H}t  d |d|…¡¡}|j |j f|vrq¦| |j |j f¡q\|j |j f|vrÒˆd t | ¡| f¡n4ˆd || f¡t|ƒd}ˆ||| |¡| d nˆd t | ¡| f¡q°ˆd | | f¡q°q dS) aÊ This is a closure (function utilizing variables from it's parent function's scope) so that we only need one copy of all the containers. Note that this function uses side effects (See the Variables used from outer scope). :arg topdir: The directory we are walking for files :arg rel_offset: Integer defining how many characters to strip off of the beginning of a path :arg parent_dirs: Directories that we're copying that this directory is in. :kwarg rel_base: String to prepend to the path after ``rel_offset`` is applied to form the relative path. Variables used from the outer scope ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :r_files: Dictionary of files in the hierarchy. See the return value for :func:`walk` for the structure of this dictionary. :local_follow: Read-only inside of :func:`_recurse`. Whether to follow symlinks Nr)r+réÿÿÿÿú/r*é)Úrel_base)ÚosÚwalkrÚjoinÚislinkÚrealpathÚisfileÚappendÚreadlinkÚstatÚst_devÚst_inoÚsetÚdirnameÚsplitÚsepÚrangeÚlenÚaddÚunion)ÚtopdirZ rel_offsetZ parent_dirsr0Ú base_pathZ sub_foldersr)ÚfilenameÚfilepathZ dest_filepathZ real_filer=ÚdirpathZ dest_dirpathZreal_dirÚ dir_statsZ new_parentsZparent_dir_listÚparentZ parent_statÚoffset©Ú_recurseÚ local_followZr_filesrrrMXsB      z_walk_dirs.._recurseFNr/r+)r,)Úendswithr1rr?r=Ú startswithrAr4r8Úbasenamer9Ú frozensetr:r;)rDrErNÚtrailing_slash_detectorZsource_trailing_slashrKrIÚparentsrrLrÚ _walk_dirs7s. S       rUcsBeZdZdZdd„Zdd„Zdd„Zdd „Zd ‡fd d „ Z‡Z S)Ú ActionModuleTcCs’d|vr>|jjrd|d<n$|jj ¡|d<|jj ¡|dd<t|dtƒrŽd|dvrdd|dd<|d di¡ d¡durŽd|ddd<|S)NZ invocationzCENSORED: no_log is setr#r%z'CENSORED: content is a no_log parameterZ#VALUE_SPECIFIED_IN_NO_LOG_PARAMETER)Ú _play_contextZno_logÚ_taskÚargsÚcopyÚ isinstancer Úget)ÚselfÚresultrrrÚ_ensure_invocationÐs   zActionModule._ensure_invocationc Cs’t|jj dd¡dd}t|jj dd¡dd} t|jj dd¡dd} i} g| d <z|jj||d }WnDty¬} z,d| d <d |t| ƒf| d <| WYd} ~ Sd} ~ 00d} |jj dd¡dkrÜdt  t  |¡j ¡} |j j  |¡rþ|j j  ||¡}n|}|j|||| d}|drt|drt|durR| ||¡d| d <d| d <| S|j j  ||¡}|j|||| d}|drˆ| sˆdSt|ƒ}||dkr¸|jjrÆ| sÆ| d  | |||¡¡|jjrè| ||¡d| d<| S|j j  |j j jd¡}d}| s| ||¡}n | ||¡| ||¡|j |¡|rT| |j j j|f¡| r^dSt|jjƒ}| t||||d¡|jj d¡s˜||d<| r¦| |d<|jd||d}n¸| ||¡|j |¡| rÚdS|r|j||dd}|drd|  ¡vr|d}t!|jjƒ}| t||ddd¡z |d =Wnt"yPYn0| r`| |d<|jd!||d}| d¡s„||d<|  |¡| S)"Nr&TF©ÚstrictrZyesÚrawÚnoÚdiff)r&Úfailedzcould not find src=%s, %sÚmsgÚmodeÚpreservez0%03o)Úall_varsÚfollowrÚexistsÚisdirú&can not use content with a dir as destrÚchangedÚsource)rÚdestrrjúansible.legacy.copy©Ú module_namer#Ú task_vars)rirjZislnkZ lnk_sourceÚfile)rprrrrúansible.legacy.file)#r rXrYr\Z_loaderZ get_real_filerr r9ÚS_IMODEr1Úst_modeÚ _connectionÚ_shellÚpath_has_trailing_slashÚ join_pathZ_execute_remote_statÚ#_remove_tempfile_if_content_definedrrWrdr7Z_get_diff_dataZ check_modeÚtmpdirZ_transfer_fileZcleanup_tmp_fileZ _fixup_perms2r'Úupdater Ú_execute_moduleÚkeysr$ÚKeyError)r]Ú source_fullÚ source_relr%Úcontent_tempfilerprtrjr&rrbr^ÚeZlmodeZ dest_fileZ dest_statusZlocal_checksumZtmp_srcZ remote_pathÚnew_module_argsÚ module_returnZdest_status_nofollowrrrÚ _copy_fileçs²        üÿ   üÿ    zActionModule._copy_filec Csˆtjtjd\}}t |d¡}t|ƒ}zRz| |¡Wn6tyl}zt  |¡t|ƒ‚WYd}~n d}~00W|  ¡n |  ¡0|S)z. Create a tempfile containing defined content )ÚdirÚwbN) ÚtempfileZmkstempÚCZDEFAULT_LOCAL_TMPr1Úfdopenr ÚwriteÚ ExceptionÚremoveÚclose)r]r%Úfdr…ÚfÚerrrrrÚ_create_content_tempfile„s   z%ActionModule._create_content_tempfilecCs|durt |¡dSr)r1r‘)r]r%r…rrrr}’sz0ActionModule._remove_tempfile_if_content_definedNc sÎ|durtƒ}tt|ƒ ||¡}~|jj dd¡}|jj dd¡}|jj dd¡}t|jj dd¡dd}t|jj dd ¡dd}d |d <|s |dur d |d <nN|s®d |d <n@|rÄ|durÄd|d <n*|durè|durè| d¡rèd|d <n|d =| d ¡r|  |¡Sd} |duršz|  t  |¡¡} n |  |¡} | }WnHty–} z.d |d <dt| ƒ|d <|  |¡WYd} ~ Sd} ~ 00nÔ|r¾| |jd|d¡|  |¡S| tjj¡} z| d|¡}WnPty,} z6d |d <t| ƒ|d <t ¡|d<|  |¡WYd} ~ Sd} ~ 00| | tjj¡krn|dtjjkrb|dd…}n |tjj}gggdœ} tj t|dd¡rÆt|||jjj d} |jj  |¡sÜ|jj !|d¡}n|tj "|¡fg| d<d}tdd}d}| #|¡}t$ƒ}| dD]Þ\}}| drd}nt|jj dd¡dd}| %|||| |||¡}|durZq| d ¡r~| |¡|  |¡Stj &|¡}d}|D]}tj '||¡| (|¡q’d|vrÌ|dsÌ|d=d }|pà| d d¡}q| dD]ª\}}||vrqît)|jjƒ}tj '||¡|d!<d"|d#<|jj d$d¡|d%<d|d&<|d=|jd'||d(}| d ¡r€| |¡|  |¡Sd }|p”| d d¡}qî| d)D]¸\}}t)|jjƒ}tj '||¡|d!<||d<d*|d#<d |d+<| dròd|d<| d%d¡d,kr| *d%¡|jd'||d(}d }| d ¡rF| |¡|  |¡S|pV| d d¡}q¢|r t+| dƒd-kr | |¡d!|vr´d|vr´|d!|d<n| t|||d.¡| ,|jjj-¡|  |¡S)/z& handler for file transfer operations Nrr%rpÚ remote_srcFr`rNTrezsrc (or content) is requiredrfzdest is requiredz&src and content are mutually exclusiver.rmz%could not write content temp file: %srq)rsrtr)Ú exceptionr-r(Zsurrogate_or_strict)Úerrors)rNrSr,)rnr*rjrdrnrZ directoryrZdirectory_modergrrvrrr+Úlinkrrhr/)rprrn).r ÚsuperrVÚrunrXrYr\r rOr_r[Úlistr–ÚjsonÚdumpsrr rr€r1rr?Z _find_needlerr Ú tracebackÚ format_excrlr rUryrzr{r|rQZ_remote_expand_userr<r‰r>r3rBr$ÚpoprAZ_remove_tmp_pathr~)r]Útmprtr^ror%rpr—rNr…r•Ztrailing_slashr†Z source_filesrnrˆZmodule_executedZimplicit_directoriesrƒr„rjÚpathsZdir_pathZ dir_componentrZ dest_pathr‡Z target_path©Ú __class__rrrœ–sê          "      ÿ                 zActionModule.run)NN) Ú__name__Ú __module__Ú __qualname__ZTRANSFERS_FILESr_r‰r–r}rœÚ __classcell__rrr¥rrVÌsrV)NFN)&Z __future__rrrÚtypeZ __metaclass__ržr1Zos.pathr9rŒr ZansiblerrZansible.errorsrrZansible.module_utils.basicrZansible.module_utils._textr r r Z)ansible.module_utils.parsing.convert_boolr Zansible.plugins.actionr Zansible.utils.hashingrrRrrCrr$r'rUrVrrrrÚs,      ÿ