...
authoralex <[email protected]>
Tue, 7 Dec 2021 07:04:00 +0000 (23:04 -0800)
committeralex <[email protected]>
Tue, 7 Dec 2021 07:04:00 +0000 (23:04 -0800)
src/torrent/add.c

index 6b80dd173da9d041056b041d17dcadf98da124bf..ce012c8e09253e1acc2b5a69de5b48d8c3835816 100644 (file)
@@ -77,14 +77,13 @@ static int torrent_files_resize(struct torrent *torrent_p, size_t new_size) {
        for(size_t i=0;i<torrent_p->files->size;i++) {
                p = torrent_p->files->map[i];
                if(p!=NULL) {
-                       if(
-                               ((ret = torrent_add_file_by_root(new,p))<=0) ||
-                               ((ret = torrent_add_file_by_path(new,p))<=0)
-                               ) {
+                       if((ret = torrent_add_file_by_root(new,p))<=0) {
                                if(ret<0) { return -1; }
-                               hashmap_clear(new);
-                               hashmap_free(new);
-                               return torrent_files_resize(torrent_p,new_size<<1);
+                               goto resize;
+                       }
+
+                       if(ret==0) {
+                               if((ret = torrent_add_file_by_path(new,p))<=0) { goto resize; }
                        }
                }
        }
@@ -97,4 +96,9 @@ static int torrent_files_resize(struct torrent *torrent_p, size_t new_size) {
        hashmap_free(old);
 
        return 1;
+resize:
+       if(ret<0) { return -1; }
+       hashmap_clear(new);
+       hashmap_free(new);
+       return torrent_files_resize(torrent_p,new_size<<1);
 }