diff options
Diffstat (limited to 'src/host/Sessions.zig')
| -rw-r--r-- | src/host/Sessions.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/host/Sessions.zig b/src/host/Sessions.zig index cf0ab24..d6caf9c 100644 --- a/src/host/Sessions.zig +++ b/src/host/Sessions.zig @@ -191,6 +191,19 @@ pub fn open(gpa: std.mem.Allocator, io: std.Io, want: Mode, path: []const u8, fi return s; } +/// The database at `path`, read only and no session started in it: for +/// its `present` with no run of the sketch (`fs` with the sketch closed). +pub fn openRead(gpa: std.mem.Allocator, io: std.Io, path: []const u8) !Sessions { + var s: Sessions = .{ .gpa = gpa, .io = io }; + errdefer s.deinit(); + s.file = try std.Io.Dir.cwd().openFile(io, path, .{}); + s.buffer = try gpa.create(std.Io.Writer.Allocating); + s.buffer.?.* = .init(gpa); + s.db = .{ .file = try Disk.init(io, .{ .file = s.file.?, .buffer = s.buffer.?, .fsync = false }) }; + s.session = try s.count(.sessions); + return s; +} + pub fn deinit(s: *Sessions) void { s.dropQueued(); s.queued.deinit(s.gpa); |
