Github messages for voidlinux
 help / color / mirror / Atom feed
From: classabbyamp <classabbyamp@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: [PR PATCH] xbps-src: add purge-binpkgs action
Date: Wed, 14 Feb 2024 05:57:53 +0100	[thread overview]
Message-ID: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-48715@inbox.vuxu.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

There is a new pull request by classabbyamp against master on the void-packages repository

https://github.com/classabbyamp/void-packages begone-fowl-demons
https://github.com/void-linux/void-packages/pull/48715

xbps-src: add purge-binpkgs action
gets rid of binpkgs that don't match what's in srcpkgs/ (different version or missing) and cleans all repodatas.

WIP: need to document this better

#### Testing the changes
- I tested the changes in this PR: **briefly**



A patch file from https://github.com/void-linux/void-packages/pull/48715.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-begone-fowl-demons-48715.patch --]
[-- Type: text/x-diff, Size: 3615 bytes --]

From 31a0cc6c0abce0324301d37dc03ffc27af923350 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Tue, 13 Feb 2024 23:56:22 -0500
Subject: [PATCH] xbps-src: add purge-binpkgs action

---
 common/xbps-src/shutils/purge_binpkgs.sh | 80 ++++++++++++++++++++++++
 xbps-src                                 |  6 ++
 2 files changed, 86 insertions(+)
 create mode 100644 common/xbps-src/shutils/purge_binpkgs.sh

diff --git a/common/xbps-src/shutils/purge_binpkgs.sh b/common/xbps-src/shutils/purge_binpkgs.sh
new file mode 100644
index 00000000000000..259e7ca9ec843f
--- /dev/null
+++ b/common/xbps-src/shutils/purge_binpkgs.sh
@@ -0,0 +1,80 @@
+# scans binpkgs for packages that don't match the current version and removes them.
+
+purge_binpkgs() {
+	local max cur percent pnew dir rdata arch template pkg ver rev
+	local binpkg pkgfile pkgver pkgname version repos
+	local -a binpkg_dirs templates binpkgs
+	local -A versions
+
+	if [ -z "$XBPS_REPOSITORY" ]; then
+		msg_error "The variable \$XBPS_REPOSITORY is not set."
+		exit 1
+	fi
+
+	# Scan all templates for their current versions
+	mapfile -t templates < <(find srcpkgs -mindepth 1 -maxdepth 1 -type d -printf "srcpkgs/%f/template\n")
+	max="${#templates[@]}"
+	cur=0
+	if [ -z "$max" ]; then
+		msg_error "No srcpkgs/*/template files found. Wrong working directory?"
+		exit 1
+	fi
+	percent=-1
+	for template in "${templates[@]}"; do
+		pkg="${template#*/}"
+		pkg="${pkg%/*}"
+		if [ ! -L "srcpkgs/$pkg" ]; then
+			ver="$(grep -Eh "^version=.*$" "${template}")"
+			rev="$(grep -Eh "^revision=.*$" "${template}")"
+			versions["$pkg"]="${ver#*=}_${rev#*=}"
+		fi
+		cur=$((cur + 1))
+		pnew=$((100 * cur / max))
+		if [ $pnew -ne $percent ]; then
+			percent="$pnew"
+			printf "\rScanning templates: %3d%% (%d/%d)" "$percent" "$cur" "$max"
+		fi
+	done
+	echo
+
+	binpkgs=("$XBPS_REPOSITORY"/**/*.xbps)
+	max=${#binpkgs[@]}
+	if [ -z "$max" ]; then
+		msg_error "No binpkgs found in '$XBPS_REPOSITORY'"
+		exit 1
+	fi
+	cur=0
+	for binpkg in "${binpkgs[@]}"; do
+		pkgfile="${binpkg##*/}"
+		pkgver="${pkgfile%.*.*}"
+		pkgname="$(find -P srcpkgs -maxdepth 2 -samefile "srcpkgs/${pkgver%-*}/template" 2>/dev/null | cut -d/ -f2)"
+		[ -z "$pkgname" ] && pkgname="${pkgver%-*}"
+		version="${pkgver##*-}"
+		# existing package
+		if [ -n "${versions[$pkgname]}" ]; then
+			# remove if not matching the template version
+			if ! xbps-uhelper cmpver "${versions[$pkgname]}" "$version"; then
+				rm -vf "$binpkg"
+				cur=$((cur + 1))
+			fi
+		else
+			# nonexistant package, remove
+			rm -vf "$binpkg"
+			cur=$((cur + 1))
+		fi
+	done
+
+	mapfile -t binpkg_dirs < <(find "$XBPS_REPOSITORY" -type d)
+	repos=0
+	for dir in "${binpkg_dirs[@]}"; do
+		for rdata in "$dir"/*-repodata; do
+			arch="${rdata##*/}"
+			arch="${arch%-repodata}"
+			XBPS_TARGET_ARCH="${arch}" xbps-rindex -c "$dir"
+			repos=$((repos + 1))
+		done
+	done
+	echo "Cleaned $cur/$max binpkgs in $XBPS_REPOSITORY"
+	echo "Cleaned $repos repositories in $XBPS_REPOSITORY"
+	echo "Done."
+}
diff --git a/xbps-src b/xbps-src
index 77695b9f510d34..760cf311d3e2e6 100755
--- a/xbps-src
+++ b/xbps-src
@@ -84,6 +84,9 @@ remove-autodeps
 purge-distfiles
     Removes all obsolete distfiles in <hostdir>/sources.
 
+purge-distfiles
+    Removes all obsolete packages in <hostdir>/binpkgs.
+
 show <pkgname>
     Show information for the specified package.
 
@@ -860,6 +863,9 @@ case "$XBPS_TARGET" in
     list)
         $XBPS_QUERY_CMD -l
         ;;
+    purge-binpkgs)
+        purge_binpkgs
+        ;;
     purge-distfiles)
         purge_distfiles
         ;;

             reply	other threads:[~2024-02-14  4:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14  4:57 classabbyamp [this message]
2024-02-16 13:46 ` [PR REVIEW] " ftpd
2024-02-16 13:46 ` Calandracas606
2024-02-16 13:57 ` Calandracas606
2024-02-18  1:28 ` [PR PATCH] [Updated] " classabbyamp
2024-05-25  1:46 ` github-actions
2024-06-08  1:47 ` [PR PATCH] [Closed]: " github-actions

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-48715@inbox.vuxu.org \
    --to=classabbyamp@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).