aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremmett1 <emmett1.2miligrams@protonmail.com>2025-06-04 00:01:22 +0800
committeremmett1 <emmett1.2miligrams@protonmail.com>2025-06-04 00:01:22 +0800
commit59e368e39d3b935a52b3912a0a670dc6a390ec82 (patch)
tree91b1fa03e59eb9869f43ad54e2ba9c3daa73cf88
parent0a5dfa6c3f9cf8caed723243df48fd2ac775872c (diff)
downloadspm-59e368e39d3b935a52b3912a0a670dc6a390ec82.tar.gz
spm-59e368e39d3b935a52b3912a0a670dc6a390ec82.zip
improved install & remove
-rwxr-xr-xspm31
1 files changed, 19 insertions, 12 deletions
diff --git a/spm b/spm
index ba7bdd7..f47ab21 100755
--- a/spm
+++ b/spm
@@ -142,12 +142,8 @@ spm_install() {
done
if [ -f "$SPMDIR/conflict.list" ] && [ ! "$SPM_FORCEINSTALL" ]; then
- cat "$SPMDIR/conflict.list" | while read -r line; do
- p=$(grep -x $line $PKGDB/* | awk -F : '{print $1}' | head -n1)
- p=${p##*/}
- echo "${p:-(none)}: $line"
- done
- msg "File conflict found. Enable 'SPM_FORCEINSTALL' env to force install."
+ cat "$SPMDIR/conflict.list"
+ msg "File conflict found."
rm -f "$SPMDIR"/*.list "/tmp/spminstall.lock"
exit 1
fi
@@ -256,16 +252,27 @@ spm_remove() {
msgerr "Package '$1' not installed."
fi
- cd $PKGDB
- tail -n+2 $1 | tac | while read -r line; do
+ cd "${SPM_ROOT:-/}"
+
+ # while loop is way to slow, but need to use it only for space separated filenames
+ grep ' ' $PKGDB/$1 | sort | while read -r line; do
case $line in
- */) grep -x "$line" * | grep -v $1: >/dev/null || rmdir $VERBOSE "${SPM_ROOT%/}"/"$line";;
- etc/*) rm $VERBOSE "${SPM_ROOT%/}"/"$line"; rm -f $VERBOSE "${SPM_ROOT%/}"/"$line".new;;
- *) rm $VERBOSE "${SPM_ROOT%/}"/"$line";;
+ */) rmdir $VERBOSE "$line";;
+ *) rm $VERBOSE "$line";;
esac
+ sed "\|^$line$|d" -i $PKGDB/$1
done
- rm -f $1 $PERMDIR/$1 $OWNDIR/$1
+ # remove files
+ rm $VERBOSE $(tail -n+2 $PKGDB/$1 | tac | grep -v /$)
+
+ # list all dirs except for target pkg
+ grep /$ $PKGDB/* | grep -v /$1: | awk -F : '{print $2}' | sort | uniq > $SPMDIR/remove.all
+ grep /$ $PKGDB/* | grep /$1: | awk -F : '{print $2}' | sort | uniq > $SPMDIR/remove.target
+ grep -Fxv -f $SPMDIR/remove.all $SPMDIR/remove.target > $SPMDIR/remove.rmlist
+ rmdir $VERBOSE $(sort $SPMDIR/remove.rmlist | tac)
+
+ rm -f $PKGDB/$1 $PERMDIR/$1 $OWNDIR/$1 $SPMDIR/remove.*
msg "Package '$1' removed."
exit 0