Skip to content

Commit 6ff23b7

Browse files
committed
fix(package): handle provide without target
1 parent 25ee70e commit 6ff23b7

2 files changed

Lines changed: 36 additions & 34 deletions

File tree

soar-cli/src/utils.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -176,33 +176,37 @@ pub async fn mangle_package_symlinks(
176176

177177
let provides = provides.unwrap_or_default();
178178
for provide in provides {
179-
if let Some(ref target) = provide.target {
180-
let real_path = install_dir.join(provide.name.clone());
179+
let real_path = install_dir.join(provide.name.clone());
180+
let target_name = if let Some(ref target) = provide.target {
181181
let is_symlink = matches!(
182182
provide.strategy,
183183
Some(ProvideStrategy::KeepTargetOnly) | Some(ProvideStrategy::KeepBoth)
184184
);
185185
if is_symlink {
186-
let target_name = bin_dir.join(target);
187-
if target_name.is_symlink() || target_name.is_file() {
188-
std::fs::remove_file(&target_name)
189-
.with_context(|| format!("removing provide {}", target_name.display()))?;
190-
}
191-
unix::fs::symlink(&real_path, &target_name).with_context(|| {
192-
format!(
193-
"creating symlink {} -> {}",
194-
real_path.display(),
195-
target_name.display()
196-
)
197-
})?;
198-
199-
symlinks.push((real_path, target_name));
186+
bin_dir.join(target)
187+
} else {
188+
continue;
200189
}
190+
} else {
191+
bin_dir.join(provide.name.clone())
192+
};
193+
194+
if target_name.is_symlink() || target_name.is_file() {
195+
std::fs::remove_file(&target_name)
196+
.with_context(|| format!("removing provide {}", target_name.display()))?;
201197
}
198+
unix::fs::symlink(&real_path, &target_name).with_context(|| {
199+
format!(
200+
"creating symlink {} -> {}",
201+
real_path.display(),
202+
target_name.display()
203+
)
204+
})?;
205+
symlinks.push((real_path, target_name));
202206
}
203207

204208
if provides.is_empty() {
205-
for entry in fs::read_dir(&install_dir).with_context(|| {
209+
for entry in fs::read_dir(install_dir).with_context(|| {
206210
format!(
207211
"reading install directory {} for ELF detection",
208212
install_dir.display()
@@ -216,27 +220,25 @@ pub async fn mangle_package_symlinks(
216220
)
217221
})?
218222
.path();
219-
if path.is_file() {
220-
if is_elf(&path).await {
221-
if let Some(file_name) = path.file_name() {
222-
let symlink_target_path = bin_dir.join(file_name);
223-
if symlink_target_path.is_symlink() || symlink_target_path.is_file() {
224-
std::fs::remove_file(&symlink_target_path).with_context(|| {
225-
format!(
226-
"removing existing file/symlink at {}",
227-
symlink_target_path.display()
228-
)
229-
})?;
230-
}
231-
unix::fs::symlink(&path, &symlink_target_path).with_context(|| {
223+
if path.is_file() && is_elf(&path).await {
224+
if let Some(file_name) = path.file_name() {
225+
let symlink_target_path = bin_dir.join(file_name);
226+
if symlink_target_path.is_symlink() || symlink_target_path.is_file() {
227+
std::fs::remove_file(&symlink_target_path).with_context(|| {
232228
format!(
233-
"creating ELF symlink {} -> {}",
234-
path.display(),
229+
"removing existing file/symlink at {}",
235230
symlink_target_path.display()
236231
)
237232
})?;
238-
symlinks.push((path.clone(), symlink_target_path.clone()));
239233
}
234+
unix::fs::symlink(&path, &symlink_target_path).with_context(|| {
235+
format!(
236+
"creating ELF symlink {} -> {}",
237+
path.display(),
238+
symlink_target_path.display()
239+
)
240+
})?;
241+
symlinks.push((path.clone(), symlink_target_path.clone()));
240242
}
241243
}
242244
}

soar-core/src/database/repository.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a> PackageRepository<'a> {
7575
|| ["==", "=>", ":"]
7676
.iter()
7777
.find_map(|&delim| p.split_once(delim))
78-
.map_or(false, |(first, _)| first == package.pkg_name);
78+
.is_some_and(|(first, _)| first == package.pkg_name);
7979
matches.then(|| PackageProvide::from_string(&p))
8080
})
8181
.collect::<Vec<PackageProvide>>()

0 commit comments

Comments
 (0)