mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
0d11c52e4d
commit
46e7c4d102
2 changed files with 18 additions and 5 deletions
|
|
@ -15,12 +15,12 @@ pub struct File {
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn from(path: &Path) -> Result<File> {
|
pub async fn from(path: &Path) -> Result<Self> {
|
||||||
let meta = fs::metadata(path).await?;
|
let meta = fs::metadata(path).await?;
|
||||||
Ok(Self::from_meta(path, meta).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 is_link = meta.is_symlink();
|
||||||
let mut link_to = None;
|
let mut link_to = None;
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl File {
|
||||||
|
|
||||||
let length = if meta.is_dir() { None } else { Some(meta.len()) };
|
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);
|
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 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::cmp::Ordering;
|
use std::{cmp::Ordering, mem, path::PathBuf};
|
||||||
|
|
||||||
use config::{manager::SortBy, MANAGER};
|
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]
|
#[inline]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue