diff --git a/ftw.c b/ftw.c index 97bad71..722ebb3 100644 --- a/ftw.c +++ b/ftw.c @@ -26,6 +26,8 @@ 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 */ @@ -135,6 +137,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; @@ -195,6 +198,21 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds, continue; } + bool should_skip = false; + 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) { + should_skip = true; + 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 f8e1ece..4ba566e 100644 --- a/init.c +++ b/init.c @@ -257,6 +257,8 @@ 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" + " 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" @@ -280,6 +282,8 @@ 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" + " 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" @@ -429,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'}, @@ -455,11 +460,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 +488,9 @@ EXPORT void init(struct metafile *m, int argc, char *argv[]) case 'd': m->no_creation_date = 1; break; + case 'e': + ll_extend(m->exclude_list, get_slist(optarg)); + break; case 'f': m->force_overwrite = 1; break; @@ -604,5 +615,7 @@ EXPORT void cleanup_metafile(struct metafile *m) ll_free(m->web_seed_list, NULL); + ll_free(m->exclude_list, NULL); + 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 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