|
|
|
@ -334,19 +334,19 @@ fn sort_paths(dir_path: &str, reverse_sort: bool) -> Result<Vec<DirEntry>> {
|
|
|
|
|
paths.sort_by(|a, b| {
|
|
|
|
|
let a_is_dir = is_dir(a);
|
|
|
|
|
let b_is_dir = is_dir(b);
|
|
|
|
|
let ord = if a_is_dir && b_is_dir || !a_is_dir && !b_is_dir {
|
|
|
|
|
alphanumeric_sort::compare_os_str(a.path().as_ref(), b.path().as_ref())
|
|
|
|
|
if a_is_dir && b_is_dir || !a_is_dir && !b_is_dir {
|
|
|
|
|
let ord = alphanumeric_sort::compare_os_str(a.path().as_ref(), b.path().as_ref());
|
|
|
|
|
if reverse_sort {
|
|
|
|
|
ord.reverse()
|
|
|
|
|
} else {
|
|
|
|
|
ord
|
|
|
|
|
}
|
|
|
|
|
} else if is_dir(a) {
|
|
|
|
|
Ordering::Less
|
|
|
|
|
} else if is_dir(b) {
|
|
|
|
|
Ordering::Greater
|
|
|
|
|
} else {
|
|
|
|
|
Ordering::Equal // what
|
|
|
|
|
};
|
|
|
|
|
if reverse_sort {
|
|
|
|
|
ord.reverse()
|
|
|
|
|
} else {
|
|
|
|
|
ord
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Ok(paths)
|
|
|
|
@ -368,7 +368,8 @@ mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_sort_directory() {
|
|
|
|
|
let paths = sort_paths("tests/sort", false).unwrap();
|
|
|
|
|
assert_eq!(str_path!(paths[0]), "phetch-v0.1.7-linux-armv7.tar.gz");
|
|
|
|
|
assert_eq!(str_path!(paths[0]), "zzz");
|
|
|
|
|
assert_eq!(str_path!(paths[1]), "phetch-v0.1.7-linux-armv7.tar.gz");
|
|
|
|
|
assert_eq!(
|
|
|
|
|
str_path!(paths[paths.len() - 1]),
|
|
|
|
|
"phetch-v0.1.11-macos.zip"
|
|
|
|
@ -378,7 +379,8 @@ mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_rsort_directory() {
|
|
|
|
|
let paths = sort_paths("tests/sort", true).unwrap();
|
|
|
|
|
assert_eq!(str_path!(paths[0]), "phetch-v0.1.11-macos.zip");
|
|
|
|
|
assert_eq!(str_path!(paths[0]), "zzz");
|
|
|
|
|
assert_eq!(str_path!(paths[1]), "phetch-v0.1.11-macos.zip");
|
|
|
|
|
assert_eq!(
|
|
|
|
|
str_path!(paths[paths.len() - 1]),
|
|
|
|
|
"phetch-v0.1.7-linux-armv7.tar.gz"
|
|
|
|
|