Skip to content

Commit 682f746

Browse files
committed
nix-utils: replace is_valid_path with nix-bindings-store C API
1 parent 4c230f9 commit 682f746

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

subprojects/crates/nix-utils/include/nix.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ rust::String get_build_dir();
2525
rust::String get_log_dir();
2626
rust::String get_state_dir();
2727

28-
bool is_valid_path(const StoreWrapper &wrapper, rust::Str path);
2928
InternalPathInfo query_path_info(const StoreWrapper &wrapper, rust::Str path);
3029
void clear_path_info_cache(const StoreWrapper &wrapper);
3130
uint64_t compute_closure_size(const StoreWrapper &wrapper, rust::Str path);

subprojects/crates/nix-utils/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ mod ffi {
134134
fn get_build_dir() -> String;
135135
fn get_log_dir() -> String;
136136
fn get_state_dir() -> String;
137-
fn is_valid_path(store: &StoreWrapper, path: &str) -> Result<bool>;
138137
fn query_path_info(store: &StoreWrapper, path: &str) -> Result<InternalPathInfo>;
139138
fn compute_closure_size(store: &StoreWrapper, path: &str) -> Result<u64>;
140139
fn clear_path_info_cache(store: &StoreWrapper) -> Result<()>;
@@ -578,11 +577,19 @@ where
578577
impl BaseStore for BaseStoreImpl {
579578
#[inline]
580579
async fn is_valid_path(&self, path: &StorePath) -> bool {
581-
let store = self.wrapper.clone();
582580
let path = self.print_store_path(path);
583-
asyncify(move || ffi::is_valid_path(store.as_raw(), &path))
584-
.await
585-
.unwrap_or(false)
581+
let uri = self.uri.clone();
582+
asyncify_anyhow(move || -> Result<bool, Error> {
583+
let store_uri = if uri.is_empty() { None } else { Some(uri.as_str()) };
584+
let mut nbs = nix_bindings_store::store::Store::open(
585+
store_uri,
586+
std::iter::empty::<(&str, &str)>(),
587+
)?;
588+
let nbs_path = nbs.parse_store_path(&path)?;
589+
Ok(nbs.is_valid_path(&nbs_path))
590+
})
591+
.await
592+
.unwrap_or(false)
586593
}
587594

588595
#[inline]

subprojects/crates/nix-utils/src/nix.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ rust::String get_log_dir() { return nix::settings.getLogFileSettings().nixLogDir
6666
rust::String get_state_dir() { return nix::settings.nixStateDir.string(); }
6767

6868

69-
bool is_valid_path(const StoreWrapper &wrapper, rust::Str path) {
70-
auto store = wrapper._store;
71-
return store->isValidPath(store->parseStorePath(AS_VIEW(path)));
72-
}
73-
7469
InternalPathInfo query_path_info(const StoreWrapper &wrapper, rust::Str path) {
7570
auto store = wrapper._store;
7671
auto info = store->queryPathInfo(store->parseStorePath(AS_VIEW(path)));

0 commit comments

Comments
 (0)