From 7101f47610eaca367cec63ca027b69f2cce7e55e Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 1 Jul 2026 08:12:20 +0800 Subject: [PATCH] make indexedb in-memory only (for now) --- src/Config.zig | 39 +--------------------- src/browser/Session.zig | 2 +- src/browser/webapi/storage/idb/Manager.zig | 38 ++++----------------- src/help.zon | 3 -- 4 files changed, 8 insertions(+), 74 deletions(-) diff --git a/src/Config.zig b/src/Config.zig index 9fa8d6f7d..004cae330 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -85,37 +85,7 @@ fn logLevelValidator(_: Allocator, args: *std.process.ArgIterator) !?log.Level { } /// Common CLI args. -const CommonOptions = .{ - .{ .name = "obey_robots", .type = bool }, - .{ .name = "proxy_bearer_token", .type = ?[:0]const u8 }, - .{ .name = "http_proxy", .type = ?[:0]const u8 }, - .{ .name = "http_max_concurrent", .type = ?u8 }, - .{ .name = "http_max_host_open", .type = ?u8 }, - .{ .name = "http_timeout", .type = ?u31 }, - .{ .name = "http_connect_timeout", .type = ?u31 }, - .{ .name = "http_max_response_size", .type = ?usize }, - .{ .name = "ws_max_concurrent", .type = ?u8 }, - .{ .name = "insecure_disable_tls_host_verification", .type = bool }, - .{ .name = "log_level", .type = ?log.Level, .validator = logLevelValidator }, - .{ .name = "log_format", .type = ?log.Format }, - .{ .name = "log_filter_scopes", .type = log.FilterRule, .multiple = true, .validator = logFilterScopesValidator }, - .{ .name = "user_agent_suffix", .type = ?[]const u8 }, - .{ .name = "http_cache_dir", .type = ?[]const u8 }, - .{ .name = "web_bot_auth_key_file", .type = ?[]const u8 }, - .{ .name = "web_bot_auth_keyid", .type = ?[]const u8 }, - .{ .name = "web_bot_auth_domain", .type = ?[]const u8 }, - .{ .name = "user_agent", .type = ?[]const u8 }, - .{ .name = "block_private_networks", .type = bool }, - .{ .name = "block_cidrs", .type = ?[]const u8 }, - .{ .name = "cookie", .type = ?[]const u8 }, - .{ .name = "cookie_jar", .type = ?[]const u8 }, - .{ .name = "storage_engine", .type = ?Storage.EngineType }, - .{ .name = "storage_sqlite_path", .type = ?[:0]const u8 }, - .{ .name = "disable_subframes", .type = bool }, - .{ .name = "disable_workers", .type = bool }, - .{ .name = "enable_external_stylesheets", .type = bool }, - .{ .name = "indexdb_dir", .type = ?[:0]const u8 }, -}; +const CommonOptions = .{ .{ .name = "obey_robots", .type = bool }, .{ .name = "proxy_bearer_token", .type = ?[:0]const u8 }, .{ .name = "http_proxy", .type = ?[:0]const u8 }, .{ .name = "http_max_concurrent", .type = ?u8 }, .{ .name = "http_max_host_open", .type = ?u8 }, .{ .name = "http_timeout", .type = ?u31 }, .{ .name = "http_connect_timeout", .type = ?u31 }, .{ .name = "http_max_response_size", .type = ?usize }, .{ .name = "ws_max_concurrent", .type = ?u8 }, .{ .name = "insecure_disable_tls_host_verification", .type = bool }, .{ .name = "log_level", .type = ?log.Level, .validator = logLevelValidator }, .{ .name = "log_format", .type = ?log.Format }, .{ .name = "log_filter_scopes", .type = log.FilterRule, .multiple = true, .validator = logFilterScopesValidator }, .{ .name = "user_agent_suffix", .type = ?[]const u8 }, .{ .name = "http_cache_dir", .type = ?[]const u8 }, .{ .name = "web_bot_auth_key_file", .type = ?[]const u8 }, .{ .name = "web_bot_auth_keyid", .type = ?[]const u8 }, .{ .name = "web_bot_auth_domain", .type = ?[]const u8 }, .{ .name = "user_agent", .type = ?[]const u8 }, .{ .name = "block_private_networks", .type = bool }, .{ .name = "block_cidrs", .type = ?[]const u8 }, .{ .name = "cookie", .type = ?[]const u8 }, .{ .name = "cookie_jar", .type = ?[]const u8 }, .{ .name = "storage_engine", .type = ?Storage.EngineType }, .{ .name = "storage_sqlite_path", .type = ?[:0]const u8 }, .{ .name = "disable_subframes", .type = bool }, .{ .name = "disable_workers", .type = bool }, .{ .name = "enable_external_stylesheets", .type = bool } }; fn dumpValidator(_: Allocator, args: *std.process.ArgIterator) !?DumpFormat { // Peek next argument. @@ -568,13 +538,6 @@ pub fn storageSqlitePath(self: *const Config) ?[:0]const u8 { }; } -pub fn indexDBDir(self: *const Config) ?[:0]const u8 { - return switch (self.mode) { - inline .serve, .fetch, .mcp, .agent => |opts| opts.indexdb_dir, - else => unreachable, - }; -} - pub const DumpFormat = enum { html, markdown, diff --git a/src/browser/Session.zig b/src/browser/Session.zig index 33f041104..c572df9ad 100644 --- a/src/browser/Session.zig +++ b/src/browser/Session.zig @@ -159,7 +159,7 @@ pub fn init(self: *Session, browser: *Browser, notification: *Notification) !voi // The prototype (EventTarget) for Navigation is created when a Frame is created. .navigation = .{ ._proto = undefined }, .storage_shed = .{}, - .idb = IdbManager.init(allocator, browser.app.config.indexDBDir()), + .idb = IdbManager.init(allocator), .browser = browser, .notification = notification, .cookie_jar = storage.Cookie.Jar.init(allocator, notification), diff --git a/src/browser/webapi/storage/idb/Manager.zig b/src/browser/webapi/storage/idb/Manager.zig index c69a33037..0803dfe26 100644 --- a/src/browser/webapi/storage/idb/Manager.zig +++ b/src/browser/webapi/storage/idb/Manager.zig @@ -27,11 +27,10 @@ const Allocator = std.mem.Allocator; const Manager = @This(); allocator: Allocator, -base_dir: []const u8, engines: std.StringHashMapUnmanaged(*Engine) = .empty, -pub fn init(allocator: Allocator, base_dir: ?[]const u8) Manager { - return .{ .allocator = allocator, .base_dir = base_dir orelse ":memory:" }; +pub fn init(allocator: Allocator) Manager { + return .{ .allocator = allocator }; } pub fn deinit(self: *Manager) void { @@ -55,7 +54,7 @@ pub fn engineForOrigin(self: *Manager, origin: []const u8) !*Engine { const engine = try self.allocator.create(Engine); errdefer self.allocator.destroy(engine); - engine.* = try self.open(origin); + engine.* = try Engine.open(":memory:"); errdefer engine.close(); gop.key_ptr.* = try self.allocator.dupe(u8, origin); @@ -63,29 +62,9 @@ pub fn engineForOrigin(self: *Manager, origin: []const u8) !*Engine { return engine; } -fn open(self: *Manager, origin: []const u8) !Engine { - if (std.mem.eql(u8, self.base_dir, ":memory:")) { - return Engine.open(":memory:"); - } - - // we hash the origin for two reason: - // 1 - it fixes the length, so we don't have to worry about illegally long filename - // 2 - It removes any unsafe characters - var digest: [16]u8 = undefined; - std.crypto.hash.Blake3.hash(origin, &digest, .{}); - var name_buf: [64]u8 = undefined; - const file_name = std.fmt.bufPrint(&name_buf, "idb-{x}.sqlite", .{&digest}) catch unreachable; - - const path = try std.fs.path.joinZ(self.allocator, &.{ self.base_dir, file_name }); - defer self.allocator.free(path); - - log.debug(.storage, "idb open", .{ .origin = origin, .path = path }); - return Engine.open(path); -} - const testing = @import("../../../../testing.zig"); test "IDB - Manager: same origin returns same engine, distinct origins differ" { - var mgr = Manager.init(testing.allocator, null); + var mgr = Manager.init(testing.allocator); defer mgr.deinit(); const a1 = try mgr.engineForOrigin("https://a.com"); @@ -97,7 +76,7 @@ test "IDB - Manager: same origin returns same engine, distinct origins differ" { } test "IDB - Manager: in-memory engines are origin-isolated" { - var mgr = Manager.init(testing.allocator, null); + var mgr = Manager.init(testing.allocator); defer mgr.deinit(); const a = try mgr.engineForOrigin("https://a.com"); @@ -108,12 +87,7 @@ test "IDB - Manager: in-memory engines are origin-isolated" { } test "IDB - Manager: on-disk engines hash to per-origin files, isolated" { - var tmp = std.testing.tmpDir(.{}); - defer tmp.cleanup(); - const dir = try tmp.dir.realpathAlloc(testing.allocator, "."); - defer testing.allocator.free(dir); - - var mgr = Manager.init(testing.allocator, dir); + var mgr = Manager.init(testing.allocator); defer mgr.deinit(); // A long origin (hostname near the 253-byte limit) must still open: the diff --git a/src/help.zon b/src/help.zon index 6fd17dc9a..eb9d11c2d 100644 --- a/src/help.zon +++ b/src/help.zon @@ -367,8 +367,5 @@ \\ --storage-sqlite-path \\ Path to the SQLite database file for persistent storage. \\ Use ":memory:" for in-memory storage. - \\ --indexdb_dir - \\ Directory to store an SQLite database for IndexDB. - \\ Defaults to ":memory:" , }