Improve file cleanup for search-related functions.

This patch revisits some cleanup path, and makes sure that
the temporary files are deleted where appropriate.

Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
mauro.giachero 2009-05-21 08:07:40 +00:00
parent d8a74980be
commit da958c527d

View file

@ -753,7 +753,6 @@ get_category_list() {
check_if_repo_exists check_if_repo_exists
cd $REPO_DIR cd $REPO_DIR
#rm -f $SBOPKGTMP/sbopkg_category_list 2> /dev/null
rm -f $SBOPKGTMP/sbopkg_category_list rm -f $SBOPKGTMP/sbopkg_category_list
DIR=( */ ) DIR=( */ )
if [[ -n $DIR ]]; then if [[ -n $DIR ]]; then
@ -962,6 +961,7 @@ info_item() {
local CURPACKAGE INSTALLEDPACKAGE MENUPACKAGE TITLEPACKAGE RENAMEDPACKAGE local CURPACKAGE INSTALLEDPACKAGE MENUPACKAGE TITLEPACKAGE RENAMEDPACKAGE
local CHOICE PARSED_SLACK_DESC local CHOICE PARSED_SLACK_DESC
local APP="$(< $SBOPKGTMP/sbopkg_item_selection)" local APP="$(< $SBOPKGTMP/sbopkg_item_selection)"
local RETVAL=0
# We need to check and see if the APP has ever been renamed. # We need to check and see if the APP has ever been renamed.
get_old_name OLDPKG $APP get_old_name OLDPKG $APP
@ -1045,14 +1045,9 @@ info_item() {
2> $SBOPKGTMP/sbopkg_info_selection 2> $SBOPKGTMP/sbopkg_info_selection
case $? in case $? in
1 ) # Return to Main Menu 1 ) # Return to Main Menu
rm -f $SBOPKGTMP/sbopkg_category_manual_selection RETVAL=1; break ;;
rm -f $SBOPKGTMP/sbopkg_category_selection 3 ) # Back
rm -f $SBOPKGTMP/sbopkg_info_selection break ;;
rm -f $SBOPKGTMP/sbopkg_item_selection
rm -f $SBOPKGTMP/sbopkg_search_*
return 1
;;
3 ) return 0 ;; # Back
0 ) # OK 0 ) # OK
DEFAULTITEM="$(< $SBOPKGTMP/sbopkg_info_selection)" DEFAULTITEM="$(< $SBOPKGTMP/sbopkg_info_selection)"
CATEGORY="$(< $SBOPKGTMP/sbopkg_category_selection)" CATEGORY="$(< $SBOPKGTMP/sbopkg_category_selection)"
@ -1087,12 +1082,13 @@ info_item() {
;; ;;
esac esac
;; ;;
*) # ESC * ) # ESC
rm -f $SBOPKGTMP/sbopkg_* break ;;
break
;;
esac esac
done done
rm -f $SBOPKGTMP/sbopkg_info_selection
return $RETVAL
} }
customize_item() { customize_item() {
@ -1159,8 +1155,10 @@ browse_categories() {
break break
fi fi
DEFAULTITEM=$(< $SBOPKGTMP/sbopkg_category_manual_selection) DEFAULTITEM=$(< $SBOPKGTMP/sbopkg_category_manual_selection)
gen_search_package '*' $DEFAULTITEM || return 0 gen_search_package '*' $DEFAULTITEM || break
done done
rm -f $SBOPKGTMP/sbopkg_category_manual_selection
rm -f $SBOPKGTMP/sbopkg_category_list
} }
view_cache_dir() { view_cache_dir() {
@ -1861,6 +1859,7 @@ gen_search_package() {
cd $REPO_DIR cd $REPO_DIR
local PKG=$1 local PKG=$1
local CATEGORY=${2:-\*} local CATEGORY=${2:-\*}
local RETVAL=0
local CAT_SELECTION=$SBOPKGTMP/sbopkg_category_selection local CAT_SELECTION=$SBOPKGTMP/sbopkg_category_selection
local ITEM_SELECTION=$SBOPKGTMP/sbopkg_item_selection local ITEM_SELECTION=$SBOPKGTMP/sbopkg_item_selection
local SEARCH_CHOICE=$SBOPKGTMP/sbopkg_search_choice local SEARCH_CHOICE=$SBOPKGTMP/sbopkg_search_choice
@ -1900,12 +1899,11 @@ gen_search_package() {
CHOICE=$? CHOICE=$?
if [[ $CHOICE =~ '^(1|255|-1)$' ]]; then if [[ $CHOICE =~ '^(1|255|-1)$' ]]; then
# Back or ESC # Back or ESC
rm -f $SEARCH_RESULTS break
return 0
elif [[ $CHOICE == 2 ]]; then elif [[ $CHOICE == 2 ]]; then
# Main Menu # Main Menu
rm -f $SEARCH_RESULTS RETVAL=1
return 1 break
fi fi
SRCHPICK="$(< $SEARCH_CHOICE)" SRCHPICK="$(< $SEARCH_CHOICE)"
if [[ $CATEGORY == '*' ]]; then if [[ $CATEGORY == '*' ]]; then
@ -1923,10 +1921,13 @@ gen_search_package() {
if [[ $CHOICE == 0 ]]; then if [[ $CHOICE == 0 ]]; then
echo $SRCHPKG > $ITEM_SELECTION echo $SRCHPKG > $ITEM_SELECTION
cd $REPO_DIR cd $REPO_DIR
info_item || return 1 if ! info_item; then
RETVAL=1
break
fi
else # $CHOICE = 3 else # $CHOICE = 3
add_item_to_queue $SRCHPKG $RVERSION-$RBUILD ON add_item_to_queue $SRCHPKG $RVERSION-$RBUILD ON
return 0 break
fi fi
done done
else else
@ -1943,7 +1944,8 @@ gen_search_package() {
fi fi
fi fi
return 0 rm -f $SEARCH_RESULTS $SEARCH_CHOICE $CAT_SELECTION $ITEM_SELECTION
return $RETVAL
} }
string_search() { string_search() {
@ -2014,7 +2016,11 @@ string_search() {
case $BUTTON in case $BUTTON in
0) 0)
echo $SRCHPKG > $ITEM_SELECTION echo $SRCHPKG > $ITEM_SELECTION
info_item || return 1 if ! info_item; then
rm -f $PICKED_FILE $MENU_FILE $CAT_SELECTION \
$ITEM_SELECTION
return 1
fi
;; ;;
3) 3)
SHORTPATH=$REPO_DIR/$SRCHCAT/$SRCHPKG SHORTPATH=$REPO_DIR/$SRCHCAT/$SRCHPKG
@ -2026,7 +2032,7 @@ string_search() {
continue continue
;; ;;
*) *)
rm -f $PICKED_FILE rm -f $PICKED_FILE $MENU_FILE $CAT_SELECTION $ITEM_SELECTION
return 0 return 0
;; ;;
esac esac
@ -3198,7 +3204,7 @@ main_search() {
0 ) # Package search 0 ) # Package search
PKG=yes ;; PKG=yes ;;
* ) # Cancel or ESC * ) # Cancel or ESC
return 0 ;; break ;;
esac esac
if [[ -s $TERM_FILE ]]; then if [[ -s $TERM_FILE ]]; then
@ -3215,15 +3221,18 @@ main_search() {
continue continue
fi fi
else else
return 0 break
fi fi
if [[ $PKG ]]; then if [[ $PKG ]]; then
gen_search_package "$SEARCH_TERM" || return gen_search_package "$SEARCH_TERM" || break
elif [[ $STRING ]]; then elif [[ $STRING ]]; then
string_search "$SEARCH_TERM" || return string_search "$SEARCH_TERM" || break
fi fi
done done
rm -f $TERM_FILE
return 0
} }
main_updates() { main_updates() {
@ -3290,9 +3299,7 @@ main_menu() {
"Browse" ) "Browse" )
browse_categories ;; browse_categories ;;
"Search" ) "Search" )
main_search main_search ;;
# FIXME main_search should delete this
rm -f $SBOPKGTMP/sbopkg_search_* ;;
"Utilities" ) "Utilities" )
utilities_menu ;; utilities_menu ;;
"Queue" ) "Queue" )