update: add full_path to readTemplateFile

This commit is contained in:
Lucas F. 2026-01-14 14:14:59 -03:00
parent 7f47cf440b
commit 8b36704652

View file

@ -41,14 +41,17 @@ pub const Renderer = struct {
return null;
}
fn readTemplateFile(self: *const Renderer, path: []const u8) RenderError![]const u8 {
fn readTemplateFile(self: *const Renderer, path: []const u8) ![]const u8 {
const max_size = 10 * 1024 * 1024;
return std.fs.cwd().readFileAlloc(self.allocator, path, max_size) catch |err| switch (err) {
error.FileNotFound => return RenderError.FileNotFound,
error.AccessDenied => return RenderError.AccessDenied,
error.FileTooBig => return RenderError.FileTooBig,
error.NoSpaceLeft => return RenderError.NoSpaceLeft,
error.OutOfMemory => return RenderError.OutOfMemory,
const full_path = try std.fs.path.join(self.allocator, &.{ self.cache.default_path.?, path });
defer self.allocator.free(full_path);
const file = try std.fs.cwd().openFile(full_path, .{});
defer file.close();
// return std.fs.cwd().readFileAlloc(self.allocator, path, max_size) catch |err| switch (err) {
return file.readToEndAlloc(self.allocator, max_size) catch |err| switch (err) {
else => return RenderError.Unexpected,
};
}