mirror of
https://github.com/RGBCube/dix
synced 2025-07-27 11:47:46 +00:00
chore: reduce macro usage
This commit is contained in:
parent
021c972a0f
commit
60d7a4d9ae
1 changed files with 22 additions and 21 deletions
43
src/store.rs
43
src/store.rs
|
@ -7,6 +7,7 @@ use std::{
|
||||||
use anyhow::{
|
use anyhow::{
|
||||||
Context as _,
|
Context as _,
|
||||||
Result,
|
Result,
|
||||||
|
anyhow,
|
||||||
};
|
};
|
||||||
use derive_more::Deref;
|
use derive_more::Deref;
|
||||||
|
|
||||||
|
@ -15,24 +16,6 @@ use crate::{
|
||||||
StorePath,
|
StorePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! path_to_str {
|
|
||||||
($path:ident) => {
|
|
||||||
let $path = $path.canonicalize().with_context(|| {
|
|
||||||
format!(
|
|
||||||
"failed to canonicalize path '{path}'",
|
|
||||||
path = $path.display(),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let $path = $path.to_str().with_context(|| {
|
|
||||||
format!(
|
|
||||||
"failed to convert path '{path}' to valid unicode",
|
|
||||||
path = $path.display(),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deref)]
|
#[derive(Deref)]
|
||||||
pub struct Connection(rusqlite::Connection);
|
pub struct Connection(rusqlite::Connection);
|
||||||
|
|
||||||
|
@ -47,6 +30,24 @@ pub fn connect() -> Result<Connection> {
|
||||||
Ok(Connection(inner))
|
Ok(Connection(inner))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn path_to_canonical_string(path: &Path) -> Result<String> {
|
||||||
|
let path = path.canonicalize().with_context(|| {
|
||||||
|
format!(
|
||||||
|
"failed to canonicalize path '{path}'",
|
||||||
|
path = path.display(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let path = path.into_os_string().into_string().map_err(|path| {
|
||||||
|
anyhow!(
|
||||||
|
"failed to convert path '{path}' to valid unicode",
|
||||||
|
path = path.display(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(path)
|
||||||
|
}
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
/// Gets the total closure size of the given store path by summing up the nar
|
/// Gets the total closure size of the given store path by summing up the nar
|
||||||
/// size of all depdendent derivations.
|
/// size of all depdendent derivations.
|
||||||
|
@ -65,7 +66,7 @@ impl Connection {
|
||||||
JOIN ValidPaths ON p = id;
|
JOIN ValidPaths ON p = id;
|
||||||
";
|
";
|
||||||
|
|
||||||
path_to_str!(path);
|
let path = path_to_canonical_string(path)?;
|
||||||
|
|
||||||
let closure_size = self
|
let closure_size = self
|
||||||
.prepare_cached(QUERY)?
|
.prepare_cached(QUERY)?
|
||||||
|
@ -93,7 +94,7 @@ impl Connection {
|
||||||
JOIN ValidPaths ON id = p;
|
JOIN ValidPaths ON id = p;
|
||||||
";
|
";
|
||||||
|
|
||||||
path_to_str!(path);
|
let path = path_to_canonical_string(path)?;
|
||||||
|
|
||||||
let packages: result::Result<Vec<(DerivationId, StorePath)>, _> = self
|
let packages: result::Result<Vec<(DerivationId, StorePath)>, _> = self
|
||||||
.prepare_cached(QUERY)?
|
.prepare_cached(QUERY)?
|
||||||
|
@ -132,7 +133,7 @@ impl Connection {
|
||||||
SELECT p, c from graph;
|
SELECT p, c from graph;
|
||||||
";
|
";
|
||||||
|
|
||||||
path_to_str!(path);
|
let path = path_to_canonical_string(path)?;
|
||||||
|
|
||||||
let mut adj = HashMap::<DerivationId, Vec<DerivationId>>::new();
|
let mut adj = HashMap::<DerivationId, Vec<DerivationId>>::new();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue