Skip to content

Commit 51ff766

Browse files
committed
refactor
- make sure we fallback to something *probably* better than the empty string.
1 parent f5bdc4f commit 51ff766

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

gix-features/src/fs.rs

Lines changed: 17 additions & 4 deletions
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 {
@@ -221,8 +220,22 @@ pub mod walkdir {
221220
inner: WalkDirImpl::new(root)
222221
.sort_by(|a, b| {
223222
// 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());
223+
let storage_a;
224+
let storage_b;
225+
let a_name = match gix_path::os_str_into_bstr(a.file_name()) {
226+
Ok(f) => f,
227+
Err(_) => {
228+
storage_a = a.file_name().to_string_lossy();
229+
storage_a.as_ref().into()
230+
}
231+
};
232+
let b_name = match gix_path::os_str_into_bstr(b.file_name()) {
233+
Ok(f) => f,
234+
Err(_) => {
235+
storage_b = b.file_name().to_string_lossy();
236+
storage_b.as_ref().into()
237+
}
238+
};
226239
// "common." < "common/" < "common0"
227240
let common = a_name.len().min(b_name.len());
228241
a_name[..common].cmp(&b_name[..common]).then_with(|| {

0 commit comments

Comments
 (0)