#include<add.h>
-//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) {
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;i<session.torrent_count;i++) {
+ if(add_find_all(session.torrents[i])<0) { return -1; }
+ }
+
+ hashmap_free(add_queue);
+ return -1;
+}
+
+static int add_find_all(struct torrent *p) {
+ log_info(ADD_MESSAGE_ADDING_TORRENT,p->root,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;
}
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) { }