feat: browse container and volume files in a Files tab #29

Merged
jfro merged 1 commit from feat/13-file-browser into main 2026-11-30 20:33:54 +00:00
Owner

Closes #13

Stacked on #28 (#16 engine picker): it uses the shared engine client.

What

  • Files tab on a container (not on compose projects) and on a volume (Info / Files on the Volumes page).
  • Path bar with clickable crumbs and Up; folders first, then files, with their size and age; symlinks show their target. Double-click opens a folder, follows a link, or previews a file.
  • Preview: the first 256 KB of the selected file. Binary files show only their size.
  • Save…: copies the selected file or folder (or the current folder) into a folder you choose. It's streamed, never held in memory. It won't overwrite, and paths that would leave the folder are refused (tar unpack_in).
  • Copy Path, and Reload.

How (from Nye's write-up on #13)

  • Running container: a busybox:1.37 helper shares its PID namespace (SYS_PTRACE, no network) and reads /proc/1/root<dir>. Each folder is one exec, about 70 ms whatever its size. The archive API would tar the whole subtree, volumes included. Preview and save go through the helper too, so tmpfs mounts (which the archive API can't see) work. Links are resolved one hop at a time inside the container, never through /proc/1/root.
  • Stopped container: tar headers from GET /archive, capped at 256 MB or 10 s. Past the cap it shows the listing so far, with a note to start the container or open a subfolder.
  • Volume: a helper with the volume mounted read-only at /v.
  • Helpers are labeled krane.helper=files. They're killed and removed when you leave the tab or the selection changes, and the first browse sweeps any left behind. If busybox:1.37 is missing, it's pulled.
  • New deps: tar, tokio-util (io), bytes. Save uses QtQuick.Dialogs' FolderDialog, so the .deb now depends on qml6-module-qtquick-dialogs and the README's apt line has it. Fedora's qt6-qtdeclarative already includes it.

Tests

  • Unit tests: helper listing parsing (names with spaces and newlines), archive listing depth and the cut-off prefix, text/binary detection, path normalizing.
  • Live (cargo test live_browse -- --ignored): a running container as uid 1000 with a tmpfs (list, preview text and binary, resolve a link, save, no overwrite, helper removed on drop), the same container stopped (archive listing of its volume), and a volume. Passes on Docker 29.9.1 and Podman 5.4.2.
  • Local CI (fmt, clippy ×2, build ×2, tests ×2) is green.

Screenshots (mock data)

Container files Volume files
files volume files

Light: files light

Mock file trees for a container and a volume are in src/mock.rs, with new screenshot scenes files and volume-files. The tab switcher is now a shared SegmentedTabs.qml.

Left out

  • Upload (PUT /archive), which the issue marks as "later, maybe".
  • Open folder for a volume's mountpoint is the existing Open in File Manager button on the volume header (shown only when it's readable).

Seen on the way, not fixed here: on Podman, bollard can't parse the stopping container state, so the container list fails while a container is stopping ("unknown variant stopping").

Closes #13 Stacked on #28 (#16 engine picker): it uses the shared engine client. ## What - **Files tab** on a container (not on compose projects) and on a volume (Info / Files on the Volumes page). - Path bar with clickable crumbs and Up; folders first, then files, with their size and age; symlinks show their target. Double-click opens a folder, follows a link, or previews a file. - **Preview**: the first 256 KB of the selected file. Binary files show only their size. - **Save…**: copies the selected file or folder (or the current folder) into a folder you choose. It's streamed, never held in memory. It won't overwrite, and paths that would leave the folder are refused (`tar` `unpack_in`). - **Copy Path**, and **Reload**. ## How (from Nye's write-up on #13) - **Running container**: a `busybox:1.37` helper shares its PID namespace (`SYS_PTRACE`, no network) and reads `/proc/1/root<dir>`. Each folder is one exec, about 70 ms whatever its size. The archive API would tar the whole subtree, volumes included. Preview and save go through the helper too, so tmpfs mounts (which the archive API can't see) work. Links are resolved one hop at a time inside the container, never through `/proc/1/root`. - **Stopped container**: tar headers from `GET /archive`, capped at 256 MB or 10 s. Past the cap it shows the listing so far, with a note to start the container or open a subfolder. - **Volume**: a helper with the volume mounted read-only at `/v`. - Helpers are labeled `krane.helper=files`. They're killed and removed when you leave the tab or the selection changes, and the first browse sweeps any left behind. If `busybox:1.37` is missing, it's pulled. - New deps: `tar`, `tokio-util` (io), `bytes`. Save uses QtQuick.Dialogs' FolderDialog, so the .deb now depends on `qml6-module-qtquick-dialogs` and the README's apt line has it. Fedora's `qt6-qtdeclarative` already includes it. ## Tests - Unit tests: helper listing parsing (names with spaces and newlines), archive listing depth and the cut-off prefix, text/binary detection, path normalizing. - Live (`cargo test live_browse -- --ignored`): a running container as uid 1000 with a tmpfs (list, preview text and binary, resolve a link, save, no overwrite, helper removed on drop), the same container stopped (archive listing of its volume), and a volume. **Passes on Docker 29.9.1 and Podman 5.4.2.** - Local CI (fmt, clippy ×2, build ×2, tests ×2) is green. ## Screenshots (mock data) | Container files | Volume files | | --- | --- | | ![files](https://git.knope.dev/attachments/dc1924b6-fdee-460d-8430-8ec74c76cf58) | ![volume files](https://git.knope.dev/attachments/f07065bf-47c9-4f2d-9661-f652266462de) | Light: ![files light](https://git.knope.dev/attachments/90fa0743-ba4c-4803-88ea-a36e9cf9bbbe) Mock file trees for a container and a volume are in `src/mock.rs`, with new screenshot scenes `files` and `volume-files`. The tab switcher is now a shared `SegmentedTabs.qml`. ## Left out - Upload (`PUT /archive`), which the issue marks as "later, maybe". - Open folder for a volume's mountpoint is the existing Open in File Manager button on the volume header (shown only when it's readable). Seen on the way, not fixed here: on Podman, bollard can't parse the `stopping` container state, so the container list fails while a container is stopping ("unknown variant `stopping`").
feat: browse container and volume files in a Files tab
Some checks failed
CI / test (pull_request) Has been cancelled
d36730a207
Closes #13
jfro force-pushed feat/13-file-browser from d36730a207
Some checks failed
CI / test (pull_request) Has been cancelled
to 27fd6e0d04
All checks were successful
CI / test (pull_request) Successful in 5m7s
2026-11-30 19:31:48 +00:00
Compare
jfro changed target branch from feat/16-engine-picker to main 2026-11-30 19:51:51 +00:00
jfro force-pushed feat/13-file-browser from 27fd6e0d04
All checks were successful
CI / test (pull_request) Successful in 5m7s
to 5f3232d5b2
Some checks failed
CI / test (pull_request) Successful in 5m29s
CI / test (push) Has been cancelled
2026-11-30 20:18:11 +00:00
Compare
Author
Owner

F13 fixed in 5f3232d (Nye's review findings are posted here by me, since Nye's token can't comment).

  • Open Files helpers are tracked; an atexit hook removes them (kill + rm, up to 3 s) when Krane exits, so the tray's std::process::exit no longer leaves a helper holding the volume.
  • Leftovers from a killed Krane are swept at startup and on the new engine after each switch (files::spawn_sweeper), not on the first Files open.
  • Nye's edge tests (nye_edge, incl. nye_quit_leaves_no_helper) are folded into the commit. The quit proof passes: no helpers left, volume removes. Local CI (fmt, clippy ×2, build, tests ×2) and live_browse pass.

#30 is rebased onto this head (92742e2).

**F13 fixed in 5f3232d** (Nye's review findings are posted here by me, since Nye's token can't comment). - Open Files helpers are tracked; an `atexit` hook removes them (kill + rm, up to 3 s) when Krane exits, so the tray's `std::process::exit` no longer leaves a helper holding the volume. - Leftovers from a killed Krane are swept at startup and on the new engine after each switch (`files::spawn_sweeper`), not on the first Files open. - Nye's edge tests (`nye_edge`, incl. `nye_quit_leaves_no_helper`) are folded into the commit. The quit proof passes: no helpers left, volume removes. Local CI (fmt, clippy ×2, build, tests ×2) and `live_browse` pass. #30 is rebased onto this head (92742e2).
jfro left a comment

Review by Nye (posted by Upper Wolfjaw):

PR #29 (#13 file browser) review — Nye, d36730a

Gates (fmt, clippy x2, build x2, test) pass: 47 tests. live_browse passes on Docker 29.9 and Podman 5.4.

C12 edge cases, all pass (Docker; the Podman ones pass too where the images exist)

stopped "/" lists; pause (scratch, uid 65535) running -> live helper lists /; distroless nonroot that was
created and never started lists / and /etc and previews passwd; a 1 GB mealie image stopped: "/" partial=true
in 2.7 s; a live Save of a folder keeps the nested file + rel/abs symlinks; 5 previews of a 200 MB file take
0.3 s with no tar left in the helper. Tests: nye/pr29-proof (patch pr29-nye-tests.patch), notes/pr29-edge-checks.sh.

F13 (medium, proved): quit leaves the helper running

Tray "Quit Krane" -> shutdown -> std::process::exit(0) (tray.rs:523). FILES is a static, so the Session never
drops. A volume helper (sleep 2147483647) runs forever and holds the volume: docker volume rm gets 409 "volume
is in use". The sweep only runs on the first Files open of the next run (FILES_SWEPT), so the same happens after
a kill -9 until you open a Files tab. Proof: notes/pr29-quit-helper-proof.sh (test nye_quit_leaves_no_helper: a
child opens a volume Session into a static and calls process::exit, like the tray does).
Fix sketch:

  1. Before process::exit in the tray shutdown path: take FILES and block on remove_helper (with a ~3 s timeout).
  2. Run files::sweep when the engine client connects at startup (and after an engine switch, #16), not on first
    Files open.
    Then the proof passes (the child's helper is gone, or swept at the next start).

Low, for later (not blocking)

  • The sweep removes every krane.helper=files container, including another running Krane's (2 instances/one engine).
    Could scope by a per-process label value, then sweep only others whose PID is gone. Rare.
  • The live resolve/list goes through /proc/1/root, so a middle path component that is an absolute symlink
    resolves in the helper's root. Only the final hop is resolved. Rare (e.g. a link to /a/b where /a -> /x).
Review by Nye (posted by Upper Wolfjaw): # PR #29 (#13 file browser) review — Nye, d36730a Gates (fmt, clippy x2, build x2, test) pass: 47 tests. live_browse passes on Docker 29.9 and Podman 5.4. ## C12 edge cases, all pass (Docker; the Podman ones pass too where the images exist) stopped "/" lists; pause (scratch, uid 65535) running -> live helper lists /; distroless nonroot that was created and never started lists / and /etc and previews passwd; a 1 GB mealie image stopped: "/" partial=true in 2.7 s; a live Save of a folder keeps the nested file + rel/abs symlinks; 5 previews of a 200 MB file take 0.3 s with no tar left in the helper. Tests: nye/pr29-proof (patch pr29-nye-tests.patch), notes/pr29-edge-checks.sh. ## F13 (medium, proved): quit leaves the helper running Tray "Quit Krane" -> shutdown -> std::process::exit(0) (tray.rs:523). FILES is a static, so the Session never drops. A volume helper (`sleep 2147483647`) runs forever and holds the volume: `docker volume rm` gets 409 "volume is in use". The sweep only runs on the first Files open of the *next* run (FILES_SWEPT), so the same happens after a kill -9 until you open a Files tab. Proof: notes/pr29-quit-helper-proof.sh (test nye_quit_leaves_no_helper: a child opens a volume Session into a static and calls process::exit, like the tray does). Fix sketch: 1. Before process::exit in the tray shutdown path: take FILES and block on remove_helper (with a ~3 s timeout). 2. Run files::sweep when the engine client connects at startup (and after an engine switch, #16), not on first Files open. Then the proof passes (the child's helper is gone, or swept at the next start). ## Low, for later (not blocking) - The sweep removes *every* krane.helper=files container, including another running Krane's (2 instances/one engine). Could scope by a per-process label value, then sweep only others whose PID is gone. Rare. - The live resolve/list goes through /proc/1/root, so a *middle* path component that is an absolute symlink resolves in the helper's root. Only the final hop is resolved. Rare (e.g. a link to /a/b where /a -> /x).
jfro merged commit 5f3232d5b2 into main 2026-11-30 20:33:54 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/krane!29
No description provided.