Skip to content

Commit 07c8a98

Browse files
chrisbbreuerclaude
andcommitted
fix: implement listSnapshots and cleanupUnused with DirIterator
Replace stubbed snapshot cleanup functions with working implementations using compat.DirIterator, fixing test failures on CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b16d692 commit 07c8a98

1 file changed

Lines changed: 33 additions & 8 deletions

File tree

src/snapshot.zig

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,44 @@ pub const SnapshotCleanup = struct {
515515
}
516516

517517
/// Find and remove unused snapshots
518-
/// Note: Directory iteration requires Io in Zig 0.16, stubbed for now
519518
pub fn cleanupUnused(self: *Self) !usize {
520-
_ = self;
521-
// TODO: Re-implement with std.Io.Dir when Io is available
522-
return 0;
519+
var dir = compat.DirIterator.open(self.snapshot_dir) catch return 0;
520+
defer dir.close();
521+
522+
var removed: usize = 0;
523+
while (try dir.next()) |entry| {
524+
if (entry.kind != .file) continue;
525+
if (!std.mem.endsWith(u8, entry.name, ".snap")) continue;
526+
527+
// Check if this snapshot is marked as used
528+
if (!self.used_snapshots.contains(entry.name)) {
529+
// Delete unused snapshot
530+
const full_path = try std.fs.path.join(self.allocator, &.{ self.snapshot_dir, entry.name });
531+
defer self.allocator.free(full_path);
532+
compat.deleteFile(self.allocator, full_path) catch {};
533+
removed += 1;
534+
}
535+
}
536+
return removed;
523537
}
524538

525539
/// List all snapshot files
526-
/// Note: Directory iteration requires Io in Zig 0.16, stubbed for now
527540
pub fn listSnapshots(self: *Self) !std.ArrayList([]const u8) {
528-
_ = self;
529-
// TODO: Re-implement with std.Io.Dir when Io is available
530-
return std.ArrayList([]const u8).empty;
541+
var result = std.ArrayList([]const u8).empty;
542+
errdefer {
543+
for (result.items) |item| self.allocator.free(item);
544+
result.deinit(self.allocator);
545+
}
546+
547+
var dir = compat.DirIterator.open(self.snapshot_dir) catch return result;
548+
defer dir.close();
549+
550+
while (try dir.next()) |entry| {
551+
if (entry.kind != .file) continue;
552+
if (!std.mem.endsWith(u8, entry.name, ".snap")) continue;
553+
try result.append(self.allocator, try self.allocator.dupe(u8, entry.name));
554+
}
555+
return result;
531556
}
532557
};
533558

0 commit comments

Comments
 (0)