
    x[h                         S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  \R                  " \	5      r
SrSrSS\4S jjrSS\4S jjrS r\ R"                  SS	 j5       rSS\4S
 jjrSS\4S jjrg)    N)utilz/run/cloud-init/tmpz/var/tmp/cloud-init	needs_exec                     U b  U $ U(       a  [         $ [        R                  " 5       S:X  a  [        $ [        R                  R                  SS5      $ )Nr   TMPDIRz/tmp)_EXE_ROOT_TMPDIRosgetuid_ROOT_TMPDIRenvironget)odirr   s     6/usr/lib/python3/dist-packages/cloudinit/temp_utils.pyget_tmp_ancestorr      s?    	yy{a::>>(F++    c                 0   [        X5      n[        R                  R                  U5      (       d-  [        R                  " U5        [        R
                  " US5        U(       a2  [        R                  " US5      (       a  [        R                  SU5        U$ )a  Return the proper 'dir' argument for tempfile functions.

When root, cloud-init will use /run/cloud-init/tmp to avoid
any cleaning that a distro boot might do on /tmp (such as
systemd-tmpfiles-clean).

If the caller of this function (mkdtemp or mkstemp) was provided
with a 'dir' argument, then that is respected.

@param odir: original 'dir' arg to 'mkdtemp' or other.
@param needs_exe: Boolean specifying whether or not exe permissions are
    needed for tempdir. This is needed because /run is mounted noexec.
i  noexeczDRequested temporal dir with exe permission `%s` is mounted as noexec)
r   r   pathisdirmakedirschmodr   has_mount_optLOGwarning)r   r   tdirs      r   _tempfile_dir_argr      sl     D,D77==
D
vdH--KK%
 Kr   c                     ^ [        5       U S'   [        R                  " S0 U D6mS nUTl        U4S jn[	        TSU5        T$ )Ndirc                      [         R                  " U 5        g ! [         a*  nUR                  [        R                  :w  a  Ue S nAg S nAff = fN)r   unlinkOSErrorerrnoENOENT)r   es     r   _unlink_if_exists0ExtendedTemporaryFile.<locals>._unlink_if_exists?   s<    	IIdO 	ww%,,& '	s    
A AAc                  <   > T R                  T R                  5        g r   )r    name)fhs   r   
unlink_now)ExtendedTemporaryFile.<locals>.unlink_nowM   s    
		"''r   r*    )r   tempfileNamedTemporaryFiler    setattr)kwargsr%   r*   r)   s      @r   ExtendedTemporaryFiler1   8   sH    %'F5M		$	$	.v	.B
 "BI Bj)Ir   c              +      #    [        S0 UD6n Uv   [        R                  " X S9  g ! [        R                  " X S9  f = f7f)N)ignore_errorsr,   )mkdtempshutilrmtree)rmtree_ignore_errorsr0   r   s      r   tempdirr8   T   s7     
 VD@
d?d?s   A( A>Ac                 H    [        X5      n [        R                  " SSU 0UD6$ Nr   r,   )r   r-   r4   r   r   r0   s      r   r4   r4   `   %    
C
+C..v..r   c                 H    [        X5      n [        R                  " SSU 0UD6$ r:   )r   r-   mkstempr;   s      r   r>   r>   e   r<   r   )NF)F)
contextlibr"   loggingr   r5   r-   	cloudinitr   	getLogger__name__r   r
   r   boolr   r   r1   contextmanagerr8   r4   r>   r,   r   r   <module>rF      s       	   !$( ,4 ,D :8 @ @/ /
/ /r   