a '¡DgÅ ã@sªddlZddlZddlZddlZddlZddlZddlmZe e ¡Z dZ dZ de dœdd„Zde dœd d „Zd d „Zejdd d„ƒZde dœdd„Zde dœdd„ZdS)éN)Úutilz/run/cloud-init/tmpz/var/tmp/cloud-initF)Ú needs_execCs2|dur |S|rtSt ¡dkr$tStj dd¡S)NrZTMPDIRz/tmp)Ú_EXE_ROOT_TMPDIRÚosÚgetuidÚ _ROOT_TMPDIRÚenvironÚget)Úodirr©r ú8/usr/lib/python3.9/site-packages/cloudinit/temp_utils.pyÚget_tmp_ancestors r cCsLt||ƒ}tj |¡s,t |¡t |d¡|rHt |d¡rHt  d|¡|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ÿZnoexeczDRequested temporal dir with exe permission `%s` is mounted as noexec) r rÚpathÚisdirÚmakedirsÚchmodrZ has_mount_optÚLOGZwarning)r rÚtdirr r r Ú_tempfile_dir_args     ýrc sDtƒ|d<tjfi|¤Ž‰dd„}|ˆ_‡fdd„}tˆd|ƒˆS)NÚdirc SsHzt |¡Wn4tyB}z|jtjkr.|‚WYd}~n d}~00dS©N)rÚunlinkÚOSErrorÚerrnoÚENOENT)rÚer r r Ú_unlink_if_exists?s  z0ExtendedTemporaryFile.._unlink_if_existscsˆ ˆj¡dSr)rÚnamer ©Zfhr r Ú unlink_nowMsz)ExtendedTemporaryFile..unlink_nowr)rÚtempfileZNamedTemporaryFilerÚsetattr)Úkwargsrrr rr ÚExtendedTemporaryFile8s   r#c ks<tfi|¤Ž}z|VWtj||d�ntj||d�0dS)N)Ú ignore_errors)ÚmkdtempÚshutilÚrmtree)Zrmtree_ignore_errorsr"rr r r ÚtempdirTsr(cKst||ƒ}tjfd|i|¤ŽS©Nr)rr r%©rrr"r r r r%`s r%cKst||ƒ}tjfd|i|¤ŽSr))rr Úmkstempr*r r r r+es r+)NF)NF)F)NF)NF)Ú contextlibrZloggingrr&r Z cloudinitrZ getLoggerÚ__name__rrrÚboolr rr#Úcontextmanagerr(r%r+r r r r Ús