diff --git a/core/src/files/file.rs b/core/src/files/file.rs index 6b4ba4a6..355e932d 100644 --- a/core/src/files/file.rs +++ b/core/src/files/file.rs @@ -15,12 +15,12 @@ pub struct File { impl File { #[inline] - pub async fn from(path: &Path) -> Result { + pub async fn from(path: &Path) -> Result { let meta = fs::metadata(path).await?; Ok(Self::from_meta(path, meta).await) } - pub async fn from_meta(path: &Path, mut meta: Metadata) -> File { + pub async fn from_meta(path: &Path, mut meta: Metadata) -> Self { let is_link = meta.is_symlink(); let mut link_to = None; @@ -31,7 +31,7 @@ impl File { let length = if meta.is_dir() { None } else { Some(meta.len()) }; let is_hidden = path.file_name().map(|s| s.to_string_lossy().starts_with('.')).unwrap_or(false); - File { path: path.to_path_buf(), meta, length, link_to, is_link, is_hidden } + Self { path: path.to_path_buf(), meta, length, link_to, is_link, is_hidden } } } diff --git a/core/src/files/sorter.rs b/core/src/files/sorter.rs index 2f4bc857..f1404122 100644 --- a/core/src/files/sorter.rs +++ b/core/src/files/sorter.rs @@ -1,4 +1,4 @@ -use std::cmp::Ordering; +use std::{cmp::Ordering, mem, path::PathBuf}; use config::{manager::SortBy, MANAGER}; @@ -70,7 +70,20 @@ impl FilesSorter { } }); - items.sort_unstable_by_key(|_| indices.pop().unwrap()); + let dummy = File { + path: PathBuf::new(), + meta: items[0].meta.clone(), + length: None, + link_to: None, + is_link: false, + is_hidden: false, + }; + + let mut new = Vec::with_capacity(indices.len()); + for i in indices { + new.push(mem::replace(&mut items[i], dummy.clone())); + } + *items = new; } #[inline]