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