Zig 0.16: boring fs/io

This commit is contained in:
LN Liberda 2026-05-23 03:52:42 +02:00
parent 3ecdb536d3
commit 0703b62a1a
2 changed files with 10 additions and 14 deletions

View file

@ -42,30 +42,30 @@ fn err(e: anyerror) bool {
return main.state != .delete;
}
fn deleteItem(dir: std.fs.Dir, path: [:0]const u8, ptr: *align(1) ?*model.Entry) bool {
fn deleteItem(dir: std.Io.Dir, path: [:0]const u8, ptr: *align(1) ?*model.Entry) bool {
entry = ptr.*.?;
main.handleEvent(false, false);
if (main.state != .delete)
return true;
if (entry.dir()) |d| {
var fd = dir.openDirZ(path, .{ .no_follow = true, .iterate = false }) catch |e| return err(e);
var fd = dir.openDir(main.io, path, .{ .follow_symlinks = false, .iterate = false }) catch |e| return err(e);
var it = &d.sub.ptr;
parent = d;
defer parent = parent.parent.?;
while (it.*) |n| {
if (deleteItem(fd, n.name(), it)) {
fd.close();
fd.close(main.io);
return true;
}
if (it.* == n) // item deletion failed, make sure to still advance to next
it = &n.next.ptr;
}
fd.close();
dir.deleteDirZ(path) catch |e|
fd.close(main.io);
dir.deleteDir(main.io, path) catch |e|
return if (e != error.DirNotEmpty or d.sub.ptr == null) err(e) else false;
} else
dir.deleteFileZ(path) catch |e| return err(e);
dir.deleteFile(main.io, path) catch |e| return err(e);
ptr.*.?.zeroStats(parent);
ptr.* = ptr.*.?.next.ptr;
return false;
@ -144,7 +144,7 @@ pub fn delete() ?*model.Entry {
path.appendSlice(main.allocator, entry.name()) catch unreachable;
if (main.config.delete_command.len == 0) {
_ = deleteItem(std.fs.cwd(), util.arrayListBufZ(&path, main.allocator), it);
_ = deleteItem(std.Io.Dir.cwd(), util.arrayListBufZ(&path, main.allocator), it);
model.inodes.addAllStats();
return if (it.* == e) e else next_sel;
} else {

View file

@ -640,13 +640,9 @@ pub fn getch(block: bool) i32 {
}
fn waitInput() void {
if (@hasDecl(std.io, "getStdIn")) {
std.io.getStdIn().reader().skipUntilDelimiterOrEof('\n') catch unreachable;
} else {
var buf: [512]u8 = undefined;
var rd = std.fs.File.stdin().reader(&buf);
_ = rd.interface.discardDelimiterExclusive('\n') catch unreachable;
}
var buf: [512]u8 = undefined;
var rd = std.Io.File.stdin().reader(main.io, &buf);
_ = rd.interface.discardDelimiterExclusive('\n') catch unreachable;
}
pub fn runCmd(cmd: []const []const u8, cwd: ?[]const u8, reporterr: bool) void {