Skip to content

Commit

Permalink
remove old commented code and use map instead of for
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Detjens <[email protected]>
  • Loading branch information
detjensrobert committed Dec 27, 2024
1 parent 76fca9e commit 03a13c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 65 deletions.
23 changes: 5 additions & 18 deletions src/builder/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,15 @@ async fn extract_files(
files
);

// try_join_all(
// files
// .iter()
// .enumerate() // need index to avoid copy collisions
// .map(|(i, f)| docker::copy_file(container, f, None)),
// )
// .await

let mut results = vec![];

for f in files.iter() {
let from = Path::new(f);
// if no rename is given, use basename of `from` as target path
// these files should go in chal directory, so pass it in
try_join_all(files.iter().map(|f| {
let from = PathBuf::from(f);
let to = chal
.directory
.join(from.file_name().unwrap().to_str().unwrap());

results.push(copy_file(container, from, &to).await?);
}

Ok(results)
copy_file(container, from, to)
}))
.await
}

/// Extract one file from container and rename
Expand Down
6 changes: 3 additions & 3 deletions src/builder/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ pub async fn remove_container(name: &str) -> Result<()> {
Ok(())
}

pub async fn copy_file(container_id: &str, from: &Path, to: &Path) -> Result<PathBuf> {
info!("copying {container_id}:{from:?} to {to:?}");
pub async fn copy_file(container_id: &str, from: PathBuf, to: PathBuf) -> Result<PathBuf> {
debug!("copying {container_id}:{from:?} to {to:?}");

let client = client().await?;

Expand Down Expand Up @@ -182,7 +182,7 @@ pub async fn copy_file(container_id: &str, from: &Path, to: &Path) -> Result<Pat
if let Some(mut entry_r) = tar.entries()?.next() {
let mut entry = entry_r?;
trace!("got entry: {:?}", entry.path());
let mut target = File::create(to)?;
let mut target = File::create(&to)?;
io::copy(&mut entry, &mut target)?;
} else {
bail!("downloaded archive for {container_id}:{from:?} has no files in it!");
Expand Down
47 changes: 3 additions & 44 deletions src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ fn build_challenge(
}

if extract_artifacts {
info!("extracting build artifacts for chal {:?}", chal.directory);

// find the matching tag for Provide entries that have a `from:` source
let image_assoc = chal
.provide
Expand All @@ -114,12 +116,6 @@ fn build_challenge(
})
.collect_vec();

debug!(
"extracting {} build artifacts for chal {:?}",
image_assoc.len(),
chal.directory
);

let assets = image_assoc
.into_iter()
.map(|(p, tag)| {
Expand All @@ -145,44 +141,7 @@ fn build_challenge(
.flatten_ok()
.collect::<Result<Vec<_>>>()?;

debug!("extracted assets: {:?}", assets);
info!("extracted artifacts: {:?}", assets);
}
Ok(built_tags)
}

// /// Push passed tags to registry
// pub fn push_tags(tags: Vec<String>) -> Result<Vec<String>> {
// let config = get_config()?;

// let built_tags = tags
// .iter()
// .map(|tag| {
// push_image(tag, &config.registry.build)
// .with_context(|| format!("error pushing image {tag}"))
// })
// .collect::<Result<_>>()?;

// Ok(built_tags)
// }

// /// Extract any assets needed from given challenges
// pub fn extract_assets(
// profile_name: &str,
// built_chals: Vec<&ChallengeConfig>,
// ) -> Result<Vec<String>> {
// built_chals.iter().map(|chal| {
// chal.provide.iter().filter(|p| p.from.is_some()).map(|p| {
// assets::extract_asset(p, container)
// })

// // let tag = format!(
// // image_tag!(),
// // registry = config.registry.domain,
// // challenge = chal.name,
// // container = p.name,
// // profile = profile_name
// // );
// });

// Ok(vec![])
// }

0 comments on commit 03a13c8

Please sign in to comment.