Skip to content

Detect damaged package records before updating - #11478

Open
yashranaway wants to merge 8 commits into
omacom:quattrofrom
yashranaway:fix/update-check-package-database
Open

yashranaway wants to merge 8 commits into
omacom:quattrofrom
yashranaway:fix/update-check-package-database

Conversation

@yashranaway

@yashranaway yashranaway commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Stops updates when an interrupted package transaction has left empty or missing database records. Addresses #11316.

<<<< AI wording below >>>>

Problem

After an interrupted package transaction, a local package record can have an empty desc file. Pacman can accept that state and let a later update complete while the package remains damaged.

Addresses the damaged database records reported in #11316.

Fix

Check the configured local package database before pruning, snapshots or keyring installation, and when the package-update command runs directly. Report every missing or empty description and missing file-list record. Empty file lists remain valid. Print manual backup, database repair and reinstall commands without changing any records automatically. This does not detect every damaged installed payload or truncated file list.

Verification

bash test/shell.d/update-package-database-test.sh passes. Changed Bash files pass syntax checks and git diff --check passes. Update sequencing, locking, disk-space, conflict handling and user-PATH regressions also pass. The CLI suite stops at the same VS Code theme assertion on this branch and the unmodified base.

Review follow-up, 1 October

Unreadable or nontraversable database records stop verification. Repair instructions restore a known dependency install reason and explicitly report when that metadata is missing.

Focused regressions, command metadata, Bash syntax, and diff checks pass. Hardware and live Hyprland behavior were not exercised on this host.

@llstrk

llstrk commented Oct 1, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: The new stop message gives no working repair for the records it catches, so every later omarchy update stops at the check.

The stop message gives no working repair

The message does not say how to restore the entry. With desc and files emptied, a plain pacman -S <pkg> fails with "exists in filesystem" for every file the package owns, because the empty file list makes each one a conflict. With them missing, pacman -S, -S --dbonly and -S --overwrite '*' all fail with "invalid or corrupted package" until the record directory is removed. Impact: a user who cannot work out the repair gets no package updates through omarchy update.

Suggested change: print the sequence that worked in testing for each damaged record: sudo rm -r <record>, sudo pacman -S --dbonly <pkg>, then sudo pacman -S <pkg>.

Reproducer (pacman 7.1.0, throwaway root)

For a package that no repository has, the same sequence worked in testing with pacman -U --dbonly <file> and pacman -U <file> in place of the two pacman -S commands.

What the stop message ("Restore this package's database entry and reinstall it before retrying omarchy update.") takes in practice, on a throwaway pacman root. It needs pacman, fakeroot, bsdtar and repo-add, writes only to temporary files and directories that are removed on exit, and never touches the system database. Run with bash repro-repair-guidance.sh.

Reviewed head: a886c18. Run with pacman v7.1.0 (libalpm v16.0.1) and fakeroot 1.37.2.

#!/bin/bash
# What "restore this package's database entry and reinstall it" takes, on a
# throwaway pacman root. Needs pacman, fakeroot, bsdtar and repo-add; writes only
# inside a temporary directory and never touches the system database.
set -u

lab=$(mktemp -d)
trap 'rm -rf "$lab"' EXIT
mkdir -p "$lab"/{root,db,cache,gpg,hooks,log,repo}
cat >"$lab/pacman.conf" <<EOF
[options]
RootDir = $lab/root
DBPath = $lab/db
CacheDir = $lab/cache
LogFile = $lab/log/pacman.log
GPGDir = $lab/gpg
HookDir = $lab/hooks
Architecture = auto
SigLevel = Never

[lab]
Server = file://$lab/repo
EOF
: >"$lab/fakeroot.state"
pm() {
  fakeroot -i "$lab/fakeroot.state" -s "$lab/fakeroot.state" -- \
    pacman --config "$lab/pacman.conf" --noconfirm "$@"
}
show() {
  printf '$ pacman'
  printf ' %q' "$@"
  echo
  pm "$@" 2>&1 | grep -E '^(error|demo:|No database errors|reinstalling|installing)'
  echo "exit=${PIPESTATUS[0]}"
}

# A package "demo" with two files, in a local repository.
pkg=$lab/build
mkdir -p "$pkg/usr/share/demo"
yes payload | head -c 65536 >"$pkg/usr/share/demo/snapshot.bin"
echo notes >"$pkg/usr/share/demo/notes.txt"
cat >"$pkg/.PKGINFO" <<EOF
pkgname = demo
pkgver = 1.0-1
pkgdesc = demo
builddate = 1700000000
packager = demo
size = 65542
arch = any
EOF
(cd "$pkg" && bsdtar -czf "$lab/repo/demo-1.0-1-any.pkg.tar.gz" --uid 0 --gid 0 .PKGINFO usr)
repo-add -q "$lab/repo/lab.db.tar.gz" "$lab/repo/demo-1.0-1-any.pkg.tar.gz"
pm -Sy >/dev/null 2>&1 && pm -S demo >/dev/null 2>&1 || { echo "setup failed"; exit 1; }
record=$lab/db/local/demo-1.0-1

echo "## 1. The #11316 shape: empty desc and files, truncated payload"
: >"$record/desc"
: >"$record/files"
: >"$lab/root/usr/share/demo/snapshot.bin"
show -Dk
echo
echo "## 2. Reinstalling it, as the message says"
show -S demo
echo
echo "## 3. Rewriting the record first, then reinstalling"
show -S --dbonly demo
show -S demo
echo "snapshot.bin is $(stat -c %s "$lab/root/usr/share/demo/snapshot.bin") bytes again"
echo
echo "## 4. desc and files missing (interrupted before pacman wrote them)"
rm "$record/desc" "$record/files"
show -S --dbonly demo
show -S --overwrite '*' demo
echo
echo "## 5. Removing the record, then rewriting it and reinstalling"
echo "\$ rm -r $record"
rm -r "$record"
show -S --dbonly demo
show -S demo
show -Dk

Actual output:

## 1. The #11316 shape: empty desc and files, truncated payload
$ pacman -Dk
No database errors have been found!
exit=0

## 2. Reinstalling it, as the message says
$ pacman -S demo
error: failed to commit transaction (conflicting files)
demo: /tmp/tmp.PkqUccV3lo/root/usr/share/demo/notes.txt exists in filesystem
demo: /tmp/tmp.PkqUccV3lo/root/usr/share/demo/snapshot.bin exists in filesystem
exit=1

## 3. Rewriting the record first, then reinstalling
$ pacman -S --dbonly demo
reinstalling demo...
exit=0
$ pacman -S demo
reinstalling demo...
exit=0
snapshot.bin is 65536 bytes again

## 4. desc and files missing (interrupted before pacman wrote them)
$ pacman -S --dbonly demo
error: could not open file /tmp/tmp.PkqUccV3lo/db/local/demo-1.0-1/desc: No such file or directory
error: failed to prepare transaction (invalid or corrupted package)
exit=1
$ pacman -S --overwrite \* demo
error: could not open file /tmp/tmp.PkqUccV3lo/db/local/demo-1.0-1/desc: No such file or directory
error: failed to prepare transaction (invalid or corrupted package)
exit=1

## 5. Removing the record, then rewriting it and reinstalling
$ rm -r /tmp/tmp.PkqUccV3lo/db/local/demo-1.0-1
$ pacman -S --dbonly demo
installing demo...
exit=0
$ pacman -S demo
reinstalling demo...
exit=0
$ pacman -Dk
No database errors have been found!
exit=0

Exit status of the script: 0 (stderr empty). Sections 2 and 4 are the literal "reinstall it" and the obvious variants; sections 3 and 5 are what works.

More findings: a damaged archlinux-keyring record never reaches the check

omarchy update runs omarchy-update-keyring, which reinstalls archlinux-keyring on every run, before omarchy-update-system-pkgs. If that record is the damaged one, the update stops with pacman's raw "exists in filesystem" or "invalid or corrupted package" error and the new guidance never appears. The merge-base behaves the same, so this is a gap rather than a regression. Impact: the one record this flow rewrites on every run gets no repair guidance.

Suggested change: run the record check before omarchy-update-keyring, for example from a small helper that bin/omarchy-update calls ahead of the keyring step.

Reproducer (shows the gap at a886c18):

Runs bin/omarchy-update -y from an Omarchy checkout against a throwaway pacman root, with omarchy-update-keyring and omarchy-update-system-pkgs real and every other step stubbed (sudo and pacman-key are stubs too). It needs pacman, fakeroot, bsdtar and repo-add, and writes only to temporary files and directories that are removed on exit. Run bash repro-keyring-order.sh /path/to/omarchy with the checkout at the reviewed head a886c18. pacman v7.1.0.

#!/bin/bash
# Usage: bash repro-keyring-order.sh <omarchy checkout>
# Runs that checkout's bin/omarchy-update -y against a throwaway pacman root,
# with omarchy-update-keyring and omarchy-update-system-pkgs real and the other
# steps stubbed. Needs pacman, fakeroot, bsdtar and repo-add. Writes only inside
# a temporary directory; sudo and pacman-key are stubs.
set -u
repo=$(cd "${1:?usage: repro-keyring-order.sh <omarchy checkout>}" && pwd)

lab=$(mktemp -d)
trap 'rm -rf "$lab"' EXIT
mkdir -p "$lab"/{root,db,cache,gpg,hooks,log,repo,build,stubs}
cat >"$lab/pacman.conf" <<EOF
[options]
RootDir = $lab/root
DBPath = $lab/db
CacheDir = $lab/cache
LogFile = $lab/log/pacman.log
GPGDir = $lab/gpg
HookDir = $lab/hooks
Architecture = auto
SigLevel = Never

[lab]
Server = file://$lab/repo
EOF
: >"$lab/fakeroot.state"

for spec in archlinux-keyring:usr/share/pacman/keyrings/archlinux.gpg \
  omarchy-keyring:usr/share/pacman/keyrings/omarchy.gpg demo:usr/share/demo/data.bin; do
  name=${spec%%:*} file=${spec#*:} dir=$lab/build/${spec%%:*}
  mkdir -p "$dir/$(dirname "$file")"
  echo "$name" >"$dir/$file"
  printf 'pkgname = %s\npkgver = 1.0-1\npkgdesc = lab\nbuilddate = 1700000000\npackager = lab\nsize = 1\narch = any\n' "$name" >"$dir/.PKGINFO"
  (cd "$dir" && bsdtar -czf "$lab/repo/$name-1.0-1-any.pkg.tar.gz" --uid 0 --gid 0 .PKGINFO usr)
done
repo-add -q "$lab/repo/lab.db.tar.gz" "$lab"/repo/*.pkg.tar.gz

cat >"$lab/stubs/pacman" <<EOF
#!/bin/bash
exec fakeroot -i "$lab/fakeroot.state" -s "$lab/fakeroot.state" -- /usr/bin/pacman --config "$lab/pacman.conf" "\$@"
EOF
cat >"$lab/stubs/pacman-conf" <<EOF
#!/bin/bash
exec /usr/bin/pacman-conf --config "$lab/pacman.conf" "\$@"
EOF
printf '#!/bin/bash\nexec "$@"\n' >"$lab/stubs/sudo"
printf '#!/bin/bash\nexit 0\n' >"$lab/stubs/pacman-key"
printf '#!/bin/bash\nwhile [[ $1 == -* ]]; do shift; done\nexec "$@"\n' >"$lab/stubs/systemd-run"
for step in omarchy-update-lock omarchy-update-requires-free-space omarchy-update-pkg-prune \
  omarchy-snapshot omarchy-update-stay-awake omarchy-update-dev omarchy-migrate omarchy-hook \
  omarchy-update-aur-pkgs omarchy-update-mise omarchy-update-orphan-pkgs \
  omarchy-update-analyze-logs omarchy-update-status omarchy-update-restart; do
  printf '#!/bin/bash\nexit 0\n' >"$lab/stubs/$step"
done
chmod +x "$lab"/stubs/*
export PATH="$lab/stubs:$repo/bin:/usr/bin:/bin"

reset_lab() {
  rm -rf "$lab"/{root,db,cache}/* "$lab/fakeroot.state"
  : >"$lab/fakeroot.state"
  pacman --noconfirm -Sy >/dev/null 2>&1 &&
    pacman --noconfirm -S archlinux-keyring omarchy-keyring demo >/dev/null 2>&1 || { echo "setup failed"; exit 1; }
}
update() {
  OMARCHY_UPDATE_LOGGED=1 bash "$repo/bin/omarchy-update" -y 2>&1 </dev/null |
    sed 's/\x1b\[[0-9;]*m//g' | grep -v '^$' | grep -v "Can't set user"
  echo "exit=${PIPESTATUS[0]}"
}

echo "## demo's record emptied: the new check reports it"
reset_lab
: >"$lab/db/local/demo-1.0-1/desc"
: >"$lab/db/local/demo-1.0-1/files"
update
echo
echo "## archlinux-keyring's record emptied: the keyring step stops first"
reset_lab
: >"$lab/db/local/archlinux-keyring-1.0-1/desc"
: >"$lab/db/local/archlinux-keyring-1.0-1/files"
update

Actual output (stderr empty, script exit status 0):

## demo's record emptied: the new check reports it
Update Arch signing keys
Keys are correct
Damaged package database record: /tmp/tmp.609CC2dfCR/db/local/demo-1.0-1/
Restore this package's database entry and reinstall it before retrying omarchy update.
Something went wrong during the update!
Please review the output above carefully, correct the error, and retry the update.
If you need assistance, get help from the community at https://omarchy.org/discord
exit=1

## archlinux-keyring's record emptied: the keyring step stops first
Update Arch signing keys
error: failed to commit transaction (conflicting files)
archlinux-keyring: /tmp/tmp.609CC2dfCR/root/usr/share/pacman/keyrings/archlinux.gpg exists in filesystem
Something went wrong during the update!
Please review the output above carefully, correct the error, and retry the update.
If you need assistance, get help from the community at https://omarchy.org/discord
exit=1

The same keyring-step failure happens at the merge-base, so this is a gap in where the new check runs, not a regression.

More findings: only the first damaged record is reported

The exit 1 inside the loop stops at the first hit. Impact: when one interruption damages several records, each extra one costs another full omarchy update run (confirmation, cache prune, snapshot, keyring step) to find. The new test has one record, so it cannot catch this.

Suggested change: collect every damaged record, print the repair for each, and exit after the loop.

Reproducer (fails at a886c18):

A test in the style of test/shell.d/update-package-database-test.sh. Save it as test/shell.d/update-package-database-all-records-test.sh and run bash test/shell.d/update-package-database-all-records-test.sh from the repository root. It fails at the reviewed head a886c18 because the check exits at the first damaged record.

#!/bin/bash

set -euo pipefail
source "$(dirname "$0")/base-test.sh"

# Two records damaged by the same interruption: one run should name both, or
# every repair costs another full omarchy update (snapshot included) to find
# the next one.
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
mkdir -p "$test_tmp/bin"
export TEST_DATABASE="$test_tmp/database"
for record in first-1.0-1 second-1.0-1; do
  mkdir -p "$TEST_DATABASE/local/$record"
  : >"$TEST_DATABASE/local/$record/desc"
  : >"$TEST_DATABASE/local/$record/files"
done
cat >"$test_tmp/bin/pacman-conf" <<'STUB'
#!/bin/bash
printf '%s\n' "$TEST_DATABASE"
STUB
cat >"$test_tmp/bin/omarchy-update-pacman" <<'STUB'
#!/bin/bash
exit 0
STUB
chmod +x "$test_tmp/bin/"*
export PATH="$test_tmp/bin:$PATH"

if bash "$ROOT/bin/omarchy-update-system-pkgs" >"$test_tmp/output" 2>&1; then
  fail "damaged records stop the update"
fi
cat "$test_tmp/output"
grep -Fq "first-1.0-1/" "$test_tmp/output" || fail "the first damaged record is named"
grep -Fq "second-1.0-1/" "$test_tmp/output" || fail "every damaged record is named in one run"
pass "every damaged record is named in one run"

Actual output at the reviewed head (stdout, then stderr; exit status 1):

Damaged package database record: /tmp/tmp.1mecVHbarj/database/local/first-1.0-1/
Restore this package's database entry and reinstall it before retrying omarchy update.
not ok - every damaged record is named in one run
Details

Verified (sandbox, pacman 7.1.0):

  • On the omarchy update does not detect package corruption after an interrupted pacman transaction #11316 shape, pacman -Dk prints "No database errors have been found!" and the merge-base script's pacman -Syu completes; the head script stops before any pacman call on both the automatic and the interactive conflict path.
  • Healthy records always have a non-empty desc and a files file, which is 0 bytes for a package that owns no files, so the rule does not block healthy systems.
  • The new test fails against the merge-base script, and the pacman-conf stubs added to the two conflict tests keep them off the host database.

Optional notes:

  • Omarchy's default pacman-conf DBPath is /var/lib/pacman/, so the message prints /var/lib/pacman//local/<pkg>-<ver>/; database=${database%/} removes the double slash.
  • Not detected, as a limit: a record whose files list is cut short or emptied while desc survives passes the check, and a plain reinstall of it then fails with file conflicts.
  • Open Make package ownership the Quattro update boundary #9070 rewrites bin/omarchy-update-system-pkgs and both conflict tests, so whichever lands second needs to carry this check and the stubs over.

Review information

Test scope: Source review and sandbox tests with synthetic pacman 7.1.0 databases only, at a886c18; not tested on a real system or after a real crash.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@yashranaway

Copy link
Copy Markdown
Contributor Author

Moved the check before keyring updates, report every damaged record, and added manual backup/repair/reinstall steps. Database and update-boundary regressions pass; the CLI suite hits the same VS Code assertion on base.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no outstanding findings or new actionable issues were identified.

Summary

The PR adds a read-only check for missing or empty local package descriptions and missing file-list records. It runs before update preparation and when the package-update command is invoked directly, stopping on damage and printing manual repair guidance. Both previous findings were addressed, and their threads are resolved.

  • Adds regression coverage for damaged and inaccessible records, update ordering, and direct package updates.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Confirm and authorize update] --> B[Verify local package records]
  B -->|Damaged or inaccessible| C[Stop and print repair guidance]
  B -->|Valid| D[Prune and snapshot]
  D --> E[Update keys]
  E --> F[Verify again before package transaction]
  F --> G[Upgrade packages]
Loading

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/qua..." · Reviewed by Greptile

@jandrusk

Copy link
Copy Markdown

Thanks, the repair steps read well now. This conflicts with quattro, so it needs a rebase. One small nit while you're there: omarchy-update calls omarchy-update-verify-package-database right after authorize_update, and then omarchy-update-system-pkgs (which omarchy-update runs) calls it again. Keeping the call in only one place (probably omarchy-update-system-pkgs, so direct callers are covered too) avoids scanning the database twice and printing the damage report twice when something is wrong.

@omarchybot omarchybot added the enhancement New feature or request label Oct 14, 2026
# Conflicts:
#	test/shell.d/fixtures/sudo-boundary-test.sh
@yashranaway

Copy link
Copy Markdown
Contributor Author

I merged current quattro and resolved the test conflict at 5f930ac. I kept both checks because the keyring update uses pacman before the system-package step, while that step can also run directly. A damaged record stops at the first check, so the report prints once. The focused update tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants