Library mappings
The server and the Bridge usually run in different containers, so a library at
/audiosilo/books on the server may be somewhere else for the Bridge, or not there
at all. Before the Bridge may write into a library it has to prove it sees the
server's copy of it. A mapping is checked, never assumed: a wrong mount must
never let a later job write into the wrong folder. The code is the Bridge's
internal/mapping and the heartbeat loop in internal/app.
Where the Bridge looks
For each library the server lists (in the answer to every heartbeat), the Bridge looks at:
- Its configured mapping for that library id, if there is one: the
librariessetting (AUDIOSILO_BRIDGE_LIBRARIES="<id>=<path>;...", or the Bridge folder field on the Libraries tab of its page). The path must be absolute. - Otherwise the server's own root path for the library. A compose stack that mounts the libraries at the same path in both containers (read-only for the server, read-write for the Bridge) needs no mapping at all; this is the default the compose example uses.
The check
For a books library with an indexed sample, the Bridge checks the following.
- The folder. The mount path must exist and be a folder.
- A known book. The Bridge asks the server for the library's sample book
(
GET /bridge/libraries/{id}/bookwith no path) and gets its files with the sizes the server sees on its own disk right now. The server picks the first whole book (every file still on its disk) among the library's first five by title. So one book deleted before a scan notices doesn't make the whole library look unmapped. A single-file book is listed as its own one file. - The sizes. It stats each of those files through its mount (at most 50; every
path goes through its
SafeJoin, which refuses absolute paths,..and NUL) and compares the size with the server's. Only when every file is there with the server's size is the library mapped. - Writing. Only then does it probe whether it can write: it creates a file
named
.audiosilo-bridge-probe-<random>in the mount folder (exclusively, so it can never replace anything), writes a line and removes it. If that works the library is writable. The leading dot keeps a probe a crash leaves behind out of the server's scan, which never walks hidden names.
A different share or a stale copy can sit at the expected mount path. The file sizes give the Bridge a way to detect that mismatch.
The marker for empty books libraries and podcast libraries
When the server answers the books library's sample lookup with no_book,
the Bridge checks the root marker. Other lookup errors follow the normal error
path. Podcast libraries always use this marker. In both cases
internal/mapping/podcast.go reads or creates .audiosilo/library.json.
{"version":1,"library_id":3,"nonce":"a1b2c3d4e5f60718a1b2c3d4e5f60718"}
The Bridge reuses a marker naming this library, or probes writability and creates
a missing marker. It asks the server to read the marker from its own root with
GET /api/v1/bridge/libraries/{id}/marker. A matching nonce proves mapped.
The Bridge then probes for writable. If the server cannot confirm a marker
the Bridge just wrote, the Bridge removes it. It can replace a removed library's
marker and refuses one naming another current library. The marker's limit: if a
share disconnects and both processes see the same bare mount point, the check
can pass there too.
Both sides require:
- version 1;
- a 32-character lowercase hex nonce;
- a regular file no larger than 4 KiB;
- a
.audiosilodirectory that is not a symlink.
The server also checks the library id and answers only {nonce}. A marker that
is absent or invalid is 404 no_marker. checked_path is
.audiosilo/library.json. An older Bridge's
sample-book lookup on a podcast library returns 404 no_book, so it cannot map
it as books.
What a failed check means:
| Answer | Means |
|---|---|
no_marker, or a nonce mismatch | "this folder isn't the library the server sees" |
library_not_found | "the library was removed from the server" |
| a failed marker check | A definite refusal clears the mapping. A temporary error can keep a recent check while the same marker is still present. |
A pre-existing marker survives a transient failure. Cleanup removes only
artifacts created by that failed check. The normal mapping recheck interval
applies. bridge.verify below remains a book check.
Podcast fetch and retention jobs recheck the mapping before mutations, including recovery. Then:
- Staging, publication and deletion stay on that show's filesystem.
- Regular files and real show and attachment directories are required.
- Audio install tries an exclusive hard link. Where links are unsupported, it falls back to a no-replace rename.
- A present file is never overwritten or adopted merely because it has the assigned name.
What it reports
Each check becomes one entry of the heartbeat's libraries:
| Field | Meaning |
|---|---|
library_id | the server's library |
mount_path | where the Bridge looked |
mapped | the sample book's file sizes matched, or the server confirmed the library marker |
writable | the probe file could be written and removed there |
checked_path | the sample book's path, or .audiosilo/library.json for a marker check |
error | why it isn't mapped or writable, "" when it is both |
The errors the Bridge writes:
error | Means |
|---|---|
the folder <path> is not found here (or ... is permission denied) | nothing at the mount path, or the Bridge can't read it |
<path> is not a folder | the mount path is a file |
the library has no indexed book to compare against yet | the server has no sample book and the link does not support marker reads |
could not ask the server for a book: ... | the book lookup failed |
this folder doesn't hold the server's copy of the library (<file>: <reason>) | a file is missing (not found here), unreadable (permission denied) or a different size (size differs: N bytes here, M on the server) |
mapped, but not writable here: permission denied | the right library, but the Bridge can't write there |
The server stores the entries as reported. The console shows each library with the server's path, the Bridge's path, the book it checked, the error and its state:
- Ready (mapped and writable);
- Can't write (mapped, read-only);
- Not found (not mapped);
- Not reported yet.
Write jobs, like sidecars.generate, are refused for a library that isn't both
mapped and writable. The server answers 409 library_not_writable, and the
Bridge checks again before it writes.
When it checks
Not on every heartbeat. A check stats files and writes a probe, and doing that every 30 seconds would keep a NAS's spun-down disks awake (an Unraid array, say). The Bridge checks:
- after pairing, and when the server's list of libraries changes (a library added, removed, renamed or moved);
- when a check is due: every
mapping.check_minutes(default 10, 1 to 1440); - when someone asks: Check now on its page's Libraries tab checks every library, and changing one library's folder there re-checks that library only.
A check runs in the background, one library at a time, and checks never overlap. One asked for while another runs is done right after it, with the newest server link, so a mapping changed mid-check is never missed. When a check finishes, the Bridge sends a heartbeat at once so the console sees the results. Every heartbeat in between carries the last results.
A temporary refusal (429, server unavailable or timeout) keeps the last mapping result and its check time for up to three check intervals. The Bridge verifies that the sample file or library marker still proves the same folder. The Libraries tab shows Last check. Without current proof, writes wait for the next check. A slow mount shows Waiting for the folder.
bridge.verify is the same check, on demand
The console's Verify queues bridge.verify,
which runs the same comparison for one library's sample book (or a book an admin
names) as a job, and probes writing in the book's own folder rather than the
library's root. A folder inside a library can refuse writes where the root allows
them, so a job that writes into a book checks that book's folder.