Skip to content

Commit 7e6e751

Browse files
committed
refactor
- make sure we fallback to something *probably* better than the empty string.
1 parent 38b63c2 commit 7e6e751

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

gix-features/src/fs.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//! along with runtime costs for maintaining a global [`rayon`](https://docs.rs/rayon) thread pool.
55
//!
66
//! For information on how to use the [`WalkDir`] type, have a look at
7-
//! * [`jwalk::WalkDir`](https://docs.rs/jwalk/0.5.1/jwalk/type.WalkDir.html) if `parallel` feature is enabled
8-
//! * [walkdir::WalkDir](https://docs.rs/walkdir/2.3.1/walkdir/struct.WalkDir.html) otherwise
7+
// TODO: Move all this to `gix-fs` in a breaking change.
98

109
#[cfg(feature = "walkdir")]
1110
mod shared {
@@ -220,9 +219,22 @@ pub mod walkdir {
220219
WalkDir {
221220
inner: WalkDirImpl::new(root)
222221
.sort_by(|a, b| {
223-
// Ignore non-utf8 file name on Windows, which would probably be rejected by caller.
224-
let a_name = gix_path::os_str_into_bstr(a.file_name()).unwrap_or("".as_ref());
225-
let b_name = gix_path::os_str_into_bstr(b.file_name()).unwrap_or("".as_ref());
222+
let storage_a;
223+
let storage_b;
224+
let a_name = match gix_path::os_str_into_bstr(a.file_name()) {
225+
Ok(f) => f,
226+
Err(_) => {
227+
storage_a = a.file_name().to_string_lossy();
228+
storage_a.as_ref().into()
229+
}
230+
};
231+
let b_name = match gix_path::os_str_into_bstr(b.file_name()) {
232+
Ok(f) => f,
233+
Err(_) => {
234+
storage_b = b.file_name().to_string_lossy();
235+
storage_b.as_ref().into()
236+
}
237+
};
226238
// "common." < "common/" < "common0"
227239
let common = a_name.len().min(b_name.len());
228240
a_name[..common].cmp(&b_name[..common]).then_with(|| {

0 commit comments

Comments
 (0)