1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! SQLite construction constrained by an already held physical file claim.
use super::*;
use crate::file_identity::DatabaseFileIdentity;
impl StorageBackend {
/// Refuse any database other than `expected` before initializing identity or WAL.
/// `read_only` retains the explicit topology mode; a writable request still
/// honors an existing file's filesystem read-only mode.
///
/// On Unix, the host must initialize the claimed-file observer at process
/// startup before any SQLite I/O, under `pool::initialize_claimed_file_observer`'s
/// unsafe precondition. Unsupported or uninitialized Unix hosts refuse.
/// Native open-time I/O is outside the pre-SQL refusal guarantee.
pub fn sqlite_with_claimed_file_identity(
path: impl AsRef<Path>,
max_readers: Option<usize>,
wal_ceiling: WalCeilingPolicy,
read_only: bool,
expected: DatabaseFileIdentity,
) -> Result<Self, SqliteError> {
let config = PoolConfig {
expected_file_identity: Some(expected),
wal_ceiling,
..PoolConfig::default()
};
if read_only {
Self::sqlite_read_only_with_pool_config(path, config, max_readers)
} else {
Self::sqlite_with_pool_config(path, config, max_readers)
}
}
/// Writable [`Self::sqlite_with_claimed_file_identity`] that carries the
/// host's captured disk policy and shared volume-lock directory.
pub fn sqlite_with_claimed_file_identity_and_policies(
path: impl AsRef<Path>,
max_readers: Option<usize>,
wal_ceiling: WalCeilingPolicy,
expected: DatabaseFileIdentity,
disk_guard_config: crate::EffectiveDiskGuardConfig,
volume_lock_dir: std::path::PathBuf,
) -> Result<Self, SqliteError> {
let config = PoolConfig {
expected_file_identity: Some(expected),
wal_ceiling,
disk_guard_config: Some(disk_guard_config),
volume_lock_dir: Some(volume_lock_dir),
..PoolConfig::default()
};
Self::sqlite_with_pool_config(path, config, max_readers)
}
}