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