blob: ba2de2777fe2c05fb3d6c61e366a127543337915 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//! Verifies that a file exists in a directory.
//!
//! Usage:
//!
//! ```
//! exists_in <dir> <path>
//! ```
//!
//! Where `<dir>/<path>` is the full path to the file.
//! `<dir>` must be an absolute path.
const std = @import("std");
pub fn main() !void {
var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const arena = arena_state.allocator();
defer arena_state.deinit();
try run(arena);
}
fn run(allocator: std.mem.Allocator) !void {
var args = try std.process.argsWithAllocator(allocator);
defer args.deinit();
_ = args.next() orelse unreachable; // skip binary name
const dir_path = args.next() orelse {
std.log.err("missing <dir> argument", .{});
return error.BadUsage;
};
const relpath = args.next() orelse {
std.log.err("missing <path> argument", .{});
return error.BadUsage;
};
const io = std.Io.Threaded.global_single_threaded.ioBasic();
var dir = try std.Io.Dir.cwd().openDir(io, dir_path, .{});
defer dir.close(io);
_ = try dir.statFile(io, relpath, .{});
}
|