use uqa_storage::{
mvcc::{DatabaseId, SerializableGraph, VersionResult},
read_control::StorageReadControl,
};
use crate::ManagedConnection;
pub(super) struct Exclusion {
#[cfg(any(windows, all(unix, not(target_os = "emscripten"))))]
_snapshots: crate::mvcc::leases::NativeLeaseAdmission,
#[cfg(any(windows, all(unix, not(target_os = "emscripten"))))]
_participants: crate::mvcc::leases::NativeLeaseAdmission,
#[cfg(any(windows, all(unix, not(target_os = "emscripten"))))]
_receipts: crate::mvcc::leases::NativeLeaseAdmission,
#[cfg(any(windows, all(unix, not(target_os = "emscripten"))))]
_resources: crate::mvcc::leases::NativeLeaseAdmission,
}
pub(super) fn exclude(
connection: &ManagedConnection,
identity: DatabaseId,
graph: &SerializableGraph,
control: &StorageReadControl,
) -> VersionResult<Exclusion> {
control.check()?;
#[cfg(any(windows, all(unix, not(target_os = "emscripten"))))]
{
let path = connection.database_path().expect("file restore owner");
let participants = crate::mvcc::serializable::lease_file(path, graph)?;
let participants = empty(&participants, control)?;
let resources = crate::mvcc::resources::lease_file(path, identity)?;
let resources = empty(&resources, control)?;
let receipts = crate::mvcc::receipts::lease_file(path, identity)?;
let receipts = empty(&receipts, control)?;
let uqa_storage::PersistentStorageIdentity::File(path) =
uqa_storage::PersistentStorageIdentity::for_database_path(path)?
else {
unreachable!("file restore identity")
};
let snapshots = crate::mvcc::retention::lease_file(&path, identity)?;
let snapshots = empty(&snapshots, control)?;
Ok(Exclusion {
_snapshots: snapshots,
_participants: participants,
_receipts: receipts,
_resources: resources,
})
}
#[cfg(not(any(windows, all(unix, not(target_os = "emscripten")))))]
{
let _ = (connection, identity, graph);
Ok(Exclusion {})
}
}
#[cfg(any(windows, all(unix, not(target_os = "emscripten"))))]
fn empty(
file: &crate::mvcc::leases::NativeLeaseFile,
control: &StorageReadControl,
) -> VersionResult<crate::mvcc::leases::NativeLeaseAdmission> {
let admission = file.admit(control)?;
let mut live = false;
file.visit(control, &mut |_| {
live = true;
Ok(())
})?;
if live {
return Err(uqa_storage::mvcc::VersionError::Storage(
crate::SQLiteError::DatabaseRestoreBusy.into(),
));
}
Ok(admission)
}