Skip to content

Commit 61e6ad5

Browse files
feat: sync with upstream to 2.8.2
1 parent 2cdf8f1 commit 61e6ad5

File tree

6 files changed

+49
-23
lines changed

6 files changed

+49
-23
lines changed

ChangeLog

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

4+
2.8.2 - 2025-05-01
5+
- Still requires Zig 0.14
6+
- Fix a build error on MacOS
7+
8+
2.8.1 - 2025-04-28
9+
- Still requires Zig 0.14
10+
- Fix integer overflow in binary export
11+
- Fix crash when `fstatat()` returns EINVAL
12+
- Minor build system improvements
13+
414
2.8 - 2025-03-05
515
- Now requires Zig 0.14
616
- Add support for @-prefixed lines to ignore errors in config file

build.zig

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@ pub fn build(b: *std.Build) void {
77
const target = b.standardTargetOptions(.{});
88
const optimize = b.standardOptimizeOption(.{});
99

10-
const pie = b.option(bool, "pie", "Build with PIE support (by default false)") orelse false;
10+
const pie = b.option(bool, "pie", "Build with PIE support (by default: target-dependant)");
1111
const strip = b.option(bool, "strip", "Strip debugging info (by default false)") orelse false;
1212

13-
const exe = b.addExecutable(.{
14-
.name = "ncdu",
13+
const main_mod = b.createModule(.{
1514
.root_source_file = b.path("src/main.zig"),
1615
.target = target,
1716
.optimize = optimize,
1817
.strip = strip,
1918
.link_libc = true,
2019
});
20+
main_mod.linkSystemLibrary("ncursesw", .{});
21+
main_mod.linkSystemLibrary("zstd", .{});
2122

23+
const exe = b.addExecutable(.{
24+
.name = "ncdu",
25+
.root_module = main_mod,
26+
});
2227
exe.pie = pie;
23-
exe.root_module.linkSystemLibrary("ncursesw", .{});
24-
exe.root_module.linkSystemLibrary("libzstd", .{});
2528
// https://github.com/ziglang/zig/blob/faccd79ca5debbe22fe168193b8de54393257604/build.zig#L745-L748
2629
if (target.result.os.tag.isDarwin()) {
2730
// useful for package maintainers
2831
exe.headerpad_max_install_names = true;
2932
}
3033
b.installArtifact(exe);
34+
// exe.addLibraryPath(.{ .cwd_relative = "/lib/x86_64-linux-gnu" });
3135

3236
const run_cmd = b.addRunArtifact(exe);
3337
run_cmd.step.dependOn(b.getInstallStep());
@@ -39,14 +43,9 @@ pub fn build(b: *std.Build) void {
3943
run_step.dependOn(&run_cmd.step);
4044

4145
const unit_tests = b.addTest(.{
42-
.root_source_file = b.path("src/main.zig"),
43-
.target = target,
44-
.optimize = optimize,
45-
.link_libc = true,
46+
.root_module = main_mod,
4647
});
4748
unit_tests.pie = pie;
48-
unit_tests.root_module.linkSystemLibrary("ncursesw", .{});
49-
unit_tests.root_module.linkSystemLibrary("libzstd", .{});
5049

5150
const run_unit_tests = b.addRunArtifact(unit_tests);
5251

ncdu.1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" SPDX-FileCopyrightText: Yorhel <[email protected]>
22
.\" SPDX-License-Identifier: MIT
3-
.Dd November 19, 2024
3+
.Dd May 1, 2025
44
.Dt NCDU 1
55
.Os
66
.Sh NAME
@@ -286,7 +286,7 @@ when given twice it will also add
286286
thus ensuring that there is no way to modify the file system from within
287287
.Nm .
288288
.It Fl \-si , \-no\-si
289-
List sizes using base 10 prefixes, that is, powers of 1000 (KB, MB, etc), as
289+
List sizes using base 10 prefixes, that is, powers of 1000 (kB, MB, etc), as
290290
defined in the International System of Units (SI), instead of the usual base 2
291291
prefixes (KiB, MiB, etc).
292292
.It Fl \-disk\-usage , \-apparent\-size
@@ -392,6 +392,7 @@ is given on the command line.
392392
.Pp
393393
The configuration file format is simply one command line option per line.
394394
Lines starting with '#' are ignored.
395+
A line can be prefixed with '@' to suppress errors while parsing the option.
395396
Example configuration file:
396397
.Bd -literal -offset indent
397398
# Always enable extended mode
@@ -402,6 +403,9 @@ Example configuration file:
402403

403404
# Exclude .git directories
404405
\-\-exclude .git
406+
407+
# Read excludes from ~/.ncduexcludes, ignore error if the file does not exist
408+
@--exclude-from ~/.ncduexcludes
405409
.Ed
406410
.
407411
.Sh KEYS

src/bin_export.zig

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub const global = struct {
1717
var root_itemref: u64 = 0;
1818
};
1919

20-
const BLOCK_SIZE: usize = 64*1024;
21-
2220
pub const SIGNATURE = "\xbfncduEX1";
2321

2422
pub const ItemKey = enum(u5) {
@@ -81,10 +79,15 @@ fn blockSize(num: u32) usize {
8179
else 2048<<10; // 32768
8280
}
8381

82+
// Upper bound on the return value of blockSize()
83+
// (config.export_block_size may be larger than the sizes listed above, let's
84+
// stick with the maximum block size supported by the file format to be safe)
85+
const MAX_BLOCK_SIZE: usize = 1<<28;
86+
8487

8588
pub const Thread = struct {
8689
buf: []u8 = undefined,
87-
off: usize = std.math.maxInt(usize) - (1<<10), // large number to trigger a flush() for the first write
90+
off: usize = MAX_BLOCK_SIZE, // pretend we have a full block to trigger a flush() for the first write
8891
block_num: u32 = std.math.maxInt(u32),
8992
itemref: u64 = 0, // ref of item currently being written
9093

@@ -124,7 +127,7 @@ pub const Thread = struct {
124127

125128
global.lock.lock();
126129
defer global.lock.unlock();
127-
// This can only really happen when the root path exceeds BLOCK_SIZE,
130+
// This can only really happen when the root path exceeds our block size,
128131
// in which case we would probably have error'ed out earlier anyway.
129132
if (expected_len > t.buf.len) ui.die("Error writing data: path too long.\n", .{});
130133

@@ -430,7 +433,7 @@ pub const Dir = struct {
430433

431434
pub fn createRoot(stat: *const sink.Stat, threads: []sink.Thread) Dir {
432435
for (threads) |*t| {
433-
t.sink.bin.buf = main.allocator.alloc(u8, BLOCK_SIZE) catch unreachable;
436+
t.sink.bin.buf = main.allocator.alloc(u8, blockSize(0)) catch unreachable;
434437
}
435438

436439
return .{ .stat = stat.* };

src/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: Yorhel <[email protected]>
22
// SPDX-License-Identifier: MIT
33

4-
pub const program_version = "2.8";
4+
pub const program_version = "2.8.2";
55

66
const std = @import("std");
77
const model = @import("model.zig");

src/scan.zig

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,23 @@ fn truncate(comptime T: type, comptime field: anytype, x: anytype) std.meta.fiel
4747

4848

4949
fn statAt(parent: std.fs.Dir, name: [:0]const u8, follow: bool, symlink: *bool) !sink.Stat {
50-
const stat = try std.posix.fstatatZ(parent.fd, name, if (follow) 0 else std.posix.AT.SYMLINK_NOFOLLOW);
51-
symlink.* = std.posix.S.ISLNK(stat.mode);
50+
// std.posix.fstatatZ() in Zig 0.14 is not suitable due to https://github.com/ziglang/zig/issues/23463
51+
var stat: std.c.Stat = undefined;
52+
if (std.c.fstatat(parent.fd, name, &stat, if (follow) 0 else std.c.AT.SYMLINK_NOFOLLOW) != 0) {
53+
return switch (std.c._errno().*) {
54+
@intFromEnum(std.c.E.NOENT) => error.FileNotFound,
55+
@intFromEnum(std.c.E.NAMETOOLONG) => error.NameTooLong,
56+
@intFromEnum(std.c.E.NOMEM) => error.OutOfMemory,
57+
@intFromEnum(std.c.E.ACCES) => error.AccessDenied,
58+
else => error.Unexpected,
59+
};
60+
}
61+
symlink.* = std.c.S.ISLNK(stat.mode);
5262
return sink.Stat{
5363
.etype =
54-
if (std.posix.S.ISDIR(stat.mode)) .dir
64+
if (std.c.S.ISDIR(stat.mode)) .dir
5565
else if (stat.nlink > 1) .link
56-
else if (!std.posix.S.ISREG(stat.mode)) .nonreg
66+
else if (!std.c.S.ISREG(stat.mode)) .nonreg
5767
else .reg,
5868
.blocks = clamp(sink.Stat, .blocks, stat.blocks),
5969
.size = clamp(sink.Stat, .size, stat.size),

0 commit comments

Comments
 (0)