Something went wrong. Try again.
Open SIMH's computer history simulators, built with the Zig build system
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>//// SPDX-License-Identifier: MIT
//! copy_tree SOURCE DESTINATION//!//! Copies the directory SOURCE into DESTINATION, giving everything the//! default, writable, permissions rather than the source's. The simulator//! test scripts run on such a copy because some write files beside//! themselves, and a copy that kept the modes of a Nix store path would be//! as read-only as the original.
const std = @import("std");
pub fn main(init: std.process.Init) !void { const io = init.io; const args = try init.minimal.args.toSlice(init.arena.allocator()); if (args.len != 3) { std.log.err("usage: {s} SOURCE DESTINATION", .{args[0]}); std.process.exit(2); }
const cwd = std.Io.Dir.cwd(); var source = try cwd.openDir(io, args[1], .{ .iterate = true }); defer source.close(io); try cwd.createDirPath(io, args[2]); var destination = try cwd.openDir(io, args[2], .{}); defer destination.close(io);
var walker = try source.walk(init.gpa); defer walker.deinit(); while (try walker.next(io)) |entry| switch (entry.kind) { .directory => try destination.createDirPath(io, entry.path), .file => try source.copyFile(entry.path, destination, entry.path, io, .{ .permissions = .default_file, }), else => {}, };}