From 87e2ab7e1bb8ba3182a451a81ca06a1849aa5644 Mon Sep 17 00:00:00 2001 From: sectasy0 Date: Sat, 11 May 2024 10:03:08 +0200 Subject: [PATCH] refactor(rename): PersistanceHandler to persistance.Handler --- src/main.zig | 4 ++-- src/server/processing/commands.zig | 1 - src/server/storage/memory.zig | 6 +++--- src/server/storage/persistance.zig | 14 +++++++------- src/tests/fixtures.zig | 11 ++++++++--- src/tests/helper.zig | 2 +- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main.zig b/src/main.zig index bd54301..db3fe77 100644 --- a/src/main.zig +++ b/src/main.zig @@ -90,7 +90,7 @@ pub fn main() void { }; defer config.deinit(); - var persister = persistance.PersistanceHandler.init( + var persister = persistance.Handler.init( allocator, config, logger, @@ -98,7 +98,7 @@ pub fn main() void { ) catch |err| { logger.log( .Error, - "# failed to init PersistanceHandler: {?}", + "# failed to init persistance.Handler: {?}", .{err}, ); return; diff --git a/src/server/processing/commands.zig b/src/server/processing/commands.zig index 044259f..81930d2 100644 --- a/src/server/processing/commands.zig +++ b/src/server/processing/commands.zig @@ -3,7 +3,6 @@ const std = @import("std"); const ZType = @import("../../protocol/types.zig").ZType; const Memory = @import("../storage/memory.zig"); -const PersistanceHandler = @import("../storage/persistance.zig"); const TracingAllocator = @import("../tracing.zig").TracingAllocator; const Config = @import("../config.zig"); diff --git a/src/server/storage/memory.zig b/src/server/storage/memory.zig index 541a4d9..ba43bd6 100644 --- a/src/server/storage/memory.zig +++ b/src/server/storage/memory.zig @@ -2,7 +2,7 @@ const std = @import("std"); const types = @import("../../protocol/types.zig"); const TracingAllocator = @import("../tracing.zig"); -const PersistanceHandler = @import("../storage/persistance.zig").PersistanceHandler; +const persistance = @import("../storage/persistance.zig"); const Logger = @import("../logger.zig"); const Config = @import("../config.zig"); @@ -13,7 +13,7 @@ const Memory = @This(); internal: std.StringHashMap(types.ZType), allocator: std.mem.Allocator, -persister: *PersistanceHandler, +persister: *persistance.Handler, config: Config, @@ -24,7 +24,7 @@ last_save: i64, pub fn init( allocator: std.mem.Allocator, config: Config, - persister: *PersistanceHandler, + persister: *persistance.Handler, ) Memory { return Memory{ .internal = std.StringHashMap(types.ZType).init(allocator), diff --git a/src/server/storage/persistance.zig b/src/server/storage/persistance.zig index adcabbf..e8da8c4 100644 --- a/src/server/storage/persistance.zig +++ b/src/server/storage/persistance.zig @@ -17,7 +17,7 @@ const DEFAULT_PATH: []const u8 = "./persist/"; const FileEntry = struct { name: []const u8, ctime: i128, size: usize }; -pub const PersistanceHandler = @This(); +pub const Handler = @This(); allocator: std.mem.Allocator, @@ -33,8 +33,8 @@ pub fn init( config: Config, logger: Logger, path: ?[]const u8, -) !PersistanceHandler { - var persister = PersistanceHandler{ +) !Handler { + var persister = Handler{ .allocator = allocator, .config = config, .deserializer = try Deserializer.init(allocator), @@ -47,11 +47,11 @@ pub fn init( return persister; } -pub fn deinit(self: *PersistanceHandler) void { +pub fn deinit(self: *Handler) void { self.deserializer.deinit(); } -pub fn save(self: *PersistanceHandler, memory: *Memory) !usize { +pub fn save(self: *Handler, memory: *Memory) !usize { var serializer = Serializer.init(self.allocator); defer serializer.deinit(); @@ -110,7 +110,7 @@ pub fn save(self: *PersistanceHandler, memory: *Memory) !usize { } // have to load latest file from `self.path` -pub fn load(self: *PersistanceHandler, memory: *Memory) !void { +pub fn load(self: *Handler, memory: *Memory) !void { var dir = try std.fs.cwd().openDir(self.path.?, .{ .no_follow = true, .access_sub_paths = false, @@ -185,7 +185,7 @@ pub fn load(self: *PersistanceHandler, memory: *Memory) !void { } } -fn get_latest_file(self: *PersistanceHandler, dir: std.fs.Dir) !?FileEntry { +fn get_latest_file(self: *Handler, dir: std.fs.Dir) !?FileEntry { var latest: ?FileEntry = null; var iterator = dir.iterate(); diff --git a/src/tests/fixtures.zig b/src/tests/fixtures.zig index cff96dc..d0a3506 100644 --- a/src/tests/fixtures.zig +++ b/src/tests/fixtures.zig @@ -5,7 +5,7 @@ const Config = @import("../server/config.zig"); const TracingAllocator = @import("../server/tracing.zig"); -const PersistanceHandler = @import("../server/storage/persistance.zig"); +const persistance = @import("../server/storage/persistance.zig"); const Memory = @import("../server/storage/memory.zig"); pub const ContextFixture = struct { @@ -13,7 +13,7 @@ pub const ContextFixture = struct { tracing_allocator: TracingAllocator, logger: Logger, config: Config, - persistance: ?PersistanceHandler, + persistance: ?persistance.Handler, memory: ?Memory, pub fn init() !ContextFixture { @@ -42,7 +42,12 @@ pub const ContextFixture = struct { pub fn create_persistance(self: *ContextFixture) !void { if (self.persistance != null) self.persistance.?.deinit(); - self.persistance = try PersistanceHandler.init(self.allocator, self.config, self.logger, null); + self.persistance = try persistance.Handler.init( + self.allocator, + self.config, + self.logger, + null, + ); } pub fn deinit(self: *ContextFixture) void { diff --git a/src/tests/helper.zig b/src/tests/helper.zig index 3db6ab9..ffb500a 100644 --- a/src/tests/helper.zig +++ b/src/tests/helper.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const PersistanceHandler = @import("../server/storage/persistance.zig"); +const persistance = @import("../server/storage/persistance.zig"); const Memory = @import("../server/storage/memory.zig"); const commands = @import("../server/processing/commands.zig");