Skip to content

Commit e800cc6

Browse files
committed
Work around Windows stat issue
1 parent 3bb580b commit e800cc6

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/snapshot.zig

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,24 +463,19 @@ fn processPath(gpa: Allocator, path: []const u8, maybe_fuzz_corpus_path: ?[]cons
463463
};
464464
defer gpa.free(canonical_path);
465465

466-
const stat = std.fs.cwd().statFile(canonical_path) catch |err| {
467-
std.log.err("failed to stat path '{s}': {s}", .{ canonical_path, @errorName(err) });
468-
return .{ .success = 0, .failed = 1 };
469-
};
466+
// Try to open as directory first
467+
if (std.fs.cwd().openDir(canonical_path, .{ .iterate = true })) |dir_handle| {
468+
var dir = dir_handle;
469+
defer dir.close();
470470

471-
if (stat.kind == .directory) {
472-
// Check if this is a multi-file snapshot directory
471+
// It's a directory
473472
if (isMultiFileSnapshot(canonical_path)) {
474473
try processMultiFileSnapshot(gpa, canonical_path);
475474
processed_count += 1;
476475
return .{ .success = processed_count, .failed = failed_count };
477476
} else {
478-
var dir = try std.fs.cwd().openDir(path, .{ .iterate = true });
479-
defer dir.close();
480-
481477
var dir_iterator = dir.iterate();
482478
while (try dir_iterator.next()) |entry| {
483-
484479
// Skip hidden files and special directories
485480
if (entry.name[0] == '.') continue;
486481

@@ -501,17 +496,23 @@ fn processPath(gpa: Allocator, path: []const u8, maybe_fuzz_corpus_path: ?[]cons
501496
}
502497
}
503498
}
504-
} else if (stat.kind == .file) {
505-
if (isSnapshotFile(canonical_path)) {
506-
if (try processSnapshotFile(gpa, canonical_path, maybe_fuzz_corpus_path)) {
507-
processed_count += 1;
499+
} else |dir_err| {
500+
// Not a directory, try as file
501+
if (dir_err == error.NotDir) {
502+
if (isSnapshotFile(canonical_path)) {
503+
if (try processSnapshotFile(gpa, canonical_path, maybe_fuzz_corpus_path)) {
504+
processed_count += 1;
505+
} else {
506+
std.log.err("failed to process snapshot file: {s}", .{canonical_path});
507+
std.log.err("make sure the file starts with '~~~META' and has valid snapshot format", .{});
508+
failed_count += 1;
509+
}
508510
} else {
509-
std.log.err("failed to process snapshot file: {s}", .{canonical_path});
510-
std.log.err("make sure the file starts with '~~~META' and has valid snapshot format", .{});
511-
failed_count += 1;
511+
std.log.err("file '{s}' is not a snapshot file (must end with .md)", .{canonical_path});
512512
}
513513
} else {
514-
std.log.err("file '{s}' is not a snapshot file (must end with .md)", .{canonical_path});
514+
std.log.err("failed to access path '{s}': {s}", .{ canonical_path, @errorName(dir_err) });
515+
return .{ .success = 0, .failed = 1 };
515516
}
516517
}
517518

0 commit comments

Comments
 (0)