coven/storage/local/
mod.rs

1//! Local managed blob storage.
2//!
3//! Files are stored at content-addressed paths under
4//! `storage/{ab}/{cd}/{file_id}` as plaintext. Local files are never encrypted —
5//! encryption happens only on upload to the cloud home.
6mod traits;
7
8pub use traits::BlobStore;
9
10/// Hash-based storage path for a file: `storage/{ab}/{cd}/{file_id}`
11///
12/// Deterministic from the file_id alone. Used for both local storage
13/// (relative to the library dir) and cloud keys.
14pub fn storage_path(file_id: &str) -> String {
15    crate::library_dir::LibraryDir::hashed_path("storage", file_id)
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn storage_path_uses_first_four_hex_chars() {
24        let id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890";
25        let path = storage_path(id);
26        assert_eq!(path, format!("storage/a1/b2/{}", id));
27    }
28
29    #[test]
30    fn storage_path_preserves_original_id_with_dashes() {
31        let id = "12345678-aaaa-bbbb-cccc-ddddeeeeaaaa";
32        let path = storage_path(id);
33        // prefix from dashless hex: "12" and "34"
34        assert_eq!(path, format!("storage/12/34/{}", id));
35        // The full id with dashes is the filename
36        assert!(path.ends_with(id));
37    }
38}