Commit Graph

72 Commits

Author SHA1 Message Date
andy.boot c8568e5674 Code cleanup from previous commit 2020-10-21 22:16:40 +01:00
Tyler Bailey 9d13994526 Cleanup (#121)
* remove unneeded identity .map()

* remove redunant field name in struct

* impl num_siblings for Node

* replace nested if w/ match in get_tree_chars

* remove unneeded field name in struct

* remove redundant println! & logic in display_node

* make get_children_from_node a Node method

* Revert "remove redundant println! & logic in display_node"

This reverts commit 40777025d5.
2020-10-21 22:01:18 +01:00
Ryan Winograd 53af0d486d Change behavior of depth flag
Change the depth flag so that it only changes the depth of displayed
subdirectories, not the depth of the directory size calculation (i.e.,
changing --depth does not change the displayed directory size, rather it
only changes how many levels of subdirectories are shown).
2020-09-03 21:47:52 +01:00
andy.boot 873456eb97 Add Hide hidden flag
From feature request to respect the .gitignore file. Decided to bundle in
respect for hidden files into the same feature [otherwise if you obey
the .gitignore file you still endup showing the .git directory]
2020-09-03 00:04:27 +01:00
andy.boot 4ea8d9339e Support listing directories by number of files
Based of https://github.com/bootandy/dust/pull/104

Idea is to allow users to find the number of files in each directory
instead of size.
2020-08-30 10:39:03 +01:00
andy.boot c0048b2ae4 Handle running with bad parameter
Earlier refactor caused running with: 'dust -' to crash
2020-03-28 15:59:07 +00:00
andy.boot 1953e107c2 Move everything to ignore instead of jwalk 2020-03-22 23:58:07 +00:00
Rasmus Halland efb455c739 Opening files on windows got a lot cheaper.
We avoid passing FILE_READ_DATA to CreateFile.
2020-03-01 14:41:21 +01:00
andy.boot 2c58041885 Clean up windows performance
Instead of generating random values for the drive and inode counter on
windows we return None instead
2020-03-01 14:41:21 +01:00
Rasmus Halland c30f31c22c Avoid opening all files for reading on windows
It can be very expensive to do that, especially when it causes windows defender to read the files and scan them.
2020-03-01 14:41:21 +01:00
Neel Chotai 58b395e7ee fix compiler warning 2020-03-01 00:49:10 +00:00
andy.boot 657858df16 Simplify inodes & devices by removing Option
This code now won't compile on none-(windows/unix family)
systems. [unix family includes mac]

Removing this method allows us to remove an Option and simplify the code
slightly
2020-02-09 14:33:46 +00:00
andy.boot be2250d241 Refactor: use if let instead of is_some 2020-02-09 14:10:53 +00:00
andy.boot b6aa1378de Fix bug for devices and apparent size
If apparent_size was set and ignore files on other devices was set then
the latter flat would not work.

Fix this bug
2020-02-09 13:57:08 +00:00
andy.boot 2082141dfc Add tests for should_ignore_file function
function currently has a bug that is highlighted by second test
2020-02-09 13:57:08 +00:00
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