diff options
Diffstat (limited to 'src/Db.zig')
| -rw-r--r-- | src/Db.zig | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -95,40 +95,6 @@ pub fn statePath(buf: []u8, dir_setting: []const u8) ?[]const u8 { return std.fmt.bufPrint(buf, "{s}/" ++ file_name, .{dir}) catch null; } -/// The database, opened (made, when its file is not there) at its first use -/// and again once the DumpDir names another: null when this session keeps -/// none, or it cannot be had now (the next use tries again). -fn opened(db: *Db, p: *Pardes) ?*Open { - switch (db.kind) { - .off => return null, - .disk => { - var buf: [4200]u8 = undefined; - const path = statePath(&buf, p.settings.dump_dir.get()) orelse return null; - if (db.open) |o| { - // The same file still: another session's compaction renames - // a new one over it, which this one then opens. - if (std.mem.eql(u8, o.where.disk.path, path) and !replaced(o)) return o; - // The DumpDir moved: its own file, read afresh. - db.deinit(); - db.seen = 0; - } - db.open = openDisk(p.recentGpa(), path) catch return null; - }, - .memory => if (db.open == null) { - const gpa = p.recentGpa(); - const o = gpa.create(Open) catch return null; - o.* = .{ .gpa = gpa, .buffer = .init(gpa), .where = undefined }; - o.where = .{ .memory = .{ .db = Memory.init(ioOf(), .{ .buffer = &o.buffer, .hash_id = hash_id }) catch { - o.buffer.deinit(); - gpa.destroy(o); - return null; - } } }; - db.open = o; - }, - } - return db.open; -} - /// The state file at `path`, its directory made: a new one is written under /// the file's lock (two sessions starting at once write one header), one a /// power loss tore is opened at its last whole commit (`mend`), and a file @@ -1140,6 +1106,40 @@ pub const Cache = struct { const testing = std.testing; +/// The database, opened (made, when its file is not there) at its first use +/// and again once the DumpDir names another: null when this session keeps +/// none, or it cannot be had now (the next use tries again). +fn opened(db: *Db, p: *Pardes) ?*Open { + switch (db.kind) { + .off => return null, + .disk => { + var buf: [4200]u8 = undefined; + const path = statePath(&buf, p.settings.dump_dir.get()) orelse return null; + if (db.open) |o| { + // The same file still: another session's compaction renames + // a new one over it, which this one then opens. + if (std.mem.eql(u8, o.where.disk.path, path) and !replaced(o)) return o; + // The DumpDir moved: its own file, read afresh. + db.deinit(); + db.seen = 0; + } + db.open = openDisk(p.recentGpa(), path) catch return null; + }, + .memory => if (db.open == null) { + const gpa = p.recentGpa(); + const o = gpa.create(Open) catch return null; + o.* = .{ .gpa = gpa, .buffer = .init(gpa), .where = undefined }; + o.where = .{ .memory = .{ .db = Memory.init(ioOf(), .{ .buffer = &o.buffer, .hash_id = hash_id }) catch { + o.buffer.deinit(); + gpa.destroy(o); + return null; + } } }; + db.open = o; + }, + } + return db.open; +} + /// A window keeping its state in `dir` (never the user's DumpDir). fn testWindow(dir: []const u8) !*Pardes { var config: [4200]u8 = undefined; |
