update: add full_path to readTemplateFile
This commit is contained in:
parent
7f47cf440b
commit
8b36704652
1 changed files with 10 additions and 7 deletions
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue