Skip to content

Commit 723fa99

Browse files
Ensure list_files returns sorted in numeric order
Fixes an issue with pach repacking ensuring the same order of files as original
1 parent 3762f2f commit 723fa99

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::ffi::OsStr;
22
use std::fs::{read_dir, File, OpenOptions};
33
use std::io::{BufWriter, Read, Seek, SeekFrom, Write};
44
use std::path::{Path, PathBuf};
5+
use std::str::FromStr;
56

67
pub mod bpe;
78
pub mod epac;
@@ -69,7 +70,16 @@ fn list_files(
6970
padding_zero_num,
7071
});
7172
}
72-
vec.sort_by(|i1, i2| i1.path.cmp(&i2.path));
73+
// Sort files numerically
74+
vec.sort_by(|i1, i2| {
75+
let name1 = i1.path.file_name().unwrap().to_string_lossy();
76+
let name2 = i2.path.file_name().unwrap().to_string_lossy();
77+
78+
let num1 = u32::from_str(&name1).unwrap_or_default();
79+
let num2 = u32::from_str(&name2).unwrap_or_default();
80+
81+
num1.cmp(&num2)
82+
});
7383
vec
7484
}
7585

0 commit comments

Comments
 (0)