sup rev 51

Fast remove (thanks to tazpkg code)
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 18 18:22:13 2017 +0100 (2017-03-18)
parents e21511078740
children 9c53aa99d1f6
files libsup.sh sup
line diff
     1.1 --- a/libsup.sh	Sat Mar 11 11:57:32 2017 +0200
     1.2 +++ b/libsup.sh	Sat Mar 18 18:22:13 2017 +0100
     1.3 @@ -132,8 +132,9 @@
     1.4  	
     1.5  	# Remove existing package files to avoid untracked files
     1.6  	if [ -d "$installed/$PACKAGE" ]; then
     1.7 -		gettext "Removing existing package files..."
     1.8 +		gettext "Removing old package files..."
     1.9  		remove_sup "$PACKAGE" >/dev/null; status
    1.10 +		. receip
    1.11  	fi
    1.12  	
    1.13  	newline
    1.14 @@ -160,10 +161,13 @@
    1.15  		gettext "Creating the list of installed files..."; echo
    1.16  	fi
    1.17  	files_list="${cache}/install/${PACKAGE}-${VERSION}/files.list"
    1.18 +	dirs_list="${cache}/install/${PACKAGE}-${VERSION}/dirs.list"
    1.19  	cd ${cache}/install/${PACKAGE}-${VERSION}/files
    1.20  	find . -type f -print > ${files_list}
    1.21  	find . -type l -print >> ${files_list}
    1.22 +	find . -type d -print > ${dirs_list}
    1.23  	sed -i s'/^.//'g ${files_list}
    1.24 +	sed -i s'/^.//'g ${dirs_list}
    1.25  	
    1.26  	# Back to pkg tree
    1.27  	cd ${cache}/install/${PACKAGE}-${VERSION}
    1.28 @@ -178,7 +182,7 @@
    1.29  	data="${installed}/${PACKAGE}"
    1.30  	mkdir -p ${data}
    1.31  	
    1.32 -	for file in receip README files.list; do
    1.33 +	for file in receip README files.list dirs.list; do
    1.34  		[ -f "$file" ] && cp -f ${file} ${data}
    1.35  	done
    1.36  	for file in $(ls -A files); do
    1.37 @@ -192,8 +196,11 @@
    1.38  # Remove a sup package
    1.39  remove_sup() {
    1.40  	pkg="$1"
    1.41 +	. ${installed}/${pkg}/receip
    1.42 +	
    1.43  	files_list="$installed/$pkg/files.list"
    1.44 -	. ${installed}/${pkg}/receip
    1.45 +	dirs_list="$installed/$pkg/dirs.list"
    1.46 +	touch ${dirs_list}
    1.47  	
    1.48  	newline
    1.49  	echo -n "$(colorize 33 $(gettext 'Removing package:'))"
    1.50 @@ -207,27 +214,22 @@
    1.51  	in=$((7 + ${char}))
    1.52  	indent $(($(tty_size) - ${in})) "[ $(colorize 033 $files) ]"
    1.53  	
    1.54 -	# Remove all files
    1.55 -	for file in $(cat $files_list)
    1.56 -	do
    1.57 -		# --verbose
    1.58 -		if [ "$verbose" ]; then
    1.59 -			gettext "Removing file   :"; echo -n " ${file#/}"
    1.60 -			rm -f "${HOME}${file}"; status
    1.61 -			# Empty folder ?
    1.62 -			if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then
    1.63 -				path="$(dirname $file)"
    1.64 -				gettext "Removing folder :"; echo -n " ${path#/}"
    1.65 -				rmdir "${HOME}$(dirname $file)"; status
    1.66 -			fi
    1.67 -		else
    1.68 -			rm -f "${HOME}${file}"
    1.69 -			# Empty folder ?
    1.70 -			if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then
    1.71 -				rmdir "${HOME}$(dirname $file)"
    1.72 -			fi
    1.73 -		fi
    1.74 -	done
    1.75 +	# Remove all files and empty folders (code idea from Tazpkg :-)
    1.76 +	IFS=$'\n'
    1.77 +	files2remove="$(mktemp)"
    1.78 +	dirs2remove="$(mktemp)"
    1.79 +	
    1.80 +	awk -vhome="$HOME" '{ printf "%s%s\n", home, $0; }' \
    1.81 +		"$files_list" > "$files2remove"
    1.82 +	xargs rm < "$files2remove"
    1.83 +	
    1.84 +	awk -vhome="$HOME" '{ printf "%s%s\n", home, $0; }' \
    1.85 +		"$dirs_list" > "$dirs2remove"
    1.86 +	xargs rmdir -p < "$dirs2remove" 2>/dev/null
    1.87 +	
    1.88 +	rm ${files2remove} ${dirs2remove}
    1.89 +	unset IFS
    1.90 +	
    1.91  	gettext "Removing packages from local database..."
    1.92  	rm -rf ${installed}/${pkg}; status
    1.93  	newline
     2.1 --- a/sup	Sat Mar 11 11:57:32 2017 +0200
     2.2 +++ b/sup	Sat Mar 18 18:22:13 2017 +0100
     2.3 @@ -46,7 +46,7 @@
     2.4    --force    update  $(gettext "Force recharging packages database")
     2.5    --db       list    $(gettext "List all packages in database")
     2.6    --init     cook    $(gettext "Initialize sup cook environment")
     2.7 -  --list     info    $(gettext "List files installed by a package")
     2.8 +  --list     pkg     $(gettext "List files installed by a package")
     2.9    --verbose  all     $(gettext "Display more output messages")
    2.10  
    2.11  $(colorize 33 Manual)               man sup