rename from_path to from_derivation

This commit is contained in:
cy 2025-04-28 20:50:16 -04:00
parent 878e096494
commit 54d4c714af
3 changed files with 18 additions and 14 deletions

View file

@ -22,19 +22,19 @@ pub struct PathInfo {
} }
impl PathInfo { impl PathInfo {
pub async fn from_path(path: &Path, store: &Store) -> Result<Self> { pub async fn from_derivation(drv: &Path, store: &Store) -> Result<Self> {
debug!("query path info for {:?}", path); debug!("query path info for {:?}", drv);
let derivation = match path.extension() { let derivation = match drv.extension() {
Some(ext) if ext == "drv" => path.as_os_str().as_encoded_bytes(), Some(ext) if ext == "drv" => drv.as_os_str().as_encoded_bytes(),
_ => { _ => {
&Command::new("nix") &Command::new("nix")
.arg("path-info") .arg("path-info")
.arg("--derivation") .arg("--derivation")
.arg(path) .arg(drv)
.output() .output()
.await .await
.context(format!("run command: nix path-info --derivaiton {path:?}"))? .context(format!("run command: nix path-info --derivaiton {drv:?}"))?
.stdout .stdout
} }
}; };
@ -43,16 +43,20 @@ impl PathInfo {
if derivation.is_empty() { if derivation.is_empty() {
return Err(anyhow!( return Err(anyhow!(
"nix path-info did not return a derivation for {path:#?}" "nix path-info did not return a derivation for {drv:#?}"
)); ));
} }
let store_path = StorePath::from_absolute_path(derivation.trim().as_bytes()) Self::from_path(derivation.trim(), store).await
.context("storepath from derivation")?; }
pub async fn from_path(path: &str, store: &Store) -> Result<Self> {
let store_path =
StorePath::from_absolute_path(path.as_bytes()).context("storepath from path")?;
store store
.query_path_info(store_path) .query_path_info(store_path)
.await .await
.context("query pathinfo for derivation") .context("query pathinfo for path")
} }
pub async fn get_closure(&self, store: &Store) -> Result<Vec<Self>> { pub async fn get_closure(&self, store: &Store) -> Result<Vec<Self>> {

View file

@ -79,7 +79,7 @@ impl Push {
let store = self.store.clone(); let store = self.store.clone();
futs.push(tokio::spawn(async move { futs.push(tokio::spawn(async move {
let path_info = PathInfo::from_path(path.as_path(), &store) let path_info = PathInfo::from_derivation(path.as_path(), &store)
.await .await
.context("get path info for path")?; .context("get path info for path")?;
debug!("path-info for {path:?}: {path_info:?}"); debug!("path-info for {path:?}: {path_info:?}");

View file

@ -11,7 +11,7 @@ const HELLO_DRV: &str = "iqbwkm8mjjjlmw6x6ry9rhzin2cp9372-hello-2.12.1.drv";
async fn path_info_from_package() { async fn path_info_from_package() {
let ctx = common::context(); let ctx = common::context();
let path = PathBuf::from(HELLO); let path = PathBuf::from(HELLO);
let path_info = PathInfo::from_path(&path, &ctx.store) let path_info = PathInfo::from_derivation(&path, &ctx.store)
.await .await
.expect("get pathinfo from package"); .expect("get pathinfo from package");
assert_eq!(path_info.path.to_string(), HELLO_DRV); assert_eq!(path_info.path.to_string(), HELLO_DRV);
@ -28,7 +28,7 @@ async fn path_info_from_path() {
.unwrap(); .unwrap();
let ctx = common::context(); let ctx = common::context();
let path = PathBuf::from("/nix/store/9bwryidal9q3g91cjm6xschfn4ikd82q-hello-2.12.1"); let path = PathBuf::from("/nix/store/9bwryidal9q3g91cjm6xschfn4ikd82q-hello-2.12.1");
let path_info = PathInfo::from_path(&path, &ctx.store) let path_info = PathInfo::from_derivation(&path, &ctx.store)
.await .await
.expect("get pathinfo from package"); .expect("get pathinfo from package");
assert_eq!(path_info.path.to_string(), HELLO_DRV); assert_eq!(path_info.path.to_string(), HELLO_DRV);
@ -38,7 +38,7 @@ async fn path_info_from_path() {
async fn closure() { async fn closure() {
let ctx = common::context(); let ctx = common::context();
let path = PathBuf::from(HELLO); let path = PathBuf::from(HELLO);
let path_info = PathInfo::from_path(&path, &ctx.store) let path_info = PathInfo::from_derivation(&path, &ctx.store)
.await .await
.expect("get pathinfo from package"); .expect("get pathinfo from package");
let closure = path_info.get_closure(&ctx.store).await.unwrap(); let closure = path_info.get_closure(&ctx.store).await.unwrap();