Refactor fold to map
Summary: This is to make parallelising this in the next step easier. Reviewed By: jknoxville Differential Revision: D21405192 fbshipit-source-id: b1f2841526a65fcbf545feb69f258874c2134603
This commit is contained in:
committed by
Facebook GitHub Bot
parent
42e080776f
commit
634bd00ab5
@@ -42,8 +42,8 @@ fn pack(
|
|||||||
.get(platform)
|
.get(platform)
|
||||||
.ok_or_else(|| error::Error::MissingPlatformDefinition(platform.clone()))?;
|
.ok_or_else(|| error::Error::MissingPlatformDefinition(platform.clone()))?;
|
||||||
packtype_paths
|
packtype_paths
|
||||||
.iter()
|
.into_iter()
|
||||||
.try_fold(vec![], |mut acc, (pack_type, pack_files)| {
|
.map(|(pack_type, pack_files)| {
|
||||||
print!(
|
print!(
|
||||||
"Packing for platform {:?} type {:?} ... ",
|
"Packing for platform {:?} type {:?} ... ",
|
||||||
platform, pack_type
|
platform, pack_type
|
||||||
@@ -63,9 +63,9 @@ fn pack(
|
|||||||
tar.finish()?;
|
tar.finish()?;
|
||||||
println!("done.");
|
println!("done.");
|
||||||
|
|
||||||
acc.push((*pack_type, output_path));
|
Ok((*pack_type, output_path))
|
||||||
Ok(acc)
|
|
||||||
})
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pack_platform(
|
fn pack_platform(
|
||||||
@@ -192,14 +192,23 @@ fn gen_manifest(archive_paths: &[(PackType, path::PathBuf)]) -> Result<PackManif
|
|||||||
fn gen_manifest_files(
|
fn gen_manifest_files(
|
||||||
archive_paths: &[(PackType, path::PathBuf)],
|
archive_paths: &[(PackType, path::PathBuf)],
|
||||||
) -> Result<BTreeMap<PackType, HashSum>> {
|
) -> Result<BTreeMap<PackType, HashSum>> {
|
||||||
archive_paths.into_iter().try_fold(
|
let res = archive_paths
|
||||||
BTreeMap::new(),
|
.into_iter()
|
||||||
|mut acc: BTreeMap<PackType, HashSum>, (pack_type, path)| {
|
.map(|(pack_type, path)| {
|
||||||
let reader = BufReader::new(File::open(path)?);
|
let reader = BufReader::new(File::open(path)?);
|
||||||
acc.insert(*pack_type, sha256_digest(reader)?);
|
let hash = sha256_digest(reader)?;
|
||||||
Ok(acc)
|
Ok((*pack_type, hash))
|
||||||
},
|
})
|
||||||
)
|
.collect::<Result<Vec<_>>>()?
|
||||||
|
.into_iter()
|
||||||
|
.fold(
|
||||||
|
BTreeMap::new(),
|
||||||
|
|mut acc: BTreeMap<PackType, HashSum>, (pack_type, hash_sum)| {
|
||||||
|
acc.insert(pack_type, hash_sum);
|
||||||
|
acc
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user