stage2: enhance zig init-lib and zig init-exe

Stop `src/main.zig` from being overwritten.
This commit is contained in:
Hadrien Dorio 2021-09-22 23:58:50 +02:00 committed by Andrew Kelley
parent 736d14fd5f
commit f615648d7b

View File

@ -2800,6 +2800,12 @@ pub fn cmdInit(
error.FileNotFound => {},
else => fatal("unable to test existence of build.zig: {s}\n", .{@errorName(err)}),
}
if (fs.cwd().access("src" ++ s ++ "main.zig", .{})) |_| {
fatal("existing src" ++ s ++ "main.zig file would be overwritten", .{});
} else |err| switch (err) {
error.FileNotFound => {},
else => fatal("unable to test existence of src" ++ s ++ "main.zig: {s}\n", .{@errorName(err)}),
}
var src_dir = try fs.cwd().makeOpenPath("src", .{});
defer src_dir.close();