Skip to content

Commit

Permalink
Merge pull request #233 from solidiquis/sort-definition-fix
Browse files Browse the repository at this point in the history
fix sort definitions
  • Loading branch information
solidiquis authored Aug 10, 2023
2 parents 07b7017 + c2c2c83 commit cfca1e6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/context/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ pub enum Type {
Rsize,

/// Sort entries by newer to older Accessing Date
#[value(alias("atime"))]
Access,

/// Sort entries by older to newer Accessing Date
#[value(alias("ratime"))]
Raccess,

/// Sort entries by newer to older Creation Date
#[value(alias("ctime"))]
Create,

/// Sort entries by older to newer Creation Date
#[value(alias("rctime"))]
Rcreate,

/// Sort entries by newer to older Alteration Date
#[value(alias("mtime"))]
Mod,

/// Sort entries by older to newer Alteration Date
#[value(alias("rmtime"))]
Rmod,
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
clippy::style,
clippy::suspicious
)]
#![allow(clippy::cast_precision_loss, clippy::struct_excessive_bools)]
#![allow(clippy::cast_precision_loss, clippy::struct_excessive_bools, clippy::wildcard_imports)]

use clap::CommandFactory;
use context::{layout, Context};
Expand Down
4 changes: 0 additions & 4 deletions src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,6 @@ impl Tree {

let node = tree[index].get();

#[cfg(unix)]
Self::update_column_properties(column_properties, node, ctx);

#[cfg(not(unix))]
Self::update_column_properties(column_properties, node, ctx);

// If a hard-link is already accounted for then don't increment parent dir size.
Expand Down
22 changes: 10 additions & 12 deletions src/tree/node/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ fn base_comparator(sort_type: sort::Type) -> Box<NodeComparator> {
}

mod time_stamping {
pub(self) use crate::tree::node::Node;
pub(self) use core::cmp::Ordering;
pub(self) use std::time::SystemTime;

pub mod accessed {
use crate::tree::node::Node;
use core::cmp::Ordering;
use std::time::SystemTime;
use super::*;

/// Comparator that sorts [Node]s by Last Access timestamp, newer to older.
pub fn comparator(a: &Node, b: &Node) -> Ordering {
let a_stamp = a.accessed().unwrap_or_else(SystemTime::now);
let b_stamp = b.accessed().unwrap_or_else(SystemTime::now);
a_stamp.cmp(&b_stamp)
b_stamp.cmp(&a_stamp)
}

/// Comparator that sorts [Node]s by Access timestamp, older to newer.
Expand All @@ -82,15 +84,13 @@ mod time_stamping {
}

pub mod created {
use crate::tree::node::Node;
use core::cmp::Ordering;
use std::time::SystemTime;
use super::*;

/// Comparator that sorts [Node]s by Creation timestamp, newer to older.
pub fn comparator(a: &Node, b: &Node) -> Ordering {
let a_stamp = a.created().unwrap_or_else(SystemTime::now);
let b_stamp = b.created().unwrap_or_else(SystemTime::now);
a_stamp.cmp(&b_stamp)
b_stamp.cmp(&a_stamp)
}

/// Comparator that sorts [Node]s by Creation timestamp, older to newer.
Expand All @@ -100,15 +100,13 @@ mod time_stamping {
}

pub mod modified {
use crate::tree::node::Node;
use core::cmp::Ordering;
use std::time::SystemTime;
use super::*;

/// Comparator that sorts [Node]s by Alteration timestamp, newer to older.
pub fn comparator(a: &Node, b: &Node) -> Ordering {
let a_stamp = a.modified().unwrap_or_else(SystemTime::now);
let b_stamp = b.modified().unwrap_or_else(SystemTime::now);
a_stamp.cmp(&b_stamp)
b_stamp.cmp(&a_stamp)
}

/// Comparator that sorts [Node]s by Alteration timestamp, older to newer.
Expand Down

0 comments on commit cfca1e6

Please sign in to comment.