fix: Packages without root, Rio under sudo, logo aspect - #189
Merged
Conversation
Three defects found by diffing `sudo retch --full` against a plain run. Packages appeared only under sudo. The RPM SQLite database was opened read-write; it is root-owned inside a root-owned directory, so SQLite could not create its journal sidecars and every *query* failed with "attempt to write a readonly database" — not the open(), which is why the existing warning never fired and the field vanished silently. Now opened read-only over a `file:...?immutable=1` URI, and the query error is reported instead of swallowed. Rio lost all graphics support under sudo: it was identified only by TERM_PROGRAM, which env_reset drops. `is_rio_terminal` now also accepts TERM=rio/xterm-rio, which sudo preserves. The Kitty logo was stretched ~3x vertically. `c=26,r=10` was hardcoded and Kitty forces an image into that rectangle, while display.rs assumed a fixed 40-column width and derived the row count a third way. A single pure `fit_logo_cells` now feeds all three protocol emitters and plan_layout. Passing both correct values still left a 9% stretch from cell quantisation, so the Kitty spec carries only the limiting dimension and lets Kitty derive the other — measured 0.0% aspect error in a PTY. The chafa box widens 28 -> 45 columns (row cap unchanged at 10) so wide lockup assets stay legible: the Fedora logo goes from 4 rows to 7. The side-by-side threshold is unaffected (45 + 45 <= 95), pinned by a test. Also fixes a test-isolation defect the change exposed: once supports_iterm2 read TERM, the host's TERM leaked into a test that guarded only TERM_PROGRAM, failing on a Rio box and passing on CI. Documents the privilege trade-off in both directions (root-only phys-mem and btrfs snapshot counts; user-only editor/desktop/wm) in a new NOTES section, README, and a man-page PRIVILEGES section. Assisted-By: Claude Opus 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three user-reported defects, all surfaced by diffing a
sudo retch --fullrunagainst a plain one on corrino (i7-1360P, Fedora 44, Rio), plus the documentation
that makes the remaining differences legible.
1.
Packagesappeared only undersudo(bugfix)detect_packagesopened/var/lib/rpm/rpmdb.sqlitewithrusqlite::Connection::open— i.e. read-write. The rpmdb is
root:root 0644inside a root-owned directory, soSQLite cannot create the journal sidecars it wants and every query fails with
attempt to write a readonly database.Note query, not
open(): the existingeprintln!guarded only the open, so thefailure was completely silent and the field just disappeared. Plain
mode=rodoes nothelp for the same reason — it still needs to touch the directory.
Fixed with
open_with_flags(rpm_db_uri(path), SQLITE_OPEN_READ_ONLY | SQLITE_OPEN_URI | SQLITE_OPEN_NO_MUTEX)over afile:…?immutable=1URI, which lets SQLite skip lockingand sidecars entirely. The query error is now surfaced instead of swallowed.
2. Rio lost graphics support under
sudo(bugfix)supports_kitty/supports_iterm2/supports_sixelidentified Rio only byTERM_PROGRAM, which is not in sudo's defaultenv_keep. Sosudo retchsilently fellall the way through to Chafa while the same command as the user used the Kitty protocol
— which is exactly why the two pasted runs looked like they had different logos.
New
is_rio_terminal()also acceptsTERM=rio/xterm-rio, which sudo does preserve.3. The Kitty logo was stretched ~3× vertically (bugfix)
print_graphical_logoemitted a hardcodedc=26,r=10, and Kitty forces an imageinto the
c×rrectangle — it does not preserve aspect when both are given. Five assetsare wide horizontal lockups (
fedora.pngis 384×108, i.e. 3.56:1; also arch/nixos/ubuntu/tux), so they were squashed into a roughly 1:1 box.
Compounding it,
display.rsseparately assumed a fixed 40-column width for layoutwhile
graphical_logo_height_linesderived the row count a third way — threeinconsistent answers for one footprint.
Fixed with a single pure
fit_logo_cells(...) -> LogoFit(aspect-preserving, in pixelsso non-square cells are handled) now used by all three protocol emitters and by
plan_layout.Computing
candrcorrectly is not sufficient. Cells are indivisible, so therounded rectangle is never exactly the image's aspect. Measured in a PTY at real
geometry (169×47 cells, 22×51 px):
c=26,r=10candrc=45only, Kitty derives the restLogoFit::width_limitedrecords which dimension the image touches first andkitty_placement_specemits just that one. The layout'sdiv_ceilreservation (6 rowsfor a 5.46-row draw) still covers it — the safe direction.
4. Chafa logo box widened 28 → 45 columns
Row cap unchanged at 10. Chafa fits within the box preserving aspect, so a narrow box
caps a wide image's height long before the row cap does: at 28 columns the Fedora logo
collapsed to 4 rows of symbols and was unreadable; at 45 it renders 7.
The side-by-side threshold is unaffected — the text column floors at 45 and
45 + 45 = 90 ≤ 95, so a full-width logo still sits beside the text at the 95-column
cutoff. Pinned by a new
plan_layouttest at both 95 and 169 columns.Assets deliberately not changed: cropping the wide lockups to their square icon
halves would render larger still, but that is a content decision and was declined in
favour of the layout-only fix.
5. Documentation
New NOTES §6b documents the privilege-dependent fields in both directions — root-only
phys-memand btrfs snapshot counts, user-onlyeditor/desktop/wm— mirrored inREADME.mdand a newPRIVILEGESsection indocs/retch.1.md.Test-isolation defect fixed in passing
Same class as #155 / v0.6.2: once
supports_iterm2began readingTERM,test_supports_iterm2_heuristics(which guarded onlyTERM_PROGRAM) let the host'sTERMleak in, so its negative assertions failed on a Rio box while passing on CI. Itnow guards and clears
TERMtoo.Test plan
just check— fmt + clippy--workspace+ clippy--features graphics, all cleancargo test --workspace— 69 cli + 117 sysinfo + 15 integration, green with and without--features graphicsjust man— regenerates idempotently, footerretch 0.6.18, 0 doubled font runsjust pr— full gate green (audit shows only the pre-existing allowedpasteRUSTSEC-2024-0436)retch --fields packagesas an unprivileged user →Packages: 2509, identical to thesudorunretch --fields phys-memunprivileged → still absent (genuinely root-only, now documented)TERM_PROGRAMunset andTERM=xterm-rio(the sudo case) → Kitty escape emitted,c=45, 0.0% aspect errorchafa --size 45x10onfedora.png→ 7 content rows (was 4 at28x10)Manual verification for a reviewer: run
retch --fullin Rio/kitty and confirm thelogo sits beside the text, undistorted. Then run it in a terminal identified only by
TERM_PROGRAM(e.g. WezTerm) to confirm no regression in the non-Rio paths.Versions
retch-sysinfo→0.1.53(library behaviour change);retch-cli→0.6.18. Patch bump.Wiki updated ahead of this PR (
4025d35..7fc584f):Troubleshooting.mdgains a"What
sudo retchactually changes" section;Configuration-and-Theming.mdnotes thatpackagesno longer needs root.