From 0489ee1e567a8a7674fab9b27014b2c3f7383004 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Mon, 3 Nov 2025 07:48:38 +0100 Subject: Hide current elpa directory behind a symlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplifies rollbacks: revert symlink to previous directory. Also, * make directory names more intuitive: use $(date) for the _new_ directory, instead of the old one; * write update patches to the new directory, instead of the old one; * tee update summary to the new directory, so that it survives the transient shell the update was run from. Also, ask the augurs why 'test' has both -h and -L for symbolic links, https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html and get no answer 🤷 --- .local/bin/emacs-update-packages | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/.local/bin/emacs-update-packages b/.local/bin/emacs-update-packages index 2f162a5..ecf5267 100755 --- a/.local/bin/emacs-update-packages +++ b/.local/bin/emacs-update-packages @@ -8,7 +8,15 @@ set -euo pipefail test "${DEBUG:-}" && set -x -BKPDIR=.elpa.$(date +%F-%T) +cd ~/.config/emacs + +test -L elpa || { + echo >&2 "'elpa' directory must be a symlink." + exit 1 +} + +OLDELPADIR=$(readlink elpa) +NEWELPADIR=.elpa.$(date +%F-%T) read-packages () { @@ -57,8 +65,8 @@ compare-packages () # Make a patch for later review. ( set +e - diff > ${BKPDIR}/update-${pkg}.patch \ - -ru ${BKPDIR}/${pkg}-${oldv} elpa/${pkg}-${newv} + diff > ${NEWELPADIR}/update-${pkg}.patch \ + -ru ${OLDELPADIR}/${pkg}-${oldv} ${NEWELPADIR}/${pkg}-${newv} diffstatus=$? @@ -73,15 +81,15 @@ compare-packages () done } -( - cd ~/.config/emacs - cp -a elpa ${BKPDIR} +cp -a ${OLDELPADIR} ${NEWELPADIR} + +declare -A OLDPACKAGES NEWPACKAGES - declare -A OLDPACKAGES NEWPACKAGES +read-packages OLDPACKAGES +ln -fsT ${NEWELPADIR} elpa - read-packages OLDPACKAGES - emacs -f package-upgrade-all -f package-autoremove - read-packages NEWPACKAGES +emacs -f package-upgrade-all -f package-autoremove +read-packages NEWPACKAGES - enum-packages | compare-packages | column -ts$'\t' -) +enum-packages | compare-packages | column -ts$'\t' | + tee ${NEWELPADIR}/update.sum -- cgit v1.2.3