From 99ff6a0bf6b19b6a370f6f4586194860f6254def Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Fri, 22 Jan 2021 11:24:08 -0500 Subject: [PATCH 01/13] Add exclude command line option. Excludes files based on a glob string --- ftw.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++------------ init.c | 15 ++++++++++++-- main.c | 1 + 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/ftw.c b/ftw.c index 97bad71..1880fb1 100644 --- a/ftw.c +++ b/ftw.c @@ -26,10 +26,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include #include #include +#include +#include #include "export.h" #include "mktorrent.h" /* DIRSEP_CHAR */ #include "ftw.h" +#include "msg.h" struct dir_state { @@ -108,7 +111,7 @@ static unsigned int dir_state_close(struct dir_state *ds) return 0; } -static unsigned int cleanup(struct dir_state *ds, char *path, int ret) +static unsigned int cleanup(struct dir_state *ds, char *path, struct ll *exclude_list, int ret) { while (ds->prev) ds = ds->prev; @@ -122,6 +125,9 @@ static unsigned int cleanup(struct dir_state *ds, char *path, int ret) if (path) free(path); + if( exclude_list ) + ll_free(exclude_list, NULL); + return ret; } @@ -135,6 +141,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, struct dir_state *ds = dir_state_new(NULL, NULL); struct dir_state *first_open; unsigned int nopen; + struct metafile *m = data; if (ds == NULL) return -1; @@ -142,7 +149,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, path = malloc(path_size); if (path == NULL) { fprintf(stderr, "fatal error: out of memory\n"); - return cleanup(ds, NULL, -1); + return cleanup(ds, NULL, NULL, -1); } path_max = path + path_size; @@ -157,7 +164,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, new_path = realloc(path, 2*path_size); if (new_path == NULL) { fprintf(stderr, "fatal error: out of memory\n"); - return cleanup(ds, path, -1); + return cleanup(ds, path, NULL, -1); } end = new_path + path_size; path_size *= 2; @@ -173,13 +180,29 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, } if (dir_state_open(ds, path, end - path)) - return cleanup(ds, path, -1); + return cleanup(ds, path, NULL, -1); first_open = ds; nopen = 1; *end = DIRSEP_CHAR; + struct ll *exclude_file_list = ll_new(); + FATAL_IF0(exclude_file_list == NULL, "out of memory\n"); + + LL_FOR(tier_node, m->exclude_list) { + LL_FOR(exclude_node, LL_DATA_AS(tier_node, struct ll*)) { + const char *exclude_glob = LL_DATA_AS(exclude_node, const char*); + glob_t globbuf; + + if( glob(exclude_glob, 0, NULL, &globbuf) == 0 ) { + for(size_t i=0; idir); @@ -194,6 +217,19 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, && de->d_name[2] == '\0'))) { continue; } + + bool should_skip = false; + LL_FOR(exclude_file_node, exclude_file_list) { + const char *exclude_file = LL_DATA_AS(exclude_file_node, const char*); + if(strncmp(de->d_name, exclude_file, strlen(exclude_file)) == 0 ) { + if(m->verbose) + printf("skipping %s\n", de->d_name); + should_skip = true; + } + } + + if(should_skip) + continue; end = path + ds->length + 1; p = de->d_name; @@ -206,7 +242,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, new_path = realloc(path, 2*path_size); if (new_path == NULL) { fprintf(stderr, "fatal error: out of memory\n"); - return cleanup(ds, path, -1); + return cleanup(ds, path, exclude_file_list, -1); } end = new_path + path_size; path_size *= 2; @@ -218,29 +254,29 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, if (stat(path, &sbuf)) { fprintf(stderr, "fatal error: cannot stat '%s': %s\n", path, strerror(errno)); - return cleanup(ds, path, -1); + return cleanup(ds, path, exclude_file_list, -1); } r = callback(path, &sbuf, data); if (r) - return cleanup(ds, path, r); + return cleanup(ds, path, exclude_file_list, r); if (S_ISDIR(sbuf.st_mode)) { if (ds->next == NULL && (ds->next = dir_state_new(ds, NULL)) == NULL) - return cleanup(ds, path, -1); + return cleanup(ds, path, exclude_file_list, -1); ds = ds->next; if (nopen == nfds) { if (dir_state_close(first_open)) - return cleanup(ds, path, -1); + return cleanup(ds, path, exclude_file_list, -1); first_open = first_open->next; nopen--; } if (dir_state_open(ds, path, end - path)) - return cleanup(ds, path, -1); + return cleanup(ds, path, exclude_file_list, -1); nopen++; @@ -251,7 +287,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, path[ds->length] = '\0'; fprintf(stderr, "fatal error: cannot close '%s': %s\n", path, strerror(errno)); - return cleanup(ds, path, -1); + return cleanup(ds, path, exclude_file_list, -1); } if (ds->prev == NULL) @@ -262,12 +298,12 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, if (ds->dir == NULL) { if (dir_state_reopen(ds, path)) - return cleanup(ds, path, -1); + return cleanup(ds, path, exclude_file_list, -1); first_open = ds; nopen++; } } } - return cleanup(ds, path, 0); + return cleanup(ds, path, exclude_file_list, 0); } diff --git a/init.c b/init.c index f8e1ece..822400b 100644 --- a/init.c +++ b/init.c @@ -280,6 +280,7 @@ static void print_help() " additional -a adds backup trackers\n" "-c : add a comment to the metainfo\n" "-d : don't write the creation date\n" + "-e : exclude file based on glob\n" "-f : overwrite output file if it exists\n" "-h : show this help screen\n" "-l : set the piece length to 2^n bytes,\n" @@ -455,11 +456,14 @@ EXPORT void init(struct metafile *m, int argc, char *argv[]) m->file_list = ll_new(); FATAL_IF0(m->file_list == NULL, "out of memory\n"); + m->exclude_list = ll_new(); + FATAL_IF0(m->exclude_list == NULL, "out of memory\n"); + /* now parse the command line options given */ #ifdef USE_PTHREADS -#define OPT_STRING "a:c:dfhl:n:o:ps:t:vw:x" +#define OPT_STRING "a:c:e:dfhl:n:o:ps:t:vw:x" #else -#define OPT_STRING "a:c:dfhl:n:o:ps:vw:x" +#define OPT_STRING "a:c:e:dfhl:n:o:ps:vw:x" #endif #ifdef USE_LONG_OPTIONS while ((c = getopt_long(argc, argv, OPT_STRING, @@ -480,6 +484,11 @@ EXPORT void init(struct metafile *m, int argc, char *argv[]) case 'd': m->no_creation_date = 1; break; + case 'e': + FATAL_IF0( + ll_append(m->exclude_list, get_slist(optarg), 0) == NULL, + "out of memory\n"); + break; case 'f': m->force_overwrite = 1; break; @@ -604,5 +613,7 @@ EXPORT void cleanup_metafile(struct metafile *m) ll_free(m->web_seed_list, NULL); + ll_free(m->exclude_list, free_inner_list); + free(m->metainfo_file_path); } diff --git a/main.c b/main.c index 48a6943..79dd5d9 100644 --- a/main.c +++ b/main.c @@ -125,6 +125,7 @@ int main(int argc, char *argv[]) 0, /* cross_seed */ 0, /* verbose */ 0, /* force_overwrite */ + NULL, /* exclude_list */ #ifdef USE_PTHREADS 0, /* threads, initialised by init() */ #endif From e13966e5c9527552c06ba240ed6f69b478ec5195 Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sat, 23 Jan 2021 14:01:08 -0500 Subject: [PATCH 02/13] Forgot to include mktorrent.h --- mktorrent.h | 1 + 1 file changed, 1 insertion(+) diff --git a/mktorrent.h b/mktorrent.h index b5ae7cf..2ce3393 100644 --- a/mktorrent.h +++ b/mktorrent.h @@ -48,6 +48,7 @@ struct metafile { int cross_seed; /* ensure info hash is unique for easier cross-seeding */ int verbose; /* be verbose */ int force_overwrite; /* overwrite existing output file */ + struct ll *exclude_list; /* exclude list */ #ifdef USE_PTHREADS long threads; /* number of threads used for hashing */ #endif From c1fd45b6619706834b832a1f524033bb59c5ce65 Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sat, 23 Jan 2021 14:15:34 -0500 Subject: [PATCH 03/13] Re-wrote exclude to use fnmatch instead of glob --- ftw.c | 63 ++++++++++++++++++++++------------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/ftw.c b/ftw.c index 1880fb1..e65d289 100644 --- a/ftw.c +++ b/ftw.c @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include #include #include -#include +#include #include "export.h" #include "mktorrent.h" /* DIRSEP_CHAR */ @@ -111,7 +111,7 @@ static unsigned int dir_state_close(struct dir_state *ds) return 0; } -static unsigned int cleanup(struct dir_state *ds, char *path, struct ll *exclude_list, int ret) +static unsigned int cleanup(struct dir_state *ds, char *path, int ret) { while (ds->prev) ds = ds->prev; @@ -125,9 +125,6 @@ static unsigned int cleanup(struct dir_state *ds, char *path, struct ll *exclude if (path) free(path); - if( exclude_list ) - ll_free(exclude_list, NULL); - return ret; } @@ -149,7 +146,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, path = malloc(path_size); if (path == NULL) { fprintf(stderr, "fatal error: out of memory\n"); - return cleanup(ds, NULL, NULL, -1); + return cleanup(ds, NULL, -1); } path_max = path + path_size; @@ -164,7 +161,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, new_path = realloc(path, 2*path_size); if (new_path == NULL) { fprintf(stderr, "fatal error: out of memory\n"); - return cleanup(ds, path, NULL, -1); + return cleanup(ds, path, -1); } end = new_path + path_size; path_size *= 2; @@ -180,29 +177,13 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, } if (dir_state_open(ds, path, end - path)) - return cleanup(ds, path, NULL, -1); + return cleanup(ds, path, -1); first_open = ds; nopen = 1; *end = DIRSEP_CHAR; - struct ll *exclude_file_list = ll_new(); - FATAL_IF0(exclude_file_list == NULL, "out of memory\n"); - - LL_FOR(tier_node, m->exclude_list) { - LL_FOR(exclude_node, LL_DATA_AS(tier_node, struct ll*)) { - const char *exclude_glob = LL_DATA_AS(exclude_node, const char*); - glob_t globbuf; - - if( glob(exclude_glob, 0, NULL, &globbuf) == 0 ) { - for(size_t i=0; idir); @@ -217,14 +198,16 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, && de->d_name[2] == '\0'))) { continue; } - + bool should_skip = false; - LL_FOR(exclude_file_node, exclude_file_list) { - const char *exclude_file = LL_DATA_AS(exclude_file_node, const char*); - if(strncmp(de->d_name, exclude_file, strlen(exclude_file)) == 0 ) { - if(m->verbose) - printf("skipping %s\n", de->d_name); - should_skip = true; + LL_FOR(tier_node, m->exclude_list) { + LL_FOR(exclude_node, LL_DATA_AS(tier_node, struct ll*)) { + const char *exclude_pattern = LL_DATA_AS(exclude_node, const char*); + if (fnmatch(exclude_pattern, de->d_name, 0) != FNM_NOMATCH) { + if (m->verbose) + printf("skipping %s\n", de->d_name); + should_skip = true; + } } } @@ -242,7 +225,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, new_path = realloc(path, 2*path_size); if (new_path == NULL) { fprintf(stderr, "fatal error: out of memory\n"); - return cleanup(ds, path, exclude_file_list, -1); + return cleanup(ds, path, -1); } end = new_path + path_size; path_size *= 2; @@ -254,29 +237,29 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, if (stat(path, &sbuf)) { fprintf(stderr, "fatal error: cannot stat '%s': %s\n", path, strerror(errno)); - return cleanup(ds, path, exclude_file_list, -1); + return cleanup(ds, path, -1); } r = callback(path, &sbuf, data); if (r) - return cleanup(ds, path, exclude_file_list, r); + return cleanup(ds, path, r); if (S_ISDIR(sbuf.st_mode)) { if (ds->next == NULL && (ds->next = dir_state_new(ds, NULL)) == NULL) - return cleanup(ds, path, exclude_file_list, -1); + return cleanup(ds, path, -1); ds = ds->next; if (nopen == nfds) { if (dir_state_close(first_open)) - return cleanup(ds, path, exclude_file_list, -1); + return cleanup(ds, path, -1); first_open = first_open->next; nopen--; } if (dir_state_open(ds, path, end - path)) - return cleanup(ds, path, exclude_file_list, -1); + return cleanup(ds, path, -1); nopen++; @@ -287,7 +270,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, path[ds->length] = '\0'; fprintf(stderr, "fatal error: cannot close '%s': %s\n", path, strerror(errno)); - return cleanup(ds, path, exclude_file_list, -1); + return cleanup(ds, path, -1); } if (ds->prev == NULL) @@ -298,12 +281,12 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, if (ds->dir == NULL) { if (dir_state_reopen(ds, path)) - return cleanup(ds, path, exclude_file_list, -1); + return cleanup(ds, path, -1); first_open = ds; nopen++; } } } - return cleanup(ds, path, exclude_file_list, 0); + return cleanup(ds, path, 0); } From cba0e1d1410667d34b87e6706f6dd0e5d761c745 Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sat, 23 Jan 2021 14:43:30 -0500 Subject: [PATCH 04/13] Added long option for exclude --- init.c | 86 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/init.c b/init.c index 822400b..1263dc5 100644 --- a/init.c +++ b/init.c @@ -253,52 +253,55 @@ static void print_help() "Usage: mktorrent [OPTIONS] \n\n" "Options:\n" #ifdef USE_LONG_OPTIONS - "-a, --announce=[,]* : specify the full announce URLs\n" - " additional -a adds backup trackers\n" - "-c, --comment= : add a comment to the metainfo\n" - "-d, --no-date : don't write the creation date\n" - "-f, --force : overwrite output file if it exists\n" - "-h, --help : show this help screen\n" - "-l, --piece-length= : set the piece length to 2^n bytes,\n" - " default is calculated from the total size\n" - "-n, --name= : set the name of the torrent\n" - " default is the basename of the target\n" - "-o, --output= : set the path and filename of the created file\n" - " default is .torrent\n" - "-p, --private : set the private flag\n" - "-s, --source= : add source string embedded in infohash\n" + "-a, --announce=[,]* : specify the full announce URLs\n" + " additional -a adds backup trackers\n" + "-c, --comment= : add a comment to the metainfo\n" + "-d, --no-date : don't write the creation date\n" + "-e, --exclude=[,]* : exclude files based on filename pattern\n" + " matching, see fnmatch man page\n" + "-f, --force : overwrite output file if it exists\n" + "-h, --help : show this help screen\n" + "-l, --piece-length= : set the piece length to 2^n bytes,\n" + " default is calculated from the total size\n" + "-n, --name= : set the name of the torrent\n" + " default is the basename of the target\n" + "-o, --output= : set the path and filename of the created file\n" + " default is .torrent\n" + "-p, --private : set the private flag\n" + "-s, --source= : add source string embedded in infohash\n" #ifdef USE_PTHREADS - "-t, --threads= : use threads for calculating hashes\n" - " default is the number of CPU cores\n" + "-t, --threads= : use threads for calculating hashes\n" + " default is the number of CPU cores\n" #endif - "-v, --verbose : be verbose\n" - "-w, --web-seed=[,]* : add web seed URLs\n" - " additional -w adds more URLs\n" - "-x, --cross-seed : ensure info hash is unique for easier cross-seeding\n" + "-v, --verbose : be verbose\n" + "-w, --web-seed=[,]* : add web seed URLs\n" + " additional -w adds more URLs\n" + "-x, --cross-seed : ensure info hash is unique for easier cross-seeding\n" #else - "-a [,]* : specify the full announce URLs\n" - " additional -a adds backup trackers\n" - "-c : add a comment to the metainfo\n" - "-d : don't write the creation date\n" - "-e : exclude file based on glob\n" - "-f : overwrite output file if it exists\n" - "-h : show this help screen\n" - "-l : set the piece length to 2^n bytes,\n" - " default is calculated from the total size\n" - "-n : set the name of the torrent,\n" - " default is the basename of the target\n" - "-o : set the path and filename of the created file\n" - " default is .torrent\n" - "-p : set the private flag\n" - "-s : add source string embedded in infohash\n" + "-a [,]* : specify the full announce URLs\n" + " additional -a adds backup trackers\n" + "-c : add a comment to the metainfo\n" + "-d : don't write the creation date\n" + "-e [,]* : exclude files based on filename pattern\n" + " matching, see fnmatch man page\n" + "-f : overwrite output file if it exists\n" + "-h : show this help screen\n" + "-l : set the piece length to 2^n bytes,\n" + " default is calculated from the total size\n" + "-n : set the name of the torrent,\n" + " default is the basename of the target\n" + "-o : set the path and filename of the created file\n" + " default is .torrent\n" + "-p : set the private flag\n" + "-s : add source string embedded in infohash\n" #ifdef USE_PTHREADS - "-t : use threads for calculating hashes\n" - " default is the number of CPU cores\n" + "-t : use threads for calculating hashes\n" + " default is the number of CPU cores\n" #endif - "-v : be verbose\n" - "-w [,]* : add web seed URLs\n" - " additional -w adds more URLs\n" - "-x : ensure info hash is unique for easier cross-seeding\n" + "-v : be verbose\n" + "-w [,]* : add web seed URLs\n" + " additional -w adds more URLs\n" + "-x : ensure info hash is unique for easier cross-seeding\n" #endif "\nPlease send bug reports, patches, feature requests, praise and\n" "general gossip about the program to: mktorrent@rudde.org\n"); @@ -430,6 +433,7 @@ EXPORT void init(struct metafile *m, int argc, char *argv[]) {"announce", 1, NULL, 'a'}, {"comment", 1, NULL, 'c'}, {"no-date", 0, NULL, 'd'}, + {"exclude", 1, NULL, 'e'}, {"force", 0, NULL, 'f'}, {"help", 0, NULL, 'h'}, {"piece-length", 1, NULL, 'l'}, From bc2b463f8abc418422429f5cbebe9977ba21fdcc Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sat, 23 Jan 2021 16:53:20 -0500 Subject: [PATCH 05/13] Remove whitespace --- ftw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftw.c b/ftw.c index e65d289..6e34a37 100644 --- a/ftw.c +++ b/ftw.c @@ -198,7 +198,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, && de->d_name[2] == '\0'))) { continue; } - + bool should_skip = false; LL_FOR(tier_node, m->exclude_list) { LL_FOR(exclude_node, LL_DATA_AS(tier_node, struct ll*)) { From 8c0e0c4bae65a7bbcb153d5992426be738dd9cb1 Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sat, 23 Jan 2021 17:05:37 -0500 Subject: [PATCH 06/13] Removed the need for a double-linked list --- ftw.c | 21 ++++++++++----------- init.c | 6 ++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/ftw.c b/ftw.c index 6e34a37..6531c5f 100644 --- a/ftw.c +++ b/ftw.c @@ -200,20 +200,19 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, } bool should_skip = false; - LL_FOR(tier_node, m->exclude_list) { - LL_FOR(exclude_node, LL_DATA_AS(tier_node, struct ll*)) { - const char *exclude_pattern = LL_DATA_AS(exclude_node, const char*); - if (fnmatch(exclude_pattern, de->d_name, 0) != FNM_NOMATCH) { - if (m->verbose) - printf("skipping %s\n", de->d_name); - should_skip = true; - } + LL_FOR(exclude_node, m->exclude_list) { + const char *exclude_pattern = LL_DATA(exclude_node); + if (fnmatch(exclude_pattern, de->d_name, 0) != FNM_NOMATCH) { + if (m->verbose) + printf("skipping %s\n", de->d_name); + should_skip = true; + break; } } - - if(should_skip) + + if (should_skip) continue; - + end = path + ds->length + 1; p = de->d_name; while ((*end = *p)) { diff --git a/init.c b/init.c index 1263dc5..d242951 100644 --- a/init.c +++ b/init.c @@ -489,9 +489,7 @@ EXPORT void init(struct metafile *m, int argc, char *argv[]) m->no_creation_date = 1; break; case 'e': - FATAL_IF0( - ll_append(m->exclude_list, get_slist(optarg), 0) == NULL, - "out of memory\n"); + ll_extend(m->exclude_list, get_slist(optarg)); break; case 'f': m->force_overwrite = 1; @@ -617,7 +615,7 @@ EXPORT void cleanup_metafile(struct metafile *m) ll_free(m->web_seed_list, NULL); - ll_free(m->exclude_list, free_inner_list); + ll_free(m->exclude_list, NULL); free(m->metainfo_file_path); } From 2bf86395e87557f283bb0ba274d1346df953bcea Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sat, 23 Jan 2021 17:10:53 -0500 Subject: [PATCH 07/13] Updated help messages --- init.c | 88 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/init.c b/init.c index d242951..1ed862f 100644 --- a/init.c +++ b/init.c @@ -253,55 +253,55 @@ static void print_help() "Usage: mktorrent [OPTIONS] \n\n" "Options:\n" #ifdef USE_LONG_OPTIONS - "-a, --announce=[,]* : specify the full announce URLs\n" - " additional -a adds backup trackers\n" - "-c, --comment= : add a comment to the metainfo\n" - "-d, --no-date : don't write the creation date\n" - "-e, --exclude=[,]* : exclude files based on filename pattern\n" - " matching, see fnmatch man page\n" - "-f, --force : overwrite output file if it exists\n" - "-h, --help : show this help screen\n" - "-l, --piece-length= : set the piece length to 2^n bytes,\n" - " default is calculated from the total size\n" - "-n, --name= : set the name of the torrent\n" - " default is the basename of the target\n" - "-o, --output= : set the path and filename of the created file\n" - " default is .torrent\n" - "-p, --private : set the private flag\n" - "-s, --source= : add source string embedded in infohash\n" + "-a, --announce=[,]* : specify the full announce URLs\n" + " additional -a adds backup trackers\n" + "-c, --comment= : add a comment to the metainfo\n" + "-d, --no-date : don't write the creation date\n" + "-e, --exclude=[,

]* : exclude files whose name matches the pattern

\n" + " see the man page glob(7)\n" + "-f, --force : overwrite output file if it exists\n" + "-h, --help : show this help screen\n" + "-l, --piece-length= : set the piece length to 2^n bytes,\n" + " default is calculated from the total size\n" + "-n, --name= : set the name of the torrent\n" + " default is the basename of the target\n" + "-o, --output= : set the path and filename of the created file\n" + " default is .torrent\n" + "-p, --private : set the private flag\n" + "-s, --source= : add source string embedded in infohash\n" #ifdef USE_PTHREADS - "-t, --threads= : use threads for calculating hashes\n" - " default is the number of CPU cores\n" + "-t, --threads= : use threads for calculating hashes\n" + " default is the number of CPU cores\n" #endif - "-v, --verbose : be verbose\n" - "-w, --web-seed=[,]* : add web seed URLs\n" - " additional -w adds more URLs\n" - "-x, --cross-seed : ensure info hash is unique for easier cross-seeding\n" + "-v, --verbose : be verbose\n" + "-w, --web-seed=[,]* : add web seed URLs\n" + " additional -w adds more URLs\n" + "-x, --cross-seed : ensure info hash is unique for easier cross-seeding\n" #else - "-a [,]* : specify the full announce URLs\n" - " additional -a adds backup trackers\n" - "-c : add a comment to the metainfo\n" - "-d : don't write the creation date\n" - "-e [,]* : exclude files based on filename pattern\n" - " matching, see fnmatch man page\n" - "-f : overwrite output file if it exists\n" - "-h : show this help screen\n" - "-l : set the piece length to 2^n bytes,\n" - " default is calculated from the total size\n" - "-n : set the name of the torrent,\n" - " default is the basename of the target\n" - "-o : set the path and filename of the created file\n" - " default is .torrent\n" - "-p : set the private flag\n" - "-s : add source string embedded in infohash\n" + "-a [,]* : specify the full announce URLs\n" + " additional -a adds backup trackers\n" + "-c : add a comment to the metainfo\n" + "-d : don't write the creation date\n" + "-e : exclude files whose name matches the pattern

\n" + " see the man page glob(7)\n" + "-f : overwrite output file if it exists\n" + "-h : show this help screen\n" + "-l : set the piece length to 2^n bytes,\n" + " default is calculated from the total size\n" + "-n : set the name of the torrent,\n" + " default is the basename of the target\n" + "-o : set the path and filename of the created file\n" + " default is .torrent\n" + "-p : set the private flag\n" + "-s : add source string embedded in infohash\n" #ifdef USE_PTHREADS - "-t : use threads for calculating hashes\n" - " default is the number of CPU cores\n" + "-t : use threads for calculating hashes\n" + " default is the number of CPU cores\n" #endif - "-v : be verbose\n" - "-w [,]* : add web seed URLs\n" - " additional -w adds more URLs\n" - "-x : ensure info hash is unique for easier cross-seeding\n" + "-v : be verbose\n" + "-w [,]* : add web seed URLs\n" + " additional -w adds more URLs\n" + "-x : ensure info hash is unique for easier cross-seeding\n" #endif "\nPlease send bug reports, patches, feature requests, praise and\n" "general gossip about the program to: mktorrent@rudde.org\n"); From b850ea85df1bdfd6dfd79fd1c34c6f1d2b858a54 Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sun, 24 Jan 2021 17:06:21 -0500 Subject: [PATCH 08/13] Remove msg.h --- ftw.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ftw.c b/ftw.c index 6531c5f..457bef8 100644 --- a/ftw.c +++ b/ftw.c @@ -32,7 +32,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "export.h" #include "mktorrent.h" /* DIRSEP_CHAR */ #include "ftw.h" -#include "msg.h" struct dir_state { From f04ea681dda589fdcd67038b1a3377f6aaa29b6c Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sun, 24 Jan 2021 17:08:26 -0500 Subject: [PATCH 09/13] Moved verbose message out of loop --- ftw.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ftw.c b/ftw.c index 457bef8..18579db 100644 --- a/ftw.c +++ b/ftw.c @@ -202,15 +202,16 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, LL_FOR(exclude_node, m->exclude_list) { const char *exclude_pattern = LL_DATA(exclude_node); if (fnmatch(exclude_pattern, de->d_name, 0) != FNM_NOMATCH) { - if (m->verbose) - printf("skipping %s\n", de->d_name); should_skip = true; break; } } - if (should_skip) + if (should_skip) { + if (m->verbose) + printf("skipping %s\n", de->d_name); continue; + } end = path + ds->length + 1; p = de->d_name; From 1683b0ddf3c138da1138be11b34ed002946743a8 Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Sun, 24 Jan 2021 17:29:05 -0500 Subject: [PATCH 10/13] Use in help message --- init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/init.c b/init.c index 1ed862f..bd5aa0b 100644 --- a/init.c +++ b/init.c @@ -257,7 +257,7 @@ static void print_help() " additional -a adds backup trackers\n" "-c, --comment= : add a comment to the metainfo\n" "-d, --no-date : don't write the creation date\n" - "-e, --exclude=[,

]* : exclude files whose name matches the pattern

\n" + "-e, --exclude=[,]* : exclude files whose name matches the pattern \n" " see the man page glob(7)\n" "-f, --force : overwrite output file if it exists\n" "-h, --help : show this help screen\n" @@ -278,11 +278,11 @@ static void print_help() " additional -w adds more URLs\n" "-x, --cross-seed : ensure info hash is unique for easier cross-seeding\n" #else - "-a [,]* : specify the full announce URLs\n" + "-a [,]* : sdpecify the full announce URLs\n" " additional -a adds backup trackers\n" "-c : add a comment to the metainfo\n" "-d : don't write the creation date\n" - "-e : exclude files whose name matches the pattern

\n" + "-e : exclude files whose name matches the pattern \n" " see the man page glob(7)\n" "-f : overwrite output file if it exists\n" "-h : show this help screen\n" From d0b1d2205ee9d19cca1ac1f1914b9b3102d9d534 Mon Sep 17 00:00:00 2001 From: Jeremy Harmon Date: Mon, 25 Jan 2021 08:14:21 -0500 Subject: [PATCH 11/13] Fixed help message --- init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.c b/init.c index bd5aa0b..75e0620 100644 --- a/init.c +++ b/init.c @@ -278,7 +278,7 @@ static void print_help() " additional -w adds more URLs\n" "-x, --cross-seed : ensure info hash is unique for easier cross-seeding\n" #else - "-a [,]* : sdpecify the full announce URLs\n" + "-a [,]* : specify the full announce URLs\n" " additional -a adds backup trackers\n" "-c : add a comment to the metainfo\n" "-d : don't write the creation date\n" From 9e3a57e4be25cfc01a2e34238aeb1fa276c7fd0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Mon, 25 Jan 2021 15:54:19 +0100 Subject: [PATCH 12/13] Remove extra whitespaces --- ftw.c | 4 ++-- init.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ftw.c b/ftw.c index 18579db..722ebb3 100644 --- a/ftw.c +++ b/ftw.c @@ -206,13 +206,13 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, break; } } - + if (should_skip) { if (m->verbose) printf("skipping %s\n", de->d_name); continue; } - + end = path + ds->length + 1; p = de->d_name; while ((*end = *p)) { diff --git a/init.c b/init.c index 75e0620..54cf7c7 100644 --- a/init.c +++ b/init.c @@ -258,8 +258,8 @@ static void print_help() "-c, --comment= : add a comment to the metainfo\n" "-d, --no-date : don't write the creation date\n" "-e, --exclude=[,]* : exclude files whose name matches the pattern \n" - " see the man page glob(7)\n" - "-f, --force : overwrite output file if it exists\n" + " see the man page glob(7)\n" + "-f, --force : overwrite output file if it exists\n" "-h, --help : show this help screen\n" "-l, --piece-length= : set the piece length to 2^n bytes,\n" " default is calculated from the total size\n" @@ -283,7 +283,7 @@ static void print_help() "-c : add a comment to the metainfo\n" "-d : don't write the creation date\n" "-e : exclude files whose name matches the pattern \n" - " see the man page glob(7)\n" + " see the man page glob(7)\n" "-f : overwrite output file if it exists\n" "-h : show this help screen\n" "-l : set the piece length to 2^n bytes,\n" From 9a48ca43a8f62877b2b697448bafa7493fd39156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Mon, 25 Jan 2021 15:58:03 +0100 Subject: [PATCH 13/13] Add missing metavar for the '-e' option in help text --- init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.c b/init.c index 54cf7c7..4ba566e 100644 --- a/init.c +++ b/init.c @@ -282,7 +282,7 @@ static void print_help() " additional -a adds backup trackers\n" "-c : add a comment to the metainfo\n" "-d : don't write the creation date\n" - "-e : exclude files whose name matches the pattern \n" + "-e [,]* : exclude files whose name matches the pattern \n" " see the man page glob(7)\n" "-f : overwrite output file if it exists\n" "-h : show this help screen\n"