From 2665f83f7f3db4fbfcfa29f3e8efc1566ec0ab10 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Fri, 19 Jul 2019 15:38:58 +0000 Subject: [PATCH] Add recursive scanning --- erinaco-data.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/erinaco-data.c b/erinaco-data.c index 28d468d..0ccbcef 100644 --- a/erinaco-data.c +++ b/erinaco-data.c @@ -18,6 +18,9 @@ static struct cdb_make cdb; static const char *hostname; +extern void process_directory(const Ustr *); + + int scandir_filter (const struct dirent *entry) { return entry->d_name[0] != '.'; @@ -58,7 +61,26 @@ void process_dirent_regular(Ustr *path, Ustr **gophermap) void process_dirent_directory(const Ustr *path, Ustr **gophermap) { - gophermap_add_entry(gophermap, path, '1'); + Ustr *name; + Ustr *dirname; + + name = ustr_filename(path); + dirname = ustr_dup(path); + ustr_add_cstr(&dirname, "/"); + + ustr_add_cstr(gophermap, "1"); + ustr_add(gophermap, name); + ustr_add_cstr(gophermap, "\t"); + ustr_add_cstr(gophermap, ustr_cstr(path) + 1); + ustr_add_cstr(gophermap, "/\t"); + ustr_add_cstr(gophermap, hostname); + ustr_add_cstr(gophermap, "\t70\r\n"); + + process_directory(dirname); + + ustr_free(name); + ustr_free(dirname); + } void process_dirent(const Ustr *here, const struct dirent *d, Ustr **gophermap) @@ -84,6 +106,7 @@ void process_directory(const Ustr *here) n = scandir(ustr_cstr(here), &entries, &scandir_filter, &alphasort); if (n < 0) { write2("fatal: failed to scan directory\n"); + printf("%s\n", ustr_cstr(here)); exit(1); } -- 2.11.4.GIT