From 8ac9253ea3dff87a2a1cbe28619c5536ca0d662e Mon Sep 17 00:00:00 2001 From: cy Date: Wed, 16 Apr 2025 03:46:56 -0400 Subject: [PATCH] change stuff to our way --- src/bindings/mod.rs | 17 ++++++++++------- src/bindings/nix.cpp | 8 ++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/bindings/mod.rs b/src/bindings/mod.rs index 521df2e..f636f4c 100644 --- a/src/bindings/mod.rs +++ b/src/bindings/mod.rs @@ -15,17 +15,17 @@ limitations under the License. */ //! `libnixstore` Bindings +#![allow(dead_code)] use std::cell::UnsafeCell; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; +use anyhow::Result; use futures::stream::{Stream, StreamExt}; use tokio::io::{AsyncWrite, AsyncWriteExt}; -use crate::{AtticError, AtticResult}; - // The C++ implementation takes care of concurrency #[repr(transparent)] pub struct FfiNixStore(UnsafeCell>); @@ -43,7 +43,7 @@ impl FfiNixStore { } /// Obtain a handle to the Nix store. -pub unsafe fn open_nix_store() -> AtticResult { +pub unsafe fn open_nix_store() -> Result { match ffi::open_nix_store() { Ok(ptr) => { let cell = UnsafeCell::new(ptr); @@ -116,7 +116,7 @@ impl AsyncWriteAdapter { } /// Write everything the sender sends to us. - pub async fn write_all(mut self, mut writer: Box) -> AtticResult<()> { + pub async fn write_all(mut self, mut writer: Box) -> Result<()> { let writer = writer.as_mut(); while let Some(data) = self.next().await { @@ -139,7 +139,7 @@ impl AsyncWriteAdapter { } impl Stream for AsyncWriteAdapter { - type Item = AtticResult>; + type Item = Result>; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.receiver.poll_recv(cx) { @@ -149,7 +149,7 @@ impl Stream for AsyncWriteAdapter { match message { Data(v) => Poll::Ready(Some(Ok(v))), Error(exception) => { - let error = AtticError::CxxError { exception }; + let error = anyhow::Error::msg(format!("cxx error: {exception}")); Poll::Ready(Some(Err(error))) } Eof => { @@ -181,7 +181,7 @@ mod ffi { } unsafe extern "C++" { - include!("attic/src/nix_store/bindings/nix.hpp"); + include!("nix.hpp"); // ========= // CNixStore @@ -266,5 +266,8 @@ mod ffi { /// Returns the CA field of the store path. fn ca(self: Pin<&mut CPathInfo>) -> String; + + /// Returns the derivation that built this path + fn deriver(self: Pin<&mut CPathInfo>) -> String; } } diff --git a/src/bindings/nix.cpp b/src/bindings/nix.cpp index 167244c..7783b4b 100644 --- a/src/bindings/nix.cpp +++ b/src/bindings/nix.cpp @@ -103,6 +103,14 @@ RString CPathInfo::ca() { } } +RString CPathInfo::deriver() { + if (this->pi->deriver) { + return RString((this->pi->deriver).to_string()); + } else { + return RString(""); + } +} + // ========= // CNixStore // =========