Make remove_sources() generic and name it remove_files().

This is a preparation patch that should have minimal
changes in functionality (some on-screen messages change,
though). Its purpose is to enable the use of the
aforementioned function to remove more than source files.

Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
mauro.giachero 2009-07-10 07:44:00 +00:00
parent 104ad3804f
commit be45ca8aec

View file

@ -1293,7 +1293,7 @@ view_cache_dir() {
ls -A $SRCDIR | sed "s/^\(.*\)$/\"\\1\"/g" \ ls -A $SRCDIR | sed "s/^\(.*\)$/\"\\1\"/g" \
> $SBOPKGTMP/sbopkg_app_sources > $SBOPKGTMP/sbopkg_app_sources
remove_sources "" OFF remove_files $SRCDIR "sources" $SBOPKGTMP/sbopkg_app_sources OFF
} }
view_perm_log() { view_perm_log() {
@ -2635,7 +2635,7 @@ remove_sources_for_app() {
APP=${INFO##*/} APP=${INFO##*/}
APP=${APP%%.*} APP=${APP%%.*}
get_source_names --all "$INFO" | sed "s/^\(.*\)$/\"\\1\"/g" > $APP_SOURCES get_source_names --all "$INFO" | sed "s/^\(.*\)$/\"\\1\"/g" > $APP_SOURCES
remove_sources "$APP" OFF remove_files $SRCDIR "$APP sources" $APP_SOURCES OFF
} }
remove_obsoleted_sources() { remove_obsoleted_sources() {
@ -2684,51 +2684,54 @@ remove_obsoleted_sources() {
# Quote file names # Quote file names
sed -i "s/^\(.*\)$/\"\\1\"/" $SOURCES sed -i "s/^\(.*\)$/\"\\1\"/" $SOURCES
remove_sources "obsolete" ON remove_files $SRCDIR "obsolete sources" $SOURCES ON
} }
remove_sources() { remove_files() {
# Remove all sources specified in $APP_SOURCES from $SRCDIR. # Selectively remove files, after showing a checklist of them.
# The source names _must_ be quoted. # The file names (specified in $3) _must_ be quoted.
# $1 is the application name (used for display purposes only) # $1 is the files path
# $2 is either "ON" or "OFF", and is used as the default checklist status # $2 is the topic (used for display purposes only, like "foo sources")
# $3 is a file containing the list of the files to be shown
# $4 is either "ON" or "OFF", and is used as the default checklist status
local APP="$1" local FILESPATH="$1"
local ONOFF="$2" local TOPIC="$2"
local APP_SOURCES=$SBOPKGTMP/sbopkg_app_sources local FILES="$3"
local APP_SOURCES_CHECKLIST=$SBOPKGTMP/sbopkg_app_sources_checklist local ONOFF="$4"
local APP_SOURCES_DELETING=$SBOPKGTMP/sbopkg_app_sources_deleting local FILES_CHECKLIST=$SBOPKGTMP/sbopkg_file_removal_checklist
local FILES_DELETING=$SBOPKGTMP/sbopkg_file_removal_deleting
local SRC USER_OPTS DELETE ANS DLGWIDTH local SRC USER_OPTS DELETE ANS DLGWIDTH
cd $SRCDIR cd $FILESPATH
if [[ -s $APP_SOURCES ]]; then if [[ -s $FILES ]]; then
sed "s/^\(.*\)$/\\1 \"\" $ONOFF/g" < $APP_SOURCES | sed "s/^\(.*\)$/\\1 \"\" $ONOFF/g" < $FILES |
sort > $APP_SOURCES_CHECKLIST sort > $FILES_CHECKLIST
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
# Compute a reasonable dialog width # Compute a reasonable dialog width
DLGWIDTH=$(wc -L < $APP_SOURCES_CHECKLIST) DLGWIDTH=$(wc -L < $FILES_CHECKLIST)
(( DLGWIDTH += 3 )) (( DLGWIDTH += 3 ))
if [[ $DLGWIDTH -lt 50 ]]; then if [[ $DLGWIDTH -lt 50 ]]; then
DLGWIDTH=50 DLGWIDTH=50
fi fi
dialog --title "$(crunch "Displaying $APP sources")" \ dialog --title "$(crunch "Displaying $TOPIC")" \
--ok-label "Keep all" --extra-label "Delete selected" \ --ok-label "Keep all" --extra-label "Delete selected" \
--cancel-label "OK" --no-cancel --extra-button \ --cancel-label "OK" --no-cancel --extra-button \
--separate-output --checklist "$(crunch "Would you like to \ --separate-output --checklist "$(crunch "Would you like to \
keep the $APP sources in the cache directory $SRCDIR?")"\ keep the $TOPIC in $FILESPATH?")"\
20 $DLGWIDTH 12 \ 20 $DLGWIDTH 12 \
--file $APP_SOURCES_CHECKLIST 2> $APP_SOURCES_DELETING --file $FILES_CHECKLIST 2> $FILES_DELETING
if [[ $? == 3 ]]; then if [[ $? == 3 ]]; then
DELETE=1 DELETE=1
fi fi
else else
# Unquote file names # Unquote file names
tr -d \" < $APP_SOURCES > $APP_SOURCES_DELETING tr -d \" < $FILES > $FILES_DELETING
echo -e "[ Displaying $APP sources ]\n" | echo -e "[ Displaying $TOPIC ]\n" |
cat - $APP_SOURCES_DELETING | $PAGER cat - $FILES_DELETING | $PAGER
while :; do while :; do
echo echo
echo "Do you want to delete these source files?" echo "Do you want to delete these files?"
echo "Press (Y)es to delete or (N)o to keep them." echo "Press (Y)es to delete or (N)o to keep them."
read ANS read ANS
case $ANS in case $ANS in
@ -2738,29 +2741,28 @@ remove_sources() {
esac esac
done done
fi fi
if [[ $DELETE && -s $APP_SOURCES_DELETING ]]; then if [[ $DELETE && -s $FILES_DELETING ]]; then
# Reading from $APP_SOURCES_DELETING... # Reading from $FILES_DELETING...
while read SRC; do while read SRC; do
rm -f $SRCDIR/"$SRC" rm -f $FILESPATH/"$SRC"
done < $APP_SOURCES_DELETING done < $FILES_DELETING
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
dialog --title "Done" --msgbox \ dialog --title "Done" --msgbox \
"$(crunch "The selected $APP sources have been \ "$(crunch "The selected $TOPIC have been \
cleared.")" 8 30 cleared.")" 8 30
else else
echo "$(crunch "The $APP sources have been cleared.")" echo "$(crunch "The $TOPIC have been cleared.")"
fi fi
fi fi
else else
if [[ $DIAG ]]; then if [[ $DIAG ]]; then
dialog --title "ERROR" --msgbox "$(crunch "It appears there are \ dialog --title "ERROR" --msgbox "$(crunch "It appears there are \
no $APP sources in the cache directory.")" 8 30 no $TOPIC in $FILESPATH.")" 8 30
else else
echo "$(crunch "It appears there are no $APP sources in \ echo "$(crunch "It appears there are no $TOPIC in $FILESPATH.")"
the cache directory.")"
fi fi
fi fi
rm -f $APP_SOURCES{,_CHECKLIST,_DELETING} rm -f $FILES{,_CHECKLIST,_DELETING}
} }
add_options() { add_options() {