Skip to content

Commit ff9f0e4

Browse files
feat: sync with upstream to 2.6
1 parent 5903957 commit ff9f0e4

20 files changed

+3739
-1404
lines changed

ChangeLog

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
# SPDX-FileCopyrightText: Yorhel <[email protected]>
22
# SPDX-License-Identifier: MIT
33

4+
2.6 - 2024-09-27
5+
- Still requires Zig 0.12 or 0.13
6+
- Add dependency on libzstd
7+
- Add new export format to support threaded export and low-memory browsing
8+
- Add `-O` and `--compress-level` CLI flags
9+
- Add progress indicator to hardlink counting stage
10+
- Fix displaying and exporting zero values when extended info is not available
11+
- Fix clearing screen in some error cases
12+
- Fix uncommon edge case in hardlink counting on refresh
13+
- Use integer math instead of floating point to format numbers
14+
15+
2.5 - 2024-07-24
16+
- Still requires Zig 0.12 or 0.13
17+
- Add parallel scanning with `-t,--threads` CLI flags
18+
- Improve JSON export and import performance
19+
- `--exclude-kernfs` is no longer checked on the top-level scan path
20+
- Fix entries sometimes not showing up after refresh
21+
- Fix file descriptor leak with `--exclude-caches` checking
22+
- Fix possible crash on invalid UTF8 when scanning in `-1` UI mode
23+
- Fix JSON export and import of the "other filesystem" flag
24+
- Fix JSON import containing directories with a read error
25+
- Fix mtime display of 'special' files
26+
- Fix edge case bad performance when deleting hardlinks with many links
27+
- Increased memory use for hardlinks (by ~10% in extreme cases, sorry)
28+
429
2.4 - 2024-04-21
530
- Now requires Zig 0.12
631
- Revert default color scheme back to 'off'

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ZIG ?= zig
99
PREFIX ?= /usr/local
1010
BINDIR ?= ${PREFIX}/bin
1111
MANDIR ?= ${PREFIX}/share/man/man1
12-
ZIG_FLAGS ?= --release
12+
ZIG_FLAGS ?= --release=fast
1313

1414
NCDU_VERSION=$(shell grep 'program_version = "' src/main.zig | sed -e 's/^.*"\(.\+\)".*$$/\1/')
1515

@@ -52,9 +52,21 @@ dist:
5252
rm -rf ncdu-${NCDU_VERSION}
5353

5454

55-
# ASSUMPTION: the ncurses source tree has been extracted into ncurses/
55+
# ASSUMPTION:
56+
# - the ncurses source tree has been extracted into ncurses/
57+
# - the zstd source tree has been extracted into zstd/
58+
# Would be nicer to do all this with the Zig build system, but no way am I
59+
# going to write build.zig's for these projects.
5660
static-%.tar.gz:
5761
mkdir -p static-$*/nc static-$*/inst/pkg
62+
cp -R zstd/lib static-$*/zstd
63+
make -C static-$*/zstd -j8 libzstd.a V=1\
64+
ZSTD_LIB_DICTBUILDER=0\
65+
ZSTD_LIB_MINIFY=1\
66+
ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP=1\
67+
CC="${ZIG} cc --target=$*"\
68+
LD="${ZIG} cc --target=$*"\
69+
AR="${ZIG} ar" RANLIB="${ZIG} ranlib"
5870
cd static-$*/nc && ../../ncurses/configure --prefix="`pwd`/../inst"\
5971
--with-pkg-config-libdir="`pwd`/../inst/pkg"\
6072
--without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs\
@@ -71,8 +83,9 @@ static-%.tar.gz:
7183
@# --build-file ../build.zig --search-prefix inst/ --cache-dir zig -Drelease-fast=true
7284
@# Alternative approach, bypassing zig-build
7385
cd static-$* && ${ZIG} build-exe -target $*\
74-
-Iinst/include -Iinst/include/ncursesw -lc inst/lib/libncursesw.a\
86+
-Iinst/include -Iinst/include/ncursesw -Izstd -lc inst/lib/libncursesw.a zstd/libzstd.a\
7587
--cache-dir zig-cache -static -fstrip -O ReleaseFast ../src/main.zig
88+
strip -R .eh_frame -R .eh_frame_hdr static-$*/main
7689
cd static-$* && mv main ncdu && tar -czf ../static-$*.tar.gz ncdu
7790
rm -rf static-$*
7891

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ C version (1.x).
2020

2121
## Requirements
2222

23-
- Zig 0.12.0
23+
- Zig 0.12 or 0.13.
2424
- Some sort of POSIX-like OS
25-
- ncurses libraries and header files
25+
- ncurses
26+
- libzstd
2627

2728
## Install
2829

build.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const std = @import("std");
55

66
pub fn build(b: *std.Build) void {
77
const target = b.standardTargetOptions(.{});
8-
const optimize = b.standardOptimizeOption(.{
9-
.preferred_optimize_mode = .ReleaseFast,
10-
});
8+
const optimize = b.standardOptimizeOption(.{});
119

1210
const pie = b.option(bool, "pie", "Build with PIE support (by default false)") orelse false;
1311

@@ -21,6 +19,7 @@ pub fn build(b: *std.Build) void {
2119

2220
exe.pie = pie;
2321
exe.root_module.linkSystemLibrary("ncursesw", .{});
22+
exe.root_module.linkSystemLibrary("libzstd", .{});
2423
// https://github.com/ziglang/zig/blob/b52be973dfb7d1408218b8e75800a2da3dc69108/build.zig#L551-L554
2524
if (target.result.isDarwin()) {
2625
// useful for package maintainers

ncdu.1

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
.\" SPDX-FileCopyrightText: Yorhel <[email protected]>
22
.\" SPDX-License-Identifier: MIT
3-
.Dd April 20, 2024
3+
.Dd September 27, 2024
44
.Dt NCDU 1
55
.Os
66
.Sh NAME
77
.Nm ncdu
88
.Nd NCurses Disk Usage
9+
.
910
.Sh SYNOPSIS
1011
.Nm
1112
.Op Fl f Ar file
1213
.Op Fl o Ar file
14+
.Op Fl O Ar file
1315
.Op Fl e , \-extended , \-no\-extended
1416
.Op Fl \-ignore\-config
1517
.Op Fl x , \-one\-file\-system , \-cross\-file\-system
@@ -18,6 +20,8 @@
1820
.Op Fl \-include\-caches , \-exclude\-caches
1921
.Op Fl L , \-follow\-symlinks , \-no\-follow\-symlinks
2022
.Op Fl \-include\-kernfs , \-exclude\-kernfs
23+
.Op Fl t , \-threads Ar num
24+
.Op Fl \-compress\-level Ar num
2125
.Op Fl 0 , 1 , 2
2226
.Op Fl q , \-slow\-ui\-updates , \-fast\-ui\-updates
2327
.Op Fl \-enable\-shell , \-disable\-shell
@@ -44,11 +48,13 @@
4448
.Op Fl h , \-help
4549
.Nm
4650
.Op Fl v , V , \-version
51+
.
4752
.Sh DESCRIPTION
4853
.Nm
4954
(NCurses Disk Usage) is an interactive curses-based version of the well-known
5055
.Xr du 1 ,
5156
and provides a fast way to see what directories are using your disk space.
57+
.
5258
.Sh OPTIONS
5359
.Ss Mode Selection
5460
.Bl -tag -width Ds
@@ -59,10 +65,13 @@ Print version and quit.
5965
.It Fl f Ar file
6066
Load the given file, which has earlier been created with the
6167
.Fl o
68+
or
69+
.Fl O
6270
flag.
6371
If
6472
.Ar file
6573
is equivalent to '\-', the file is read from standard input.
74+
Reading from standard input is only supported for the JSON format.
6675
.Pp
6776
For the sake of preventing a screw-up, the current version of
6877
.Nm
@@ -73,7 +82,7 @@ will be disabled.
7382
.It Ar dir
7483
Scan the given directory.
7584
.It Fl o Ar file
76-
Export all necessary information to
85+
Export the directory tree in JSON format to
7786
.Ar file
7887
instead of opening the browser interface.
7988
If
@@ -87,6 +96,22 @@ directory with many files.
8796
uncompressed, or a little over 100 KiB when compressed with gzip.
8897
This scales linearly, so be prepared to handle a few tens of megabytes when
8998
dealing with millions of files.
99+
.Pp
100+
When running a multi-threaded scan or when scanning a directory tree that may
101+
not fit in memory, consider using
102+
.Fl O
103+
instead.
104+
.It Fl O Ar file
105+
Export the directory tree in binary format to
106+
.Ar file
107+
instead of opening the browser interface.
108+
If
109+
.Ar file
110+
is '\-', the data is written to standard output.
111+
The binary format has built-in compression, supports low-memory multi-threaded
112+
export (in combination with
113+
.Fl t )
114+
and can be browsed without importing the entire directory tree into memory.
90115
.It Fl e , \-extended , \-no\-extended
91116
Enable/disable extended information mode.
92117
This will, in addition to the usual file information, also read the ownership,
@@ -105,6 +130,7 @@ using 'm' and 'M', respectively.
105130
.It Fl \-ignore\-config
106131
Do not attempt to load any configuration files.
107132
.El
133+
.
108134
.Ss Scan Options
109135
These options affect the scanning progress, they have no effect when importing
110136
directory information from a file.
@@ -147,7 +173,28 @@ The exact counting behavior of this flag is subject to change in the future.
147173
.Pp
148174
The complete list of currently known pseudo filesystems is: binfmt, bpf, cgroup,
149175
cgroup2, debug, devpts, proc, pstore, security, selinux, sys, trace.
176+
.It Fl t , \-threads Ar num
177+
Number of threads to use when scanning the filesystem, defaults to 1.
178+
.Pp
179+
In single-threaded mode, the JSON export (see
180+
.Fl o )
181+
can operate with very little memory, but in multi-threaded mode the entire
182+
directory tree is first constructed in memory and written out after the
183+
filesystem scan has completed,
184+
This causes a delay in output and requires significantly more memory for large
185+
directory trees.
186+
The binary format (see
187+
.Fl O )
188+
does not have this problem and supports efficient exporting with any number of
189+
threads.
190+
.It Fl \-compress\-level Ar num
191+
Set the Zstandard compression level when using
192+
.Fl O
193+
to create a binary export.
194+
Valid values are 1 (fastest) to 19 (slowest).
195+
Defaults to 4.
150196
.El
197+
.
151198
.Ss Interface Options
152199
.Bl -tag -width Ds
153200
.It Fl 0
@@ -159,9 +206,8 @@ When exporting the data with
159206
ncurses will not be initialized at all.
160207
This option is the default when exporting to standard output.
161208
.It Fl 1
162-
Similar to
163-
.Fl 0 ,
164-
but does give feedback on the scanning progress with a single line of output.
209+
Write progress information to the terminal, but don't open a full-screen
210+
ncurses interface.
165211
This option is the default when exporting to a file.
166212
.Pp
167213
In some cases, the ncurses browser interface which you'll see after the
@@ -297,6 +343,7 @@ color scheme that also works in terminals with a light background.
297343
The default is
298344
.Ar off .
299345
.El
346+
.
300347
.Sh CONFIGURATION
301348
.Nm
302349
can be configured by placing command-line options in
@@ -325,6 +372,7 @@ Example configuration file:
325372
# Exclude .git directories
326373
\-\-exclude .git
327374
.Ed
375+
.
328376
.Sh KEYS
329377
.Bl -tag -width Ds
330378
.It ?
@@ -411,6 +459,7 @@ itself does not (currently) warn about or prevent this situation.
411459
.It q
412460
Quit
413461
.El
462+
.
414463
.Sh FILE FLAGS
415464
Entries in the browser interface may be prefixed by a one\-character flag.
416465
These flags have the following meaning:
@@ -434,6 +483,7 @@ Same file was already counted (hard link).
434483
.It e
435484
Empty directory.
436485
.El
486+
.
437487
.Sh EXAMPLES
438488
To scan and browse the directory you're currently in, all you need is a simple:
439489
.Dl ncdu
@@ -473,20 +523,23 @@ the local system without any network latency, and
473523
.Nm
474524
does not keep the entire directory structure in memory when exporting, so this
475525
won't consume much memory on the remote system.
526+
.
476527
.Sh SEE ALSO
477528
.Xr du 1 ,
478529
.Xr tree 1 .
479530
.Pp
480531
.Nm
481532
has a website:
482533
.Lk https://dev.yorhel.nl/ncdu
534+
.
483535
.Sh AUTHORS
484536
Written by
485537
.An Yorhel Aq Mt [email protected]
538+
.
486539
.Sh BUGS
487540
Directory hard links and firmlinks (MacOS) are not supported.
488-
They are not detected as being hard links, and will thus get scanned and
489-
counted multiple times.
541+
They are not detected as being hard links and will thus get scanned and counted
542+
multiple times.
490543
.Pp
491544
Some minor glitches may appear when displaying filenames that contain multibyte
492545
or multicolumn characters.

0 commit comments

Comments
 (0)