Commit 90c9c6be authored by Vitaly Lipatov's avatar Vitaly Lipatov

improve mktemp result checking and add remote_on_exit

parent 81641e8b
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
__alt_fix_triggers() __alt_fix_triggers()
{ {
local TDIR="$(mktemp -d)" local TDIR
TDIR="$(mktemp -d)" || fatal
remote_on_exit $TDIR
assure_exists time assure_exists time
touch $TDIR/added touch $TDIR/added
for ft in $(ls /usr/lib/rpm/*.filetrigger | sort) ; do for ft in $(ls /usr/lib/rpm/*.filetrigger | sort) ; do
......
...@@ -67,8 +67,8 @@ __download_pkg_urls() ...@@ -67,8 +67,8 @@ __download_pkg_urls()
local url local url
[ -z "$pkg_urls" ] && return [ -z "$pkg_urls" ] && return
for url in $pkg_urls ; do for url in $pkg_urls ; do
local tmppkg="$(mktemp -d)" || fatal "failed mktemp -d" local tmppkg
remove_on_exit "$tmppkg" tmppkg="$(mktemp -d)" || fatal
docmd chmod $verbose a+rX $tmppkg docmd chmod $verbose a+rX $tmppkg
showcmd cd $tmppkg showcmd cd $tmppkg
cd $tmppkg || fatal cd $tmppkg || fatal
...@@ -147,7 +147,8 @@ __epm_print_url_alt_check() ...@@ -147,7 +147,8 @@ __epm_print_url_alt_check()
{ {
local pkg=$1 local pkg=$1
shift shift
local tm="$(mktemp)" local tm
tm="$(mktemp)" || fatal
assure_exists curl assure_exists curl
load_helper epm-site load_helper epm-site
quiet=1 quiet=1
......
...@@ -112,8 +112,9 @@ epm_pack() ...@@ -112,8 +112,9 @@ epm_pack()
exit exit
fi fi
local tmpdir="$(mktemp -d --tmpdir=$BIGTMPDIR)" local tmpdir
remove_on_exit $tmpdir tmpdir="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
remove_on_exit "$tmpdir"
local packname="$1" local packname="$1"
local tarname="$2" local tarname="$2"
......
...@@ -99,7 +99,8 @@ __list_app_packages_table() ...@@ -99,7 +99,8 @@ __list_app_packages_table()
__list_installed_app() __list_installed_app()
{ {
local i local i
local tapt="$(mktemp)" || fatal local tapt
tapt="$(mktemp)" || fatal
remove_on_exit $tapt remove_on_exit $tapt
__list_app_packages_table >$tapt __list_app_packages_table >$tapt
# get all installed packages and convert it to a apps list # get all installed packages and convert it to a apps list
...@@ -115,7 +116,8 @@ __list_installed_app() ...@@ -115,7 +116,8 @@ __list_installed_app()
__list_installed_packages() __list_installed_packages()
{ {
local i local i
local tapt="$(mktemp)" || fatal local tapt
tapt="$(mktemp)" || fatal
remove_on_exit $tapt remove_on_exit $tapt
__list_app_packages_table >$tapt __list_app_packages_table >$tapt
# get all installed packages # get all installed packages
...@@ -370,8 +372,9 @@ __epm_play_initialize_ipfs() ...@@ -370,8 +372,9 @@ __epm_play_initialize_ipfs()
fi fi
# download and merge with local db # download and merge with local db
local t=$(mktemp) || fatal local t
remove_on_exit "$t" t=$(mktemp) || fatal
remove_on_exit $t
__epm_play_download_epm_file "$t" "eget-ipfs-db.txt" || warning "Can't update IPFS DB" __epm_play_download_epm_file "$t" "eget-ipfs-db.txt" || warning "Can't update IPFS DB"
if [ -s "$t" ] ; then if [ -s "$t" ] ; then
echo >>$t echo >>$t
......
...@@ -30,7 +30,8 @@ __epm_repack_to_deb() ...@@ -30,7 +30,8 @@ __epm_repack_to_deb()
repacked_pkgs='' repacked_pkgs=''
local TDIR="$(mktemp -d --tmpdir=$BIGTMPDIR)" local TDIR
TDIR="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
remove_on_exit $TDIR remove_on_exit $TDIR
for pkg in $pkgs ; do for pkg in $pkgs ; do
......
...@@ -90,9 +90,6 @@ __apply_fix_code() ...@@ -90,9 +90,6 @@ __apply_fix_code()
__create_rpmmacros() __create_rpmmacros()
{ {
# FIXME:
[ -n "$TMPDIR" ] || TMPDIR=/tmp
cat <<EOF >$HOME/.rpmmacros cat <<EOF >$HOME/.rpmmacros
%_topdir $HOME/RPM %_topdir $HOME/RPM
%_tmppath $TMPDIR %_tmppath $TMPDIR
...@@ -140,8 +137,9 @@ __epm_repack_to_rpm() ...@@ -140,8 +137,9 @@ __epm_repack_to_rpm()
fi fi
local pkg local pkg
export HOME="$(mktemp -d --tmpdir=$BIGTMPDIR)" HOME="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
remove_on_exit $HOME remove_on_exit $HOME
export HOME
__create_rpmmacros __create_rpmmacros
local alpkg local alpkg
......
...@@ -24,8 +24,8 @@ load_helper epm-sh-altlinux ...@@ -24,8 +24,8 @@ load_helper epm-sh-altlinux
__epm_get_file_from_url() __epm_get_file_from_url()
{ {
local url="$1" local url="$1"
local tmpfile=$(mktemp) local tmpfile
remove_on_exit "$tmpfile" tmpfile=$(mktemp) || fatal
eget -O "$tmpfile" "$url" >/dev/null eget -O "$tmpfile" "$url" >/dev/null
echo "$tmpfile" echo "$tmpfile"
} }
...@@ -116,7 +116,8 @@ __epm_addkey_dnf() ...@@ -116,7 +116,8 @@ __epm_addkey_dnf()
local target="/etc/yum.repos.d/$name.repo" local target="/etc/yum.repos.d/$name.repo"
[ -s $target ] && return [ -s $target ] && return
local tmpfile=$(mktemp) local tmpfile
tmpfile=$(mktemp) || fatal
remove_on_exit $tmpfile remove_on_exit $tmpfile
cat >$tmpfile <<EOF cat >$tmpfile <<EOF
[$name] [$name]
......
...@@ -397,7 +397,8 @@ __epm_restore_meson() ...@@ -397,7 +397,8 @@ __epm_restore_meson()
# gtk_wayland_dep = dependency('gtk4-wayland', required: false) # gtk_wayland_dep = dependency('gtk4-wayland', required: false)
# packagekit_dep = dependency('packagekit-glib2', version: '>= 1.2', required: get_option('packagekit')) # packagekit_dep = dependency('packagekit-glib2', version: '>= 1.2', required: get_option('packagekit'))
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
local lt=$(mktemp) local lt
lt=$(mktemp) || fatal
echo echo
__epm_restore_print_comment "$req_file" " dependency" __epm_restore_print_comment "$req_file" " dependency"
grep "dependency(" $req_file | sed -e 's|.*dependency(||' -e 's|).*||' -e 's|, required.*||' -e 's|, version:||' -e "s|'||g" >$lt grep "dependency(" $req_file | sed -e 's|.*dependency(||' -e 's|).*||' -e 's|, required.*||' -e 's|, version:||' -e "s|'||g" >$lt
...@@ -407,7 +408,8 @@ __epm_restore_meson() ...@@ -407,7 +408,8 @@ __epm_restore_meson()
fi fi
info "Install requirements from $req_file ..." info "Install requirements from $req_file ..."
local lt=$(mktemp) local lt
lt=$(mktemp) || fatal
grep "dependency(" $req_file | sed -e 's|.*dependency(||' -e 's|).*||' -e 's|, required.*||' -e 's|, version:||' -e "s|'||g" >$lt grep "dependency(" $req_file | sed -e 's|.*dependency(||' -e 's|).*||' -e 's|, required.*||' -e 's|, version:||' -e "s|'||g" >$lt
ilist="$ilist $(__epm_print_meson_list "" $lt)" ilist="$ilist $(__epm_print_meson_list "" $lt)"
...@@ -424,7 +426,8 @@ __epm_restore_npm() ...@@ -424,7 +426,8 @@ __epm_restore_npm()
assure_exists jq || fatal assure_exists jq || fatal
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
local lt=$(mktemp) local lt
lt=$(mktemp) || fatal
a= jq .dependencies <$req_file >$lt a= jq .dependencies <$req_file >$lt
echo echo
__epm_restore_print_comment "$req_file" __epm_restore_print_comment "$req_file"
...@@ -439,7 +442,8 @@ __epm_restore_npm() ...@@ -439,7 +442,8 @@ __epm_restore_npm()
fi fi
info "Install requirements from $req_file ..." info "Install requirements from $req_file ..."
local lt=$(mktemp) local lt
lt=$(mktemp) || fatal
a= jq .dependencies <$req_file >$lt a= jq .dependencies <$req_file >$lt
ilist="$(__epm_print_npm_list "" $lt)" ilist="$(__epm_print_npm_list "" $lt)"
a= jq .devDependencies <$req_file >$lt a= jq .devDependencies <$req_file >$lt
...@@ -454,7 +458,8 @@ __epm_restore_perl() ...@@ -454,7 +458,8 @@ __epm_restore_perl()
local req_file="$1" local req_file="$1"
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
local lt=$(mktemp) local lt
lt=$(mktemp) || fatal
a= /usr/bin/perl $req_file PRINT_PREREQ=1 >$lt a= /usr/bin/perl $req_file PRINT_PREREQ=1 >$lt
# all requirements will autodetected during packing, put it to the buildreq # all requirements will autodetected during packing, put it to the buildreq
echo echo
...@@ -465,7 +470,8 @@ __epm_restore_perl() ...@@ -465,7 +470,8 @@ __epm_restore_perl()
fi fi
info "Install requirements from $req_file ..." info "Install requirements from $req_file ..."
local lt=$(mktemp) local lt
lt=$(mktemp) || exit
a= /usr/bin/perl $req_file PRINT_PREREQ=1 >$lt a= /usr/bin/perl $req_file PRINT_PREREQ=1 >$lt
ilist="$(__epm_print_perl_list "" $lt)" ilist="$(__epm_print_perl_list "" $lt)"
rm -f $lt rm -f $lt
...@@ -480,7 +486,8 @@ __epm_restore_perl_shyaml() ...@@ -480,7 +486,8 @@ __epm_restore_perl_shyaml()
assure_exists shyaml || fatal assure_exists shyaml || fatal
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
local lt=$(mktemp) local lt
lt=$(mktemp) || fatal
a= shyaml get-value requires <$req_file >$lt a= shyaml get-value requires <$req_file >$lt
# all requirements will autodetected during packing, put it to the buildreq # all requirements will autodetected during packing, put it to the buildreq
echo echo
...@@ -496,7 +503,8 @@ __epm_restore_perl_shyaml() ...@@ -496,7 +503,8 @@ __epm_restore_perl_shyaml()
fi fi
info "Install requirements from $req_file ..." info "Install requirements from $req_file ..."
local lt=$(mktemp) local lt
lt=$(mktemp) || fatal
a= shyaml get-value requires <$req_file >$lt a= shyaml get-value requires <$req_file >$lt
ilist="$(__epm_print_perl_list "" $lt)" ilist="$(__epm_print_perl_list "" $lt)"
a= shyaml get-value build_requires <$req_file >$lt a= shyaml get-value build_requires <$req_file >$lt
......
...@@ -254,7 +254,7 @@ subst_option() ...@@ -254,7 +254,7 @@ subst_option()
store_output() store_output()
{ {
# use make_temp_file from etersoft-build-utils # use make_temp_file from etersoft-build-utils
RC_STDOUT="$(mktemp)" RC_STDOUT="$(mktemp)" || fatal
local CMDSTATUS=$RC_STDOUT.pipestatus local CMDSTATUS=$RC_STDOUT.pipestatus
echo 1 >$CMDSTATUS echo 1 >$CMDSTATUS
#RC_STDERR=$(mktemp) #RC_STDERR=$(mktemp)
...@@ -909,6 +909,7 @@ subst() ...@@ -909,6 +909,7 @@ subst()
fi fi
check_core_commands() check_core_commands()
{ {
#which which >/dev/null || fatal "Can't find which command (which or debianutils package is missed?)" #which which >/dev/null || fatal "Can't find which command (which or debianutils package is missed?)"
......
...@@ -22,7 +22,8 @@ load_helper epm-query ...@@ -22,7 +22,8 @@ load_helper epm-query
__convert_pkgallowscripts_to_regexp() __convert_pkgallowscripts_to_regexp()
{ {
local tmpalf="$(mktemp)" || fatal local tmpalf
tmpalf="$(mktemp)" || fatal
# copied from eget's filter_glob # copied from eget's filter_glob
# check man glob # check man glob
# remove commentы and translate glob to regexp # remove commentы and translate glob to regexp
......
remove_on_exit()
{
list_on_exit="$1"
}
fatal()
{
echo "$*" >&2
exit 1
}
# guarantied temp file/dir removed on exit
epm_mktemp()
{
local tmp
tmp="$(2mktemp "$@")" || fatal "Can't create temp file"
remove_on_exit "$tmp"
echo "$tmp"
}
test_func()
{
local tm
tm=$(epm_mktemp) || fatal "ETEST"
echo "tm:$tm"
}
file=$(epm_mktemp)
test_func
echo "file:$file"
echo "list_on_exit: $list_on_exit"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment