Commit bbb9c176 authored by Vitaly Lipatov's avatar Vitaly Lipatov

rewrite tmp file cleaning

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