x[h ddlZddlZddlZddlZddlZddlZddlmZeje Z dZ dZ d de fdZd de fdZdZej"d d Zd de fd Zd de fd Zy)N)utilz/run/cloud-init/tmpz/var/tmp/cloud-init needs_exec||S|rtStjdk(rtStjj ddS)NrTMPDIRz/tmp)_EXE_ROOT_TMPDIRosgetuid _ROOT_TMPDIRenvironget)odirrs 6/usr/lib/python3/dist-packages/cloudinit/temp_utils.pyget_tmp_ancestorrs?   yy{a ::>>(F ++ct||}tjj|s+tj|tj |d|r,t j|drtjd||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) rrpathisdirmakedirschmodr has_mount_optLOGwarning)r rtdirs r_tempfile_dir_argrsh D) ,D 77==  D v   dH - KK%  Krc t|d<tjdi|d}|_fd}t d|S)Ndirc tj|y#t$r)}|jtjk7r|Yd}~yd}~wwxYwN)runlinkOSErrorerrnoENOENT)res r_unlink_if_existsz0ExtendedTemporaryFile.._unlink_if_exists?s<  IIdO ww%,,&' s A AA c<jjyr)r name)fhsr unlink_nowz)ExtendedTemporaryFile..unlink_nowMs "''rr))rtempfileNamedTemporaryFiler setattr)kwargsr%r)r(s @rExtendedTemporaryFiler/8sH%'F5M  $ $ .v .B "BI B j) Irc+Ktdi|} |tj||y#tj||wxYww)N) ignore_errorsr*)mkdtempshutilrmtree)rmtree_ignore_errorsr.rs rtempdirr6Ts>  V D@  d*>? d*>?s A+AAAc Ht||}tjdd|i|SNrr*)rr+r2rrr.s rr2r2`' C +C    . .v ..rc Ht||}tjdd|i|Sr8)rr+mkstempr9s rr<r<er:r)NF)F) contextlibr"loggingrr3r+ cloudinitr getLogger__name__rr rboolrrr/contextmanagerr6r2r<r*rrrDs  g!$ (,4,D:8 @@// //r