
    ܍~c                         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  ej	        e
          ZdadZdZddefdZddefd	Zd
 Ze j        dd            ZddefdZddefdZdS )    N)log)utilz/run/cloud-init/tmpz/var/tmp/cloud-initF	needs_exec                     | | S |rt           S t          rt          S t          j                    dk    rt          S t          j                            dd          S )Nr   TMPDIRz/tmp)_EXE_ROOT_TMPDIR_TMPDIRosgetuid_ROOT_TMPDIRenvironget)odirr   s     6/usr/lib/python3/dist-packages/cloudinit/temp_utils.pyget_tmp_ancestorr      sU       	y{{a:>>(F+++    c                 &   t          | |          }t          j                            |          s)t          j        |           t          j        |d           |r0t          j        |d          rt          	                    d|           | |s|a
|S )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warningr	   )r   r   tdirs      r   _tempfile_dir_argr      s     D),,D7== 
D
v dH-- 	KK%   |I|Kr   c                      t          |                     dd           |                     dd                    | d<   t          j        di | d }|_        fd}t          d|           S )Ndirr   Fc                     	 t          j        |            d S # t          $ r"}|j        t          j        k    r|Y d }~d S d }~ww xY wN)r
   unlinkOSErrorerrnoENOENT)r   es     r   _unlink_if_existsz0ExtendedTemporaryFile.<locals>._unlink_if_existsI   s_    	IdOOOOO 	 	 	w%,&& '&&&&&	s    
A?Ac                  <                           j                   d S r!   )r"   name)fhs   r   
unlink_nowz)ExtendedTemporaryFile.<locals>.unlink_nowW   s    
		"'r   r+    )r   poptempfileNamedTemporaryFiler"   setattr)kwargsr'   r+   r*   s      @r   ExtendedTemporaryFiler2   @   s    %

5$K!?!? F5M 
	$	.	.v	.	.B
   "BI     Bj)))Ir   c              +      K   t          di |}	 |V  t          j        ||            d S # t          j        ||            w xY w)N)ignore_errorsr,   )mkdtempshutilrmtree)rmtree_ignore_errorsr1   r   s      r   tempdirr9   ^   sb      
 VD@


d*>??????d*>?????s	   , Ac                 H    t          | |          } t          j        dd| i|S Nr   r,   )r   r.   r5   r   r   r1   s      r   r5   r5   j   -    
C
+
+C...v...r   c                 H    t          | |          } t          j        dd| i|S r;   )r   r.   mkstempr<   s      r   r?   r?   o   r=   r   )NF)F)
contextlibr$   r
   r6   r.   	cloudinitr   loggingr   	getLogger__name__r   r	   r   r   boolr   r   r2   contextmanagerr9   r5   r?   r,   r   r   <module>rG      s?        				   $ $ $ $ $ $      g!!
$( 	, 	,4 	, 	, 	, 	, D    D  < @ @ @ @/ / / / / /
/ / / / / / / /r   