feature. See also
. The project being documented here (as the example) is the Zig library itself.
Fetch.recursiveDirectoryCopy
fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void
File
Code
fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void {
const gpa = f.arena.child_allocator;
const io = f.job_queue.io;
var it = try dir.walk(gpa);
defer it.deinit();
while (try it.next(io)) |entry| {
switch (entry.kind) {
.directory => {},
.file => {
dir.copyFile(entry.path, tmp_dir, entry.path, io, .{}) catch |err| switch (err) {
error.FileNotFound => {
if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.createDirPath(io, dirname);
try dir.copyFile(entry.path, tmp_dir, entry.path, io, .{});
},
else => |e| return e,
};
},
.sym_link => {
var buf: [fs.max_path_bytes]u8 = undefined;
const link_name = buf[0..try dir.readLink(io, entry.path, &buf)];
// the destination directory, fail with an error instead.
tmp_dir.symLink(io, link_name, entry.path, .{}) catch |err| switch (err) {
error.FileNotFound => {
if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.createDirPath(io, dirname);
try tmp_dir.symLink(io, link_name, entry.path, .{});
},
else => |e| return e,
};
},
else => return error.IllegalFileTypeInPackage,
}
}
}