Commit Graph

57 Commits

Author SHA1 Message Date
andy.boot 8a9b5e889d Refactor path depth calculation
Factor out duplicate code,
Add comment explaining why filter is necessary (thanks to rivy)
2020-02-09 13:57:08 +00:00
Roy Ivy III a3d8fc00e1 Refactor ~ use AsRef<Path> where possible 2020-02-03 16:56:50 -06:00
Roy Ivy III 9d4531d48b Refactor ~ use PathBuf instead of String 2020-02-03 16:56:47 -06:00
Roy Ivy III 36ebb1b2b0 refactor ~ strip_trailing_curdirs() -> normalize_path() (a more accurate descriptor) 2020-01-29 18:36:13 -06:00
Roy Ivy III e126a01096 Tests ~ improve portability of tests for 'Fix ~ improve portability of path manipulation' 2020-01-29 18:36:13 -06:00
Roy Ivy III 7a38a26593 Fix ~ (WinAPI) must use Handle::from_path_any() if target path might be a directory
.# [why]

"If you use `from_path()` on a directory, then subsequent queries using that handle will fail."
Instead, use `from_path_any()` which supports opening files or directories.

ref: "Struct winapi_util::Handle" from <https://docs.rs/crate/winapi-util>
2020-01-29 18:36:13 -06:00
Roy Ivy III 26ef8c3e59 Tests ~ add test case to 'Fix ~ improve portability of path manipulation' 2020-01-29 18:36:13 -06:00
Roy Ivy III 7c34389aea Fix ~ improve portability of path manipulation 2020-01-29 18:36:12 -06:00
andy boot 0bf8c914b7 Merge pull request #59 from Celti/exclude-multiple
Allow multiple --ignore-directory flags
2020-01-21 23:32:49 +00:00
Celti Burroughs 95888d5f31 Allow multiple --ignore-directory flags 2020-01-21 15:40:04 -07:00
Adam Lesperance 0c7b05fec9 Fix get_metadata on windows
The MetadataExt functions are nightly-only right now so we need to call
the windows api ourselves to get the device number.  The winapi_util
package has a nice wrapper to do this for us.

The get_device function doesn't appear to be used anywhere so I removed
it.
2020-01-21 00:06:41 -06:00
andy.boot 842a8ec673 Clean up clippy warnings 2020-01-19 09:32:35 +00:00
andy.boot d97edba041 Add option to ignore directories
https://github.com/bootandy/dust/issues/46

Add -X flag used to ignore any file or directory that matches the
provided substring.
This means that -X e will ignore any file or directory with an 'e' in
it.
2020-01-19 09:23:13 +00:00
andy.boot b9c27f9838 get_filesystem returns Result instead of option
Removes unwrap and returns a Result instead of panicing if an invalid
path is given.
Previously if the flag: '-x' was provided with an argument of an
invalid directory the code would crash here
2020-01-16 23:50:56 +00:00
andy.boot 5541df6a73 Refactor code
Reduce complexity of examine_dir.

No logic changes
2020-01-15 20:10:33 +00:00
andy.boot bdc3d404ef Support excluding filesystems with -x
https://github.com/bootandy/dust/issues/50

Add optional -x flag to limit search to the current filesystem.

Add (untested) support for windows for the equivalent of inode and
device.
2020-01-15 19:51:16 +00:00
Adam Lesperance 38938e005e Fix colors on windows
* Initialize ansi_term if we're on windows
* Silence build warning on non-unix targets
* Update ansi-term which has windows specific fixes (and assert_cli while I'm at it)
2019-12-30 21:36:49 +00:00
andy.boot 356d14ac0f Hack fix around JWalk behaviour.
Jwalk returns '/' as a child of the current node which breaks things.
https://github.com/jessegrosjean/jwalk/issues/13
2019-12-23 15:51:12 +00:00
andy.boot 311bc45388 Verify that '/' is parent of everything
Bug could occur when run with '/' as it wasn't considered the parent of
'/usr' due to having the same number of '/'s in the name
2019-12-23 15:50:01 +00:00
andy.boot 5535478fe8 Fix substring bug
When one directory was a substring of another the directory would appear
as a subdirectory instead of a sibling

Fixed originally by this: 6e03dd77e6
Broken by this: db6c8a019d

Added integration test as this has bitten me before
2019-12-05 21:35:15 +00:00
andy.boot 7ba91a4a22 Rename variable
cpu -> threads. threads more accurately represents the number of threads
we will start to run
2019-12-04 20:49:45 +00:00
Xavier L'Heureux b66523cff3 Apply clippy lints 2019-12-03 18:34:47 -05:00
Xavier L'Heureux 19a41aa382 Add CLI option for the number of threads to spawn 2019-12-03 18:27:02 -05:00
Xavier L'Heureux 62ac9b623a Make sure to count the hidden directories 2019-11-26 08:31:52 -05:00
Xavier L'Heureux f8ce6c97bf Use more rusty patterns and preallocate enough space 2019-11-26 08:31:52 -05:00
Xavier L'Heureux 86b3cccaf6 perf(IO): use parallel walkdir (jwalk) for super faster traversal 2019-11-26 08:31:52 -05:00
andy.boot 4cffc4370b Bring back the reverse flag
Following the large refactor on the previous commit, this commit fixes
the reverse functionality.

Depth detection moved into the tree building instead of being calculated
when drawing the tree to screen
2019-10-06 22:00:40 +01:00
andy.boot db6c8a019d Massive refactor
WIP

Replace array of (string, int) pairs with tree of nodes.

A tree of nodes more accurately represents the underlying file structure
and hence is a better fit for the problem space.

Regression: Reverse doesn't work in this commit.

I suspect more methods can be simplifed and reduced.
2019-10-05 17:57:47 +01:00
andy.boot 1d9a56e025 A way of supporting reverse 2019-10-02 22:31:49 +01:00
andy.boot ec2d9e19d4 Run format, introduce new function.
strip_end_slash_including_root will remove end slashes including the
root directory.

The root directory has been a long running problem because if we strip
the final slash we will run dust on no directory instead of the root.
2019-10-02 20:14:13 +01:00
Bob d46b63fad8 Add detection of files which fail permission
Old code caught some file permission denied but not all.
2019-10-01 22:44:17 +01:00
Bob 872a49bb7d better var name 2019-10-01 22:35:29 +01:00
Bob 2f7a88e8dc Fix issues from running on root directory
clean up: 80338f4

Fixes -d flag to work again. Add test to stop regression
2019-10-01 22:18:16 +01:00
bootandy 80338f4731 Fix running on root dir /
Fixes: https://github.com/bootandy/dust/issues/22

Allows code to run on the root directory
2019-07-04 00:03:33 +01:00
bootandy d327bd2e68 Fix code to handle single dots in path
Before this fix adding a single dot to the end of a path would cause the
code to crash.
2019-07-02 00:56:43 +01:00
bootandy 7db6cf2f32 Add test to handle single dot in path 2019-07-02 00:54:58 +01:00
bootandy 76d0762c97 Add assert to stop infinite loops 2019-07-01 22:43:10 +01:00
bootandy 876609f2cb Obey new clippy
Clippy is like having a reviewer fix your dodgy code.
2019-07-01 22:25:06 +01:00
andy.boot b1b933d851 Refactor & Optimize use of depth
Code Refactored

Using Depth now prunes the tree below the displayable depth so display
calls finish quicker.
2018-05-10 17:36:56 +01:00
andy.boot 51561994c5 Break up display_node function slightly
Also: run rustformat
2018-05-09 11:28:23 +01:00
andy.boot dd75ec4aa7 wip: code to remove duplicate arguments
Also handle case where an argument is a substring of another argument
2018-05-09 10:35:30 +01:00
bootandy 3e9f09e339 Remove unnecessary path & pathbuf code 2018-05-02 00:42:03 +01:00
bootandy 2556885622 Rust format 2018-05-02 00:39:57 +01:00
bootandy 39db8b86fd Replace simple match with map_or 2018-05-01 14:38:34 +01:00
bootandy c5830c5d00 Stop using target_os just use target_family
target_family unix covers linux and mac and wraps up the call for inodes
in a common interface.
2018-05-01 13:59:48 +01:00
andy.boot 4ac85d7dc9 Simplify tests
dust sort is now more predictable as it orders first by size and second
by name.

Walkdir still gives different iteration orders on different systems so
all output is not entirely predictable
2018-04-27 11:35:47 +01:00
andy.boot e6c777fb8b Add support for -d depth flag
Following a user request the option '-d N' allows a user to output N
levels of sub directories.

Fixed bug: so that trailing slashes are now removed.
2018-04-27 10:01:41 +01:00
andy.boot 24c97ef92f Rewrite to use walkdir instead of recursion
Advised to use walkdir by burntsushi as using recursion on file systems
can blow the stack.

walkdir is slower but allows the code to be cleaner and more reliable

Also experimented with ignore but locking the hashmap resulted in
similar performance to walkdir but with much uglier code.
2018-04-24 14:53:47 +01:00
andy.boot 0c5b08e1d2 Change package name to du-dust
The binary is still called dust. Sadly dust was taken on crates.io.
This change should allow us to send this crate to crates.io
2018-04-18 13:40:52 +01:00
bootandy 74b9178017 Refactor code 2018-04-07 17:14:06 +01:00