
    VhWl                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z
 d dlmZmZmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZ  e ej8                               j;                  d
      Zd Zd Z ddZ! G d de      Z"y)    )annotationsN)	constants)AnsibleErrorAnsibleActionFailAnsibleFileNotFound)FILE_COMMON_ARGUMENTS)to_bytes	to_nativeto_text)boolean)
ActionBase)checksum)statepath_original_basenamerecurseforce
_diff_peeksrcc                B    t        d | j                         D              S )z)remove keys that are not relevant to filec              3  <   K   | ]  \  }}|t         v s||f  y wN)REAL_FILE_ARGS.0kvs      K/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/action/copy.py	<genexpr>z+_create_remote_file_args.<locals>.<genexpr>-   s     N41a!~:MANs   	dictitemsmodule_argss    r   _create_remote_file_argsr%   +   s    N;#4#4#6NNN    c                B    t        d | j                         D              S )zremove action plugin only keysc              3  4   K   | ]  \  }}|d vs||f  yw))contentdecryptN r   s      r   r   z+_create_remote_copy_args.<locals>.<genexpr>2   s      Z41a!CY:YAZs   	r    r#   s    r   _create_remote_copy_argsr,   0   s    Z;#4#4#6ZZZr&   c                  	 g g g d	d	fd	d}|r	 ||       }n)| j                  t        j                  j                        }|| }|st        j                  j	                  |      }| j                  |      rt        |      }|r ||      sdz  }n.|j                  t        j                  j                        sdz  }t        j                  j                  |       r;s9t        j                  |       t        j                  j                  |       f	d<   	S t        j                  |       }t        |j                  |j                  ff      } | |       	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symlinksc           
     L   t        j                  |       D ]  \  }}}|D ]  }t         j                  j                  ||      }t         j                  j                  |||d       }	t         j                  j	                  |      rt         j                  j                  |      }
r6t         j                  j                  |
      rd   j                  |
|	f       d   j                  t        j                  |      |	f       d   j                  ||	f        |D ]}  }t         j                  j                  ||      }t         j                  j                  |||d       }t         j                  j                  |      }t        j                  |      }t         j                  j	                  |      r͉r|j                  |j                  f|v r*d   j                  t        j                  |      |f       t               }t         j                  j                  |      j                  t         j                  j                        }t!        t#        |      dd      D ]l  }t        j                  dj                  |d|             }|j                  |j                  f|v r n)|j%                  |j                  |j                  f       n |j                  |j                  f|v r+d   j                  t        j                  |      |f       d   j                  ||f       t#        |      dz   } |||j'                  |      |	       =d   j                  t        j                  |      |f       hd   j                  ||f         y)
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/   r1   r   /r0      )rel_base)oswalkr   joinislinkrealpathisfileappendreadlinkstatst_devst_inosetdirnamesplitseprangelenaddunion)topdir
rel_offsetparent_dirsr6   	base_pathsub_foldersr/   filenamefilepathdest_filepath	real_filerC   dirpathdest_dirpathreal_dir	dir_statsnew_parentsparent_dir_listparentparent_statoffset_recurselocal_followr_filess                        r   r\   z_walk_dirs.<locals>._recurseV   s
   * .0WWV_ :	K)I{E! G77<<	8< "Xx
7L M77>>(+ " 0 0 :I#y(A(//M0JK  
+22BKK4I=3YZ G$++X},EFG" ' (K'',,y':!ww||Hgjk6JK77++G4GGH-	77>>'*#%,,i.>.>?;N $J/66G8Ll7[\ +.%K.0ggoog.F.L.LRWW[[.YO*/O0Da*L Z.0ggdiiPWQW@X6Y.Z$/$6$68J8J#K{#Z
 %* +1C1C[EWEW0X YZ !* 0 0)2B2BC{R !(
 3 : :BKK<PR^;_ ` !( 6 = =x>V W),X): (6;;L;L[;Ydp q  
+22BKK4H,3WX M*117L2IJQ(K%:	Kr&   Fr5   r1   ) )endswithr7   r   rE   rC   
startswithrG   r:   r>   basenamer?   	frozensetr@   rA   )
rJ   rM   r]   trailing_slash_detectorsource_trailing_slashr[   rV   parentsr\   r^   s
     `     @@r   
_walk_dirsrg   5   s.   > 22>GOKf " 7 ? & < 	 GGOOI.	#Y '>y'I!,!	ww~~fl!{{62BGG4D4DV4LM
I)**I,<,<=?@GVVW%Nr&   c                  <     e Zd ZdZd Zd Zd Zd Zd fd	Z xZ	S )ActionModuleTc                   d|vrm| j                   j                  rd|d<   nQ| j                   j                  j                         |d<   | j                   j                  j                         |d   d<   t	        |d   t
              r>d|d   v rd|d   d<   |d   j                  di       j                  d      d|d   d   d<   |S )N
invocationzCENSORED: no_log is setr$   r)   z'CENSORED: content is a no_log parameter#VALUE_SPECIFIED_IN_NO_LOG_PARAMETER)_taskno_logargscopy
isinstancer!   get)selfresults     r   _ensure_invocationzActionModule._ensure_invocation   s     v%zz  '@|$ (,zz';';'=|$6:jjoo6J6J6L|$]3f\*D1F<002[|$Y/l#''r:>>yIUAf|$]3I>r&   c                
   t        | j                  j                  j                  dd      d      }t        | j                  j                  j                  dd      d      }	t        | j                  j                  j                  dd      d      }
i }g |d	<   	 | j                  j                  ||
      }d }| j                  j                  j                  dd       dk(  r5dt        j                  t        j                  |      j                        z  }| j                  j                  j                  |      r'| j                  j                  j                  ||      }n|}| j!                  ||||	      }|d   r`|d   r[|| j#                  ||       d|d<   d|d<   |S | j                  j                  j                  ||      }| j!                  ||||	      }|d   r|	sy t%        |      }||d   k7  r| j                  j&                  r(|
s&|d	   j)                  | j+                  ||||             | j                  j,                  r| j#                  ||       d|d<   |S | j                  j                  j                  | j                  j                  j.                  d      }t        j0                  j3                  |      d   }|r||z  }d }|
s| j5                  ||      }n| j5                  ||       | j#                  ||       | j                  j7                  |       |r1| j9                  | j                  j                  j.                  |f       |
ry t;        | j                  j                        }|j=                  t?        ||||             | j                  j                  j                  d      s||d<   |r||d<   | jA                  d||      }n| j#                  ||       | j                  j7                  |       |
ry |r0| j!                  ||d      }|d   rd|jC                         v r|d   }tE        | j                  j                        }|j=                  t?        ||dd !             	 |d"= |r||d<   | jA                  d#||      }|j                  d      s||d<   |j=                  |       |S # t        $ r%}d|d<   d|dt        |      |d<   |cY d }~S d }~ww xY w# tF        $ r Y w xY w)$Nr*   TFstrictr   yesrawnodiff)r*   failedzcould not find src=z, msgmodepreservez0%03o)all_varsfollowr   existsisdir&can not use content with a dir as destr   changedz.sourcer5   )r   destr   r   ansible.legacy.copymodule_namer$   	task_vars)r   r   islnk
lnk_sourcefile)r   r   r   r   r   ansible.legacy.file)$r   rm   ro   rr   _loaderget_real_filer   r   r?   S_IMODEr7   st_mode_connection_shellpath_has_trailing_slash	join_path_execute_remote_stat#_remove_tempfile_if_content_definedr   r|   r=   _get_diff_data
check_modetmpdirr   splitext_transfer_filecleanup_tmp_file_fixup_perms2r,   updater!   _execute_modulekeysr%   KeyError)rs   source_full
source_relr)   content_tempfiler   r   r   r*   r   rz   rt   elmode	dest_filedest_statuslocal_checksumtmp_srcsuffixremote_pathnew_module_argsmodule_returndest_status_nofollows                          r   
_copy_filezActionModule._copy_file   s   $**//--i>uM

++GU;EJdjjoo))%6uEv	,,44['4RK ::??vt,
:dll277;+?+G+GHHE
 ""::4@((//99$
KII //	IV\gl/mx [%9"88BRS#'x  Hu !,,33==dJO	"77	I^dot7ux  "+.[44 zzsv%%d&9&9)[R[]d&efzz$$88BRS$(y! &&--778H8H8O8O8V8VXabG WW%%i03F6!K"11+wG##K; 44W>NOLL))+6 ""D$4$4$;$;$B$BK#PQ 7tzzGO""'1!	 ::??&&z2.<
+*/' 00=R`o  |E0  FM
 44W>NOLL))+6
 '+'@'@U^gl'@'m$'0\EYE^E^E`5`/=D 7tzzGO""'1! 	#E* */' !00=R`o  |E0  FM  ,(6M*%m$i # 	#F8;FPQ
SF5MM	N  s0   S S> 	S;S60S;6S;>	T
	T
c                j   t        j                  t        j                  d      \  }}t	        j
                  |d      }t        |      }	 |j                  |       	 |j                          |S # t        $ r%}t	        j                  |       t        |      d}~ww xY w# |j                          w xY w)z. Create a tempfile containing defined content .)dirprefixwbN)tempfilemkstempCDEFAULT_LOCAL_TMPr7   fdopenr	   write	Exceptionremoveclose)rs   r)   fdr   ferrs         r   _create_content_tempfilez%ActionModule._create_content_tempfile  s    '//A4G4GPSTIIb$7#	GGG
 GGI  	!II&'C. 	! GGIs$   A/ /	B8 BBB   B2c                4    |t        j                  |       y y r   )r7   r   )rs   r)   r   s      r   r   z0ActionModule._remove_tempfile_if_content_defined  s    II&' r&   c           
        |
t               }t        t        |   ||      }~dD ]7  }| j                  j
                  j                  |d      *t        d| d       | j                  j
                  j                  dd      }| j                  j
                  j                  dd      }| j                  j
                  j                  dd      }t        | j                  j
                  j                  dd	      d	
      }t        | j                  j
                  j                  dd      d	
      }	d|d<   |s|d|d<   n0|sd|d<   n(|r|d|d<   n|||j                  d      rd|d<   n|d= |j                  d      r| j                  |      S d}
|Z	 t        |t               st        |t              r%| j                  t        j                  |            }
n| j                  |      }
|
}n|r3|j%                  | j'                  d|             | j                  |      S |j                  t(        j*                  j,                        }	 | j/                  d|      }||j                  t(        j*                  j,                        k7  rC|d   t(        j*                  j,                  k(  r|dd }n|t(        j*                  j,                  z   }g g g d}t(        j*                  j9                  t;        |d            rxt=        ||	| j>                  j@                  jB                        }| j>                  j@                  jC                  |      sL| j>                  j@                  jE                  |d      }n%|t(        j*                  jG                  |      fg|d<   d	}t        d	      }d	}| jI                  |      }tK               }|d   D ]  \  }}|d    rd	}n1t        | j                  j
                  j                  d!d	      d	
      }| jM                  ||||
|||      }|Z|j                  d      r$|j%                  |       | j                  |      c S t(        j*                  jO                  |      }d}|D ]3  }t(        j*                  jQ                  ||       |jS                  |       5 d"|v r|d"   s|d"= d}|xs |j                  d#d	      } |d    D ]  \  }}||v rtU        | j                  j
                        }t(        j*                  jQ                  ||      |d$<   d%|d&<   | j                  j
                  j                  d'd      |d(<   d	|d)<   |d= | j'                  d*||+      }|j                  d      r$|j%                  |       | j                  |      c S d}|xs |j                  d#d	      } |d,   D ]  \  }}tU        | j                  j
                        }t(        j*                  jQ                  ||      |d$<   ||d<   d-|d&<   d|d.<   |d    rd	|d!<   |j                  d(d      d/k(  r|jW                  d(       | j'                  d*||+      }d}|j                  d      r$|j%                  |       | j                  |      c S |xs |j                  d#d	      } |r3tY        |d         d0k(  r"|j%                  |       d$|v r*d|vr&|d$   |d<   n|j%                  t        |||1             | j[                  | j>                  j@                  j\                         | j                  |      S # t         $ r1}d|d<   dt#        |      z  |d<   | j                  |      cY d}~S d}~ww xY w# t0        $ rE}d|d<   t3        |      |d<   t5        j6                         |d<   | j                  |      cY d}~S d}~ww xY w)2z& handler for file transfer operations N)r   r   zInvalid parameter specified: ""r   r)   r   
remote_srcFrw   r]   Tr}   zsrc (or content) is requiredr~   zdest is requiredz&src and content are mutually exclusiver4   r   z%could not write content temp file: %sr   )r   r   r/   	exceptionr3   r.   surrogate_or_strict)errors)r]   rd   r_   )r   r0   r   r|   r   r   	directoryr   directory_moder   r   r   r   r1   linkr   r   r5   )r   r   r   )/r!   superri   runrm   ro   rr   r   r   r`   ru   rq   listr   jsondumpsr   r
   r   r   r7   r   rE   _find_needler   r   	traceback
format_excr   r	   rg   r   r   r   r   rb   _remote_expand_userrB   r   rD   r9   rH   r%   poprG   _remove_tmp_pathr   )rs   tmpr   rt   internalsourcer)   r   r   r]   r   r   trailing_slashr   source_filesr   r   module_executedimplicit_directoriesr   r   r   pathsdir_pathdir_componentr   	dest_pathr   target_path	__class__s                                r   r   zActionModule.run  s   I|T.sI> = 	VHzz""8T2>'*H
RS(TUU	V $$UD1**//%%i6zz""640TZZ__00uEeT
tzz22>4HQVWx'/:F5M.F5M+DF5M T%5$--:LDF5Mx ::h**622   7 gt,
7D0I'+'D'DTZZPWEX'Y$'+'D'DW'M$) MM$..;P\e.fg**622 $__RWW[[9N7**7F; !==":,#CR[F#bggkk1F "$BBG 77==&1FGH%f<>B>N>N>U>U>m>moL
 ##**BB4H''..88rB
 '-bgg.>.>v.F%G$HL!U+   ''-"u'3G'< 	E#K
 M* !4!4Xu!EeT OOKWN^`dfoqwxM$  *m,..v66GGMM*-EH!& 3X}5$((23 v6N"OD!2!29e!DG5	E8 +=9 	ENC 00 7tzzGO&(ggll4&COF#'2OG$&*jjoo&9&9:JD&QOF#).OI&& 00=R`o  |E0  FM  *m,..v66"OD!2!29e!DG+	E. '3:&> 	E"K6tzzGO&(ggll4&COF#%0OE"'-OG$'+OG$ M*,1) ""640J>##F+ 00=R`o  |E0  FM"O  *m,..v66D!2!29e!DG1	E4 s<#89Q>MM-( F&$8!'vMM$DfgFG 	d..55<<=&&v..o  7#'x  G)TW. Xu..v667&   7#'x  '
u&/&:&:&<{#..v66	7s=   A]
 ^ 
	^&]?9^?^	_:_
__)NN)
__name__
__module____qualname__TRANSFERS_FILESru   r   r   r   r   __classcell__)r   s   @r   ri   ri      s*    O.`D (F/ F/r&   ri   )NFN)#
__future__r   r   r7   os.pathr?   r   r   ansibler   r   ansible.errorsr   r   r   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr	   r
   r   )ansible.module_utils.parsing.convert_boolr   ansible.plugins.actionr   ansible.utils.hashingr   rc   r   rI   r   r%   r,   rg   ri   r+   r&   r   <module>r      s   & #  	     " O O < T T = - * 505578>>01
O
[
RjU/: U/r&   