Client Filesystem
Unaudited此内容尚不支持你的语言。
Clients hold keys, so a client stores plaintext. Depending on the sync scope (Sync — Synchronization Scope), a library routinely holds assets whose original is server-only, so the layout represents an asset with or without its original. The layout is a contract: rebuild assumes exactly these names. Local Gallery owns the offline-first requirements it serves.
Desktop Library Layout
Section titled “Desktop Library Layout”{library_root}/├── media/{YYYY}/{YYYY-MM}/│ ├── {uuid}.{ext} # original (plaintext; absent if not synced locally)│ ├── {uuid}.cbor # canonical signed metadata sidecar│ └── {uuid}.provenance.cbor # append-only signed provenance chain├── cache/ # thumbnails/, meta/, transcodes/ — sharded {uuid[0:2]}/{uuid[2:4]}├── index/library.sqlite # query + vector index, migrated in place└── .library/ ├── version, config, lock ├── docs/{albums,stacks}/{uuid}.cbor # signed album and stack label records └── quarantine/{uuid}.{ext} + {uuid}.reason.jsonmedia/is canonical: original, sidecar (Metadata — Sidecar Schema v1) and provenance chain (Signed Manifests and Provenance — Provenance of Library Modifications). The library MUST be reconstructible from these three files alone. Stems are UUIDv7 and extensions lowercase. The provenance file is never deleted, so a hard-deleted asset leaves a tombstone-with-history.- Trash and purge. Trash is a signed
deleterecord in the chain, not a location: a trashed asset keeps its original, sidecar and chain in itsmedia/bundle until purge, no file moves, and a rebuild derives Trashed from the chain (Asset Organization — Deletion State Machine). Purge removes the original, the sidecar and everycache/derivative, and leaves the chain. A bundle holding only a chain headed by adeleteis the asset’s peering tombstone (Asset Organization — Deletion State Machine). No file outsidemedia/records a purge, so a rebuild reproduces Purged from the chain alone. - Date bucket. Fixed at import from the capture timestamp known then. A later capture-date correction does not move the bundle: the sidecar is authoritative and maintenance (Library Maintenance and Atomic Writes — Self-Validation) repairs drift opportunistically.
cache/is derived, deletable at any time, and never a source of truth. Formats: Thumbnails and Previews — Thumbnail and Preview Formats.index/library.sqliteis a query cache over the sidecars, thesqlite-vecindex for AI (AI/ML Integrations), and the substrate for view albums (Asset Organization — System & Smart Albums (Views)). It is migrated forward in place, not dropped, because a rebuild cannot recover projections never written to disk (Versioning — Client Catalog Migration)..library/. Thelockfile MUST prevent two processes opening one library.quarantine/preserves irreplaceable bytes that failed validation verbatim, with the rejection reason (Damage Scenarios and Quarantine — Quarantine Surfaces). Aversionbump rebuilds derived structures only and never touches canonical files.docs/holds each album’s and stack’s signed label record (Asset Organization — Labels) as canonical CBOR: plaintext at rest like a sidecar, sealed under the album’s AMK whenever it leaves the device.
Mobile Clients
Section titled “Mobile Clients”Android and iOS use the app’s private sandbox with the same logical model. Rebuildable derivatives MUST NOT go in OS-managed cache locations: the OS evicts indiscriminately, and an expensive-to-regenerate thumbnail is not disposable.
The library root is excluded from the OS’s own cloud backup and device transfer, on every platform and API level, by the mechanisms in Platform Integrations — The Plaintext Boundary. It holds plaintext originals and sidecars; recovery is Capsule’s own (Backup and Recovery).
Local Index Staleness
Section titled “Local Index Staleness”SQLite may lag the filesystem: a bundle is durable before its index rows commit. Opening the workspace re-indexes any bundle with no row from its sidecar (Library Maintenance and Atomic Writes — Atomic Writes and Crash Recovery). The client checks a file exists before acting on its row and rebuilds from sidecars on structural inconsistency (Library Maintenance and Atomic Writes).
Space Recovery
Section titled “Space Recovery”Capsule reclaims space itself. Eligible: cache/ and fetched-but-unpinned originals. Never eligible: canonical media/ files the device holds as source of truth, sidecars, provenance chains and library.sqlite. An evicted representation re-fetches transparently via tiered fetch (Download — Tiered, On-Demand Fetch).
Automatic cache management
Section titled “Automatic cache management”The reclaimable set is held within a user-configurable budget (capsule-library::library::cache_sweep):
- Viewing stamps a last-access time; eviction is least-recently-accessed first.
- At equal recency, evict original, then preview, then thumbnail. The metadata tier (sidecar + LQIP) is never reclaimed, so an asset always stays listable.
- Pinned representations and device-owned originals are exempt from automatic eviction.
The budget scales with the connection class (Network Resilience — Connection Classes; capsule-sdk::cache_budget), because re-fetching an evicted representation grows costlier down the table:
| Class | Budget (× base) | Bulk transfers |
|---|---|---|
unmetered |
1 | Run |
metered |
2 | Deferred |
constrained |
2 | Deferred |
adverse |
3 | Deferred |
offline |
4 | Deferred |
The base budget is a user setting (default 2 GiB, capsule cache budget --set); capsule cache sweep runs the sweep under the current plan. On a deferring class a push runs staged (Upload — Upload Tiering (Staged Uploads)) whatever the device’s upload policy, so the index tier still publishes each asset while preview and original wait for an unmetered link. The client samples the class through a port before each sweep and each transfer and re-plans when it changes. A desktop with no OS signal reports unmetered.
Releasing a device-owned original, by the user or through streaming import (Import Pipeline — Import-Upload Streaming Mode), MUST pass the verify-before-destroy gate (Durability — Verify Before Destroy). Once released it is an ordinary server-only, re-fetchable asset.
User-driven reclamation
Section titled “User-driven reclamation”The client surfaces the largest consumers and lets the user delete selectively, pinned content included. It never touches canonical media/ files, and releasing a device-owned original is gated as above.
Free Up Space releases device copies of photos the server already holds, in bulk:
- Filters. Captured before a cutoff date; keep chosen device albums, with messaging-app albums kept by default; keep favourites; photos, videos or both.
- Review. A screen lists every candidate and the total bytes it reclaims before anything happens. Candidates that fail the verify-before-destroy gate (Durability — Verify Before Destroy) are listed as kept, with the reason, never released.
- Release through the OS. A copy in the system photo library goes to the OS trash (PHAssetChangeRequest deletion on iOS,
MediaStore.createTrashRequeston Android 11+), so the OS’s own recovery window still applies. A copy in the Capsule library becomes a server-only asset as above. - Never by surprise. Free Up Space runs only when the user confirms the review; no schedule or rule starts it.
Known Gaps
Section titled “Known Gaps”- Free Up Space is not implemented: there are no filters, no review screen and no OS-trash hand-off.
Validation
Section titled “Validation”- Init/open round-trip (unit). Directories and
version/configpresent; re-open is idempotent. - Date bucketing (unit). Asset lands in
media/{YYYY}/{YYYY-MM}/; unexplained drift triggers repair. - Lock contention (smoke). A second process is refused with a structured error.
- Sandbox placement (smoke, per platform). Library in app-private storage; survives cold start; the root carries the platform’s exclude-from-backup marking.
- Index rebuild (smoke). Drop
library.sqlite; rebuild; every query over sidecar facts matches. Index-only state (cache bookkeeping, upload guards, importer-formed stack placement) is not expected back. - Eviction (unit). LRU order, tier order at equal recency, recency promotion, pin exemption; no canonical file touched; metadata tier never reclaimed.
- Connection-class budget (unit). Each class yields its budget and bulk deferral; a class change mid-session re-plans without evicting pinned or device-owned originals.
- Release gate (smoke). Non-
durableverdict retains the original and surfaces it;durablereleases.