f ddlZddlZddlZddlZddlZddlZddlmZeje Z da dZ dZ d defdZd defdZdZej$d d Zd defd Zd defd Zy)N)utilz/run/cloud-init/tmpz/var/tmp/cloud-init needs_exec||S|rtStrtStjdk(rtStj j ddS)NrTMPDIRz/tmp)_EXE_ROOT_TMPDIR_TMPDIRosgetuid _ROOT_TMPDIRenvironget)odirrs 6/usr/lib/python3/dist-packages/cloudinit/temp_utils.pyget_tmp_ancestorrsG   yy{a ::>>(F ++ct||}tjj|s+tj|tj |d|r,t j|drtjd|||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_argrst D) ,D 77==  D v   dH - KK%   |I Krc t|jdd|jdd|d<tjdi|d}|_fd}t d|S)NdirrFc tj|y#t$r)}|jtjk7r|Yd}~yd}~wwxYwN)r unlinkOSErrorerrnoENOENT)res r_unlink_if_existsz0ExtendedTemporaryFile.._unlink_if_existsIs<  IIdO ww%,,&' s A AA c<jjyr )r!name)fhsr unlink_nowz)ExtendedTemporaryFile..unlink_nowWs "''rr*)rpoptempfileNamedTemporaryFiler!setattr)kwargsr&r*r)s @rExtendedTemporaryFiler1@sg% 5$K!?F5M  $ $ .v .B "BI B j) Irc+Ktdi|} |tj||y#tj||wxYww)N) ignore_errorsr+)mkdtempshutilrmtree)rmtree_ignore_errorsr0rs rtempdirr8^s>  V D@  d*>? d*>?s A+AAAc Ht||}tjdd|i|SNrr+)rr-r4rrr0s rr4r4j' C +C    . .v ..rc Ht||}tjdd|i|Sr:)rr-mkstempr;s rr>r>or<r)NF)F) contextlibr#loggingr r5r- cloudinitr getLogger__name__rrr rboolrrr1contextmanagerr8r4r>r+rrrFs  g! $ ( ,4 ,DD< @@// //r