mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c45ed344f | |||
| a8725711fa | |||
| 811d3b065f |
@@ -82,11 +82,11 @@ jobs:
|
|||||||
job:
|
job:
|
||||||
# { os, target, cargo-options, features, use-cross, toolchain }
|
# { os, target, cargo-options, features, use-cross, toolchain }
|
||||||
- { os: ubuntu-latest , target: arm-unknown-linux-gnueabihf , use-cross: use-cross }
|
- { os: ubuntu-latest , target: arm-unknown-linux-gnueabihf , use-cross: use-cross }
|
||||||
- { os: ubuntu-20.04 , target: i686-unknown-linux-gnu , use-cross: use-cross }
|
- { os: ubuntu-18.04 , target: i686-unknown-linux-gnu , use-cross: use-cross }
|
||||||
- { os: ubuntu-20.04 , target: i686-unknown-linux-musl , use-cross: use-cross }
|
- { os: ubuntu-18.04 , target: i686-unknown-linux-musl , use-cross: use-cross }
|
||||||
- { os: ubuntu-20.04 , target: x86_64-unknown-linux-gnu , use-cross: use-cross }
|
|
||||||
- { os: ubuntu-20.04 , target: x86_64-unknown-linux-musl , use-cross: use-cross }
|
|
||||||
- { os: ubuntu-18.04 , target: x86_64-unknown-linux-gnu , use-cross: use-cross }
|
- { os: ubuntu-18.04 , target: x86_64-unknown-linux-gnu , use-cross: use-cross }
|
||||||
|
- { os: ubuntu-18.04 , target: x86_64-unknown-linux-musl , use-cross: use-cross }
|
||||||
|
- { os: ubuntu-16.04 , target: x86_64-unknown-linux-gnu , use-cross: use-cross }
|
||||||
- { os: macos-latest , target: x86_64-apple-darwin }
|
- { os: macos-latest , target: x86_64-apple-darwin }
|
||||||
- { os: windows-latest , target: i686-pc-windows-gnu }
|
- { os: windows-latest , target: i686-pc-windows-gnu }
|
||||||
- { os: windows-latest , target: i686-pc-windows-msvc }
|
- { os: windows-latest , target: i686-pc-windows-msvc }
|
||||||
@@ -205,18 +205,6 @@ jobs:
|
|||||||
use-cross: ${{ steps.vars.outputs.CARGO_USE_CROSS }}
|
use-cross: ${{ steps.vars.outputs.CARGO_USE_CROSS }}
|
||||||
command: build
|
command: build
|
||||||
args: --release --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }}
|
args: --release --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }}
|
||||||
- name: Install cargo-deb
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: install
|
|
||||||
args: cargo-deb
|
|
||||||
if: ${{ contains(matrix.job.target, 'musl') }}
|
|
||||||
- name: Build deb
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: deb
|
|
||||||
args: --no-build --target=${{ matrix.job.target }}
|
|
||||||
if: ${{ contains(matrix.job.target, 'musl') }}
|
|
||||||
- name: Test
|
- name: Test
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
@@ -228,12 +216,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: ${{ env.PROJECT_NAME }}-${{ matrix.job.target }}
|
name: ${{ env.PROJECT_NAME }}-${{ matrix.job.target }}
|
||||||
path: target/${{ matrix.job.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}
|
path: target/${{ matrix.job.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}
|
||||||
- name: Archive deb artifacts
|
|
||||||
uses: actions/upload-artifact@master
|
|
||||||
with:
|
|
||||||
name: ${{ env.PROJECT_NAME }}-${{ matrix.job.target }}.deb
|
|
||||||
path: target/${{ matrix.job.target }}/debian
|
|
||||||
if: ${{ contains(matrix.job.target, 'musl') }}
|
|
||||||
- name: Package
|
- name: Package
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Generated
+24
-34
@@ -31,9 +31,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "assert_cmd"
|
name = "assert_cmd"
|
||||||
version = "1.0.8"
|
version = "1.0.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c98233c6673d8601ab23e77eb38f999c51100d46c5703b17288c57fddf3a1ffe"
|
checksum = "a88b6bd5df287567ffdf4ddf4d33060048e1068308e5f62d81c6f9824a045a48"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bstr",
|
"bstr",
|
||||||
"doc-comment",
|
"doc-comment",
|
||||||
@@ -62,9 +62,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
@@ -111,9 +111,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-deque"
|
name = "crossbeam-deque"
|
||||||
version = "0.8.1"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
|
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"crossbeam-epoch",
|
"crossbeam-epoch",
|
||||||
@@ -144,10 +144,10 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "difflib"
|
name = "difference"
|
||||||
version = "0.4.0"
|
version = "2.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "doc-comment"
|
name = "doc-comment"
|
||||||
@@ -157,14 +157,14 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "du-dust"
|
name = "du-dust"
|
||||||
version = "0.7.5"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.12.1",
|
"ansi_term 0.12.1",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"clap",
|
"clap",
|
||||||
"lscolors",
|
"lscolors",
|
||||||
|
"num_cpus",
|
||||||
"rayon",
|
"rayon",
|
||||||
"regex",
|
|
||||||
"stfu8",
|
"stfu8",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"terminal_size",
|
"terminal_size",
|
||||||
@@ -192,22 +192,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.19"
|
version = "0.1.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@@ -216,9 +207,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.101"
|
version = "0.2.97"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
|
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lscolors"
|
name = "lscolors"
|
||||||
@@ -231,9 +222,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.4.1"
|
version = "2.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
@@ -262,12 +253,11 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates"
|
name = "predicates"
|
||||||
version = "2.0.2"
|
version = "1.0.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c143348f141cc87aab5b950021bac6145d0e5ae754b0591de23244cee42c9308"
|
checksum = "f49cfaf7fdaa3bfacc6fa3e7054e65148878354a5cfddcf661df4c851f8021df"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"difflib",
|
"difference",
|
||||||
"itertools",
|
|
||||||
"predicates-core",
|
"predicates-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -279,9 +269,9 @@ checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates-tree"
|
name = "predicates-tree"
|
||||||
version = "1.0.3"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d7dd0fd014130206c9352efbdc92be592751b2b9274dff685348341082c6ea3d"
|
checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"predicates-core",
|
"predicates-core",
|
||||||
"treeline",
|
"treeline",
|
||||||
@@ -354,9 +344,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.2.10"
|
version = "0.2.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
|
checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|||||||
+2
-16
@@ -1,10 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "du-dust"
|
name = "du-dust"
|
||||||
description = "A more intuitive version of du"
|
description = "A more intuitive version of du"
|
||||||
version = "0.7.5"
|
version = "0.6.0"
|
||||||
authors = ["bootandy <bootandy@gmail.com>", "nebkor <code@ardent.nebcorp.com>"]
|
authors = ["bootandy <bootandy@gmail.com>", "nebkor <code@ardent.nebcorp.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "README.md"
|
|
||||||
|
|
||||||
documentation = "https://github.com/bootandy/dust"
|
documentation = "https://github.com/bootandy/dust"
|
||||||
homepage = "https://github.com/bootandy/dust"
|
homepage = "https://github.com/bootandy/dust"
|
||||||
@@ -25,12 +24,12 @@ path = "src/main.rs"
|
|||||||
ansi_term = "0.12"
|
ansi_term = "0.12"
|
||||||
clap = { version = "=2.33", features = ["wrap_help"] }
|
clap = { version = "=2.33", features = ["wrap_help"] }
|
||||||
lscolors = "0.7"
|
lscolors = "0.7"
|
||||||
|
num_cpus = "1"
|
||||||
terminal_size = "0.1"
|
terminal_size = "0.1"
|
||||||
unicode-width = "0.1"
|
unicode-width = "0.1"
|
||||||
rayon="1"
|
rayon="1"
|
||||||
thousands = "0.2"
|
thousands = "0.2"
|
||||||
stfu8 = "0.2"
|
stfu8 = "0.2"
|
||||||
regex = "1"
|
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi-util = "0.1"
|
winapi-util = "0.1"
|
||||||
@@ -42,16 +41,3 @@ tempfile = "=3"
|
|||||||
[[test]]
|
[[test]]
|
||||||
name = "integration"
|
name = "integration"
|
||||||
path = "tests/tests.rs"
|
path = "tests/tests.rs"
|
||||||
|
|
||||||
[package.metadata.deb]
|
|
||||||
section = "utils"
|
|
||||||
assets = [
|
|
||||||
["target/release/dust", "usr/bin/", "755"],
|
|
||||||
["LICENSE", "usr/share/doc/du-dust/", "644"],
|
|
||||||
["README.md", "usr/share/doc/du-dust/README", "644"],
|
|
||||||
]
|
|
||||||
extended-description = """\
|
|
||||||
Dust is meant to give you an instant overview of which directories are using
|
|
||||||
disk space without requiring sort or head. Dust will print a maximum of one
|
|
||||||
'Did not have permissions message'.
|
|
||||||
"""
|
|
||||||
|
|||||||
@@ -38,27 +38,19 @@ Dust is meant to give you an instant overview of which directories are using dis
|
|||||||
|
|
||||||
Dust will list a slightly-less-than-the-terminal-height number of the biggest subdirectories or files and will smartly recurse down the tree to find the larger ones. There is no need for a '-d' flag or a '-h' flag. The largest subdirectories will be colored.
|
Dust will list a slightly-less-than-the-terminal-height number of the biggest subdirectories or files and will smartly recurse down the tree to find the larger ones. There is no need for a '-d' flag or a '-h' flag. The largest subdirectories will be colored.
|
||||||
|
|
||||||
The different colors on the bars: These represent the combined tree hierarchy & disk usage. The shades of grey are used to indicate which parent folder a subfolder belongs to. For instance, look at the above screenshot. `.steam` is a folder taking 44% of the space. From the `.steam` bar is a light grey line that goes up. All these folders are inside `.steam` so if you delete `.steam` all that stuff will be gone too.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: dust
|
Usage: dust
|
||||||
Usage: dust <dir>
|
Usage: dust <dir>
|
||||||
Usage: dust <dir> <another_dir> <and_more>
|
Usage: dust <dir> <another_dir> <and_more>
|
||||||
Usage: dust -p (full-path - Show fullpath of the subdirectories)
|
Usage: dust -p <dir> (full-path - does not shorten the path of the subdirectories)
|
||||||
Usage: dust -s (apparent-size - shows the length of the file as opposed to the amount of disk space it uses)
|
Usage: dust -s <dir> (apparent-size - shows the length of the file as opposed to the amount of disk space it uses)
|
||||||
Usage: dust -n 30 (shows 30 directories instead of the default [default is terminal height])
|
Usage: dust -n 30 <dir> (shows 30 directories instead of the default)
|
||||||
Usage: dust -d 3 (shows 3 levels of subdirectories)
|
Usage: dust -d 3 <dir> (shows 3 levels of subdirectories)
|
||||||
Usage: dust -r (reverse order of output)
|
Usage: dust -r <dir> (reverse order of output, with root at the lowest)
|
||||||
Usage: dust -X ignore (ignore all files and directories with the name 'ignore')
|
Usage: dust -X ignore <dir> (ignore all files and directories with the name 'ignore')
|
||||||
Usage: dust -x (only show directories on the same filesystem)
|
Usage: dust -b <dir> (do not show percentages or draw ASCII bars)
|
||||||
Usage: dust -b (do not show percentages or draw ASCII bars)
|
|
||||||
Usage: dust -i (do not show hidden files)
|
|
||||||
Usage: dust -c (No colors [monochrome])
|
|
||||||
Usage: dust -f (Count files instead of diskspace)
|
|
||||||
Usage: dust -t Group by filetype
|
|
||||||
Usage: dust -e regex Only include files matching this regex (eg dust -e "\.png$" would match png files)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# ----------- To do a release ---------
|
# ----------- To do a release ---------
|
||||||
# edit version in cargo.toml
|
# edit version in cargo.toml
|
||||||
# tag a commit and push (increment version in Cargo.toml first):
|
# tag a commit and push (increment version first):
|
||||||
# git tag v0.4.5
|
# git tag v0.4.5
|
||||||
# git push origin v0.4.5
|
# git push origin v0.4.5
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use crate::node::Node;
|
use crate::node::Node;
|
||||||
use crate::utils::is_filtered_out_due_to_invert_regex;
|
|
||||||
use crate::utils::is_filtered_out_due_to_regex;
|
|
||||||
use rayon::iter::ParallelBridge;
|
use rayon::iter::ParallelBridge;
|
||||||
use rayon::prelude::ParallelIterator;
|
use rayon::prelude::ParallelIterator;
|
||||||
use regex::Regex;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use std::sync::atomic;
|
use std::sync::atomic;
|
||||||
@@ -16,29 +13,30 @@ use std::collections::HashSet;
|
|||||||
use crate::node::build_node;
|
use crate::node::build_node;
|
||||||
use std::fs::DirEntry;
|
use std::fs::DirEntry;
|
||||||
|
|
||||||
use crate::platform::get_metadata;
|
pub fn walk_it(
|
||||||
|
dirs: HashSet<PathBuf>,
|
||||||
pub struct WalkData {
|
ignore_directories: HashSet<PathBuf>,
|
||||||
pub ignore_directories: HashSet<PathBuf>,
|
use_apparent_size: bool,
|
||||||
pub filter_regex: Option<Regex>,
|
by_filecount: bool,
|
||||||
pub invert_filter_regex: Option<Regex>,
|
ignore_hidden: bool,
|
||||||
pub allowed_filesystems: HashSet<u64>,
|
) -> (Vec<Node>, bool) {
|
||||||
pub use_apparent_size: bool,
|
|
||||||
pub by_filecount: bool,
|
|
||||||
pub ignore_hidden: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: WalkData) -> (Vec<Node>, bool) {
|
|
||||||
let permissions_flag = AtomicBool::new(false);
|
let permissions_flag = AtomicBool::new(false);
|
||||||
|
|
||||||
let top_level_nodes: Vec<_> = dirs
|
let top_level_nodes: Vec<_> = dirs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|d| {
|
.filter_map(|d| {
|
||||||
let n = walk(d, &permissions_flag, &walk_data);
|
let n = walk(
|
||||||
|
d,
|
||||||
|
&permissions_flag,
|
||||||
|
&ignore_directories,
|
||||||
|
use_apparent_size,
|
||||||
|
by_filecount,
|
||||||
|
ignore_hidden,
|
||||||
|
);
|
||||||
match n {
|
match n {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
let mut inodes: HashSet<(u64, u64)> = HashSet::new();
|
let mut inodes: HashSet<(u64, u64)> = HashSet::new();
|
||||||
clean_inodes(n, &mut inodes, walk_data.use_apparent_size)
|
clean_inodes(n, &mut inodes, use_apparent_size)
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
@@ -76,39 +74,24 @@ fn clean_inodes(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool {
|
fn ignore_file(
|
||||||
|
entry: &DirEntry,
|
||||||
|
ignore_hidden: bool,
|
||||||
|
ignore_directories: &HashSet<PathBuf>,
|
||||||
|
) -> bool {
|
||||||
let is_dot_file = entry.file_name().to_str().unwrap_or("").starts_with('.');
|
let is_dot_file = entry.file_name().to_str().unwrap_or("").starts_with('.');
|
||||||
let is_ignored_path = walk_data.ignore_directories.contains(&entry.path());
|
let is_ignored_path = ignore_directories.contains(&entry.path());
|
||||||
|
(is_dot_file && ignore_hidden) || is_ignored_path
|
||||||
if !walk_data.allowed_filesystems.is_empty() {
|
|
||||||
let size_inode_device = get_metadata(&entry.path(), false);
|
|
||||||
|
|
||||||
if let Some((_size, Some((_id, dev)))) = size_inode_device {
|
|
||||||
if !walk_data.allowed_filesystems.contains(&dev) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keeping `walk_data.filter_regex.is_some()` is important for performance reasons, it stops unnecessary work
|
|
||||||
if walk_data.filter_regex.is_some()
|
|
||||||
&& entry.path().is_file()
|
|
||||||
&& is_filtered_out_due_to_regex(&walk_data.filter_regex, &entry.path())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if walk_data.invert_filter_regex.is_some()
|
|
||||||
&& entry.path().is_file()
|
|
||||||
&& is_filtered_out_due_to_invert_regex(&walk_data.invert_filter_regex, &entry.path())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
(is_dot_file && walk_data.ignore_hidden) || is_ignored_path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk(dir: PathBuf, permissions_flag: &AtomicBool, walk_data: &WalkData) -> Option<Node> {
|
fn walk(
|
||||||
|
dir: PathBuf,
|
||||||
|
permissions_flag: &AtomicBool,
|
||||||
|
ignore_directories: &HashSet<PathBuf>,
|
||||||
|
use_apparent_size: bool,
|
||||||
|
by_filecount: bool,
|
||||||
|
ignore_hidden: bool,
|
||||||
|
) -> Option<Node> {
|
||||||
let mut children = vec![];
|
let mut children = vec![];
|
||||||
|
|
||||||
if let Ok(entries) = fs::read_dir(dir.clone()) {
|
if let Ok(entries) = fs::read_dir(dir.clone()) {
|
||||||
@@ -121,22 +104,25 @@ fn walk(dir: PathBuf, permissions_flag: &AtomicBool, walk_data: &WalkData) -> Op
|
|||||||
// rayon doesn't parallelise as well giving a 3X performance drop
|
// rayon doesn't parallelise as well giving a 3X performance drop
|
||||||
// hence we unravel the recursion a bit
|
// hence we unravel the recursion a bit
|
||||||
|
|
||||||
// return walk(entry.path(), permissions_flag, ignore_directories, allowed_filesystems, use_apparent_size, by_filecount, ignore_hidden);
|
// return walk(entry.path(), permissions_flag, ignore_directories, use_apparent_size, by_filecount, ignore_hidden);
|
||||||
|
|
||||||
if !ignore_file(entry, walk_data) {
|
if !ignore_file(&entry, ignore_hidden, &ignore_directories) {
|
||||||
if let Ok(data) = entry.file_type() {
|
if let Ok(data) = entry.file_type() {
|
||||||
if data.is_dir() && !data.is_symlink() {
|
if data.is_dir() && !data.is_symlink() {
|
||||||
return walk(entry.path(), permissions_flag, walk_data);
|
return walk(
|
||||||
|
entry.path(),
|
||||||
|
permissions_flag,
|
||||||
|
ignore_directories,
|
||||||
|
use_apparent_size,
|
||||||
|
by_filecount,
|
||||||
|
ignore_hidden,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return build_node(
|
return build_node(
|
||||||
entry.path(),
|
entry.path(),
|
||||||
vec![],
|
vec![],
|
||||||
&walk_data.filter_regex,
|
use_apparent_size,
|
||||||
&walk_data.invert_filter_regex,
|
by_filecount,
|
||||||
walk_data.use_apparent_size,
|
|
||||||
data.is_symlink(),
|
|
||||||
data.is_file(),
|
|
||||||
walk_data.by_filecount,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,16 +135,7 @@ fn walk(dir: PathBuf, permissions_flag: &AtomicBool, walk_data: &WalkData) -> Op
|
|||||||
} else {
|
} else {
|
||||||
permissions_flag.store(true, atomic::Ordering::Relaxed);
|
permissions_flag.store(true, atomic::Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
build_node(
|
build_node(dir, children, use_apparent_size, by_filecount)
|
||||||
dir,
|
|
||||||
children,
|
|
||||||
&walk_data.filter_regex,
|
|
||||||
&walk_data.invert_filter_regex,
|
|
||||||
walk_data.use_apparent_size,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
walk_data.by_filecount,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
+9
-5
@@ -107,6 +107,7 @@ impl DrawData<'_> {
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn draw_it(
|
pub fn draw_it(
|
||||||
|
permission_error: bool,
|
||||||
use_full_path: bool,
|
use_full_path: bool,
|
||||||
is_reversed: bool,
|
is_reversed: bool,
|
||||||
no_colors: bool,
|
no_colors: bool,
|
||||||
@@ -115,13 +116,16 @@ pub fn draw_it(
|
|||||||
by_filecount: bool,
|
by_filecount: bool,
|
||||||
option_root_node: Option<DisplayNode>,
|
option_root_node: Option<DisplayNode>,
|
||||||
) {
|
) {
|
||||||
|
if permission_error {
|
||||||
|
eprintln!("Did not have permissions for all directories");
|
||||||
|
}
|
||||||
if option_root_node.is_none() {
|
if option_root_node.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let root_node = option_root_node.unwrap();
|
let root_node = option_root_node.unwrap();
|
||||||
|
|
||||||
let num_chars_needed_on_left_most = if by_filecount {
|
let num_chars_needed_on_left_most = if by_filecount {
|
||||||
let max_size = root_node.size;
|
let max_size = root_node.children.iter().map(|n| n.size).fold(0, max);
|
||||||
max_size.separate_with_commas().chars().count()
|
max_size.separate_with_commas().chars().count()
|
||||||
} else {
|
} else {
|
||||||
5 // Under normal usage we need 5 chars to display the size of a directory
|
5 // Under normal usage we need 5 chars to display the size of a directory
|
||||||
@@ -261,9 +265,9 @@ fn pad_or_trim_filename(node: &DisplayNode, indent: &str, display_data: &Display
|
|||||||
|
|
||||||
// Add spaces after the filename so we can draw the % used bar chart.
|
// Add spaces after the filename so we can draw the % used bar chart.
|
||||||
let name_and_padding = name
|
let name_and_padding = name
|
||||||
+ " "
|
+ &(repeat(" ")
|
||||||
.repeat(display_data.longest_string_length - width)
|
.take(display_data.longest_string_length - width)
|
||||||
.as_str();
|
.collect::<String>());
|
||||||
|
|
||||||
maybe_trim_filename(name_and_padding, display_data)
|
maybe_trim_filename(name_and_padding, display_data)
|
||||||
}
|
}
|
||||||
@@ -316,7 +320,7 @@ fn get_pretty_size(node: &DisplayNode, is_biggest: bool, display_data: &DisplayD
|
|||||||
let size_as_str = node.size.separate_with_commas();
|
let size_as_str = node.size.separate_with_commas();
|
||||||
let spaces_to_add =
|
let spaces_to_add =
|
||||||
display_data.num_chars_needed_on_left_most - size_as_str.chars().count();
|
display_data.num_chars_needed_on_left_most - size_as_str.chars().count();
|
||||||
size_as_str + " ".repeat(spaces_to_add).as_str()
|
size_as_str + &*repeat(' ').take(spaces_to_add).collect::<String>()
|
||||||
} else {
|
} else {
|
||||||
format!("{:>5}", human_readable_number(node.size))
|
format!("{:>5}", human_readable_number(node.size))
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-6
@@ -36,12 +36,11 @@ impl DisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_children_from_node(&self, is_reversed: bool) -> impl Iterator<Item = DisplayNode> {
|
pub fn get_children_from_node(&self, is_reversed: bool) -> impl Iterator<Item = DisplayNode> {
|
||||||
// we box to avoid the clippy lint warning
|
if is_reversed {
|
||||||
let out: Box<dyn Iterator<Item = DisplayNode>> = if is_reversed {
|
let children: Vec<DisplayNode> = self.children.clone().into_iter().rev().collect();
|
||||||
Box::new(self.children.clone().into_iter().rev())
|
children.into_iter()
|
||||||
} else {
|
} else {
|
||||||
Box::new(self.children.clone().into_iter())
|
self.children.clone().into_iter()
|
||||||
};
|
}
|
||||||
out
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-75
@@ -1,7 +1,6 @@
|
|||||||
use crate::display_node::DisplayNode;
|
use crate::display_node::DisplayNode;
|
||||||
use crate::node::Node;
|
use crate::node::Node;
|
||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -14,11 +13,7 @@ pub fn get_by_depth(top_level_nodes: Vec<Node>, n: usize) -> Option<DisplayNode>
|
|||||||
Some(build_by_depth(&root, n - 1))
|
Some(build_by_depth(&root, n - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_biggest(
|
pub fn get_biggest(top_level_nodes: Vec<Node>, n: usize) -> Option<DisplayNode> {
|
||||||
top_level_nodes: Vec<Node>,
|
|
||||||
n: usize,
|
|
||||||
using_a_filter: bool,
|
|
||||||
) -> Option<DisplayNode> {
|
|
||||||
if top_level_nodes.is_empty() {
|
if top_level_nodes.is_empty() {
|
||||||
// perhaps change this, bring back Error object?
|
// perhaps change this, bring back Error object?
|
||||||
return None;
|
return None;
|
||||||
@@ -27,17 +22,18 @@ pub fn get_biggest(
|
|||||||
let mut heap = BinaryHeap::new();
|
let mut heap = BinaryHeap::new();
|
||||||
let number_top_level_nodes = top_level_nodes.len();
|
let number_top_level_nodes = top_level_nodes.len();
|
||||||
let root = get_new_root(top_level_nodes);
|
let root = get_new_root(top_level_nodes);
|
||||||
let mut allowed_nodes = HashSet::new();
|
|
||||||
|
|
||||||
|
root.children.iter().for_each(|c| heap.push(c));
|
||||||
|
|
||||||
|
let mut allowed_nodes = HashSet::new();
|
||||||
allowed_nodes.insert(&root.name);
|
allowed_nodes.insert(&root.name);
|
||||||
heap = add_children(using_a_filter, &root, heap);
|
|
||||||
|
|
||||||
for _ in number_top_level_nodes..n {
|
for _ in number_top_level_nodes..n {
|
||||||
let line = heap.pop();
|
let line = heap.pop();
|
||||||
match line {
|
match line {
|
||||||
Some(line) => {
|
Some(line) => {
|
||||||
|
line.children.iter().for_each(|c| heap.push(c));
|
||||||
allowed_nodes.insert(&line.name);
|
allowed_nodes.insert(&line.name);
|
||||||
heap = add_children(using_a_filter, line, heap);
|
|
||||||
}
|
}
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
@@ -45,72 +41,6 @@ pub fn get_biggest(
|
|||||||
recursive_rebuilder(&allowed_nodes, &root)
|
recursive_rebuilder(&allowed_nodes, &root)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all_file_types(top_level_nodes: Vec<Node>, n: usize) -> Option<DisplayNode> {
|
|
||||||
let mut map: HashMap<String, DisplayNode> = HashMap::new();
|
|
||||||
build_by_all_file_types(top_level_nodes, &mut map);
|
|
||||||
let mut by_types: Vec<DisplayNode> = map.into_iter().map(|(_k, v)| v).collect();
|
|
||||||
by_types.sort();
|
|
||||||
by_types.reverse();
|
|
||||||
|
|
||||||
let displayed = if by_types.len() <= n {
|
|
||||||
by_types
|
|
||||||
} else {
|
|
||||||
let (displayed, rest) = by_types.split_at(if n > 1 { n - 1 } else { 1 });
|
|
||||||
let remaining = DisplayNode {
|
|
||||||
name: PathBuf::from("(others)"),
|
|
||||||
size: rest.iter().map(|a| a.size).sum(),
|
|
||||||
children: vec![],
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut displayed = displayed.to_vec();
|
|
||||||
displayed.push(remaining);
|
|
||||||
displayed
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = DisplayNode {
|
|
||||||
name: PathBuf::from("(total)"),
|
|
||||||
size: displayed.iter().map(|a| a.size).sum(),
|
|
||||||
children: displayed,
|
|
||||||
};
|
|
||||||
Some(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_children<'a>(
|
|
||||||
using_a_filter: bool,
|
|
||||||
line: &'a Node,
|
|
||||||
mut heap: BinaryHeap<&'a Node>,
|
|
||||||
) -> BinaryHeap<&'a Node> {
|
|
||||||
if using_a_filter {
|
|
||||||
line.children.iter().for_each(|c| {
|
|
||||||
if c.name.is_file() || c.size > 0 {
|
|
||||||
heap.push(c)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
line.children.iter().for_each(|c| heap.push(c));
|
|
||||||
}
|
|
||||||
heap
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_by_all_file_types(top_level_nodes: Vec<Node>, counter: &mut HashMap<String, DisplayNode>) {
|
|
||||||
for node in top_level_nodes {
|
|
||||||
if node.name.is_file() {
|
|
||||||
let ext = node.name.extension();
|
|
||||||
let key: String = match ext {
|
|
||||||
Some(e) => ".".to_string() + &e.to_string_lossy(),
|
|
||||||
None => "(no extension)".into(),
|
|
||||||
};
|
|
||||||
let mut display_node = counter.entry(key.clone()).or_insert(DisplayNode {
|
|
||||||
name: PathBuf::from(key),
|
|
||||||
size: 0,
|
|
||||||
children: vec![],
|
|
||||||
});
|
|
||||||
display_node.size += node.size;
|
|
||||||
}
|
|
||||||
build_by_all_file_types(node.children, counter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_by_depth(node: &Node, depth: usize) -> DisplayNode {
|
fn build_by_depth(node: &Node, depth: usize) -> DisplayNode {
|
||||||
let new_children = {
|
let new_children = {
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
|
|||||||
+20
-110
@@ -1,25 +1,20 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
extern crate regex;
|
|
||||||
extern crate unicode_width;
|
extern crate unicode_width;
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::process;
|
|
||||||
|
|
||||||
use self::display::draw_it;
|
use self::display::draw_it;
|
||||||
use clap::{App, AppSettings, Arg};
|
use clap::{App, AppSettings, Arg};
|
||||||
use dir_walker::walk_it;
|
use dirwalker::walk_it;
|
||||||
use dir_walker::WalkData;
|
use filter::{get_biggest, get_by_depth};
|
||||||
use filter::{get_all_file_types, get_biggest, get_by_depth};
|
|
||||||
use regex::Regex;
|
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use terminal_size::{terminal_size, Height, Width};
|
use terminal_size::{terminal_size, Height, Width};
|
||||||
use utils::get_filesystem_devices;
|
|
||||||
use utils::simplify_dir_names;
|
use utils::simplify_dir_names;
|
||||||
|
|
||||||
mod dir_walker;
|
mod dirwalker;
|
||||||
mod display;
|
mod display;
|
||||||
mod display_node;
|
mod display_node;
|
||||||
mod filter;
|
mod filter;
|
||||||
@@ -64,7 +59,6 @@ fn get_height_of_terminal() -> usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn get_width_of_terminal() -> usize {
|
fn get_width_of_terminal() -> usize {
|
||||||
// Windows CI runners detect a very low terminal width
|
// Windows CI runners detect a very low terminal width
|
||||||
if let Some((Width(w), Height(_h))) = terminal_size() {
|
if let Some((Width(w), Height(_h))) = terminal_size() {
|
||||||
@@ -74,28 +68,6 @@ fn get_width_of_terminal() -> usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn get_width_of_terminal() -> usize {
|
|
||||||
if let Some((Width(w), Height(_h))) = terminal_size() {
|
|
||||||
w as usize
|
|
||||||
} else {
|
|
||||||
DEFAULT_TERMINAL_WIDTH
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_regex_value(maybe_value: Option<&str>) -> Option<Regex> {
|
|
||||||
match maybe_value {
|
|
||||||
Some(v) => match Regex::new(v) {
|
|
||||||
Ok(r) => Some(r),
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Ignoring bad value for regex {:?}", e);
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let default_height = get_height_of_terminal();
|
let default_height = get_height_of_terminal();
|
||||||
let def_num_str = default_height.to_string();
|
let def_num_str = default_height.to_string();
|
||||||
@@ -135,12 +107,6 @@ fn main() {
|
|||||||
.multiple(true)
|
.multiple(true)
|
||||||
.help("Exclude any file or directory with this name"),
|
.help("Exclude any file or directory with this name"),
|
||||||
)
|
)
|
||||||
.arg(
|
|
||||||
Arg::with_name("limit_filesystem")
|
|
||||||
.short("x")
|
|
||||||
.long("limit-filesystem")
|
|
||||||
.help("Only count the files and directories on the same filesystem as the supplied directory"),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("display_apparent_size")
|
Arg::with_name("display_apparent_size")
|
||||||
.short("s")
|
.short("s")
|
||||||
@@ -174,38 +140,8 @@ fn main() {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("ignore_hidden")
|
Arg::with_name("ignore_hidden")
|
||||||
.short("i") // Do not use 'h' this is used by 'help'
|
.short("i") // Do not use 'h' this is used by 'help'
|
||||||
.long("ignore_hidden") //TODO: fix change - -> _
|
.long("ignore_hidden")
|
||||||
.help("Do not display hidden files"),
|
.help("Obey .git_ignore rules & Do not display hidden files"),
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("invert_filter")
|
|
||||||
.short("v")
|
|
||||||
.long("invert-filter")
|
|
||||||
.takes_value(true)
|
|
||||||
.number_of_values(1)
|
|
||||||
.multiple(true)
|
|
||||||
.conflicts_with("filter")
|
|
||||||
.conflicts_with("types")
|
|
||||||
.conflicts_with("depth")
|
|
||||||
.help("Exclude files matching this regex. To ignore png files type: -v \"\\.png$\" "),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("filter")
|
|
||||||
.short("e")
|
|
||||||
.long("filter")
|
|
||||||
.takes_value(true)
|
|
||||||
.number_of_values(1)
|
|
||||||
.multiple(true)
|
|
||||||
.conflicts_with("types")
|
|
||||||
.conflicts_with("depth")
|
|
||||||
.help("Only include files matching this regex. For png files type: -e \"\\.png$\" "),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("types")
|
|
||||||
.short("t")
|
|
||||||
.long("file_types")
|
|
||||||
.conflicts_with("depth")
|
|
||||||
.help("show only these file types"),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("width")
|
Arg::with_name("width")
|
||||||
@@ -215,18 +151,15 @@ fn main() {
|
|||||||
.number_of_values(1)
|
.number_of_values(1)
|
||||||
.help("Specify width of output overriding the auto detection of terminal width"),
|
.help("Specify width of output overriding the auto detection of terminal width"),
|
||||||
)
|
)
|
||||||
.arg(Arg::with_name("inputs").multiple(true).default_value("."))
|
.arg(Arg::with_name("inputs").multiple(true))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let target_dirs = options
|
let target_dirs = {
|
||||||
.values_of("inputs")
|
match options.values_of("inputs") {
|
||||||
.expect("Should be a default value here")
|
None => vec!["."],
|
||||||
.collect();
|
Some(r) => r.collect(),
|
||||||
|
}
|
||||||
let summarize_file_types = options.is_present("types");
|
};
|
||||||
|
|
||||||
let maybe_filter = get_regex_value(options.value_of("filter"));
|
|
||||||
let maybe_invert_filter = get_regex_value(options.value_of("invert_filter"));
|
|
||||||
|
|
||||||
let number_of_lines = match value_t!(options.value_of("number_of_lines"), usize) {
|
let number_of_lines = match value_t!(options.value_of("number_of_lines"), usize) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
@@ -258,54 +191,31 @@ fn main() {
|
|||||||
|
|
||||||
let by_filecount = options.is_present("by_filecount");
|
let by_filecount = options.is_present("by_filecount");
|
||||||
let ignore_hidden = options.is_present("ignore_hidden");
|
let ignore_hidden = options.is_present("ignore_hidden");
|
||||||
let limit_filesystem = options.is_present("limit_filesystem");
|
|
||||||
|
|
||||||
let simplified_dirs = simplify_dir_names(target_dirs);
|
let simplified_dirs = simplify_dir_names(target_dirs);
|
||||||
let allowed_filesystems = {
|
|
||||||
if limit_filesystem {
|
|
||||||
get_filesystem_devices(simplified_dirs.iter())
|
|
||||||
} else {
|
|
||||||
HashSet::new()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let ignored_full_path: HashSet<PathBuf> = ignore_directories
|
let ignored_full_path: HashSet<PathBuf> = ignore_directories
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|x| simplified_dirs.iter().map(move |d| d.join(x.clone())))
|
.flat_map(|x| simplified_dirs.iter().map(move |d| d.join(x.clone())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let walk_data = WalkData {
|
let (nodes, errors) = walk_it(
|
||||||
ignore_directories: ignored_full_path,
|
simplified_dirs,
|
||||||
filter_regex: maybe_filter,
|
ignored_full_path,
|
||||||
invert_filter_regex: maybe_invert_filter,
|
|
||||||
allowed_filesystems,
|
|
||||||
use_apparent_size,
|
use_apparent_size,
|
||||||
by_filecount,
|
by_filecount,
|
||||||
ignore_hidden,
|
ignore_hidden,
|
||||||
};
|
);
|
||||||
|
|
||||||
let (top_level_nodes, has_errors) = walk_it(simplified_dirs, walk_data);
|
|
||||||
|
|
||||||
let tree = {
|
let tree = {
|
||||||
match (depth, summarize_file_types) {
|
match depth {
|
||||||
(_, true) => get_all_file_types(top_level_nodes, number_of_lines),
|
None => get_biggest(nodes, number_of_lines),
|
||||||
(Some(depth), _) => get_by_depth(top_level_nodes, depth),
|
Some(depth) => get_by_depth(nodes, depth),
|
||||||
(_, _) => get_biggest(
|
|
||||||
top_level_nodes,
|
|
||||||
number_of_lines,
|
|
||||||
options.values_of("filter").is_some()
|
|
||||||
|| options.value_of("invert_filter").is_some(),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if options.is_present("filter") {
|
|
||||||
println!("Filtering by: {}", options.value_of("filter").unwrap());
|
|
||||||
}
|
|
||||||
if has_errors {
|
|
||||||
eprintln!("Did not have permissions for all directories");
|
|
||||||
}
|
|
||||||
draw_it(
|
draw_it(
|
||||||
|
errors,
|
||||||
options.is_present("display_full_paths"),
|
options.is_present("display_full_paths"),
|
||||||
!options.is_present("reverse"),
|
!options.is_present("reverse"),
|
||||||
no_colors,
|
no_colors,
|
||||||
|
|||||||
+1
-26
@@ -1,8 +1,5 @@
|
|||||||
use crate::platform::get_metadata;
|
use crate::platform::get_metadata;
|
||||||
use crate::utils::is_filtered_out_due_to_invert_regex;
|
|
||||||
use crate::utils::is_filtered_out_due_to_regex;
|
|
||||||
|
|
||||||
use regex::Regex;
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -14,37 +11,15 @@ pub struct Node {
|
|||||||
pub inode_device: Option<(u64, u64)>,
|
pub inode_device: Option<(u64, u64)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub fn build_node(
|
pub fn build_node(
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
children: Vec<Node>,
|
children: Vec<Node>,
|
||||||
filter_regex: &Option<Regex>,
|
|
||||||
invert_filter_regex: &Option<Regex>,
|
|
||||||
use_apparent_size: bool,
|
use_apparent_size: bool,
|
||||||
is_symlink: bool,
|
|
||||||
is_file: bool,
|
|
||||||
by_filecount: bool,
|
by_filecount: bool,
|
||||||
) -> Option<Node> {
|
) -> Option<Node> {
|
||||||
match get_metadata(&dir, use_apparent_size) {
|
match get_metadata(&dir, use_apparent_size) {
|
||||||
Some(data) => {
|
Some(data) => {
|
||||||
let inode_device = if is_symlink && !use_apparent_size {
|
let (size, inode_device) = if by_filecount { (1, data.1) } else { data };
|
||||||
None
|
|
||||||
} else {
|
|
||||||
data.1
|
|
||||||
};
|
|
||||||
|
|
||||||
let size = if is_filtered_out_due_to_regex(filter_regex, &dir)
|
|
||||||
|| is_filtered_out_due_to_invert_regex(invert_filter_regex, &dir)
|
|
||||||
|| (is_symlink && !use_apparent_size)
|
|
||||||
|| by_filecount && !is_file
|
|
||||||
{
|
|
||||||
0
|
|
||||||
} else if by_filecount {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
data.0
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(Node {
|
Some(Node {
|
||||||
name: dir,
|
name: dir,
|
||||||
size,
|
size,
|
||||||
|
|||||||
+2
-2
@@ -120,9 +120,9 @@ pub fn get_metadata(d: &Path, _use_apparent_size: bool) -> Option<(u64, Option<(
|
|||||||
{
|
{
|
||||||
Some((md.len(), None))
|
Some((md.len(), None))
|
||||||
} else {
|
} else {
|
||||||
get_metadata_expensive(d)
|
get_metadata_expensive(&d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => get_metadata_expensive(d),
|
_ => get_metadata_expensive(&d),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-39
@@ -1,9 +1,11 @@
|
|||||||
use platform::get_metadata;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::platform;
|
fn is_a_parent_of<P: AsRef<Path>>(parent: P, child: P) -> bool {
|
||||||
use regex::Regex;
|
let parent = parent.as_ref();
|
||||||
|
let child = child.as_ref();
|
||||||
|
child.starts_with(parent) && !parent.starts_with(child)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn simplify_dir_names<P: AsRef<Path>>(filenames: Vec<P>) -> HashSet<PathBuf> {
|
pub fn simplify_dir_names<P: AsRef<Path>>(filenames: Vec<P>) -> HashSet<PathBuf> {
|
||||||
let mut top_level_names: HashSet<PathBuf> = HashSet::with_capacity(filenames.len());
|
let mut top_level_names: HashSet<PathBuf> = HashSet::with_capacity(filenames.len());
|
||||||
@@ -31,22 +33,6 @@ pub fn simplify_dir_names<P: AsRef<Path>>(filenames: Vec<P>) -> HashSet<PathBuf>
|
|||||||
top_level_names
|
top_level_names
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_filesystem_devices<'a, P: IntoIterator<Item = &'a PathBuf>>(paths: P) -> HashSet<u64> {
|
|
||||||
// Gets the device ids for the filesystems which are used by the argument paths
|
|
||||||
paths
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|p| {
|
|
||||||
let meta = get_metadata(p, false);
|
|
||||||
|
|
||||||
if let Some((_size, Some((_id, dev)))) = meta {
|
|
||||||
Some(dev)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||||
// normalize path ...
|
// normalize path ...
|
||||||
// 1. removing repeated separators
|
// 1. removing repeated separators
|
||||||
@@ -57,26 +43,6 @@ pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
|||||||
path.as_ref().components().collect::<PathBuf>()
|
path.as_ref().components().collect::<PathBuf>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_filtered_out_due_to_regex(filter_regex: &Option<Regex>, dir: &Path) -> bool {
|
|
||||||
match filter_regex {
|
|
||||||
Some(fr) => !fr.is_match(&dir.as_os_str().to_string_lossy()),
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_filtered_out_due_to_invert_regex(filter_regex: &Option<Regex>, dir: &Path) -> bool {
|
|
||||||
match filter_regex {
|
|
||||||
Some(fr) => fr.is_match(&dir.as_os_str().to_string_lossy()),
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_a_parent_of<P: AsRef<Path>>(parent: P, child: P) -> bool {
|
|
||||||
let parent = parent.as_ref();
|
|
||||||
let child = child.as_ref();
|
|
||||||
child.starts_with(parent) && !parent.starts_with(child)
|
|
||||||
}
|
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
+132
-56
@@ -1,5 +1,4 @@
|
|||||||
use assert_cmd::Command;
|
use assert_cmd::Command;
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ fn copy_test_data(dir: &str) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize() {
|
pub fn initialize() {
|
||||||
INIT.call_once(|| {
|
INIT.call_once(|| {
|
||||||
copy_test_data("tests/test_dir");
|
copy_test_data("tests/test_dir");
|
||||||
copy_test_data("tests/test_dir2");
|
copy_test_data("tests/test_dir2");
|
||||||
@@ -46,101 +45,160 @@ fn initialize() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exact_output_test<T: AsRef<OsStr>>(valid_outputs: Vec<String>, command_args: Vec<T>) {
|
|
||||||
initialize();
|
|
||||||
|
|
||||||
let mut a = &mut Command::cargo_bin("dust").unwrap();
|
|
||||||
for p in command_args {
|
|
||||||
a = a.arg(p);
|
|
||||||
}
|
|
||||||
let output: String = str::from_utf8(&a.unwrap().stdout).unwrap().into();
|
|
||||||
|
|
||||||
assert!(valid_outputs
|
|
||||||
.iter()
|
|
||||||
.fold(false, |sum, i| sum || output.contains(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
|
// "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_main_basic() {
|
pub fn test_main_basic() {
|
||||||
// -c is no color mode - This makes testing much simpler
|
// -c is no color mode - This makes testing much simpler
|
||||||
exact_output_test(main_output(), vec!["-c", "/tmp/test_dir/"])
|
initialize();
|
||||||
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let assert = cmd.arg("-c").arg("/tmp/test_dir/").unwrap().stdout;
|
||||||
|
let output = str::from_utf8(&assert).unwrap();
|
||||||
|
assert!(output.contains(&main_output()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_main_multi_arg() {
|
pub fn test_main_multi_arg() {
|
||||||
let command_args = vec![
|
initialize();
|
||||||
"-c",
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
"/tmp/test_dir/many/",
|
let assert = cmd
|
||||||
"/tmp/test_dir",
|
.arg("-c")
|
||||||
"/tmp/test_dir",
|
.arg("/tmp/test_dir/many/")
|
||||||
];
|
.arg("/tmp/test_dir")
|
||||||
exact_output_test(main_output(), command_args);
|
.arg("/tmp/test_dir")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&assert).unwrap();
|
||||||
|
assert!(output.contains(&main_output()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_output() -> Vec<String> {
|
#[cfg(target_os = "macos")]
|
||||||
// Some linux currently thought to be Manjaro, Arch
|
fn main_output() -> String {
|
||||||
// Although probably depends on how drive is formatted
|
r#"
|
||||||
let mac_and_some_linux = r#"
|
|
||||||
0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── hello_file│████████████████████████████████████████████████ │ 100%
|
4.0K ├── hello_file│████████████████████████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ many │████████████████████████████████████████████████ │ 100%
|
4.0K ┌─┴ many │████████████████████████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
4.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string();
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
let ubuntu = r#"
|
#[cfg(target_os = "linux")]
|
||||||
|
fn main_output() -> String {
|
||||||
|
r#"
|
||||||
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── hello_file│ ░░░░░░░░░░░░░░░░█████████████████ │ 33%
|
4.0K ├── hello_file│ ░░░░░░░░░░░░░░░░█████████████████ │ 33%
|
||||||
8.0K ┌─┴ many │ █████████████████████████████████ │ 67%
|
8.0K ┌─┴ many │ █████████████████████████████████ │ 67%
|
||||||
12K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
12K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string();
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
vec![mac_and_some_linux, ubuntu]
|
#[cfg(target_os = "windows")]
|
||||||
|
fn main_output() -> String {
|
||||||
|
"windows results vary by host".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_main_long_paths() {
|
pub fn test_main_long_paths() {
|
||||||
let command_args = vec!["-c", "-p", "/tmp/test_dir/"];
|
initialize();
|
||||||
exact_output_test(main_output_long_paths(), command_args);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let assert = cmd
|
||||||
|
.arg("-c")
|
||||||
|
.arg("-p")
|
||||||
|
.arg("/tmp/test_dir/")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&assert).unwrap();
|
||||||
|
assert!(output.contains(&main_output_long_paths()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_output_long_paths() -> Vec<String> {
|
#[cfg(target_os = "macos")]
|
||||||
let mac_and_some_linux = r#"
|
fn main_output_long_paths() -> String {
|
||||||
|
r#"
|
||||||
0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100%
|
4.0K ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ /tmp/test_dir/many │█████████████████████████████ │ 100%
|
4.0K ┌─┴ /tmp/test_dir/many │█████████████████████████████ │ 100%
|
||||||
4.0K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
|
4.0K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string();
|
.to_string()
|
||||||
let ubuntu = r#"
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn main_output_long_paths() -> String {
|
||||||
|
r#"
|
||||||
0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░░█ │ 0%
|
0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░░██████████ │ 33%
|
4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░░██████████ │ 33%
|
||||||
8.0K ┌─┴ /tmp/test_dir/many │ ████████████████████ │ 67%
|
8.0K ┌─┴ /tmp/test_dir/many │ ████████████████████ │ 67%
|
||||||
12K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
|
12K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
|
||||||
"#
|
"#
|
||||||
.trim()
|
.trim()
|
||||||
.to_string();
|
.to_string()
|
||||||
vec![mac_and_some_linux, ubuntu]
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn main_output_long_paths() -> String {
|
||||||
|
"windows results vary by host".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
|
#[test]
|
||||||
|
pub fn test_apparent_size() {
|
||||||
|
initialize();
|
||||||
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let assert = cmd.arg("-c").arg("-s").arg("/tmp/test_dir").unwrap().stdout;
|
||||||
|
let output = str::from_utf8(&assert).unwrap();
|
||||||
|
assert!(output.contains(&output_apparent_size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn output_apparent_size() -> String {
|
||||||
|
r#"
|
||||||
|
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
|
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
|
4.0K ┌─┴ many │ █████████████████████████ │ 50%
|
||||||
|
8.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
|
"#
|
||||||
|
.trim()
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn output_apparent_size() -> String {
|
||||||
|
r#"
|
||||||
|
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
|
||||||
|
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░░░██ │ 3%
|
||||||
|
134B ┌─┴ many │ ████████████████████████████ │ 58%
|
||||||
|
230B ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
|
||||||
|
"#
|
||||||
|
.trim()
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn output_apparent_size() -> String {
|
||||||
|
"windows results vary by host".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check against directories and files whos names are substrings of each other
|
// Check against directories and files whos names are substrings of each other
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_substring_of_names_and_long_names() {
|
pub fn test_substring_of_names_and_long_names() {
|
||||||
let command_args = vec!["-c", "/tmp/test_dir2"];
|
initialize();
|
||||||
exact_output_test(no_substring_of_names_output(), command_args);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd.arg("-c").arg("/tmp/test_dir2").unwrap().stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
|
assert!(output.contains(&no_substring_of_names_output()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_substring_of_names_output() -> Vec<String> {
|
#[cfg(target_os = "linux")]
|
||||||
let ubuntu = "
|
fn no_substring_of_names_output() -> String {
|
||||||
|
"
|
||||||
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
|
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
|
||||||
4.0K ├── dir_name_clash
|
4.0K ├── dir_name_clash
|
||||||
4.0K │ ┌── hello
|
4.0K │ ┌── hello
|
||||||
@@ -150,9 +208,12 @@ fn no_substring_of_names_output() -> Vec<String> {
|
|||||||
24K ┌─┴ test_dir2
|
24K ┌─┴ test_dir2
|
||||||
"
|
"
|
||||||
.trim()
|
.trim()
|
||||||
.into();
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
let mac_and_some_linux = "
|
#[cfg(target_os = "macos")]
|
||||||
|
fn no_substring_of_names_output() -> String {
|
||||||
|
"
|
||||||
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
|
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
|
||||||
4.0K │ ┌── hello
|
4.0K │ ┌── hello
|
||||||
4.0K ├─┴ dir
|
4.0K ├─┴ dir
|
||||||
@@ -162,33 +223,48 @@ fn no_substring_of_names_output() -> Vec<String> {
|
|||||||
12K ┌─┴ test_dir2
|
12K ┌─┴ test_dir2
|
||||||
"
|
"
|
||||||
.trim()
|
.trim()
|
||||||
.into();
|
.into()
|
||||||
vec![mac_and_some_linux, ubuntu]
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn no_substring_of_names_output() -> String {
|
||||||
|
"PRs".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_unicode_directories() {
|
pub fn test_unicode_directories() {
|
||||||
let command_args = vec!["-c", "/tmp/test_dir_unicode"];
|
initialize();
|
||||||
exact_output_test(unicode_dir(), command_args);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd.arg("-c").arg("/tmp/test_dir_unicode").unwrap().stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
|
assert!(output.contains(&unicode_dir()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unicode_dir() -> Vec<String> {
|
#[cfg(target_os = "linux")]
|
||||||
|
fn unicode_dir() -> String {
|
||||||
// The way unicode & asian characters are rendered on the terminal should make this line up
|
// The way unicode & asian characters are rendered on the terminal should make this line up
|
||||||
let ubuntu = "
|
"
|
||||||
0B ┌── ラウトは難しいです!.japan│ █ │ 0%
|
0B ┌── ラウトは難しいです!.japan│ █ │ 0%
|
||||||
0B ├── 👩.unicode │ █ │ 0%
|
0B ├── 👩.unicode │ █ │ 0%
|
||||||
4.0K ┌─┴ test_dir_unicode │██████████████████████████████████ │ 100%
|
4.0K ┌─┴ test_dir_unicode │██████████████████████████████████ │ 100%
|
||||||
"
|
"
|
||||||
.trim()
|
.trim()
|
||||||
.into();
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
let mac_and_some_linux = "
|
#[cfg(target_os = "macos")]
|
||||||
|
fn unicode_dir() -> String {
|
||||||
|
"
|
||||||
0B ┌── ラウトは難しいです!.japan│ █ │ 0%
|
0B ┌── ラウトは難しいです!.japan│ █ │ 0%
|
||||||
0B ├── 👩.unicode │ █ │ 0%
|
0B ├── 👩.unicode │ █ │ 0%
|
||||||
0B ┌─┴ test_dir_unicode │ █ │ 0%
|
0B ┌─┴ test_dir_unicode │ █ │ 0%
|
||||||
"
|
"
|
||||||
.trim()
|
.trim()
|
||||||
.into();
|
.into()
|
||||||
vec![mac_and_some_linux, ubuntu]
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn unicode_dir() -> String {
|
||||||
|
"".into()
|
||||||
}
|
}
|
||||||
|
|||||||
+69
-77
@@ -1,25 +1,17 @@
|
|||||||
use assert_cmd::Command;
|
use assert_cmd::Command;
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file contains tests that test a substring of the output using '.contains'
|
* This file contains tests that test a substring of the output using '.contains'
|
||||||
*
|
*
|
||||||
* These tests should be the same cross platform
|
* These tests should be the same cross platform
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn build_command<T: AsRef<OsStr>>(command_args: Vec<T>) -> String {
|
|
||||||
let mut a = &mut Command::cargo_bin("dust").unwrap();
|
|
||||||
for p in command_args {
|
|
||||||
a = a.arg(p);
|
|
||||||
}
|
|
||||||
str::from_utf8(&a.unwrap().stdout).unwrap().into()
|
|
||||||
}
|
|
||||||
|
|
||||||
// We can at least test the file names are there
|
// We can at least test the file names are there
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_basic_output() {
|
pub fn test_basic_output() {
|
||||||
let output = build_command(vec!["tests/test_dir/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd.arg("tests/test_dir/").unwrap().stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
|
|
||||||
assert!(output.contains(" ┌─┴ "));
|
assert!(output.contains(" ┌─┴ "));
|
||||||
assert!(output.contains("test_dir "));
|
assert!(output.contains("test_dir "));
|
||||||
@@ -33,7 +25,9 @@ pub fn test_basic_output() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_output_no_bars_means_no_excess_spaces() {
|
pub fn test_output_no_bars_means_no_excess_spaces() {
|
||||||
let output = build_command(vec!["-b", "tests/test_dir/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd.arg("-b").arg("tests/test_dir/").unwrap().stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
// If bars are not being shown we don't need to pad the output with spaces
|
// If bars are not being shown we don't need to pad the output with spaces
|
||||||
assert!(output.contains("many"));
|
assert!(output.contains("many"));
|
||||||
assert!(!output.contains("many "));
|
assert!(!output.contains("many "));
|
||||||
@@ -41,7 +35,15 @@ pub fn test_output_no_bars_means_no_excess_spaces() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_reverse_flag() {
|
pub fn test_reverse_flag() {
|
||||||
let output = build_command(vec!["-r", "-c", "tests/test_dir/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd
|
||||||
|
.arg("-c")
|
||||||
|
.arg("-r")
|
||||||
|
.arg("tests/test_dir/")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
|
|
||||||
assert!(output.contains(" └─┬ test_dir "));
|
assert!(output.contains(" └─┬ test_dir "));
|
||||||
assert!(output.contains(" └─┬ many "));
|
assert!(output.contains(" └─┬ many "));
|
||||||
assert!(output.contains(" ├── hello_file"));
|
assert!(output.contains(" ├── hello_file"));
|
||||||
@@ -51,7 +53,15 @@ pub fn test_reverse_flag() {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_d_flag_works() {
|
pub fn test_d_flag_works() {
|
||||||
// We should see the top level directory but not the sub dirs / files:
|
// We should see the top level directory but not the sub dirs / files:
|
||||||
let output = build_command(vec!["-d", "1", "tests/test_dir/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd
|
||||||
|
.arg("-d")
|
||||||
|
.arg("1")
|
||||||
|
.arg("-s")
|
||||||
|
.arg("tests/test_dir/")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
assert!(!output.contains("hello_file"));
|
assert!(!output.contains("hello_file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +69,31 @@ pub fn test_d_flag_works() {
|
|||||||
pub fn test_d_flag_works_and_still_recurses_down() {
|
pub fn test_d_flag_works_and_still_recurses_down() {
|
||||||
// We had a bug where running with '-d 1' would stop at the first directory and the code
|
// We had a bug where running with '-d 1' would stop at the first directory and the code
|
||||||
// would fail to recurse down
|
// would fail to recurse down
|
||||||
let output = build_command(vec!["-d", "1", "-f", "-c", "tests/test_dir2/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
assert!(output.contains("4 ┌─┴ test_dir2"));
|
let output = cmd
|
||||||
|
.arg("-d")
|
||||||
|
.arg("1")
|
||||||
|
.arg("-f")
|
||||||
|
.arg("-c")
|
||||||
|
.arg("tests/test_dir2/")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
|
assert!(output.contains("7 ┌─┴ test_dir2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check against directories and files whos names are substrings of each other
|
// Check against directories and files whos names are substrings of each other
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_ignore_dir() {
|
pub fn test_ignore_dir() {
|
||||||
let output = build_command(vec!["-c", "-X", "dir_substring", "tests/test_dir2/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd
|
||||||
|
.arg("-c")
|
||||||
|
.arg("-X")
|
||||||
|
.arg("dir_substring")
|
||||||
|
.arg("tests/test_dir2")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
assert!(!output.contains("dir_substring"));
|
assert!(!output.contains("dir_substring"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +108,25 @@ pub fn test_with_bad_param() {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_hidden_flag() {
|
pub fn test_hidden_flag() {
|
||||||
// Check we can see the hidden file normally
|
// Check we can see the hidden file normally
|
||||||
let output = build_command(vec!["-c", "tests/test_dir_hidden_entries/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd
|
||||||
|
.arg("-c")
|
||||||
|
.arg("tests/test_dir_hidden_entries")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
assert!(output.contains(".hidden_file"));
|
assert!(output.contains(".hidden_file"));
|
||||||
assert!(output.contains("┌─┴ test_dir_hidden_entries"));
|
assert!(output.contains("┌─┴ test_dir_hidden_entries"));
|
||||||
|
|
||||||
// Check that adding the '-h' flag causes us to not see hidden files
|
// Check that adding the '-h' flag causes us to not see hidden files
|
||||||
let output = build_command(vec!["-c", "-i", "tests/test_dir_hidden_entries/"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd
|
||||||
|
.arg("-c")
|
||||||
|
.arg("-i")
|
||||||
|
.arg("tests/test_dir_hidden_entries")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
assert!(!output.contains(".hidden_file"));
|
assert!(!output.contains(".hidden_file"));
|
||||||
assert!(output.contains("┌── test_dir_hidden_entries"));
|
assert!(output.contains("┌── test_dir_hidden_entries"));
|
||||||
}
|
}
|
||||||
@@ -94,64 +134,16 @@ pub fn test_hidden_flag() {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_number_of_files() {
|
pub fn test_number_of_files() {
|
||||||
// Check we can see the hidden file normally
|
// Check we can see the hidden file normally
|
||||||
let output = build_command(vec!["-c", "-f", "tests/test_dir"]);
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let output = cmd
|
||||||
|
.arg("-c")
|
||||||
|
.arg("-f")
|
||||||
|
.arg("tests/test_dir")
|
||||||
|
.unwrap()
|
||||||
|
.stdout;
|
||||||
|
let output = str::from_utf8(&output).unwrap();
|
||||||
assert!(output.contains("1 ┌── a_file "));
|
assert!(output.contains("1 ┌── a_file "));
|
||||||
assert!(output.contains("1 ├── hello_file"));
|
assert!(output.contains("1 ├── hello_file"));
|
||||||
assert!(output.contains("2 ┌─┴ many"));
|
assert!(output.contains("3 ┌─┴ many"));
|
||||||
assert!(output.contains("2 ┌─┴ test_dir"));
|
assert!(output.contains("4 ┌─┴ test_dir"));
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
|
||||||
#[test]
|
|
||||||
pub fn test_apparent_size() {
|
|
||||||
// Check the '-s' Flag gives us byte sizes and that it doesn't round up to a block
|
|
||||||
let command_args = vec!["-c", "-s", "/tmp/test_dir"];
|
|
||||||
let output = build_command(command_args);
|
|
||||||
|
|
||||||
let apparent_size1 = "6B ├── hello_file│";
|
|
||||||
let apparent_size2 = "0B ┌── a_file";
|
|
||||||
assert!(output.contains(apparent_size1));
|
|
||||||
assert!(output.contains(apparent_size2));
|
|
||||||
|
|
||||||
let incorrect_apparent_size = "4.0K ├── hello_file";
|
|
||||||
assert!(!output.contains(incorrect_apparent_size));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_show_files_by_type() {
|
|
||||||
// Check we can list files by type
|
|
||||||
let output = build_command(vec!["-c", "-t", "tests"]);
|
|
||||||
assert!(output.contains(" .unicode"));
|
|
||||||
assert!(output.contains(" .japan"));
|
|
||||||
assert!(output.contains(" .rs"));
|
|
||||||
assert!(output.contains(" (no extension)"));
|
|
||||||
assert!(output.contains("┌─┴ (total)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_show_files_by_regex() {
|
|
||||||
// Check we can see '.rs' files in the tests directory
|
|
||||||
let output = build_command(vec!["-c", "-e", "\\.rs$", "tests"]);
|
|
||||||
assert!(output.contains(" ┌─┴ tests"));
|
|
||||||
assert!(!output.contains("0B ┌── tests"));
|
|
||||||
assert!(!output.contains("0B ┌─┴ tests"));
|
|
||||||
|
|
||||||
// Check there are no files named: '.match_nothing' in the tests directory
|
|
||||||
let output = build_command(vec!["-c", "-e", "match_nothing$", "tests"]);
|
|
||||||
assert!(output.contains("0B ┌── tests"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn test_show_files_by_invert_regex() {
|
|
||||||
let output = build_command(vec!["-c", "-f", "-v", "e", "tests/test_dir2"]);
|
|
||||||
// There are 0 files without 'e' in the name
|
|
||||||
assert!(output.contains("0 ┌── test_dir2"));
|
|
||||||
|
|
||||||
let output = build_command(vec!["-c", "-f", "-v", "a", "tests/test_dir2"]);
|
|
||||||
// There are 2 files without 'a' in the name
|
|
||||||
assert!(output.contains("2 ┌─┴ test_dir2"));
|
|
||||||
|
|
||||||
// There are 4 files in the test_dir2 hierarchy
|
|
||||||
let output = build_command(vec!["-c", "-f", "-v", "match_nothing$", "tests/test_dir2"]);
|
|
||||||
assert!(output.contains("4 ┌─┴ test_dir2"));
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user