path_info: check for and resolve symlink
This commit is contained in:
parent
0e97d11745
commit
14d6e9d29e
3 changed files with 33 additions and 4 deletions
|
@ -24,7 +24,6 @@ tracing = "0.1.41"
|
|||
url = { version = "2.5.4", features = ["serde"] }
|
||||
cxx = "1.0"
|
||||
console-subscriber = "0.4.1"
|
||||
tempfile = "3.19.1"
|
||||
tokio-util = { version = "0.7.15", features = ["io"] }
|
||||
bytes = "1.10.1"
|
||||
object_store = { version = "0.12.0", features = ["aws"] }
|
||||
|
@ -35,3 +34,6 @@ humansize = "2.1.3"
|
|||
[build-dependencies]
|
||||
cxx-build = "1.0"
|
||||
pkg-config = "0.3.32"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.19.1"
|
||||
|
|
|
@ -28,6 +28,14 @@ impl PathInfo {
|
|||
let derivation = match drv.extension() {
|
||||
Some(ext) if ext == "drv" => drv.as_os_str().as_encoded_bytes(),
|
||||
_ => {
|
||||
let drv = {
|
||||
// resolve symlink
|
||||
if drv.is_symlink() {
|
||||
&drv.canonicalize()?
|
||||
} else {
|
||||
drv
|
||||
}
|
||||
};
|
||||
&Command::new("nix")
|
||||
.arg("path-info")
|
||||
.arg("--derivation")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use nixcp::path_info::PathInfo;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::common::{HELLO, HELLO_DRV, HELLO_PATH};
|
||||
|
||||
mod common;
|
||||
|
@ -25,6 +27,23 @@ async fn path_info_from_path() {
|
|||
assert_eq!(path_info.path.to_string(), HELLO_DRV);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn path_info_symlink() {
|
||||
let ctx = common::context();
|
||||
|
||||
let temp_path = TempDir::new().unwrap();
|
||||
let link_path = temp_path.path().join("result");
|
||||
|
||||
// symlink at ./result (like `nix build`)
|
||||
std::os::unix::fs::symlink(HELLO_PATH, &link_path).unwrap();
|
||||
|
||||
// should resolve symlink
|
||||
let path_info = PathInfo::from_derivation(&link_path, &ctx.store)
|
||||
.await
|
||||
.expect("get pathinfo from package");
|
||||
assert_eq!(path_info.path.to_string(), HELLO_DRV);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn closure() {
|
||||
let ctx = common::context();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue