use cpp bindings to make nar
This commit is contained in:
parent
0fedae9334
commit
85fefe9e77
7 changed files with 66 additions and 50 deletions
24
src/store.rs
24
src/store.rs
|
@ -2,9 +2,13 @@ use std::{ffi::OsStr, os::unix::ffi::OsStrExt, sync::Arc};
|
|||
|
||||
use anyhow::{Context, Result};
|
||||
use nix_compat::store_path::StorePath;
|
||||
use tokio::task;
|
||||
use tokio::{io::AsyncRead, task};
|
||||
use tokio_util::io::StreamReader;
|
||||
|
||||
use crate::{bindings, path_info::PathInfo};
|
||||
use crate::{
|
||||
bindings::{self, AsyncWriteAdapter},
|
||||
path_info::PathInfo,
|
||||
};
|
||||
|
||||
pub struct Store {
|
||||
inner: Arc<bindings::FfiNixStore>,
|
||||
|
@ -75,4 +79,20 @@ impl Store {
|
|||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn nar_from_path(&self, store_path: StorePath<String>) -> impl AsyncRead {
|
||||
let inner = self.inner.clone();
|
||||
let (adapter, mut sender) = AsyncWriteAdapter::new();
|
||||
let base_name = store_path.to_string().as_bytes().to_vec();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
// Send all exceptions through the channel, and ignore errors
|
||||
// during sending (the channel may have been closed).
|
||||
if let Err(e) = inner.store().nar_from_path(base_name, sender.clone()) {
|
||||
let _ = sender.rust_error(e);
|
||||
}
|
||||
});
|
||||
|
||||
StreamReader::new(adapter)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue