diff --git a/src/args.rs b/src/args.rs index 356951d..b8050a8 100644 --- a/src/args.rs +++ b/src/args.rs @@ -307,13 +307,15 @@ where I: Iterator }; } - // -a, -m, -c, --{a,m,c}time + // -a, -m, -c, -b, --{a,m,c,b}time if input.is_any(args![b'a', "atime"]) { output.worker.by = work::OrderBy::AccessTime; } 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"]) { output.worker.by = work::OrderBy::ModifiedTime; + } else if input.is_any(args![b'b', "btime"]) { + output.worker.by = work::OrderBy::BirthTime; } // -z, -0, --nul, diff --git a/src/main.rs b/src/main.rs index 24c9ef0..ae4c13d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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!("--delim " => "Use this user-provided byte as the I/O line seperator")?; 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!("-b", "--btime" => "Sort by birth (default)")?; write_opt!("-n", "--reverse" => "Print output in reverse")?; write_opt!("-p", "--parallel cpus|" => "Run tasks in parallel, with a max number of tasks being equal ``, 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)")?; @@ -115,8 +116,7 @@ async fn main() -> eyre::Result<()> { let (tx, rx) = mpsc::channel(4096); - //TODO: Read main config from args - + //Read main config from args let args = match args::parse_args() .wrap_err("Failed to parse command line args") .with_suggestion(|| "Try `--help`")? diff --git a/src/work.rs b/src/work.rs index 2a2c8ec..aee3f50 100644 --- a/src/work.rs +++ b/src/work.rs @@ -14,7 +14,8 @@ use std::{ pub enum OrderBy { #[default] - CreationTime, + BirthTime, + ChangeTime, AccessTime, ModifiedTime, } @@ -83,14 +84,21 @@ impl FileInfo impl FileInfo { - #[inline] + #[inline] fn get_ordered_unix_time(&self) -> i64 { 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 { OrderBy::AccessTime => self.meta.atime(), - OrderBy::CreationTime => self.meta.ctime(), + OrderBy::ChangeTime => self.meta.ctime(), 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? } }