summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-04-09 18:45:41 +0200
committerrabite <rabite@posteo.de>2019-04-09 18:45:41 +0200
commit0eedd7da7f6c447cfa0e5417d1e618bb18c8d817 (patch)
treea1979069fa4235faf1ed2dbe23d1ca1008d1812f
parent0c6d65703029d006534d5fe0ce1c0ea91e60e3de (diff)
fix crash when sorting
Squashed commit of the following: commit 353e97f4dcff04929cabd707275df193bdde2f31 Author: rabite <rabite@posteo.de> Date: Tue Apr 9 18:44:10 2019 +0200 remove dbgs commit 97e9cd3eadd259742f0f2a3a619c0eaa23112e54 Author: rabite <rabite@posteo.de> Date: Mon Apr 8 17:53:15 2019 +0200 print names while sorting by name commit 698fffc4b70255268befdbf5b90948e1ae218538 Author: rabite <rabite@posteo.de> Date: Mon Apr 8 17:50:59 2019 +0200 possible fix for crash when sorting
-rw-r--r--src/files.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/files.rs b/src/files.rs
index 637b99a..f374974 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -19,6 +19,7 @@ use chrono::TimeZone;
use failure::Error;
use notify::DebouncedEvent;
use rayon::{ThreadPool, ThreadPoolBuilder};
+use alphanumeric_sort::compare_str;
use crate::fail::{HResult, HError, ErrorLog};
use crate::dirty::{AsyncDirtyBit, DirtyBit, Dirtyable};
@@ -266,23 +267,41 @@ impl Files {
match self.sort {
SortBy::Name => self
.files
- .sort_by(|a, b| alphanumeric_sort::compare_str(&a.name, &b.name)),
+ .sort_by(|a, b| {
+ compare_str(&a.name, &b.name)
+ }),
SortBy::Size => {
self.meta_all_sync().log();
self.files.sort_by(|a, b| {
- if a.meta().unwrap().size() == b.meta().unwrap().size() {
- return alphanumeric_sort::compare_str(&b.name, &a.name);
+ match (a.meta(), b.meta()) {
+ (Ok(a_meta), Ok(b_meta)) => {
+ if a_meta.size() == b_meta.size() {
+ compare_str(&b.name, &a.name)
+ } else {
+ a_meta.size().cmp(&b_meta.size()).reverse()
+ }
+
+ }
+ _ => return std::cmp::Ordering::Equal
}
- a.meta().unwrap().size().cmp(&b.meta().unwrap().size()).reverse()
+
+
});
}
SortBy::MTime => {
self.meta_all_sync().log();
self.files.sort_by(|a, b| {
- if a.meta().unwrap().mtime() == b.meta().unwrap().mtime() {
- return alphanumeric_sort::compare_str(&a.name, &b.name);
+ match (a.meta(), b.meta()) {
+ (Ok(a_meta), Ok(b_meta)) => {
+ if a_meta.mtime() == b_meta.mtime() {
+ compare_str(&b.name, &a.name)
+ } else {
+ a_meta.mtime().cmp(&b_meta.mtime()).reverse()
+ }
+
+ }
+ _ => return std::cmp::Ordering::Equal
}
- a.meta().unwrap().mtime().cmp(&b.meta().unwrap().mtime())
});
}
};