some progress at an attempt
This commit is contained in:
parent
b1e59d0a6c
commit
a17fa92c78
5 changed files with 38 additions and 11 deletions
|
@ -211,6 +211,13 @@ mod ffi {
|
||||||
/// Obtains a handle to the Nix store.
|
/// Obtains a handle to the Nix store.
|
||||||
fn open_nix_store() -> Result<UniquePtr<CNixStore>>;
|
fn open_nix_store() -> Result<UniquePtr<CNixStore>>;
|
||||||
|
|
||||||
|
/// Creates a NAR dump from a path.
|
||||||
|
fn nar_from_path(
|
||||||
|
self: Pin<&mut CNixStore>,
|
||||||
|
base_name: Vec<u8>,
|
||||||
|
sender: Box<AsyncWriteSender>,
|
||||||
|
) -> Result<()>;
|
||||||
|
|
||||||
// =========
|
// =========
|
||||||
// CPathInfo
|
// CPathInfo
|
||||||
// =========
|
// =========
|
||||||
|
|
|
@ -108,6 +108,17 @@ std::unique_ptr<std::vector<std::string>> CNixStore::compute_fs_closure(RBasePat
|
||||||
return std::make_unique<std::vector<std::string>>(result);
|
return std::make_unique<std::vector<std::string>>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CNixStore::nar_from_path(RVec<unsigned char> base_name, RBox<AsyncWriteSender> sender) {
|
||||||
|
RustSink sink(std::move(sender));
|
||||||
|
|
||||||
|
std::string_view sv((const char *)base_name.data(), base_name.size());
|
||||||
|
nix::StorePath store_path(sv);
|
||||||
|
|
||||||
|
// exceptions will be thrown into Rust
|
||||||
|
this->store->narFromPath(store_path, sink);
|
||||||
|
sink.eof();
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<CNixStore> open_nix_store() {
|
std::unique_ptr<CNixStore> open_nix_store() {
|
||||||
return std::make_unique<CNixStore>();
|
return std::make_unique<CNixStore>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
bool flip_direction,
|
bool flip_direction,
|
||||||
bool include_outputs,
|
bool include_outputs,
|
||||||
bool include_derivers);
|
bool include_derivers);
|
||||||
|
void nar_from_path(RVec<unsigned char> base_name, RBox<AsyncWriteSender> sender);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<CNixStore> open_nix_store();
|
std::unique_ptr<CNixStore> open_nix_store();
|
||||||
|
|
20
src/store.rs
20
src/store.rs
|
@ -4,7 +4,10 @@ use anyhow::{Context, Result};
|
||||||
use nix_compat::store_path::StorePath;
|
use nix_compat::store_path::StorePath;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
|
|
||||||
use crate::{bindings, path_info::PathInfo};
|
use crate::{
|
||||||
|
bindings::{self, AsyncWriteAdapter},
|
||||||
|
path_info::PathInfo,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
inner: Arc<bindings::FfiNixStore>,
|
inner: Arc<bindings::FfiNixStore>,
|
||||||
|
@ -75,4 +78,19 @@ impl Store {
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn make_nar(&self, path: StorePath<String>) -> AsyncWriteAdapter {
|
||||||
|
let inner = self.inner.clone();
|
||||||
|
let (adapter, mut sender) = AsyncWriteAdapter::new();
|
||||||
|
|
||||||
|
task::spawn_blocking(move || {
|
||||||
|
if let Err(e) = inner
|
||||||
|
.store()
|
||||||
|
.nar_from_path(path.to_string().as_bytes().to_vec(), sender.clone())
|
||||||
|
{
|
||||||
|
let _ = sender.rust_error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
adapter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,16 +139,6 @@ impl<'a> Uploader<'a> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn make_nar(&self) -> Result<Vec<u8>> {
|
|
||||||
Ok(Command::new("nix")
|
|
||||||
.arg("nar")
|
|
||||||
.arg("dump-path")
|
|
||||||
.arg(self.path.absolute_path())
|
|
||||||
.output()
|
|
||||||
.await?
|
|
||||||
.stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn narinfo_from_nar(&self, nar: &[u8]) -> Result<NarInfo> {
|
fn narinfo_from_nar(&self, nar: &[u8]) -> Result<NarInfo> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(nar);
|
hasher.update(nar);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue