Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix permissions symbolic notation #132

Merged
merged 33 commits into from
Apr 19, 2023
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2813c7b
preliminary support for unix symbolic notation permissions
solidiquis Apr 14, 2023
0b7cf9a
fix bit comparison
solidiquis Apr 14, 2023
37a2c5e
dry up code
solidiquis Apr 14, 2023
3c572f2
doc comments
solidiquis Apr 14, 2023
cb00c09
symbolic notation test
solidiquis Apr 15, 2023
1b6cbeb
cargo fmt
solidiquis Apr 15, 2023
027c04b
libc instead of nix
solidiquis Apr 15, 2023
3e323a7
setuid setgid sticky
solidiquis Apr 16, 2023
75fc6a2
function renaming
solidiquis Apr 16, 2023
2b07532
new cli arg; rename some args
solidiquis Apr 16, 2023
a06ac09
plain display for permissions
solidiquis Apr 16, 2023
c81af41
fix doc comment
solidiquis Apr 16, 2023
6bad330
style adjustments for disk usage and permissions
solidiquis Apr 16, 2023
1f6c0a8
octal permissions
solidiquis Apr 16, 2023
0685f3e
placeholder character
solidiquis Apr 17, 2023
99c85e7
support nlinks
solidiquis Apr 17, 2023
ced3e49
support blocks in long output
solidiquis Apr 18, 2023
3daece6
fix nocolor
solidiquis Apr 18, 2023
445726b
move import
solidiquis Apr 18, 2023
c3d253e
old file
solidiquis Apr 18, 2023
7c1c8ea
support timestamps
solidiquis Apr 18, 2023
7ab7d25
fix some visual bugs
solidiquis Apr 18, 2023
0537493
visual bug
solidiquis Apr 18, 2023
acab8e0
another visual bug
solidiquis Apr 18, 2023
765e49e
fix tests
solidiquis Apr 18, 2023
6d02a55
long view for report
solidiquis Apr 19, 2023
8da3388
cargo fmt
solidiquis Apr 19, 2023
9f186e3
reuse the same comparator rather than re-allocating
solidiquis Apr 19, 2023
922bdd7
ditch xattrs package; talk to c
solidiquis Apr 19, 2023
5315a3e
use '.' for regular file identifier
solidiquis Apr 19, 2023
422bb8b
reduce redundant code
solidiquis Apr 19, 2023
c64b22f
fix test
solidiquis Apr 19, 2023
c6f1b01
arg renaming
solidiquis Apr 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
arg renaming
solidiquis committed Apr 19, 2023
commit c6f1b0187a6f25cbdb5b7069f06d6996d31fa4f4
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ use clap::CommandFactory;
use render::{
context::Context,
tree::{
display::{Regular, Report},
display::{Flat, Regular},
Tree,
},
};
@@ -63,8 +63,8 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {

render::styles::init(ctx.no_color());

if ctx.report {
let tree = Tree::<Report>::try_init(ctx)?;
if ctx.flat {
let tree = Tree::<Flat>::try_init(ctx)?;
println!("{tree}");
} else {
let tree = Tree::<Regular>::try_init(ctx)?;
18 changes: 9 additions & 9 deletions src/render/context/mod.rs
Original file line number Diff line number Diff line change
@@ -57,6 +57,14 @@ pub struct Context {
#[arg(short = 'i', long)]
pub no_ignore: bool,

/// Print disk usage information in plain format without the ASCII tree
#[arg(short = 'F', long)]
pub flat: bool,

/// Print human-readable disk usage in report
#[arg(long, requires = "flat")]
pub human: bool,

/// Follow symlinks and consider their disk usage
#[arg(short = 'f', long)]
pub follow: bool,
@@ -106,14 +114,6 @@ pub struct Context {
#[arg(short = 'n', long, default_value_t = 2, value_name = "NUM")]
pub scale: usize,

/// Print disk usage information in plain format without ASCII tree
#[arg(short, long)]
pub report: bool,

/// Print human-readable disk usage in report
#[arg(long, requires = "report")]
pub human: bool,

/// Sort-order to display directory content
#[arg(short, long, value_enum, default_value_t = SortType::default())]
pub sort: SortType,
@@ -123,7 +123,7 @@ pub struct Context {
pub dirs_first: bool,

/// Number of threads to use
#[arg(short, long, default_value_t = 3)]
#[arg(short = 'T', long, default_value_t = 3)]
pub threads: usize,

/// Report disk usage in binary or SI units
8 changes: 4 additions & 4 deletions src/render/tree/display.rs
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@ pub trait TreeVariant {}
pub struct Regular {}

/// For generating plain-text report of disk usage without ASCII tree.
pub struct Report {}
pub struct Flat {}

impl TreeVariant for Regular {}
impl TreeVariant for Report {}
impl TreeVariant for Flat {}

impl Display for Tree<Regular> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
@@ -100,7 +100,7 @@ impl Display for Tree<Regular> {
}
}

impl Display for Tree<Report> {
impl Display for Tree<Flat> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let tree = self.inner();
let root = self.root();
@@ -117,7 +117,7 @@ impl Display for Tree<Report> {
continue;
}

node.report_display(f, ctx)?;
node.flat_display(f, ctx)?;
file_count_data.push(Self::compute_file_count(node_id, tree));
}

2 changes: 1 addition & 1 deletion src/render/tree/node/mod.rs
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ impl Node {
}

/// Formats the [Node] for the report presentation.
pub fn report_display(&self, f: &mut Formatter, ctx: &Context) -> fmt::Result {
pub fn flat_display(&self, f: &mut Formatter, ctx: &Context) -> fmt::Result {
self.report(f, ctx)
}

16 changes: 8 additions & 8 deletions tests/report.rs → tests/flat.rs
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ use indoc::indoc;
mod utils;

#[test]
fn report() {
fn flat() {
assert_eq!(
utils::run_cmd(&["--report", "--sort", "name", "tests/data"]),
utils::run_cmd(&["--flat", "--sort", "name", "tests/data"]),
indoc!(
"1241 B data
308 B dream_cycle
@@ -24,9 +24,9 @@ fn report() {
}

#[test]
fn report_human() {
fn flat_human() {
assert_eq!(
utils::run_cmd(&["--report", "--human", "--sort", "name", "tests/data"]),
utils::run_cmd(&["--flat", "--human", "--sort", "name", "tests/data"]),
indoc!(
"1.21 KiB data
308 B dream_cycle
@@ -45,9 +45,9 @@ fn report_human() {
}

#[test]
fn report_with_level() {
fn flat_with_level() {
assert_eq!(
utils::run_cmd(&["--report", "--level", "1", "--sort", "name", "tests/data"]),
utils::run_cmd(&["--flat", "--level", "1", "--sort", "name", "tests/data"]),
indoc!(
"1241 B data
308 B dream_cycle
@@ -64,12 +64,12 @@ fn report_with_level() {

#[test]
#[should_panic]
fn report_requires_human() {
fn flat_requires_human() {
utils::run_cmd(&["--human"]);
}

#[test]
#[should_panic]
fn report_requires_file_name() {
fn flat_requires_file_name() {
utils::run_cmd(&["--file-name"]);
}