Fixes for stdlib changes

This commit is contained in:
Yorhel 2022-08-22 13:59:33 +02:00
parent f37362af36
commit f7e774ee6e
4 changed files with 16 additions and 15 deletions

View file

@ -45,8 +45,7 @@ fn deleteItem(dir: std.fs.Dir, path: [:0]const u8, ptr: *align(1) ?*model.Entry)
return true;
if (entry.dir()) |d| {
var fd = dir.openDirZ(path, .{ .access_sub_paths = true, .iterate = false })
catch |e| return err(e);
var fd = dir.openDirZ(path, .{.no_follow = true}, false) catch |e| return err(e);
var it = &d.sub;
parent = d;
defer parent = parent.parent.?;

View file

@ -343,8 +343,7 @@ fn spawnShell() void {
env.put("NCDU_LEVEL", "1") catch unreachable;
const shell = std.os.getenvZ("NCDU_SHELL") orelse std.os.getenvZ("SHELL") orelse "/bin/sh";
var child = std.ChildProcess.init(&.{shell}, allocator) catch unreachable;
defer child.deinit();
var child = std.ChildProcess.init(&.{shell}, allocator);
child.cwd = path.items;
child.env_map = &env;

View file

@ -450,8 +450,8 @@ const Context = struct {
var active_context: *Context = undefined;
// Read and index entries of the given dir.
fn scanDir(ctx: *Context, pat: *const exclude.Patterns, dir: std.fs.Dir, dir_dev: u64) void {
var it = main.allocator.create(std.fs.Dir.Iterator) catch unreachable;
fn scanDir(ctx: *Context, pat: *const exclude.Patterns, dir: std.fs.IterableDir, dir_dev: u64) void {
var it = main.allocator.create(std.fs.IterableDir.Iterator) catch unreachable;
defer main.allocator.destroy(it);
it.* = dir.iterate();
while(true) {
@ -471,7 +471,7 @@ fn scanDir(ctx: *Context, pat: *const exclude.Patterns, dir: std.fs.Dir, dir_dev
continue;
}
ctx.stat = Stat.read(dir, ctx.name, false) catch {
ctx.stat = Stat.read(dir.dir, ctx.name, false) catch {
ctx.addSpecial(.err);
continue;
};
@ -481,7 +481,7 @@ fn scanDir(ctx: *Context, pat: *const exclude.Patterns, dir: std.fs.Dir, dir_dev
}
if (main.config.follow_symlinks and ctx.stat.symlink) {
if (Stat.read(dir, ctx.name, true)) |nstat| {
if (Stat.read(dir.dir, ctx.name, true)) |nstat| {
if (!nstat.dir) {
ctx.stat = nstat;
// Symlink targets may reside on different filesystems,
@ -497,19 +497,21 @@ fn scanDir(ctx: *Context, pat: *const exclude.Patterns, dir: std.fs.Dir, dir_dev
};
var edir =
if (ctx.stat.dir) dir.openDirZ(ctx.name, .{ .access_sub_paths = true, .iterate = true, .no_follow = true }) catch {
if (!ctx.stat.dir) null
else if (dir.dir.openDirZ(ctx.name, .{ .no_follow = true }, true)) |d| std.fs.IterableDir{.dir = d}
else |_| {
ctx.addSpecial(.err);
continue;
} else null;
};
defer if (edir != null) edir.?.close();
if (@import("builtin").os.tag == .linux and main.config.exclude_kernfs and ctx.stat.dir and isKernfs(edir.?, ctx.stat.dev)) {
if (@import("builtin").os.tag == .linux and main.config.exclude_kernfs and ctx.stat.dir and isKernfs(edir.?.dir, ctx.stat.dev)) {
ctx.addSpecial(.kernfs);
continue;
}
if (main.config.exclude_caches and ctx.stat.dir) {
if (edir.?.openFileZ("CACHEDIR.TAG", .{})) |f| {
if (edir.?.dir.openFileZ("CACHEDIR.TAG", .{})) |f| {
const sig = "Signature: 8a477f597d28d172789f06886806bc55";
var buf: [sig.len]u8 = undefined;
if (f.reader().readAll(&buf)) |len| {
@ -556,13 +558,14 @@ pub fn setupRefresh(parent: *model.Dir) void {
// To be called after setupRefresh() (or from scanRoot())
pub fn scan() void {
defer active_context.deinit();
var dir = std.fs.cwd().openDirZ(active_context.pathZ(), .{ .access_sub_paths = true, .iterate = true }) catch |e| {
var dir_ = std.fs.cwd().openDirZ(active_context.pathZ(), .{}, true) catch |e| {
active_context.last_error = main.allocator.dupeZ(u8, active_context.path.items) catch unreachable;
active_context.fatal_error = e;
while (main.state == .refresh or main.state == .scan)
main.handleEvent(true, true);
return;
};
var dir = std.fs.IterableDir{.dir = dir_};
defer dir.close();
var pat = exclude.getPatterns(active_context.pathZ());
defer pat.deinit();

View file

@ -286,8 +286,8 @@ const styles = [_]StyleDef{
};
pub const Style = lbl: {
var fields: [styles.len]std.builtin.TypeInfo.EnumField = undefined;
var decls = [_]std.builtin.TypeInfo.Declaration{};
var fields: [styles.len]std.builtin.Type.EnumField = undefined;
var decls = [_]std.builtin.Type.Declaration{};
inline for (styles) |s, i| {
fields[i] = .{
.name = s.name,