From: alex Date: Thu, 25 Nov 2021 21:21:21 +0000 (-0800) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=a23d3d5f3bf3d6fad743b5e6e6613d1e4350e822;p=seeder ... --- diff --git a/inc/torrent.h b/inc/torrent.h index 2befb2e..0bf6e4a 100644 --- a/inc/torrent.h +++ b/inc/torrent.h @@ -17,7 +17,7 @@ struct torrent { int watch_fd; }; -int torrent_add(struct torrent*,struct file*); +int torrent_add(struct torrent*,const char*,struct file*); void torrent_free(struct torrent*); int torrent_init(struct torrent**,const char*,const char*); diff --git a/inc/tree.h b/inc/tree.h index 005a491..7f74d84 100644 --- a/inc/tree.h +++ b/inc/tree.h @@ -18,7 +18,7 @@ struct tree { int watch_fd; }; -int tree_add(struct tree*,struct file*); +int tree_add(struct tree*,const char*,struct file*); void tree_entry_free(struct tree_entry*); int tree_entry_init(struct tree_entry**, struct file*); void tree_free(struct tree*); diff --git a/src/add.c b/src/add.c index 8990296..450768f 100644 --- a/src/add.c +++ b/src/add.c @@ -40,16 +40,16 @@ int add() { return 1; } -static struct file *get_next() { - struct file *p; - while(add_queue_indexsize) { - p = add_queue->map[add_queue_index]; - add_queue_index++; +static int add_find_all(struct torrent *p) { + log_info(ADD_MESSAGE_ADDING_TORRENT,p->root,p->name); + current_torrent = p; - if(p!=NULL) { return p; } + if(ftw(p->root,&ftw_helper,64)<0) { + perror("ftw"); + return -1; } - return NULL; + return 1; } static void *add_hash(void *unused) { @@ -74,19 +74,6 @@ static void *add_hash(void *unused) { return NULL; } - -static int add_find_all(struct torrent *p) { - log_info(ADD_MESSAGE_ADDING_TORRENT,p->root,p->name); - current_torrent = p; - - if(ftw(p->root,&ftw_helper,64)<0) { - perror("ftw"); - return -1; - } - - return 1; -} - static int add_queue_resize(size_t new_size) { struct file *p; struct hash_map *new, *old; @@ -139,6 +126,7 @@ static int add_to_queue(struct file *to_add) { static int ftw_helper(const char *path, const struct stat *st, int typeflag) { struct file *to_add; + const char *p; if(typeflag!=FTW_F) { return 0; } switch(global_options.file_filter) { @@ -151,10 +139,28 @@ static int ftw_helper(const char *path, const struct stat *st, int typeflag) { } if(file_init(&to_add,path)<0) { return -1; } - if(add_to_queue(to_add)<0) { return -1; } - if(torrent_add(current_torrent,to_add)<0) { return -1; } + p = strstr(path,current_torrent->root); + if((p!=NULL)&&(p==path)) { + p += strlen(current_torrent->root); + } else { + p = path; + } + + if(torrent_add(current_torrent,p,to_add)<0) { return -1; } return 0; } + +static struct file *get_next() { + struct file *p; + while(add_queue_indexsize) { + p = add_queue->map[add_queue_index]; + add_queue_index++; + + if(p!=NULL) { return p; } + } + + return NULL; +} diff --git a/src/torrent.c b/src/torrent.c index a53de68..c9f6d64 100644 --- a/src/torrent.c +++ b/src/torrent.c @@ -1,14 +1,13 @@ #include -struct torrent **torrents; - static int torrent_add_file(struct torrent *p, struct file *f); -int torrent_add(struct torrent *p, struct file *f) { +int torrent_add(struct torrent *p, const char *path, struct file *f) { if(NULL==p) { return -1; } if(NULL==f) { return -1; } + if(NULL==path) { return -1; } - if(tree_add(p->tree,f)<0) { return -1; } + if(tree_add(p->tree,path,f)<0) { return -1; } if(torrent_add_file(p,f)<0) { return -1; } return 1; diff --git a/src/tree.c b/src/tree.c index 6aacd62..6960780 100644 --- a/src/tree.c +++ b/src/tree.c @@ -3,16 +3,17 @@ static struct tree* tree_add_directory(struct tree*,const char*); static int tree_add_file(struct tree*,struct file*); -int tree_add(struct tree *root, struct file *to_add) { +int tree_add(struct tree *root, const char *path, struct file *to_add) { char *str, *p, *prev; struct tree *tree; if(NULL==root) { return -1; } if(NULL==to_add) { return -1; } + if((NULL==path)||(strlen(path)<=0)) { return -1; } tree = root; - str = strdup(to_add->path); + str = strdup(path); if(NULL==str) { return -1; } prev = NULL;