Skip to content

Commit 7abae6a

Browse files
committed
feat: support symlinks in core_dir
1 parent 3f95dcf commit 7abae6a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

cli/src/manifest.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
collections::BTreeMap,
3+
fs,
34
path::{Path, PathBuf},
45
};
56

@@ -70,25 +71,28 @@ pub struct ExternalSpec {
7071

7172
pub fn extract_artifacts(root: &Path) -> eyre::Result<Vec<Artifact>> {
7273
let mut artifacts = vec![];
73-
extract_artifacts_rec(&mut artifacts, root, root)?;
74+
extract_artifacts_rec(&mut artifacts, &PathBuf::default(), root)?;
7475
Ok(artifacts)
7576
}
7677

7778
fn extract_artifacts_rec(
7879
artifacts: &mut Vec<Artifact>,
79-
root: &Path,
80+
parent: &Path,
8081
dir: &Path,
8182
) -> eyre::Result<()> {
8283
for entry in std::fs::read_dir(dir).with_context(|| format!("reading {dir:?}"))? {
8384
let entry = entry?;
84-
if !entry.file_type()?.is_dir() {
85+
86+
let path = fs::canonicalize(entry.path())?;
87+
if !path.is_dir() {
8588
continue;
8689
}
87-
let path = entry.path();
90+
91+
let parent = parent.join(entry.file_name());
8892

8993
let piopm = path.join(".piopm");
9094
if !piopm.exists() {
91-
extract_artifacts_rec(artifacts, root, &path)?;
95+
extract_artifacts_rec(artifacts, &parent, &path)?;
9296
continue;
9397
}
9498

@@ -98,15 +102,9 @@ fn extract_artifacts_rec(
98102
serde_path_to_error::deserialize::<_, PackageManifest>(de).wrap_err_with(|| {
99103
format!("failed to parse manifest file: {}", piopm.to_string_lossy())
100104
})?;
101-
let install_path = path
102-
.strip_prefix(root)
103-
.wrap_err_with(|| {
104-
format!("File {dir:?} is not a child of {root:?}: followed a symlink?")
105-
})?
106-
.to_path_buf();
107105
artifacts.push(Artifact {
108106
manifest,
109-
install_path,
107+
install_path: parent,
110108
});
111109
}
112110

0 commit comments

Comments
 (0)