use crate::api::{
ApiResult, BackendCapabilities, ImportReport, MaintenanceStore, Snapshot, SnapshotStore,
};
use crate::storage::Storage;
#[cfg(unix)]
pub fn restrict_permissions(path: &std::path::Path, mode: u32) -> crate::Result<()> {
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(path, std::fs::Permissions::from_mode(mode)).map_err(Into::into)
}
#[cfg(not(unix))]
pub fn restrict_permissions(_path: &std::path::Path, _mode: u32) -> crate::Result<()> {
Ok(())
}
pub struct AsobiRuntime {
storage: Storage,
}
impl AsobiRuntime {
pub fn open_default() -> crate::Result<Self> {
Ok(Self {
storage: Storage::open_default()?,
})
}
pub fn from_storage(storage: Storage) -> Self {
Self { storage }
}
pub fn storage(&self) -> &Storage {
&self.storage
}
pub fn into_storage(self) -> Storage {
self.storage
}
pub fn capabilities(&self) -> ApiResult<BackendCapabilities> {
self.storage.capabilities()
}
pub fn export_snapshot(&self, scope: &[String], rationale: bool) -> ApiResult<Snapshot> {
self.storage.export_snapshot(scope, rationale)
}
pub fn import_snapshot(&self, snapshot: Snapshot) -> ApiResult<ImportReport> {
self.storage.import_snapshot(snapshot)
}
}