Skip to content

Commit a9c5a7a

Browse files
committed
fix(logger): convert mtime from nanoseconds to seconds in cleanup
The cleanup function was comparing stat.mtime (nanoseconds) with cutoff_timestamp (seconds), causing files to be incorrectly deleted. Fixed by using @divFloor(stat.mtime, std.time.ns_per_s) for proper unit conversion in all three cleanup locations. Signed-off-by: leocavalcante <[email protected]>
1 parent 59234bc commit a9c5a7a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/logger.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ pub const Logger = struct {
121121
defer file.close();
122122

123123
const stat = try file.stat();
124-
const mtime = stat.mtime;
124+
const mtime_secs = @divFloor(stat.mtime, std.time.ns_per_s);
125125

126-
if (mtime < cutoff_timestamp) {
126+
if (mtime_secs < cutoff_timestamp) {
127127
dir.deleteFile(path) catch {};
128128
}
129129
}
@@ -154,9 +154,9 @@ pub const Logger = struct {
154154
defer file.close();
155155

156156
const stat = try file.stat();
157-
const mtime = stat.mtime;
157+
const mtime_secs = @divFloor(stat.mtime, std.time.ns_per_s);
158158

159-
if (mtime < cutoff_timestamp) {
159+
if (mtime_secs < cutoff_timestamp) {
160160
dir.deleteFile(path) catch {};
161161
}
162162
}
@@ -182,9 +182,9 @@ pub const Logger = struct {
182182
defer file.close();
183183

184184
const stat = try file.stat();
185-
const mtime = stat.mtime;
185+
const mtime_secs = @divFloor(stat.mtime, std.time.ns_per_s);
186186

187-
if (mtime < cutoff_timestamp) {
187+
if (mtime_secs < cutoff_timestamp) {
188188
dir.deleteFile(path) catch {};
189189
}
190190
}

0 commit comments

Comments
 (0)