Commit graph

578 commits

Author SHA1 Message Date
Yorhel
59ef5fd27b Improved error reporting + minor cleanup 2021-05-29 19:22:00 +02:00
Yorhel
2390308883 Handle allocation failures
In a similar way to the C version of ncdu: by wrapping malloc(). It's
simpler to handle allocation failures at the source to allow for easy
retries, pushing the retries up the stack will complicate code somewhat
more. Likewise, this is a best-effort approach to handling OOM,
allocation failures in ncurses aren't handled and display glitches may
occur when we get an OOM inside a drawing function.

This is a somewhat un-Zig-like way of handling errors and adds
scary-looking 'catch unreachable's all over the code, but that's okay.
2021-05-29 13:18:23 +02:00
Yorhel
c077c5bed5 Implement JSON file import
Performance is looking great, but the code is rather ugly and
potentially buggy. Also doesn't handle hard links without an "nlink"
field yet.

Error handling of the import code is different from what I've been doing
until now. That's intentional, I'll change error handling of other
pieces to call ui.die() directly rather than propagating error enums.
The approach is less testable but conceptually simpler, it's perfectly
fine for a tiny application like ncdu.
2021-05-29 10:54:45 +02:00
Yorhel
9474aa4329 Only keep total_items + Zig test update + pointless churn 2021-05-24 11:02:26 +02:00
Yorhel
7b3ebf9241 Implement all existing browsing display options + some fixes
I plan to add more display options, but ran out of keys to bind.
Probably going for a quick-select menu thingy so that we can keep the
old key bindings for people accustomed to it.

The graph width algorithm is slightly different, but I think this one's
a minor improvement.
2021-05-23 17:34:40 +02:00
Yorhel
231ab1037d Implement export to file
The exported file format is fully compatible with ncdu 1.x, but has a
few minor differences. I've backported these changes in
ca51d4ed1a
2021-05-12 11:32:52 +02:00
Yorhel
4cc422d628 Implement confirm quit
(+ 2 minor crash fixes due to out-of-bounds cursor_idx)
2021-05-11 13:16:47 +02:00
Yorhel
b0e81ea4e9 Implement scanning UI (-0,-1,-2) 2021-05-09 20:59:09 +02:00
Yorhel
9b59d3dac4 README updates 2021-05-08 16:17:51 +02:00
Yorhel
e12eb4556d UI: Implement dir navigation & remember view of past dirs
Now we're getting somewhere. This works surprisingly well, too. Existing
ncdu behavior is to remember which entry was previously selected but not
which entry was displayed at the top, so the view would be slightly
different when switching directories. This new approach remembers both
the entry and the offset.
2021-05-07 17:16:39 +02:00
Yorhel
d1eb7ba007 Initial keyboard input handling + item&sort selection 2021-05-07 12:01:00 +02:00
Yorhel
27cb599e22 More UI stuff + shave off 16 bytes from model.Dir
I initially wanted to keep a directory's block count and size as a
separate field so that exporting an in-memory tree to a JSON dump would
be easier to do, but that doesn't seem like a common operation to
optimize for. We'll probably need the algorithms to subtract sub-items
from directory counts anyway, so such an export can still be
implemented, albeit slower.
2021-05-06 19:20:55 +02:00
Yorhel
a54c10bffb More UI stuff: nice string handling/shortening + Zig bug workaround
libc locale-dependent APIs are pure madness, but I can't avoid them as
long as I use ncurses. libtickit seems like a much saner alternative (at
first glance), but no popular application seems to use it. :(
2021-05-05 08:03:27 +02:00
Yorhel
a28a0788c3 Implement --exclude-kernfs and --exclude-pattern
Eaiser to implement now that we're linking against libc.

But exclude pattern matching is extremely slow, so that should really be
rewritten with a custom fnmatch implementation. It's exactly as slow as
in ncdu 1.x as well, I'm surprised nobody's complained about it yet.
And while I'm at it, supporting .gitignore-style patterns would be
pretty neat, too.
2021-05-03 14:41:50 +02:00
Yorhel
826c2fc067 Link to ncurses + some rudimentary TUI frameworky stuff
I tried playing with zbox (pure Zig termbox-like lib) for a bit, but I
don't think I want to have to deal with the terminal support issues that
will inevitably come with it. I already stumbled upon one myself: it
doesn't properly put the terminal in a sensible state after cleanup in
tmux. As much as I dislike ncurses, it /is/ ubiquitous and tends to kind
of work.
2021-05-03 08:01:18 +02:00
Yorhel
3e27d37012 Correct int truncating/saturating + avoid one toPosixPath() 2021-05-01 11:10:24 +02:00
Yorhel
097f49d9e6 Fix some scanning bugs + support --exclude-caches and --follow-symlinks
Supporting kernfs checking is going to be a bit more annoying.
And so is exclude patterns. Ugh.
2021-04-30 19:15:29 +02:00
Yorhel
e2805da076 Add CLI argument parsing 2021-04-29 18:59:25 +02:00
Yorhel
0783d35793 WIP: Experimenting with a rewrite to Zig & a new data model
The new data model is supposed to solve a few problems with ncdu 1.x's
'struct dir':
- Reduce memory overhead,
- Fix extremely slow counting of hard links in some scenarios
  (issue #121)
- Add support for counting 'shared' data with other directories
  (issue #36)

Quick memory usage comparison of my root directory with ~3.5 million
files (normal / extended mode):

  ncdu 1.15.1:     379M / 451M
  new (unaligned): 145M / 178M
  new (aligned):   155M / 200M

There's still a /lot/ of to-do's left before this is usable, however,
and there's a bunch of issues I haven't really decided on yet, such as
which TUI library to use.

Backporting this data model to the C version of ncdu is also possible,
but somewhat painful. Let's first see how far I get with Zig.
2021-04-29 12:48:52 +02:00
Yorhel
9337cdc99e Test for read error while reading the --exclude-from file
Fixes #171
2021-03-04 16:07:48 +01:00
Christian Göttsche
a216bc2d35 Scale size bar with max column size
Use 'max(10, column_size / 7)' instead of a fixed size of 10
2020-07-12 18:30:02 +02:00
Yorhel
1035aed81a Version bump for 1.15.1 2020-06-10 12:24:34 +02:00
Yorhel
a389443c9a Add --exclude-firmlinks and follow firmlinks by default
What a mess.

https://code.blicky.net/yorhel/ncdu/issues/153#issuecomment-764
2020-06-07 10:03:11 +02:00
Christian Göttsche
c340980b80 is_kernfs: Check only defined magic numbers
Avoid undeclared identifiers when compiling with older kernel headers.
2020-06-05 18:04:11 +02:00
Christian Göttsche
19cfe9b15c Correct misspellings 2020-05-30 19:26:00 +02:00
Yorhel
239bbf542f Version bump for 1.15 2020-05-30 10:02:02 +02:00
Yorhel
d018dc0be6 dir_import.c: Remove already-implemented TODO comment 2020-05-15 09:09:35 +02:00
Yorhel
1c4d191193 help.c: Mention "F" flag + make the flag list scrollable 2020-05-15 09:02:16 +02:00
Yorhel
bff5da3547 man page: Mention --follow-firmlinks 2020-05-15 08:51:08 +02:00
Yorhel
08564ec7b6 dir_scan.c: Call statfs() with relative path
So we get around the PATH_MAX limitation. Also a tiny bit more
efficient, I hope.
2020-05-15 08:43:45 +02:00
Saagar Jha
c9ce16a633 Support excluding firmlinks on macOS 2020-05-13 11:29:55 -07:00
Saagar Jha
684e9e04ad Typo: exlude → exclude 2020-05-07 16:10:07 -07:00
Yorhel
9a3727759c Fix calculating of directory apparent sizes with hard links
Silly one-character typo that causes directory apparent sizes to be very
off in some scenarios.

Reported & patched by Andrew Neitsch.
2020-05-06 07:04:36 +02:00
Yorhel
4a2def5223 dir_scan.c: Fix integer overflow when list of file names in dir exceeds 2GiB
Fixes #150
2020-04-21 14:13:51 +02:00
Yorhel
1563e56223 help.c: Mention new ^ file flag 2020-04-08 18:35:01 +02:00
Christian Göttsche
c209b012b1 Add option --exclude-kernfs to skip scanning Linux pseudo filesystems
(cherry picked from commit a076ac714a)
2020-04-08 18:32:11 +02:00
Christian Göttsche
50b48a6435 Mention supported color schemes in help text 2020-04-08 17:17:06 +02:00
Christian Göttsche
e3742f0c80 Remove redundant cast to the same type
(cherry picked from commit ef7b4e5c28)
2020-04-08 11:00:41 +02:00
Christian Göttsche
3959210051 Drop never read initialization
(cherry picked from commit 9f28920a64)
2020-04-08 10:59:25 +02:00
Christian Göttsche
84834ff370 Declare file local variables static
(cherry picked from commit ad5b7fce74)
2020-04-08 10:58:53 +02:00
Christian Göttsche
53e5080d9a Avoid using extension of variable length array folded to constant array
(cherry picked from commit 2faefc3b24)
2020-04-08 10:57:23 +02:00
Christian Göttsche
61d268764d Drop extra ';' outside of a function
(cherry picked from commit 32b77d0064)
2020-04-08 10:55:57 +02:00
Christian Göttsche
2bd83b3f22 Avoid using GNU empty initializer extension
(cherry picked from commit ce7036d249)
2020-04-08 10:55:36 +02:00
Christian Göttsche
70f439d9a9 Enforce const correctness on strings
(cherry picked from commit 9801f46ece)
2020-04-08 10:53:21 +02:00
Christian Göttsche
39709aa665 Use strict prototypes
(cherry picked from commit e4e8ebd9e0)
2020-04-08 10:52:25 +02:00
Christian Göttsche
bd22bf42ee Update configure.ac
* Use AS_HELP_STRING instead of deprecated AC_HELP_STRING
* Use AC_OUTPUT without arguments
* Enclose AC_INIT argument in brackets
* Add automake option std-options

(cherry picked from commit 53a33e1db2)
2020-04-08 10:48:14 +02:00
Christian Göttsche
227cdb35ae Ignore generated script compile in git
(cherry picked from commit fd75bd0c22)
2020-04-08 10:45:24 +02:00
Christian Göttsche
2fd4d8b406 Remove trailing whitespaces 2020-04-07 21:49:14 +02:00
Yorhel
888bd663c6 Also quit on EIO from getch()
Fixes #141
2020-04-01 16:54:57 +02:00
Yorhel
8d58297328 Year + version bump for 1.14.2 2020-02-10 16:02:26 +01:00