| 1 | const std = @import("std"); |
| 2 | |
| 3 | /// Checks the existence of files relative to cwd. |
| 4 | /// A path starting with ! should not exist. |
| 5 | pub fn main(init: std.process.Init) !void { |
| 6 | const arena = init.arena.allocator(); |
| 7 | const io = init.io; |
| 8 | |
| 9 | var arg_it = try init.minimal.args.iterateAllocator(arena); |
| 10 | _ = arg_it.next(); |
| 11 | |
| 12 | const cwd = std.Io.Dir.cwd(); |
| 13 | const cwd_realpath = try cwd.realPathFileAlloc(io, ".", arena); |
| 14 | |
| 15 | while (arg_it.next()) |file_path| { |
| 16 | if (file_path.len > 0 and file_path[0] == '!') { |
| 17 | errdefer std.log.err( |
| 18 | "exclusive file check '{s}{c}{s}' failed", |
| 19 | .{ cwd_realpath, std.fs.path.sep, file_path[1..] }, |
| 20 | ); |
| 21 | if (cwd.statFile(io, file_path[1..], .{})) |_| { |
| 22 | return error.FileFound; |
| 23 | } else |err| switch (err) { |
| 24 | error.FileNotFound => {}, |
| 25 | else => return err, |
| 26 | } |
| 27 | } else { |
| 28 | errdefer std.log.err( |
| 29 | "inclusive file check '{s}{c}{s}' failed", |
| 30 | .{ cwd_realpath, std.fs.path.sep, file_path }, |
| 31 | ); |
| 32 | _ = try cwd.statFile(io, file_path, .{}); |
| 33 | } |
| 34 | } |
| 35 | } |