Skip to content

Add storage layout and per-phone locking (P1-03) - #6

Merged
Axoineo merged 1 commit into
mainfrom
p1/03-storage-locking
Nov 15, 2026
Merged

Axoineo merged 1 commit into
mainfrom
p1/03-storage-locking

Conversation

@Axoineo

@Axoineo Axoineo commented Nov 15, 2026

Copy link
Copy Markdown
Owner

What changed

Task P1-03 from docs/phases/phase-1.md. One new module, crates/verone-core/src/storage.rs:

  • Data home: VERONE_HOME, then XDG_DATA_HOME/verone, then ~/.local/share/verone. Resolution is a pure function of the three values, so tests never touch the process environment.
  • Phone ids: lowercase letters, digits and hyphens, 1 to 31 characters, starting with a letter or digit. An invalid id is a usage error that names the problem and gives an example.
  • Phone folders: create, find, list and remove, plus the paths for phone.toml, state.toml, .lock and data/. Folders are created with mode 0700.
  • Per-phone lock: exclusive lock on the phone's .lock file using the standard library's file locking. A second command waits up to 10 seconds, then fails as busy (exit code 5).

Also: CHANGELOG.md updated; tempfile added as a dev-dependency (on the allow-list).

Why

Every command needs to find a phone's files, and state-changing commands must not run on the same phone at once. Later tasks (profile, container lifecycle, reset, delete) build on these paths and this lock.

Acceptance test ("Done when")

Run on the reference laptop (Arch Linux, Rust 1.99.1):

$ cargo fmt --check
(no output, exit 0)

$ cargo clippy --all-targets -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo]

$ cargo test
test result: ok. 8 passed   (verone-cli unit tests)
test result: ok. 5 passed   (verone-cli binary tests)
test result: ok. 39 passed; 1 ignored  (verone-core)

Coverage the plan asked for:

  • Each path rule: seven tests, including empty values and relative paths.
  • Every invalid id form: eleven forms (empty, too long, leading hyphen, uppercase, space, underscore, dot, slash, .., non-ASCII letter, trailing newline).
  • Two processes contending for one lock: two_processes_contend_for_one_lock starts a second process that takes the lock; the first is refused as busy; after the second is killed the lock is acquired.

Notes for the reviewer

  • The one ignored test, lock_holder_child, is the second process for the two-process test. It does nothing unless that test launches it.
  • A relative VERONE_HOME is rejected, because the container runtime needs full paths. A relative XDG_DATA_HOME is ignored, as the XDG specification requires.
  • remove_phone uses a plain recursive delete. It fails with a hint if Android's root-owned data is still present; emptying that data through the helper image is task P1-14.
  • The lock is advisory and tied to the open file, so it is released when the holding process ends for any reason, including being killed.
  • No command uses the storage module yet; the first is create in P1-11.

🤖 Generated with Claude Code

Add the storage module to verone-core: resolution of the data home
(VERONE_HOME, then XDG_DATA_HOME/verone, then ~/.local/share/verone),
validated phone ids, and creation, lookup, listing and removal of
phone folders, which are created readable by their owner only.

Add a per-phone lock on the phone's .lock file using the standard
library's file locking. A second command waits up to 10 seconds and
then fails as busy (exit code 5). The lock is released when the
holding process ends for any reason.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Axoineo
Axoineo merged commit e20d235 into main Nov 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant