From aca1e7240f618b4d84b2f5d2dfe200f9047f6c9f Mon Sep 17 00:00:00 2001 From: Fredric N Date: Thu, 22 Apr 2010 21:40:38 +0200 Subject: [PATCH] Crawler prototype --- test/dir_scan.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/dir_scan.c diff --git a/test/dir_scan.c b/test/dir_scan.c new file mode 100644 index 0000000..781164f --- /dev/null +++ b/test/dir_scan.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + time_t timer1, timer2; + int count = 0; + int output = 0; + double avg; + char *sep; + char *base; + char *path[] = {argv[1], NULL}; + FTS *tree; + FTSENT *ent; + + + if(atoi(argv[2]) == 1) { + output = 1; + printf("%s\n", argv[2]); + } + + timer1 = time (NULL); + + tree = fts_open(path, FTS_PHYSICAL | FTS_NOSTAT, NULL); + + while ( ent = fts_read(tree) ) + { + if (ent->fts_info != FTS_DP) + { + if(output){ + + base = malloc( strlen(ent->fts_path) - strlen(ent->fts_name) ); + sep = strrchr(ent->fts_path,'/'); + memcpy (base, ent->fts_path, (sep - ent->fts_path) ); + base[(sep - ent->fts_path)] = '\0'; + + printf("Got: %s %s %i\n", base, ent->fts_name, ent->fts_level); + + free(base); + + } + + count++; + } + } + + fts_close(tree); + + timer2 = time (NULL); + printf("Found: %i\n", count); + printf("Start: %ld\n", timer1); + printf("End: %ld\n", timer2); + printf("Diff: %ld\n", timer2-timer1); + if((timer2-timer1) > 0) { + avg = count / (timer2-timer1); + printf("Node/sec: %f\n", avg); + }else{ + printf("Node/sec: inst.\n"); + } + + return 0; +}