Added orderby birth (default)

Fortune for enumerate-ordered's current commit: Curse − 凶
master
Avril 2 years ago
parent 1a02da936c
commit 236e3df44e
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -307,13 +307,15 @@ where I: Iterator<Item = String>
}; };
} }
// -a, -m, -c, --{a,m,c}time // -a, -m, -c, -b, --{a,m,c,b}time
if input.is_any(args![b'a', "atime"]) { if input.is_any(args![b'a', "atime"]) {
output.worker.by = work::OrderBy::AccessTime; output.worker.by = work::OrderBy::AccessTime;
} else if input.is_any(args![b'c', "ctime"]) { } else if input.is_any(args![b'c', "ctime"]) {
output.worker.by = work::OrderBy::CreationTime; output.worker.by = work::OrderBy::ChangeTime;
} else if input.is_any(args![b'm', "mtime"]) { } else if input.is_any(args![b'm', "mtime"]) {
output.worker.by = work::OrderBy::ModifiedTime; output.worker.by = work::OrderBy::ModifiedTime;
} else if input.is_any(args![b'b', "btime"]) {
output.worker.by = work::OrderBy::BirthTime;
} }
// -z, -0, --nul, // -z, -0, --nul,

@ -85,8 +85,9 @@ where W: std::io::Write,
write_opt!("-I", "--delim ifs" => "Read the first byte of the IFS environment variable as the I/O line seperator.")?; write_opt!("-I", "--delim ifs" => "Read the first byte of the IFS environment variable as the I/O line seperator.")?;
write_opt!("--delim <byte>" => "Use this user-provided byte as the I/O line seperator")?; write_opt!("--delim <byte>" => "Use this user-provided byte as the I/O line seperator")?;
write_opt!("-a", "--atime" => "Sort by atime")?; write_opt!("-a", "--atime" => "Sort by atime")?;
write_opt!("-c", "--ctime" => "Sort by ctime (default)")?; write_opt!("-c", "--ctime" => "Sort by ctime")?;
write_opt!("-m", "--mtime" => "Sort by mtime")?; write_opt!("-m", "--mtime" => "Sort by mtime")?;
write_opt!("-b", "--btime" => "Sort by birth (default)")?;
write_opt!("-n", "--reverse" => "Print output in reverse")?; write_opt!("-n", "--reverse" => "Print output in reverse")?;
write_opt!("-p", "--parallel cpus|<max tasks>" => "Run tasks in parallel, with a max number of tasks being equal `<max tasks>`, or, if 0, to infinity (see `-P`), if 'cpus', to the number of logical CPU cores ({}, default)", *walk::NUM_CPUS)?; write_opt!("-p", "--parallel cpus|<max tasks>" => "Run tasks in parallel, with a max number of tasks being equal `<max tasks>`, or, if 0, to infinity (see `-P`), if 'cpus', to the number of logical CPU cores ({}, default)", *walk::NUM_CPUS)?;
write_opt!("-P", "--parallel 0" => "Run tasks with unbounded parallelism, no limit to the number of walker tasks running at once (note: the physical thread pool will always be the same size regardless of these flags)")?; write_opt!("-P", "--parallel 0" => "Run tasks with unbounded parallelism, no limit to the number of walker tasks running at once (note: the physical thread pool will always be the same size regardless of these flags)")?;
@ -115,8 +116,7 @@ async fn main() -> eyre::Result<()> {
let (tx, rx) = mpsc::channel(4096); let (tx, rx) = mpsc::channel(4096);
//TODO: Read main config from args //Read main config from args
let args = match args::parse_args() let args = match args::parse_args()
.wrap_err("Failed to parse command line args") .wrap_err("Failed to parse command line args")
.with_suggestion(|| "Try `--help`")? .with_suggestion(|| "Try `--help`")?

@ -14,7 +14,8 @@ use std::{
pub enum OrderBy pub enum OrderBy
{ {
#[default] #[default]
CreationTime, BirthTime,
ChangeTime,
AccessTime, AccessTime,
ModifiedTime, ModifiedTime,
} }
@ -83,14 +84,21 @@ impl FileInfo
impl FileInfo impl FileInfo
{ {
#[inline] #[inline]
fn get_ordered_unix_time(&self) -> i64 fn get_ordered_unix_time(&self) -> i64
{ {
use std::os::unix::prelude::*; use std::os::unix::prelude::*;
//use std::os::linux::fs::MetadataExt as _ ; // Doesn't show birth in `statx()` :/
use std::time::SystemTime;
match self.state.by { match self.state.by {
OrderBy::AccessTime => self.meta.atime(), OrderBy::AccessTime => self.meta.atime(),
OrderBy::CreationTime => self.meta.ctime(), OrderBy::ChangeTime => self.meta.ctime(),
OrderBy::ModifiedTime => self.meta.mtime(), OrderBy::ModifiedTime => self.meta.mtime(),
// XXX: Eh, why can't we just get `st_stat` from this? These `expect()`s are slow...
OrderBy::BirthTime => self.meta.created()
.expect("Failed to get creation time").duration_since(SystemTime::UNIX_EPOCH)
.expect("Invalid creation timestamp").as_secs() as i64,//.as_secs_f64().floor() as u64
} //XXX: Should we support nsec precision? } //XXX: Should we support nsec precision?
} }
} }

Loading…
Cancel
Save