Handle realpathAlloc failure in files.zig

This commit is contained in:
IntegratedQuantum 2025-04-26 14:49:45 +02:00
parent 62d4bf6700
commit de3b862f1e

View File

@ -123,9 +123,9 @@ pub const Dir = struct {
pub fn readToZon(self: Dir, allocator: NeverFailingAllocator, path: []const u8) !ZonElement {
const string = try self.read(main.stackAllocator, path);
defer main.stackAllocator.free(string);
const realPath = try self.dir.realpathAlloc(main.stackAllocator.allocator, path);
defer main.stackAllocator.free(realPath);
return ZonElement.parseFromString(allocator, realPath, string);
const realPath: ?[]const u8 = self.dir.realpathAlloc(main.stackAllocator.allocator, path) catch null;
defer if(realPath) |p| main.stackAllocator.free(p);
return ZonElement.parseFromString(allocator, realPath orelse path, string);
}
pub fn write(self: Dir, path: []const u8, data: []const u8) !void {