Skip to content

Commit 89631fe

Browse files
committed
feat: multirepo support
1 parent 4fff1b2 commit 89631fe

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

src/lib.rs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ pub fn install_artifact(artifact_name: &String, store: &Store) -> Result<()> {
254254

255255
#[cfg(feature = "decoding")]
256256
fn resolve_repo_path(store: &Store, path: &String) -> Result<PathBuf> {
257+
use core::error;
258+
257259
if store.cache_path.join(path).exists() {
258260
return Ok(store.cache_path.join(path));
259261
}
@@ -264,8 +266,11 @@ fn resolve_repo_path(store: &Store, path: &String) -> Result<PathBuf> {
264266
.ok_or_else(|| anyhow::anyhow!("Failed to get parent directory"))?;
265267
create_dir_all(parent)?;
266268

269+
// List of all errors accumulated in the next for loop.
270+
let mut error_list = vec![];
271+
267272
for repo in &store.repos {
268-
match store.kind {
273+
let result = match store.kind {
269274
RepoType::Https => {
270275
network::download_file(repo, &store.cache_path.join(path)).map(|_| ())
271276
}
@@ -274,11 +279,17 @@ fn resolve_repo_path(store: &Store, path: &String) -> Result<PathBuf> {
274279
.map(|_| ())
275280
.map_err(|e| anyhow::anyhow!(e))
276281
}
282+
};
283+
284+
if result.is_ok() {
285+
return Ok(store.cache_path.join(path));
277286
}
278-
.with_context(|| format!("Couldn't get {path} from {repo}"))?;
287+
288+
// If error, just add to `error_list`` and continue to next repo, do not return error
289+
error_list.push(result.unwrap_err());
279290
}
280291

281-
Ok(store.cache_path.join(path))
292+
Err(anyhow::anyhow!("{:?}", error_list))
282293
}
283294

284295
#[cfg(feature = "decoding")]
@@ -527,4 +538,54 @@ mod tests {
527538

528539
install_artifact(&"test_artifact".to_string(), &store).unwrap();
529540
}
541+
542+
#[test]
543+
#[cfg(all(feature = "encoding", feature = "decoding"))]
544+
fn test_create_and_load_artifact_multirepo() {
545+
use std::path::PathBuf;
546+
547+
use crate::{build, install_artifact};
548+
549+
let store_a = create_test_store("multirepo_a");
550+
let store_b = create_test_store("multirepo_b");
551+
552+
let store = Store {
553+
kind: store_a.kind,
554+
repos: vec![
555+
store_a.repos.first().unwrap().clone(),
556+
store_b.repos.first().unwrap().clone(),
557+
],
558+
cache_path: store_a.cache_path,
559+
path: store_a.path,
560+
};
561+
562+
let input_dir = temp_dir().join("lcas_artifact_test_multirepo");
563+
564+
// First artifact
565+
let _ = fs::remove_dir_all(&input_dir);
566+
fs::create_dir_all(&input_dir).unwrap();
567+
fs::write(input_dir.join("file1.txt"), b"Hello, world!").unwrap();
568+
569+
build(
570+
&input_dir,
571+
&PathBuf::from(&store.repos.first().unwrap()),
572+
"test_artifact_a",
573+
)
574+
.unwrap();
575+
576+
// Second artifact
577+
let _ = fs::remove_dir_all(&input_dir);
578+
fs::create_dir_all(&input_dir).unwrap();
579+
fs::write(input_dir.join("file1.txt"), b"Hello, world!").unwrap();
580+
581+
build(
582+
&input_dir,
583+
&PathBuf::from(&store.repos.first().unwrap()),
584+
"test_artifact_b",
585+
)
586+
.unwrap();
587+
588+
install_artifact(&"test_artifact_a".to_string(), &store).unwrap();
589+
install_artifact(&"test_artifact_b".to_string(), &store).unwrap();
590+
}
530591
}

0 commit comments

Comments
 (0)