diff --git a/snix/nix-compat/src/nix_daemon/handler.rs b/snix/nix-compat/src/nix_daemon/handler.rs index 8757dced2..2430b9634 100644 --- a/snix/nix-compat/src/nix_daemon/handler.rs +++ b/snix/nix-compat/src/nix_daemon/handler.rs @@ -117,7 +117,9 @@ where let io = self.io.clone(); loop { let op_code = self.reader.read_number().await?; - match TryInto::::try_into(op_code) { + let op = TryInto::::try_into(op_code); + debug!(?op, "Received operation"); + match op { // Note: please keep operations sorted in ascending order of their numerical op number. Ok(operation) => match operation { Operation::IsValidPath => { diff --git a/snix/nix-compat/src/nix_daemon/mod.rs b/snix/nix-compat/src/nix_daemon/mod.rs index 751375db9..c6fdf95a8 100644 --- a/snix/nix-compat/src/nix_daemon/mod.rs +++ b/snix/nix-compat/src/nix_daemon/mod.rs @@ -2,7 +2,6 @@ pub mod worker_protocol; use std::io::Result; -use futures::future::try_join_all; use tokio::io::AsyncRead; use tracing::warn; use types::{AddToStoreNarRequest, QueryValidPaths, UnkeyedValidPathInfo}; @@ -39,19 +38,21 @@ pub trait NixDaemonIO: Sync { fn query_valid_paths( &self, request: &QueryValidPaths, - ) -> impl std::future::Future>> + Send { + ) -> impl std::future::Future>>> + Send { async move { if request.substitute { warn!("snix does not yet support substitution, ignoring the 'substitute' flag..."); } - // Using try_join_all here to avoid returning partial results to the client. - // The only reason query_path_info can fail is due to transient IO errors, - // so we return such errors to the client as opposed to only returning paths - // that succeeded. - let results = - try_join_all(request.paths.iter().map(|path| self.query_path_info(path))).await?; - Ok(results.into_iter().flatten().collect()) + let mut results: Vec> = Vec::with_capacity(request.paths.len()); + + for path in request.paths.iter() { + if self.is_valid_path(path).await? { + results.push(path.clone()); + } + } + + Ok(results) } } @@ -178,16 +179,12 @@ mod tests { let result = io .query_valid_paths(&QueryValidPaths { - paths: vec![path], + paths: vec![path.clone()], substitute: false, }) .await .expect("expected to get a non-empty response"); - assert_eq!( - result, - vec![UnkeyedValidPathInfo::default()], - "expected to get non empty response" - ); + assert_eq!(result, vec![path], "expected to get non empty response"); } #[tokio::test]