܍~c ddlZddlZddlZddlZddlZddlmZddlmZej e Z da dZ dZddefdZddefd Zd Zejdd Zddefd Zddefd ZdS)N)log)utilz/run/cloud-init/tmpz/var/tmp/cloud-initF needs_exec||S|rtStrtStjdkrtStjddS)NrTMPDIRz/tmp)_EXE_ROOT_TMPDIR_TMPDIRosgetuid _ROOT_TMPDIRenvironget)odirrs 6/usr/lib/python3/dist-packages/cloudinit/temp_utils.pyget_tmp_ancestorrsU    y{{a :>>(F + ++c&t||}tj|s)tj|tj|d|r0t j|drt 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. inoexeczDRequested temporal dir with exe permission `%s` is mounted as noexec) rr pathisdirmakedirschmodr has_mount_optLOGwarningr )rrtdirs r_tempfile_dir_argrs D) , ,D 7==   D v  dH - -  KK%     |I| Krc t|dd|dd|d<tjdi|d}|_fd}t d|S)NdirrFc tj|dS#t$r"}|jtjkr|Yd}~dSd}~wwxYwN)r unlinkOSErrorerrnoENOENT)res r_unlink_if_existsz0ExtendedTemporaryFile.._unlink_if_existsIs_  IdOOOOO   w%,&&'&&&&& s A?Ac<jdSr!)r"name)fhsr unlink_nowz)ExtendedTemporaryFile..unlink_nowWs "'rr+)rpoptempfileNamedTemporaryFiler"setattr)kwargsr'r+r*s @rExtendedTemporaryFiler2@s% 5$K!?!?F5M  $ . .v . .B "BI B j))) Irc+Ktdi|} |Vtj||dS#tj||wxYw)N) ignore_errorsr,)mkdtempshutilrmtree)rmtree_ignore_errorsr1rs rtempdirr9^sb   V  D@  d*>?????? d*>?????s ,Ac Ht||}tjdd|i|SNrr,)rr.r5rrr1s rr5r5j- C + +C   . . .v . ..rc Ht||}tjdd|i|Sr;)rr.mkstempr<s rr?r?or=r)NF)F) contextlibr$r r6r. cloudinitrloggingr getLogger__name__rr r rboolrrr2contextmanagerr9r5r?r,rrrGs? $$$$$$g!! $ ( , ,4 , , , ,DD< @@@@////// ////////r