Commit bbb9c176 authored by Vitaly Lipatov's avatar Vitaly Lipatov

rewrite tmp file cleaning

parent dea66f9b
......@@ -97,8 +97,7 @@ epm_assure()
# can't be used in epm ei case
#docmd epm --auto install $PACKAGE || return
load_helper epm-install
# TODO: HACK: DEBUG=1 for skip to_remove_pkg handling
(DEBUG=1 repack='' non_interactive=1 pkg_names="$PACKAGE" pkg_files='' pkg_urls='' epm_install ) || return
(repack='' non_interactive=1 pkg_names="$PACKAGE" pkg_files='' pkg_urls='' epm_install ) || return
# no check if we don't need a version
[ -n "$PACKAGEVERSION" ] || return 0
......
......@@ -138,10 +138,6 @@ epm_checkpkg()
check_pkg_integrity $pkg || RETVAL=1
done
# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
[ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
#fatal "Broken package $pkg"
return $RETVAL
}
......@@ -81,7 +81,7 @@ __download_pkg_urls()
[ -s "$tmppkg/$i" ] || continue
chmod $verbose a+r "$tmppkg/$i"
[ -n "$pkg_files" ] && pkg_files="$pkg_files $tmppkg/$i" || pkg_files="$tmppkg/$i"
to_remove_pkg_files="$to_remove_pkg_files $tmppkg/$i"
remove_on_exit "$tmppkg/$i"
done
else
warning "Failed to download $url, ignoring"
......@@ -97,8 +97,6 @@ __handle_pkg_urls_to_install()
{
#[ -n "$pkg_urls" ] || return
# TODO: do it correctly
to_remove_pkg_files=
# FIXME: check type of pkg_urls separately?
if [ "$(get_package_type "$pkg_urls")" != $PKGFORMAT ] || ! __use_url_install ; then
# use workaround with eget: download and put in pkg_files
......@@ -112,20 +110,12 @@ __handle_pkg_urls_to_checking()
{
#[ -n "$pkg_urls" ] || return
# TODO: do it correctly
to_remove_pkg_files=
# use workaround with eget: download and put in pkg_files
__download_pkg_urls
pkg_urls=
}
#__clean_downloaded_pkg_files()
#{
# [ -z "$to_remove_pkg_files" ] && return
# rm -fv $to_remove_pkg_files
#}
# obsoleted
__epm_get_altpkg_url()
......
......@@ -173,9 +173,5 @@ __epm_info_by_pkgtype || __epm_info_by_pmtype
local RETVAL=$?
# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
[ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
return $RETVAL
}
......@@ -114,9 +114,8 @@ epm_pack()
exit
fi
trap "__epm_remove_tmp_files" EXIT
local tmpdir="$(mktemp -d --tmpdir=$BIGTMPDIR)"
to_clean_tmp_dirs="$to_clean_tmp_dirs $tmpdir"
remove_on_exit $tmpdir
local packname="$1"
local tarname="$2"
......
......@@ -31,8 +31,7 @@ __epm_repack_to_deb()
repacked_pkgs=''
local TDIR="$(mktemp -d --tmpdir=$BIGTMPDIR)"
to_clean_tmp_dirs="$to_clean_tmp_dirs $TDIR"
trap "__epm_remove_tmp_files" EXIT
remove_on_exit $TDIR
for pkg in $pkgs ; do
abspkg="$(realpath "$pkg")"
......@@ -49,7 +48,7 @@ __epm_repack_to_deb()
local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g")
if [ -n "$DEBCONVERTED" ] ; then
repacked_pkgs="$repacked_pkgs $(realpath $DEBCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(realpath $DEBCONVERTED)"
remove_on_exit "$(realpath $DEBCONVERTED)"
fi
clean_store_output
cd - >/dev/null
......
......@@ -94,7 +94,7 @@ __create_rpmmacros()
%_allow_root_build 1
EOF
to_remove_pkg_files="$to_remove_pkg_files $HOME/.rpmmacros"
remove_on_exit "$HOME/.rpmmacros"
}
......@@ -132,8 +132,7 @@ __epm_repack_to_rpm()
local pkg
export HOME="$(mktemp -d --tmpdir=$BIGTMPDIR)"
to_clean_tmp_dirs="$to_clean_tmp_dirs $HOME"
trap "__epm_remove_tmp_files" EXIT
remove_on_exit $HOME
__create_rpmmacros
local alpkg
......@@ -180,8 +179,7 @@ __epm_repack_to_rpm()
__apply_fix_code "generic" $tmpbuilddir/$subdir $spec $pkgname
[ -n "$SUBGENERIC" ] && __apply_fix_code "generic-$SUBGENERIC" $tmpbuilddir/$subdir $spec
__apply_fix_code $pkgname $tmpbuilddir/$subdir $spec $pkgname
# TODO: we need these dirs to be created
to_remove_pkg_dirs="$to_remove_pkg_dirs $HOME/RPM/BUILD $HOME/RPM"
remove_on_exit $HOME/RPM/BUILD $HOME/RPM
TARGETARCH=$(epm print info -a | sed -e 's|^x86$|i586|')
......@@ -196,7 +194,7 @@ __epm_repack_to_rpm()
local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)"
if [ -s "$repacked_rpm" ] ; then
repacked_pkgs="$repacked_pkgs $repacked_rpm"
to_remove_pkg_files="$to_remove_pkg_files $repacked_rpm"
remove_on_exit "$repacked_rpm"
else
warning "Can't find converted rpm for source binary package '$pkg'"
fi
......
......@@ -740,33 +740,24 @@ get_pkg_name_delimiter()
echo "-"
}
# don't remove <arg> on exit
__epm_remove_from_tmp_files()
# used via remove_on_exit
__epm_remove_tmp_files()
{
keep="$1"
[ -r "$keep" ] || return 0
if [ -n "$to_remove_pkg_files" ] ; then
to_remove_pkg_files="$(echo "$to_remove_pkg_files" | sed -e "s|$keep||")"
fi
if [ -n "$to_remove_tmp_files" ] ; then
to_remove_tmp_files="$(echo "$to_remove_tmp_files" | sed -e "s|$keep||")"
[ -n "$DEBUG" ] && return 0
if [ -n "$to_clean_tmp_dirs" ] ; then
echo "$to_clean_tmp_dirs" | while read p ; do
rm -rf "$p" 2>/dev/null
done
fi
}
# usage: trap "__epm_remove_tmp_files" EXIT
__epm_remove_tmp_files()
{
# TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then
# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -f $to_remove_pkg_files
[ -n "$to_remove_tmp_files" ] && rm -f $to_remove_tmp_files
# hack??
[ -n "$to_remove_pkg_files" ] && rmdir $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
[ -n "$to_remove_pkg_dirs" ] && rmdir $to_remove_pkg_dirs 2>/dev/null
[ -n "$to_clean_tmp_dirs" ] && rm -rf $to_clean_tmp_dirs 2>/dev/null
if [ -n "$to_clean_tmp_files" ] ; then
echo "$to_clean_tmp_files" | while read p ; do
rm -f "$p" 2>/dev/null
rmdir "$(dirname "$p")" 2>/dev/null
done
fi
return 0
}
......@@ -776,9 +767,11 @@ remove_on_exit()
trap "__epm_remove_tmp_files" EXIT
while [ -n "$1" ] ; do
if [ -d "$1" ] ; then
to_clean_tmp_dirs="$to_clean_tmp_dirs $1"
to_clean_tmp_dirs="$to_clean_tmp_dirs
$1"
elif [ -f "$1" ] ; then
to_clean_tmp_files="$to_clean_tmp_files $1"
to_clean_tmp_files="$to_clean_tmp_files
$1"
fi
shift
done
......
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