Skip to content

fix(locallibrary): drive-safety fixes for jobs, backups, racy stamps, player names, my tags and exports - #308

Merged
botandbang merged 6 commits into
mainfrom
bnb/drive-safety
Nov 1, 2026
Merged

botandbang merged 6 commits into
mainfrom
bnb/drive-safety

Conversation

@botandbang

Copy link
Copy Markdown
Contributor

What and why

This fixes data-safety bugs in the code that writes to drives.

Jobs (refresh, prep) plan a step again after a stale plan only when the drive is as the job's own earlier steps left it. Each plan's probes are measured before and after every piece of work. A change from anywhere else, such as a rekordbox export mid-job, stops the job with the stale plan.

Backups now carry the drive's journal (with its staged files) and the remembered player name and colour, and restoring one puts both back. Undo then redo, or an older backup and then a newer one, leaves the journal matching the drive. The undo plan says how many recorded edits go back on the journal. A replay seals its backup when it starts and after each step (each step's commit seals it through commit::under_backup), so a replay cut off part way can be undone without --force. Backups from earlier versions are restored as before.

There is now one racy-stamp rule, fsutil::settled, which the hash cache and scrub use. HashIndex::racy flags copies recorded too soon after their source was written. Sync, pack and collection export compare those by content, and so does the after-a-set comparison. library_write::copy records its copies in the target's hash index so they can be told apart. Unembed checks each file against a hash the embed now records (EmbeddedFile.hash, a new optional field in the RPC contract).

A sync or pack onto a stick with no exportLibrary.db leaves it without a player name or colour, and the plan says so. Stamps that differ only by an empty name or colour 0 no longer count as a change.

My Tags: exportExt.pdb gets the smallest free category id when the next one would be past u32, and planning refuses any exportExt.pdb id that can't fit.

Collection export counts online-only downloads in its space check when their cloud folder is on the target's disk, and warns which file it's waiting on after 10 s.

A lenient replay that finds none of the history lists to delete names them. Merging the same drive into a folder again merges into the folder the first merge made, by name, and adds nothing. format::disk_at refuses under LOCALLIBRARY_VOLUMES without running disk tools.

Two tests that asserted the old behaviour were updated: the nameless history-list note, and the second merge's "Club (2)" folder. The My Tag id property's model now allows the smallest free id.

Fixes LOC-72
Fixes #173
Fixes LOC-64
Fixes #165
Fixes LOC-48
Fixes #148
Fixes LOC-62
Fixes #163
Fixes LOC-37
Fixes #137
Fixes LOC-36 (prefetching the next downloads is still open in TODO.md)
Fixes #136

Refs LOC-65 (items 3 to 5; items 1 and 2 are in bnb/cli-store-reads)
Refs #166

How it was tested

  • cargo fmt --all --check, and cargo clippy -p locallibrary --all-targets -- -D warnings.
  • cargo nextest run -p locallibrary filtered on the sync, pack, export, scrub, tree, embed, journal, replay, merge, tags, format, watch and jobs tests: 852 of 854 passed, and the 2 failures (setup in two new tests) were fixed and pass.
  • Every new regression test fails with its fix reverted.
  • The clock-dependent tests (sync and pack racy, tree racy, slow wait, cut-off replay, job re-plan) ran 20 times with --retries 0: no failures.
  • docs/rpc regenerated, adding EmbeddedFile.hash and the needed_bytes doc.
  • Not run: the locallibrary-cli suite (including the_contract_in_docs_is_current) and Windows clippy.

Checklist

  • Tests cover the change
  • For locallibrary: apps/locallibrary/CHANGELOG.md has a line under Unreleased, if people using it will notice
  • The READMEs, docs/ and --help still say what the code does (apps/locallibrary/docs/rpc/ too, for a sidecar change)

…r names, My Tags and exports

Planned as these commits, folded into one because they share files:

- fix(locallibrary): plan a job's step again only over the job's own writes
- fix(locallibrary): carry the journal and player name in backups
- fix(locallibrary): tell racy size-and-mtime matches by content
- fix(locallibrary): leave a stick without onelibrary unnamed
- fix(locallibrary): check my tag ids against exportext.pdb when planning
- fix(locallibrary): count cloud downloads in the export's space check
- fix(locallibrary): name skipped history lists, merge into the same folder, hide disks under the test switch
@botandbang
botandbang requested a review from bnb as a code owner October 30, 2026 16:16
@linear-code

linear-code Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

bnb
bnb previously approved these changes Oct 30, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation locallibrary locallibrary and the loclib-* crates locallibrary: sidecar The JSON-RPC sidecar and the api module it serves locallibrary: core The core crate, the data model and rekordbox's formats tests Tests, fixtures and test harnesses labels Oct 30, 2026
# Conflicts:
#	apps/locallibrary/CHANGELOG.md
#	apps/locallibrary/TODO.md
#	crates/locallibrary/src/tree.rs
#	crates/locallibrary/src/tree/tests.rs
@botandbang

Copy link
Copy Markdown
Contributor Author

Closing and reopening so CI runs against current main (with #353's CodeQL fix). Branch unchanged.

@botandbang botandbang closed this Nov 1, 2026
auto-merge was automatically disabled November 1, 2026 16:49

Pull request was closed

@botandbang botandbang reopened this Nov 1, 2026
@botandbang botandbang closed this Nov 1, 2026
@botandbang botandbang reopened this Nov 1, 2026
@botandbang
botandbang enabled auto-merge November 1, 2026 16:50
bnb
bnb previously approved these changes Nov 1, 2026
@github-actions github-actions Bot added the locallibrary: cli The locallibrary command line label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Rust coverage

From run 64. Both are held to the thresholds in .cargo/config.toml.

Tests Lines Functions Regions
All 97.36% (84882/87188) 96.47% (13623/14121) 95.62% (186878/195441)
Hegel property tests alone 95.32% (83111/87188) 94.02% (13276/14121) 93.4% (182543/195441)

@botandbang
botandbang added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 451d53b Nov 1, 2026
30 checks passed
@botandbang
botandbang deleted the bnb/drive-safety branch November 1, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation locallibrary: cli The locallibrary command line locallibrary: core The core crate, the data model and rekordbox's formats locallibrary: sidecar The JSON-RPC sidecar and the api module it serves locallibrary locallibrary and the loclib-* crates tests Tests, fixtures and test harnesses

Projects

None yet

2 participants