Skip to content

Commit

Permalink
Change updateSnap to look for the file in src/
Browse files Browse the repository at this point in the history
  • Loading branch information
jullanggit committed Jan 5, 2025
1 parent 0cd85a8 commit e2a771b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ohsnap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
});
Expand Down

0 comments on commit e2a771b

Please sign in to comment.