wip: use Nix's sqlite db "directly"
this might not be a safe assumption, but we're gonna try
This commit is contained in:
parent
008b537385
commit
02061a5850
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -1642,6 +1642,18 @@ version = "2.5.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-iterator"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-streaming-iterator"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
|
||||
|
||||
[[package]]
|
||||
name = "fastcdc"
|
||||
version = "3.1.0"
|
||||
|
@ -2544,6 +2556,7 @@ dependencies = [
|
|||
"is_ci",
|
||||
"netrc-rs",
|
||||
"reqwest",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
|
@ -3411,6 +3424,20 @@ dependencies = [
|
|||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusqlite"
|
||||
version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a78046161564f5e7cd9008aff3b2990b3850dc8e0349119b98e8f251e099f24d"
|
||||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"fallible-iterator",
|
||||
"fallible-streaming-iterator",
|
||||
"hashlink",
|
||||
"libsqlite3-sys",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust_decimal"
|
||||
version = "1.34.3"
|
||||
|
|
|
@ -33,6 +33,7 @@ uuid = { version = "1.4.0", features = ["serde", "v7", "rand", "std"] }
|
|||
futures = "0.3"
|
||||
async-compression = "0.4"
|
||||
tracing-appender = "0.2.3"
|
||||
rusqlite = { version = "0.30", features = ["bundled"] }
|
||||
|
||||
[dependencies.tokio]
|
||||
version = "1.28.0"
|
||||
|
|
|
@ -9,34 +9,19 @@ use crate::error::Result;
|
|||
|
||||
/// Returns the list of store paths that are currently present.
|
||||
pub async fn get_store_paths(store: &NixStore) -> Result<HashSet<PathBuf>> {
|
||||
// FIXME: use the Nix API.
|
||||
let store_dir = store.store_dir();
|
||||
let mut listing = tokio::fs::read_dir(store_dir).await?;
|
||||
let mut paths = HashSet::new();
|
||||
while let Some(entry) = listing.next_entry().await? {
|
||||
let file_name = entry.file_name();
|
||||
let file_name = Path::new(&file_name);
|
||||
// FIXME(cole-h): update the nix bindings to get the dbdir of the localstore?
|
||||
let db =
|
||||
rusqlite::Connection::open("file:/nix/var/nix/db/db.sqlite?immutable=1").expect("FIXME");
|
||||
|
||||
if let Some(extension) = file_name.extension() {
|
||||
match extension.to_str() {
|
||||
None | Some("drv") | Some("chroot") => {
|
||||
tracing::debug!(
|
||||
"skipping file with weird or uninteresting extension {extension:?}"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut stmt = db.prepare("SELECT path FROM ValidPaths").expect("FIXME");
|
||||
let paths = stmt
|
||||
.query_map([], |row| -> std::result::Result<PathBuf, rusqlite::Error> {
|
||||
Ok(PathBuf::from(row.get::<_, String>(0)?))
|
||||
})
|
||||
.expect("FIXME")
|
||||
.into_iter()
|
||||
.map(|r| r.expect("FIXME"))
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
if let Some(s) = file_name.to_str() {
|
||||
// Special paths (so far only `.links`)
|
||||
if s == ".links" {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
paths.insert(store_dir.join(file_name));
|
||||
}
|
||||
Ok(paths)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue