int watch_fd;
};
-int torrent_add(struct torrent*,const char*,struct file*);
+int torrent_add(struct torrent*,struct file*);
void torrent_free(struct torrent*);
int torrent_init(struct torrent**,const char*,const char*);
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) {
if(file_init(&to_add,path)<0) { return -1; }
if(add_to_queue(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; }
+ if(torrent_add(current_torrent,to_add)<0) { return -1; }
return 0;
}
static int torrent_add_file(struct torrent *p, struct file *f);
-int torrent_add(struct torrent *p, const char *path, struct file *f) {
+int torrent_add(struct torrent *p, struct file *f) {
+ const char *path;
+
if(NULL==p) { return -1; }
if(NULL==f) { return -1; }
- if(NULL==path) { return -1; }
+
+ path = strstr(f->path,p->root);
+ if((path!=NULL)&&(path==f->path)) {
+ path += strlen(p->root);
+ } else {
+ path = f->path;
+ }
if(tree_add(p->tree,path,f)<0) { return -1; }
if(torrent_add_file(p,f)<0) { return -1; }
assert(torrent_add(torrent,file3)==1);
assert(torrent_add(torrent,file4)==1);
- assert(strcmp(torrent->tree->directories->name,TEST_DIRECTORY)==0);
- assert(torrent->tree->directories->files->file==file3);
- assert(torrent->tree->directories->files->next->file==file4);
- assert(torrent->tree->directories->files->next->next->file==file1);
- assert(torrent->tree->directories->files->next->next->next->file==file2);
+ assert(NULL==torrent->tree->directories);
+ assert(torrent->tree->files->file==file3);
+ assert(torrent->tree->files->next->file==file4);
+ assert(torrent->tree->files->next->next->file==file1);
+ assert(torrent->tree->files->next->next->next->file==file2);
torrent_free(torrent);
nope->directories = helloo;
helloo->files = entry3;
- assert(-1==tree_add(NULL,NULL));
- assert(-1==tree_add(tree,NULL));
+ assert(-1==tree_add(NULL,NULL,NULL));
+ assert(-1==tree_add(tree,NULL,NULL));
+ assert(-1==tree_add(tree,"test path",NULL));
- assert(1==tree_add(tree,file1));
- assert(1==tree_add(tree,file1));
- assert(1==tree_add(tree,file2));
- assert(1==tree_add(tree,file3));
- assert(1==tree_add(tree,file4));
+ assert(1==tree_add(tree,file1->path,file1));
+ assert(1==tree_add(tree,file1->path,file1));
+ assert(1==tree_add(tree,file2->path,file2));
+ assert(1==tree_add(tree,file3->path,file3));
+ assert(1==tree_add(tree,file4->path,file4));
assert(NULL==tree->name);
assert(NULL==tree->files);
for(int i=0;i<100;i++) {
char *path = create_random_path();
assert(1==file_init(&file,path));
- assert(1==tree_add(tree,file));
+ assert(1==tree_add(tree,path,file));
free(path);
}