std.fs: split Dir into IterableDir

Also adds safety check for attempting to iterate directory not opened with `iterate = true`.
This commit is contained in:
Veikka Tuominen
2022-07-09 18:59:21 +03:00
parent 577f9fdbae
commit 2b67f56c35
10 changed files with 145 additions and 104 deletions

View File

@@ -41,7 +41,7 @@ pub fn main() !void {
const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/glibc", .{zig_src_path});
var dest_dir = fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| {
var dest_dir = fs.cwd().openIterableDir(dest_dir_path, .{}) catch |err| {
fatal("unable to open destination directory '{s}': {s}", .{
dest_dir_path, @errorName(err),
});
@@ -63,14 +63,14 @@ pub fn main() !void {
if (mem.eql(u8, entry.path, p)) continue :walk;
}
glibc_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| {
glibc_src_dir.copyFile(entry.path, dest_dir.dir, entry.path, .{}) catch |err| {
log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {s}", .{
glibc_src_path, entry.path,
dest_dir_path, entry.path,
@errorName(err),
});
if (err == error.FileNotFound) {
try dest_dir.deleteFile(entry.path);
try dest_dir.dir.deleteFile(entry.path);
}
};
}
@@ -79,7 +79,7 @@ pub fn main() !void {
// Warn about duplicated files inside glibc/include/* that can be omitted
// because they are already in generic-glibc/*.
var include_dir = dest_dir.openDir("include", .{ .iterate = true }) catch |err| {
var include_dir = dest_dir.dir.openIterableDir("include", .{}) catch |err| {
fatal("unable to open directory '{s}/include': {s}", .{
dest_dir_path, @errorName(err),
});
@@ -116,7 +116,7 @@ pub fn main() !void {
generic_glibc_path, entry.path, @errorName(e),
}),
};
const glibc_include_contents = include_dir.readFileAlloc(
const glibc_include_contents = include_dir.dir.readFileAlloc(
arena,
entry.path,
max_file_size,