Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change updateSnap to look for the file in src/ if it exists #3

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 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