Skip to content

Commit

Permalink
Sort directory contents when loading WIT
Browse files Browse the repository at this point in the history
The order that binary wasms are added to `Resolve` can change how some
items are numbered, so to keep everything deterministic be sure to sort
by filename and don't rely on underlying filesystem ordering.
  • Loading branch information
alexcrichton committed Feb 15, 2024
1 parent 2573bb2 commit ef993b3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/wit-parser/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,12 @@ impl Resolve {
if !path.exists() {
return Ok(ret);
}
for dep in path.read_dir().context("failed to read directory")? {
let dep = dep.context("failed to read directory iterator")?;
let mut entries = path
.read_dir()
.and_then(|i| i.collect::<std::io::Result<Vec<_>>>())
.context("failed to read directory")?;
entries.sort_by_key(|e| e.file_name());
for dep in entries {
let path = dep.path();

let pkg = if dep.file_type()?.is_dir() {
Expand Down

0 comments on commit ef993b3

Please sign in to comment.