Skip to content

Commit

Permalink
minor: improvements on how we sort files and directories
Browse files Browse the repository at this point in the history
seems we should have sort first the vector then sort then the elements by filenames.

it's a weird hack but whatever.

Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl>
  • Loading branch information
uncomfyhalomacro committed Nov 1, 2024
1 parent 784931c commit 037aa62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
24 changes: 17 additions & 7 deletions libroast/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
use std::{
fs,
io,
io::Write,
path::Path,
io::{
self,
Write,
},
path::{
Path,
PathBuf,
},
};
use tar;
#[allow(unused_imports)]
Expand Down Expand Up @@ -97,8 +102,12 @@ pub fn tar_builder<T: Write>(
// Only metadata that is directly relevant to the identity of a file will be
// included. In particular, ownership and mod/access times are excluded.
builder.mode(tar::HeaderMode::Deterministic);
for f in archive_files.iter().map(|p| p.as_ref())
{
let mut archive_files: Vec<PathBuf> =
archive_files.iter().map(|p| p.as_ref().to_path_buf()).collect();
archive_files.sort();
archive_files.iter().try_for_each(|f| {
let f = PathBuf::from(f);
debug!(?f);
if f.exists()
{
// Using walkdir for deterministic ordering of the files
Expand All @@ -107,13 +116,14 @@ pub fn tar_builder<T: Write>(
let entry = entry?;
add_path_to_archive(builder, entry.path(), target_dir.as_ref(), reproducible)?;
}
Ok(())
}
else
{
error!("THIS IS A BUG. Unable to proceed. {} does not exist.", f.to_string_lossy());
return Err(io::Error::new(io::ErrorKind::Other, f.to_string_lossy()));
Err(io::Error::new(io::ErrorKind::Other, f.to_string_lossy()))
}
}
})?;

builder.finish()
}
Expand Down
1 change: 1 addition & 0 deletions libroast/src/operations/roast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ pub fn roast_opts(roast_args: cli::RoastArgs, start_trace: bool) -> io::Result<(
&exclude_canonicalized_paths,
)?;

// Deterministic order should start here
let archive_files: Vec<PathBuf> = WalkDir::new(workdir)
.into_iter()
.par_bridge()
Expand Down

0 comments on commit 037aa62

Please sign in to comment.