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
10
Cargo.toml
10
Cargo.toml
|
@ -16,15 +16,14 @@ futures = "0.3.31"
|
||||||
nix-compat = { git = "https://github.com/tvlfyi/tvix.git", version = "0.1.0" }
|
nix-compat = { git = "https://github.com/tvlfyi/tvix.git", version = "0.1.0" }
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
reqwest = "0.12.15"
|
reqwest = "0.12.15"
|
||||||
serde = { version = "1.0.219", features = [ "derive" ]}
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
tokio = { version = "1.44.1", features = [ "full", "tracing", "parking_lot" ]}
|
tokio = { version = "1.44.1", features = ["full", "tracing", "parking_lot"] }
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
url = { version = "2.5.4", features = [ "serde" ]}
|
url = { version = "2.5.4", features = ["serde"] }
|
||||||
cxx = "1.0"
|
cxx = "1.0"
|
||||||
console-subscriber = "0.4.1"
|
console-subscriber = "0.4.1"
|
||||||
tempfile = "3.19.1"
|
|
||||||
tokio-util = { version = "0.7.15", features = ["io"] }
|
tokio-util = { version = "0.7.15", features = ["io"] }
|
||||||
bytes = "1.10.1"
|
bytes = "1.10.1"
|
||||||
object_store = { version = "0.12.0", features = ["aws"] }
|
object_store = { version = "0.12.0", features = ["aws"] }
|
||||||
|
@ -35,3 +34,6 @@ humansize = "2.1.3"
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cxx-build = "1.0"
|
cxx-build = "1.0"
|
||||||
pkg-config = "0.3.32"
|
pkg-config = "0.3.32"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = "3.19.1"
|
||||||
|
|
|
@ -28,6 +28,14 @@ impl PathInfo {
|
||||||
let derivation = match drv.extension() {
|
let derivation = match drv.extension() {
|
||||||
Some(ext) if ext == "drv" => drv.as_os_str().as_encoded_bytes(),
|
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")
|
&Command::new("nix")
|
||||||
.arg("path-info")
|
.arg("path-info")
|
||||||
.arg("--derivation")
|
.arg("--derivation")
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use nixcp::path_info::PathInfo;
|
use nixcp::path_info::PathInfo;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
use crate::common::{HELLO, HELLO_DRV, HELLO_PATH};
|
use crate::common::{HELLO, HELLO_DRV, HELLO_PATH};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
@ -25,6 +27,23 @@ async fn path_info_from_path() {
|
||||||
assert_eq!(path_info.path.to_string(), HELLO_DRV);
|
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]
|
#[tokio::test]
|
||||||
async fn closure() {
|
async fn closure() {
|
||||||
let ctx = common::context();
|
let ctx = common::context();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue