about summary refs log tree commit diff
path: root/tvix/nix-compat/src/nix_daemon/handler.rs
diff options
context:
space:
mode:
authorVova Kryachko <v.kryachko@gmail.com>2024-11-08T19·22-0500
committerVladimir Kryachko <v.kryachko@gmail.com>2024-11-12T03·06+0000
commit9d114bf040b92b87196d0621aef00188f801265f (patch)
tree3a1fac60448befec525e0341311e86cbe95e5586 /tvix/nix-compat/src/nix_daemon/handler.rs
parentb564ed9d43f17c620439815b86d2940be197bd47 (diff)
feat(nix-daemon): Implement QueryPathInfo and IsValidPath. r/8908
Change-Id: Ia601e2eae24a2bc13d8851b2e8ed9d6c1808bb35
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12745
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: Vladimir Kryachko <v.kryachko@gmail.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/nix_daemon/handler.rs')
-rw-r--r--tvix/nix-compat/src/nix_daemon/handler.rs35
1 files changed, 29 insertions, 6 deletions
diff --git a/tvix/nix-compat/src/nix_daemon/handler.rs b/tvix/nix-compat/src/nix_daemon/handler.rs
index c0257d979acc..7ac281ec2ceb 100644
--- a/tvix/nix-compat/src/nix_daemon/handler.rs
+++ b/tvix/nix-compat/src/nix_daemon/handler.rs
@@ -10,11 +10,16 @@ use super::{
     worker_protocol::{server_handshake_client, ClientSettings, Operation, Trust, STDERR_LAST},
     NixDaemonIO,
 };
-use crate::wire::{
-    de::{NixRead, NixReader},
-    ser::{NixSerialize, NixWrite, NixWriter, NixWriterBuilder},
-    ProtocolVersion,
+
+use crate::{
+    store_path::StorePath,
+    wire::{
+        de::{NixRead, NixReader},
+        ser::{NixSerialize, NixWrite, NixWriter, NixWriterBuilder},
+        ProtocolVersion,
+    },
 };
+
 use crate::{nix_daemon::types::NixError, worker_protocol::STDERR_ERROR};
 
 /// Handles a single connection with a nix client.
@@ -105,6 +110,7 @@ where
 
     /// Main client connection loop, reads client's requests and responds to them accordingly.
     pub async fn handle_client(&mut self) -> Result<(), std::io::Error> {
+        let io = self.io.clone();
         loop {
             let op_code = self.reader.read_number().await?;
             match TryInto::<Operation>::try_into(op_code) {
@@ -113,6 +119,15 @@ where
                         self.client_settings = self.reader.read_value().await?;
                         self.handle(async { Ok(()) }).await?
                     }
+                    Operation::QueryPathInfo => {
+                        let path: StorePath<String> = self.reader.read_value().await?;
+                        self.handle(io.query_path_info(&path)).await?
+                    }
+                    Operation::IsValidPath => {
+                        let path: StorePath<String> = self.reader.read_value().await?;
+                        self.handle(async { Ok(io.query_path_info(&path).await?.is_some()) })
+                            .await?
+                    }
                     _ => {
                         return Err(std::io::Error::other(format!(
                             "Operation {operation:?} is not implemented"
@@ -168,18 +183,26 @@ where
 #[cfg(test)]
 mod tests {
     use super::*;
-    use std::sync::Arc;
+    use std::{io::Result, sync::Arc};
 
     use tokio::io::AsyncWriteExt;
 
     use crate::{
+        nix_daemon::types::UnkeyedValidPathInfo,
         wire::ProtocolVersion,
         worker_protocol::{ClientSettings, WORKER_MAGIC_1, WORKER_MAGIC_2},
     };
 
     struct MockDaemonIO {}
 
-    impl NixDaemonIO for MockDaemonIO {}
+    impl NixDaemonIO for MockDaemonIO {
+        async fn query_path_info(
+            &self,
+            _path: &crate::store_path::StorePath<String>,
+        ) -> Result<Option<UnkeyedValidPathInfo>> {
+            Ok(None)
+        }
+    }
 
     #[tokio::test]
     async fn test_daemon_initialization() {