aboutsummaryrefslogtreecommitdiff
path: root/src/storage/root.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage/root.zig')
-rw-r--r--src/storage/root.zig12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/storage/root.zig b/src/storage/root.zig
index 381dc45..f11798b 100644
--- a/src/storage/root.zig
+++ b/src/storage/root.zig
@@ -1,6 +1,6 @@
const std = @import("std");
-const config = @import("../config.zig");
const prompt = @import("../prompt.zig");
+const Config = @import("../config.zig");
pub const User = @import("user.zig");
@@ -15,15 +15,22 @@ const Self = @This();
dir: std.fs.Dir,
sessions: SessionManager = .empty,
images: ImageManager = .empty,
+config: Config,
allocator: std.mem.Allocator,
-pub fn init(allocator: std.mem.Allocator) !Self {
+pub fn init(
+ allocator: std.mem.Allocator,
+) !Self {
+ var config = try Config.load(allocator);
+ errdefer config.deinit();
+
const dir = std.fs.cwd().openDir(config.storage_path, .{}) catch blk: {
try std.fs.cwd().makeDir(config.storage_path);
break :blk try std.fs.cwd().openDir(config.storage_path, .{});
};
var self = Self {
+ .config = config,
.dir = dir,
.allocator = allocator,
};
@@ -67,5 +74,6 @@ pub fn init(allocator: std.mem.Allocator) !Self {
pub fn deinit(self: *Self) void {
self.dir.close();
+ self.config.deinit();
self.* = undefined;
}