Commit graph

555 commits

Author SHA1 Message Date
Yorhel
1de70064e7 Version 2.0-beta2 + more convenient static binary generation 2021-07-31 07:14:04 +02:00
Yorhel
5929bf57cc Keep track of uncounted hard links to speed up refresh+delete operations 2021-07-28 20:12:50 +02:00
Yorhel
ba14c0938f Fix Dir.fmtPath() when given the root dir 2021-07-28 20:09:48 +02:00
Yorhel
3acab71fce Fix reporting of fatal scan error in -0 or -1 UIs 2021-07-28 11:13:03 +02:00
Yorhel
0d314ca0ca Implement a more efficient hard link counting approach
As aluded to in the previous commit. This approach keeps track of hard
links information much the same way as ncdu 1.16, with the main
difference being that the actual /counting/ of hard link sizes is
deferred until the scan is complete, thus allowing the use of a more
efficient algorithm and amortizing the counting costs.

As an additional benefit, the links listing in the information window
now doesn't need a full scan through the in-memory tree anymore.

A few memory usage benchmarks:

              1.16  2.0-beta1  this commit
root:          429        162          164
backup:       3969       1686         1601
many links:    155        194          106
many links2*:  155        602          106

(I'm surprised my backup dir had enough hard links for this to be an
improvement)
(* this is the same as the "many links" benchmarks, but with a few
parent directories added to increase the tree depth. 2.0-beta1 doesn't
like that at all)

Performance-wise, refresh and delete operations can still be improved a
bit.
2021-07-28 10:35:56 +02:00
Yorhel
36bc405a69 Add parent node pointers to Dir struct + remove Parents abstraction
While this simplifies the code a bit, it's a regression in the sense
that it increases memory use.

This commit is yak shaving for another hard link counting approach I'd
like to try out, which should be a *LOT* less memory hungry compared to
the current approach. Even though it does, indeed, add an extra cost of
these parent node pointers.
2021-07-26 14:03:10 +02:00
Yorhel
b94db184f4 ChangeLog, too 2021-07-23 06:38:50 +02:00
Yorhel
7055903677 Fix README Zig version oopsie 2021-07-23 06:28:56 +02:00
Yorhel
e72768b86b Tagging this as a 2.0-beta1 release 2021-07-22 16:29:55 +02:00
Yorhel
a915fc0836 Fix counting of sizes for new directories 2021-07-19 16:58:34 +02:00
Yorhel
f473f3605e Fix building of static binaries
It's a bit ugly, but appears to work. I've not tested the 32bit arm
version, but the others run.

The static binaries are about twice as large as the ncdu 1.x
counterparts.
2021-07-19 16:44:53 +02:00
Yorhel
b96587c25f scan: Don't allocate directory iterator on the stack
I had planned to checkout out async functions here so I could avoid
recursing onto the stack alltogether, but it's still unclear to me how
to safely call into libc from async functions so let's wait for all that
to get fleshed out a bit more.
2021-07-18 16:43:02 +02:00
Yorhel
6f07a36923 Implement help window
The rewrite is now on feature-parity with ncdu 1.x. What remains is
bugfixing and polishing.
2021-07-18 16:39:19 +02:00
Yorhel
c8636b8982 Add REUSE-compliant copyright headers 2021-07-18 11:50:50 +02:00
Yorhel
ee92f403ef Add Makefile with some standard/handy tools
+ a failed initial attempt at producing static binaries.
2021-07-18 09:40:59 +02:00
Yorhel
e9c8d12c0f Store Ext before Entry
Which is slightly simpler and should provide a minor performance
improvement.
2021-07-16 19:13:04 +02:00
Yorhel
5a196125dc Use @errorName() fallback in ui.errorString()
Sticking to "compiletime-known" error types will essentially just bring
in *every* possible error anyway, so might as well take advantage of
@errorName.
2021-07-16 18:35:21 +02:00
Yorhel
3a21dea2cd Implement file deletion + a bunch of bug fixes 2021-07-16 16:18:13 +02:00
Yorhel
448fa9e7a6 Implement shell spawning 2021-07-14 11:24:19 +02:00
Yorhel
6c2ab5001c Implement directory refresh
This complicated the scan code more than I had anticipated and has a
few inherent bugs with respect to calculating shared hardlink sizes.

Still, the merge approach avoids creating a full copy of the subtree, so
that's another memory usage related win compared to the C version.
On the other hand, it does leak memory if nodes can't be reused.

Not quite as well tested as I should have, so I'm sure there's bugs.
2021-07-13 13:45:08 +02:00
Yorhel
ff3e3bccc6 Add link path listing to information window
Two differences compared to the C version:
- You can now select individual paths in the listing, pressing enter
  will open the selected path in the browser window.
- Creating this listing is much slower and requires, in the worst case,
  a full traversal through the in-memory tree. I've tested this without
  the same-dev and shared-parent optimizations (i.e. worst case) on an
  import with 30M files and performance was still quite acceptable - the
  listing completed in a second - so I didn't bother adding a loading
  indicator. On slower systems and even larger trees this may be a
  little annoying, though.

(also, calling nonl() apparently breaks detection of the return key,
neither \n nor KEY_ENTER are emitted for some reason)
2021-07-06 18:33:31 +02:00
Yorhel
618972b82b Add item info window
Doesn't display the item's path anymore (seems rather redundant) but
adds a few more other fields.
2021-06-11 13:12:00 +02:00
Yorhel
d910ed8b9f Add workaround for Zig bug on FreeBSD
The good news is: apart from this little thing, everything seems to just
work(tm) on FreeBSD. Think I had more trouble with C because of minor
header file differences.
2021-06-07 11:21:55 +02:00
Yorhel
40f9dff5d6 Update for Zig 0.8 HashMap changes
I had used them as a HashSet with mutable keys already in order to avoid
padding problems. This is not always necessary anymore now that Zig's
new HashMap uses separate arrays for keys and values, but I still need
the HashSet trick for the link_count nodes table, as the key itself
would otherwise have padding.
2021-06-07 10:57:30 +02:00
Yorhel
cc1966d6a9 Make some space for shared size in UI + speed up JSON import a bit
It still feels kind of sluggish, but not entirely sure how to improve
it.
2021-06-01 16:14:01 +02:00
Yorhel
e6b2cff356 Support hard link counts when importing old ncdu dumps
Under the assumption that there are no external references to files
mentioned in the dump, i.e. a file's nlink count matches the number of
times the file occurs in the dump.

This machinery could also be used for regular scans, when you want to
scan an individual directory without caring about external hard links.
Maybe that should be the default, even? Not sure...
2021-06-01 13:00:58 +02:00
Yorhel
5264be76c7 UI: Display shared/unique sizes + hide some columns when no space 2021-05-30 17:02:57 +02:00
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