Skip to content

Commit

Permalink
refactor(rename): PersistanceHandler to persistance.Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sectasy0 committed May 11, 2024
1 parent b37c9d4 commit 87e2ab7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ pub fn main() void {
};
defer config.deinit();

var persister = persistance.PersistanceHandler.init(
var persister = persistance.Handler.init(
allocator,
config,
logger,
null,
) catch |err| {
logger.log(
.Error,
"# failed to init PersistanceHandler: {?}",
"# failed to init persistance.Handler: {?}",
.{err},
);
return;
Expand Down
1 change: 0 additions & 1 deletion src/server/processing/commands.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/server/storage/memory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -13,7 +13,7 @@ const Memory = @This();
internal: std.StringHashMap(types.ZType),
allocator: std.mem.Allocator,

persister: *PersistanceHandler,
persister: *persistance.Handler,

config: Config,

Expand All @@ -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),
Expand Down
14 changes: 7 additions & 7 deletions src/server/storage/persistance.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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),
Expand All @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 8 additions & 3 deletions src/tests/fixtures.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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 {
allocator: std.mem.Allocator,
tracing_allocator: TracingAllocator,
logger: Logger,
config: Config,
persistance: ?PersistanceHandler,
persistance: ?persistance.Handler,
memory: ?Memory,

pub fn init() !ContextFixture {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/helper.zig
Original file line number Diff line number Diff line change
@@ -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");
Expand Down

0 comments on commit 87e2ab7

Please sign in to comment.