@@ -453,10 +453,35 @@ pub const Server = struct {
fn scanDir(db: *Db, gpa: Allocator, db_dir: Db.Path.Index, it: *std.fs.Dir.Iterator) anyerror!void {
while (try it.next()) |entry| switch (entry.kind) {
.directory, .sym_link => {
const basename = try db.getOrPutString(gpa, entry.name);
var sub_dir = try it.dir.openDir(entry.name, .{ .iterate = true });
.directory => {
var sub_dir = it.dir.openDir(entry.name, .{ .iterate = true }) catch |err| {
std.log.err("while scanning, unable to open directory '{s}': {s}", .{
entry.name, @errorName(err),
});
continue;
};
defer sub_dir.close();
const basename = try db.getOrPutString(gpa, entry.name);
var sub_it = sub_dir.iterateAssumeFirstIteration();
try scanDir(
db,
gpa,
try db.addDirectory(gpa, .{
.parent = db_dir.toOptional(),
.basename = basename,
}),
&sub_it,
);
},
.sym_link => {
var sub_dir = it.dir.openDir(entry.name, .{ .iterate = true }) catch |err| {
std.log.err("while scanning, unable to open symlink '{s}' as a directory: {s}", .{
entry.name, @errorName(err),
});
continue;
};
defer sub_dir.close();
const basename = try db.getOrPutString(gpa, entry.name);
var sub_it = sub_dir.iterateAssumeFirstIteration();
try scanDir(
db,