changeset 202:8032b5bfafbe

remove: no longer prepare removal
author David Demelier <markand@malikania.fr>
date Tue, 03 Aug 2021 12:24:51 +0200
parents 1780d9cf2d34
children c8239d2eee78
files Makefile awk/del.awk awk/remove.awk exec/remove.sh
diffstat 4 files changed, 16 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Aug 03 12:10:39 2021 +0200
+++ b/Makefile	Tue Aug 03 12:24:51 2021 +0200
@@ -99,8 +99,7 @@
                 awk/message.awk \
                 awk/orphan.awk \
                 awk/print.awk \
-                awk/protected.awk \
-                awk/remove.awk
+                awk/protected.awk
 
 DOC_SRCS=       doc/howto.download.sh \
                 doc/howto.options.sh \
--- a/awk/del.awk	Tue Aug 03 12:10:39 2021 +0200
+++ b/awk/del.awk	Tue Aug 03 12:24:51 2021 +0200
@@ -26,13 +26,11 @@
 # Pattern used when removing the package.
 #
 # $1 removing
-# $2 current package index
-# $3 total package index
-# $4 package name
-# $5 package version
+# $2 package name
+# $3 package version
 #
 /^removing/ {
-	printf "(%d/%d) removing %s-%s\n", $2, $3, $4, $5
+	printf "removing %s-%s\n", $2, $3
 }
 
 #
--- a/awk/remove.awk	Tue Aug 03 12:10:39 2021 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-#
-# remove.awk -- print a remove summary for uninstall
-#
-# Copyright (c) 2019 David Demelier <markand@malikania.fr>
-#
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-#
-
-BEGIN {
-	print "Packages to remove:\n"
-}
-
-#
-# pattern when removing packages.
-#
-# $1 the package name
-# $2 the package version
-#
-{
-	printf "    %s-%s\n", $1, $2
-}
-
-END {
-	print ""
-	printf "Proceed? [N/y] "
-}
--- a/exec/remove.sh	Tue Aug 03 12:10:39 2021 +0200
+++ b/exec/remove.sh	Tue Aug 03 12:24:51 2021 +0200
@@ -20,14 +20,12 @@
 . @LIBEXECDIR@/vpk/vpk.subr
 
 readonly libdir=/var/lib/vpk
-readonly tmpdir=$TMPDIR/vpk.remove
-readonly remove_list=$tmpdir/list
+readonly tmpdir=$(mktemp -d /tmp/vpk.build.XXXXXX)
 readonly kept_list=$tmpdir/kept
 readonly directory_list=$tmpdir/directories
 readonly preserved_list=$tmpdir/preserved
 readonly protected_list=$tmpdir/protected
 
-batch=0
 verbose=1
 
 #
@@ -37,7 +35,7 @@
 #
 clean()
 {
-	rm -rf $TMPDIR/vpk.remove
+	rm -rf $tmpdir
 }
 
 #
@@ -158,36 +156,6 @@
 }
 
 #
-# append name version
-#
-# Append to the list of packages to be removed.
-#
-append()
-{
-	if ! grep -q $1 $remove_list 2> /dev/null; then
-		echo "$1 $2" >> $remove_list
-	fi
-}
-
-#
-# list names...
-#
-# Create a list of packages to be removed if they are installed.
-#
-list()
-{
-	for pkg in $@; do
-		version=$(cat /var/lib/vpk/$pkg/version 2> /dev/null)
-
-		if [ -z "$version" ]; then
-			vpk_warning "no-package" $pkg
-		else
-			append $pkg $version
-		fi
-	done
-}
-
-#
 # remove name
 #
 # Remove the package from the disk.
@@ -212,16 +180,14 @@
 	fi
 
 	# Remove protected files that are not modified.
-	rmprotected $name
-	rmfiles $name
-	rmdirs $name
+	rmprotected $1
+	rmfiles $1
+	rmdirs $1
 
 	# Post-install step.
 	if [ -x $postfile ]; then
 		$postfile "post-uninstall"
 	fi
-
-	current=$((current + 1))
 }
 
 #
@@ -231,19 +197,15 @@
 #
 remove_all()
 {
-	total=$(wc -l $remove_list | awk '{ print $1 }')
-	current=1
+	for pkg in "$@"; do
+		version=$(cat /var/lib/vpk/$pkg/version 2> /dev/null)
 
-	cat $remove_list | while read -r pkg; do
-		name=$(echo $pkg | awk '{ print $1 }')
-		version=$(echo $pkg | awk '{ print $2 }')
-
-		if [ "$verbose" -ge 1 ]; then
-			report "removing|%d|%d|%s|%s\n" \
-			    $current $total $name $version
+		if [ -z "$version" ]; then
+			continue
 		fi
 
-		remove $name
+		report "removing|%s|%s\n" $pkg $version
+		remove $pkg
 	done
 }
 
@@ -294,23 +256,6 @@
 rm -rf $tmpdir
 mkdir -p $tmpdir
 
-list $@
-
-if [ ! -s $remove_list ]; then
-	vpk_stderr "abort: no packages to remove"
-	exit 1
-fi
-
-if [ "$batch" -eq 0 ]; then
-	awk -f $DATADIR/vpk/remove.awk $remove_list
-
-	read ans
-
-	if [ "$ans" != "y" ]; then
-		exit 0
-	fi
-fi
-
-remove_all
+remove_all "$@"
 notes
 clean