Implement automatic temp removal

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-02-05 19:32:29 +01:00
parent b944d82e92
commit 8446328bc6

View file

@ -21,6 +21,7 @@
# Print configuration directories - helper for all other scripts # Print configuration directories - helper for all other scripts
# #
# Values can be overriden from outside, so you can # Values can be overriden from outside, so you can
# customise paths as you like (for distributors, geeks and hackers) # customise paths as you like (for distributors, geeks and hackers)
: ${__cdist_config:=/etc/cdist} : ${__cdist_config:=/etc/cdist}
@ -46,10 +47,11 @@ export __cdist_remote_explorer_dir
export __cdist_remote_cache_explorer export __cdist_remote_cache_explorer
: ${__cdist_remote_cache_bin:=$__cdist_remote_base_dir/bin} : ${__cdist_remote_cache_bin:=$__cdist_remote_base_dir/bin}
# create basedir + tempfile for direct usage # Tempfiles need to be recreated for each individual script, unshared!
# FIXME: remove on exit __cdist_tmp_dir=$(mktemp -d "/tmp/cdist.XXXXXXXXXXXX")
: ${__cdist_tmp_dir:=$(mktemp -d "/tmp/cdist.XXXXXXXXXXXX")} export __cdist_tmp_dir
: ${__cdist_tmp_file:=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")} __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")
export __cdist_tmp_file
################################################################################ ################################################################################
# cconf standard vars prefixed with cdist # cconf standard vars prefixed with cdist
@ -72,6 +74,7 @@ __cdist_sane_regexp='[A-Za-z0-9]*[-A-Za-z0-9_]*'
# Used to mark file that created a specific type # Used to mark file that created a specific type
__cdist_object_source=".source" __cdist_object_source=".source"
################################################################################ ################################################################################
# Function list # Function list
# #
@ -97,3 +100,13 @@ __cdist_cache_host()
{ {
echo "${__cdist_cache_hosts}/${__cdist_target_host}" echo "${__cdist_cache_hosts}/${__cdist_target_host}"
} }
__cdist_tmp_removal()
{
rm -rf "${__cdist_tmp_dir}"
}
################################################################################
# Trap for tmp removal
#
trap __cdist_tmp_removal EXIT