Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude command line option. Excludes files based on a glob string #56

Merged
merged 13 commits into from
Jan 25, 2021
Merged

Add exclude command line option. Excludes files based on a glob string #56

merged 13 commits into from
Jan 25, 2021

Conversation

zordtk
Copy link
Contributor

@zordtk zordtk commented Jan 22, 2021

This adds a exclude option to mktorrent. It allows you to exclude files based on a glob string:
example: mktorrent -e *.nfo

You can pass multiple -e flags or separate them by commas
example: mktorrent -e *.nfo,*.jpg

@pobrn
Copy link
Owner

pobrn commented Jan 23, 2021

Thanks for the PR. I believe using glob is a bit of an overkill in this situation. I think fnmatch could be sufficient. Furthermore, you probably forgot to add your modifications in mktorrent.h to the commit because it does not build.

In file included from mktorrent.h:29,
                 from ftw.c:33:
ftw.c: In function ‘file_tree_walk’:
ftw.c:193:21: error: ‘struct metafile’ has no member named ‘exclude_list’
  193 |  LL_FOR(tier_node, m->exclude_list) {
      |                     ^~
ll.h:32:81: note: in definition of macro ‘LL_FOR_FROM_TO_STEP’
   32 | #define LL_FOR_FROM_TO_STEP(node, from, to, step) for (struct ll_node *(node) = from; node != to; step(node))
      |                                                                                 ^~~~
ll.h:33:54: note: in expansion of macro ‘LL_HEAD’
   33 | #define LL_FOR(node, list) LL_FOR_FROM_TO_STEP(node, LL_HEAD(list), NULL, LL_STEP)
      |                                                      ^~~~~~~
ftw.c:193:2: note: in expansion of macro ‘LL_FOR’
  193 |  LL_FOR(tier_node, m->exclude_list) {
      |  ^~~~~~

@zordtk
Copy link
Contributor Author

zordtk commented Jan 23, 2021

Sorry, included mktorrent.h. Thanks for your comments, I will change it to use fnmatch instead of glob.

@zordtk
Copy link
Contributor Author

zordtk commented Jan 23, 2021

I rewrote it to use fnmatch, it simplified things and removed the need for second linked list.

Edit: Should I enable the FNM_EXTMATCH flag for additional matching options?

init.c Outdated Show resolved Hide resolved
ftw.c Outdated Show resolved Hide resolved
ftw.c Outdated Show resolved Hide resolved
ftw.c Outdated Show resolved Hide resolved
ftw.c Outdated Show resolved Hide resolved
init.c Outdated Show resolved Hide resolved
@pobrn pobrn linked an issue Jan 23, 2021 that may be closed by this pull request
@pobrn
Copy link
Owner

pobrn commented Jan 23, 2021

This adds a exclude option to mktorrent. It allows you to exclude files based on a glob string:
example: mktorrent -e *.nfo

You can pass multiple -e flags or separate them by commas
example: mktorrent -e *.nfo,*.jpg

I'm not sure if the first one is a good example, since the shell might expand the pattern before running the program, and then user will be surprised.


Edit: Should I enable the FNM_EXTMATCH flag for additional matching options?

I'm not sure about that.

@zordtk
Copy link
Contributor Author

zordtk commented Jan 23, 2021

I'm not sure if the first one is a good example, since the shell might expand the pattern before running the program, and then user will be surprised.

What would be your suggestion for an example? I haven't ran into that issue with bash. Although I'm mostly using this in a shell script to auto-create torrents.

I'm not sure about that.

Ok, I'll leave it disabled.

@zordtk zordtk requested a review from pobrn January 23, 2021 22:17
@pobrn
Copy link
Owner

pobrn commented Jan 24, 2021

Consider the following:

$ ls
a.jpg  b.jpg  c.png  d.png
$ set -x
[...]
$ mktorrent -e *.jpg .
+ mktorrent -e a.jpg b.jpg .
mktorrent 1.1 (c) 2007, 2009 Emil Renner Berthing

hashing b.jpg
writing metainfo file... done

mktorrent will be called as mktorrent -e a.jpg b.jpg .. Of course, this is a minor thing, and the example is not in any piece of documentation, yet, but I wanted to bring attention to it nonetheless.

init.c Outdated Show resolved Hide resolved
ftw.c Outdated Show resolved Hide resolved
ftw.c Outdated Show resolved Hide resolved
@zordtk zordtk requested a review from pobrn January 25, 2021 02:37
init.c Outdated Show resolved Hide resolved
@pobrn pobrn merged commit 8ab1da7 into pobrn:master Jan 25, 2021
@pobrn
Copy link
Owner

pobrn commented Jan 25, 2021

Hopefully I didn't miss anything. Thanks again.

pobrn added a commit that referenced this pull request Jan 30, 2021
* Add exclude command line option. Excludes files based on a glob string (#56)
* Automatically calculate piece length (#55)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore files
2 participants