From: alex Date: Thu, 9 Sep 2021 02:52:20 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=c6e269ce5179539edb92cbac915cd8e6a40587cb;p=seeder ... --- diff --git a/inc/add.h b/inc/add.h index 3d8e699..d5a4b43 100644 --- a/inc/add.h +++ b/inc/add.h @@ -1,8 +1,15 @@ #ifndef __ADD_H_ #define __ADD_H_ +#include + +#include #include -void *add(void*); +#define ADD_MESSAGE_ADDING_TORRENT "adding all files in %s to torrent named %s\n" + +#define ADD_QUEUE_INITIAL_SIZE 8 + +int add(); #endif diff --git a/inc/main.h b/inc/main.h index b4c82cd..fa04577 100644 --- a/inc/main.h +++ b/inc/main.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/inc/torrent.h b/inc/torrent.h index 855f625..7ca8768 100644 --- a/inc/torrent.h +++ b/inc/torrent.h @@ -16,8 +16,6 @@ struct torrent { struct hash_map *files; }; -extern struct torrent **torrents; - void torrent_free(struct torrent*); int torrent_init(struct torrent**,char*,char*); diff --git a/src/add.c b/src/add.c index 9b43c1d..fbf4a38 100644 --- a/src/add.c +++ b/src/add.c @@ -1,7 +1,7 @@ #include -//pthread_t adding_thread; -//pthread_mutex_t adding_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_t adding_thread; +pthread_mutex_t adding_mutex = PTHREAD_MUTEX_INITIALIZER; //static int setup_adding() { // if(pthread_create(&adding_thread,NULL,&add,NULL)!=0) { @@ -14,6 +14,32 @@ static struct hash_map *add_queue; -void *add(void *p) { - return NULL; +static int add_find_all(); +static int ftw_helper(const char*,const struct stat*,int); + +int add() { + if(hashmap_init(&add_queue,ADD_QUEUE_INITIAL_SIZE)<0) { return -1; } + + for(size_t i=0;iroot,p->name); + + if(ftw(p->root,&ftw_helper,64)<0) { + perror("nftw"); + return -1; + } + + return -1; +} + +static int ftw_helper(const char *path, const struct stat *st, int typeflag) { + log_info("adding %s\n",path); + return 0; } diff --git a/src/main.c b/src/main.c index 204264a..d873c46 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,8 @@ int main(int argc, char **argv) { if(setup()<0) { return EXIT_FAILURE; } + if(add()<0) { return EXIT_FAILURE; } + log_err("this is a test %d %s\n",10,"what?"); while(1) { }