change stuff to our way
This commit is contained in:
parent
c956d6741a
commit
8ac9253ea3
2 changed files with 18 additions and 7 deletions
|
@ -15,17 +15,17 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! `libnixstore` Bindings
|
//! `libnixstore` Bindings
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
use futures::stream::{Stream, StreamExt};
|
use futures::stream::{Stream, StreamExt};
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::{AtticError, AtticResult};
|
|
||||||
|
|
||||||
// The C++ implementation takes care of concurrency
|
// The C++ implementation takes care of concurrency
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct FfiNixStore(UnsafeCell<cxx::UniquePtr<ffi::CNixStore>>);
|
pub struct FfiNixStore(UnsafeCell<cxx::UniquePtr<ffi::CNixStore>>);
|
||||||
|
@ -43,7 +43,7 @@ impl FfiNixStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtain a handle to the Nix store.
|
/// Obtain a handle to the Nix store.
|
||||||
pub unsafe fn open_nix_store() -> AtticResult<FfiNixStore> {
|
pub unsafe fn open_nix_store() -> Result<FfiNixStore> {
|
||||||
match ffi::open_nix_store() {
|
match ffi::open_nix_store() {
|
||||||
Ok(ptr) => {
|
Ok(ptr) => {
|
||||||
let cell = UnsafeCell::new(ptr);
|
let cell = UnsafeCell::new(ptr);
|
||||||
|
@ -116,7 +116,7 @@ impl AsyncWriteAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write everything the sender sends to us.
|
/// Write everything the sender sends to us.
|
||||||
pub async fn write_all(mut self, mut writer: Box<dyn AsyncWrite + Unpin>) -> AtticResult<()> {
|
pub async fn write_all(mut self, mut writer: Box<dyn AsyncWrite + Unpin>) -> Result<()> {
|
||||||
let writer = writer.as_mut();
|
let writer = writer.as_mut();
|
||||||
|
|
||||||
while let Some(data) = self.next().await {
|
while let Some(data) = self.next().await {
|
||||||
|
@ -139,7 +139,7 @@ impl AsyncWriteAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stream for AsyncWriteAdapter {
|
impl Stream for AsyncWriteAdapter {
|
||||||
type Item = AtticResult<Vec<u8>>;
|
type Item = Result<Vec<u8>>;
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
match self.receiver.poll_recv(cx) {
|
match self.receiver.poll_recv(cx) {
|
||||||
|
@ -149,7 +149,7 @@ impl Stream for AsyncWriteAdapter {
|
||||||
match message {
|
match message {
|
||||||
Data(v) => Poll::Ready(Some(Ok(v))),
|
Data(v) => Poll::Ready(Some(Ok(v))),
|
||||||
Error(exception) => {
|
Error(exception) => {
|
||||||
let error = AtticError::CxxError { exception };
|
let error = anyhow::Error::msg(format!("cxx error: {exception}"));
|
||||||
Poll::Ready(Some(Err(error)))
|
Poll::Ready(Some(Err(error)))
|
||||||
}
|
}
|
||||||
Eof => {
|
Eof => {
|
||||||
|
@ -181,7 +181,7 @@ mod ffi {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("attic/src/nix_store/bindings/nix.hpp");
|
include!("nix.hpp");
|
||||||
|
|
||||||
// =========
|
// =========
|
||||||
// CNixStore
|
// CNixStore
|
||||||
|
@ -266,5 +266,8 @@ mod ffi {
|
||||||
|
|
||||||
/// Returns the CA field of the store path.
|
/// Returns the CA field of the store path.
|
||||||
fn ca(self: Pin<&mut CPathInfo>) -> String;
|
fn ca(self: Pin<&mut CPathInfo>) -> String;
|
||||||
|
|
||||||
|
/// Returns the derivation that built this path
|
||||||
|
fn deriver(self: Pin<&mut CPathInfo>) -> String;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// CNixStore
|
||||||
// =========
|
// =========
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue