Skip to content

Commit 4fff1b2

Browse files
committed
feat: preliminary multi-repo support
1 parent 31f5e85 commit 4fff1b2

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

examples/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() -> Result<()> {
2222
let store = Store {
2323
kind: RepoType::Local,
2424
cache_path,
25-
repo_path: repo_dir.to_string_lossy().to_string(),
25+
repos: vec![repo_dir.to_string_lossy().to_string()],
2626
path: store_dir,
2727
};
2828

src/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Store {
3131
// The "Upstream" RepoType
3232
pub kind: RepoType,
3333
/// Path to the Repo, can be a network location depending on `kind`
34-
pub repo_path: String,
34+
pub repos: Vec<String>,
3535
/// The cache directory is currently only used with networked based `RepoType`, but may be used a future release.
3636
pub cache_path: PathBuf,
3737
/// The directory where all installed artifacts will be under, alongside the CAS System itself.
@@ -264,18 +264,19 @@ fn resolve_repo_path(store: &Store, path: &String) -> Result<PathBuf> {
264264
.ok_or_else(|| anyhow::anyhow!("Failed to get parent directory"))?;
265265
create_dir_all(parent)?;
266266

267-
match store.kind {
268-
RepoType::Https => {
269-
network::download_file(&store.repo_path, &store.cache_path.join(path)).map(|_| ())
267+
for repo in &store.repos {
268+
match store.kind {
269+
RepoType::Https => {
270+
network::download_file(repo, &store.cache_path.join(path)).map(|_| ())
271+
}
272+
RepoType::Local => {
273+
fs::copy(PathBuf::from(&repo).join(path), store.cache_path.join(path))
274+
.map(|_| ())
275+
.map_err(|e| anyhow::anyhow!(e))
276+
}
270277
}
271-
RepoType::Local => fs::copy(
272-
PathBuf::from(&store.repo_path).join(path),
273-
store.cache_path.join(path),
274-
)
275-
.map(|_| ())
276-
.map_err(|e| anyhow::anyhow!(e)),
278+
.with_context(|| format!("Couldn't get {path} from {repo}"))?;
277279
}
278-
.with_context(|| format!("Couldn't get {path} from {}", &store.repo_path))?;
279280

280281
Ok(store.cache_path.join(path))
281282
}
@@ -387,7 +388,7 @@ mod tests {
387388
cache_path: cache,
388389
kind: RepoType::Local,
389390
path: store_path,
390-
repo_path: repo.to_string_lossy().to_string(),
391+
repos: vec![repo.to_string_lossy().to_string()],
391392
};
392393
create_repo(&repo).unwrap();
393394
create_store(&store).unwrap();
@@ -519,7 +520,7 @@ mod tests {
519520

520521
build(
521522
&input_dir,
522-
&PathBuf::from(&store.repo_path),
523+
&PathBuf::from(&store.repos.first().unwrap()),
523524
"test_artifact",
524525
)
525526
.unwrap();

0 commit comments

Comments
 (0)