From e2a771b6af2ccbe6020a978f36b09f4b59ee2843 Mon Sep 17 00:00:00 2001 From: Jul Lang Date: Sun, 5 Jan 2025 13:46:54 +0100 Subject: [PATCH] Change updateSnap to look for the file in src/ --- src/ohsnap.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ohsnap.zig b/src/ohsnap.zig index 43b9486..d6c7c23 100644 --- a/src/ohsnap.zig +++ b/src/ohsnap.zig @@ -172,8 +172,10 @@ pub const Snap = struct { const arena_allocator = arena.allocator(); + // If a src directory exists, use it otherwise use the cwd + const src_dir = try std.fs.cwd().openDir("src", std.fs.Dir.OpenOptions{}) catch std.fs.cwd(); const file_text = - try std.fs.cwd().readFileAlloc(arena_allocator, snapshot.location.file, 1024 * 1024); + try src_dir.readFileAlloc(arena_allocator, snapshot.location.file, 1024 * 1024); var file_text_updated = try std.ArrayList(u8).initCapacity(arena_allocator, file_text.len); const line_zero_based = snapshot.location.line - 1; @@ -194,7 +196,7 @@ pub const Snap = struct { } try file_text_updated.appendSlice(snapshot_suffix); - try std.fs.cwd().writeFile(.{ + try src_dir.writeFile(.{ .sub_path = snapshot.location.file, .data = file_text_updated.items, });