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

Clarify how to use or fix directory.watch.added #374

Closed
ghost opened this issue Jan 19, 2016 · 14 comments
Closed

Clarify how to use or fix directory.watch.added #374

ghost opened this issue Jan 19, 2016 · 14 comments

Comments

@ghost
Copy link

ghost commented Jan 19, 2016

Your wiki page TORRENT Watch directories states that one can use inotify on Linux for watching directories:

directory.watch.added = "~/Download/watch/", load.start
On Linux you may use inotify to watch a directory, and the command is called with the the full path of new files as the first argument

However, I can't figure out how to use this command.

Having

directory.watch.added = "~/Download/watch/", load.start

in the rtorrent.rc, starting rtorrent results in the error:

rtorrent: Failed to parse command line option: Error in option file: ./.rtorrent.rc:43: Command "directory.watch.added" does not exist.

I figured, one should use it like the other commands start_tied, stop_untied, etc., so I put

schedule = inotify_watch_directory,0,0,"directory.watch.added=~/Download/watch/,load.start"

into the rc. The, rtorrent starts up, but prints:

(11:01:37) Scheduled command failed: inotify_watch_directory: Command "directory.watch.added" does not exist.

I'm on version 0.9.6-3 of the arch linux package (Rakshasa's BitTorrent client version 0.9.6.)

@chros73
Copy link
Contributor

chros73 commented Jan 19, 2016

  1. about directory.watch.added :
    It wasn't available in 0.9.4 when I tried it half a year ago. Another issue can be with it, if you want to pass on additional parameters as you can do with the traditional watch directories (I'm using them). And since you can schedule watchers 10 seconds it's not really a problem.
  2. I tried to use inotify for my queue script (outside of rtorrent) but I also gave it up:
    I couldn't figure it out how you can batch process several torrent files at a given time (e.g. when the first come in then wait for e.g. 40 seconds for possible others). I've found a python solution for it, but it wasn't so relaible. So I'm just using cron for this one (5 mins).

@chros73
Copy link
Contributor

chros73 commented Apr 16, 2017

Another issue can be with it, if you want to pass on additional parameters as you can do with the traditional watch directories

1.How can we do this? Wiki says its possible but I think it isn't with the current implementation.

2.directory.watch.added = "~/Download/watch/", load.start

  • first argument doesn't resolve commands (e.g. "cat=(cfg.dir.meta_downl),watch/")

@pyroscope
Copy link
Contributor

pyroscope commented Apr 18, 2017

  1. "Use method.insert to define more complex multi-command inotify handlers." is not obvious enough?
  2. Of course it doesn't if you quote the commands. That is what quoting does.

@chros73
Copy link
Contributor

chros73 commented Apr 18, 2017

"Use method.insert to define more complex multi-command inotify handlers." is not obvious enough?

:) Have you actually tried it out? It won't work. And if it even would you can't pass argument into that very command.

Of course it doesn't if you quote the commands. That is what quoting does.

I think it's because of this: code just takes it as it is
And it has to be "quoted" or something, otherwise watch would be the command.

@rakshasa
Copy link
Owner

rakshasa commented Apr 21, 2017

src/main.cc-       "method.insert.c_simple = group.insert_persistent_view,"
src/main.cc:       "((view.add,((argument.0)))),((view.persistent,((argument.0)))),((group.insert,((argument.0)),((argument.0))))\n"

Using arguments inside custom methods is supported.

Someone should probably add this to the wiki.

@chros73
Copy link
Contributor

chros73 commented Apr 21, 2017

Thanks, I know that :) custom method , watch_dir definition

What I meant is this:

  • you can't set a custom command for directory.watch.added
  • and even if you could do the above, current implementation doesn't allow to pass arguments for it (mainly because of the above issue)

Anyway, I'll create a new issue for this.

@pyroscope
Copy link
Contributor

The watchdir doesn't care if "load.start" or "foo.bar" is called as a handler, the file is available as "argument.0". So write a custiom method with load.start in it, and any after-load commands you need. Or even call a multi-method, the basic machinery will pass things on.

Regarding the watch dir, use (…) and not "…".

@chros73
Copy link
Contributor

chros73 commented Apr 23, 2017

So write a custiom method with load.start in it, and any after-load commands you need.

Are you talking about directory.watch.added or the scheduled watchdirs?

Regarding the watch dir, use (…) and not "…".

Yep, it was written more than a year ago, but since it's working ... :)

@chros73
Copy link
Contributor

chros73 commented Jun 10, 2017

Regarding the watch dir, use (…) and not "…"

You were right @pyroscope , the quotes were the problem around the directory definition.
I implemented the multiple commands addition and more: #616

@pyroscope
Copy link
Contributor

To make things clear, just try the following (with the client already running).

Not only can you add post-load commands as you see fit, as I mentioned before a multi-method looks just like any other method, so use it to get more out of your watch dir events. ;)

mkdir -p $HOME/tmp/hotwatch
rtxmlrpc -i @- <<EOF
method.insert = my.inotify.handler, multi|rlookup|static
method.set_key = my.inotify.handler, !log, "print = \"Got notified about \", (argument.0)"
method.set_key = my.inotify.handler, load, "load.verbose = (argument.0), d.priority.set=0"

method.set_key = event.download.inserted_new, log_loaded, ((print, "ADDED ", ((d.name)) ))

directory.watch.added = $HOME/tmp/hotwatch, my.inotify.handler
EOF
mktor -o $HOME/tmp/hotwatch README local
sleep 2
touch $HOME/tmp/hotwatch/invalid.torrent

And this is the console log you get:

(23:00:43) Got notified about /home/…/tmp/hotwatch/README.torrent
(23:00:43) ADDED README
(23:00:43) Got notified about /home/…/tmp/hotwatch/README.torrent
(23:00:45) Got notified about /home/…/tmp/hotwatch/invalid.torrent
(23:00:45) Reading torrent file failed: "/home/…/tmp/hotwatch/invalid.torrent"

The event handler is called twice, likely due to seeing both an open and a close event. As you can see above, load.verbose will complain about invalid (just partially written) metafiles, so in real configs load.normal might be the better option. But for this demo, the more feedback the merrier.

What actually needs fixing is that directory.watch.added does not seem to call path expansion, thus the $HOME in there.

Now someone edit that wiki page…

@mohkale
Copy link

mohkale commented Apr 8, 2020

is there any way to remove directories from the watch list?

@pyroscope
Copy link
Contributor

a) issues is not a support channel
b) do not add to ancient closed issues

@mohkale
Copy link

mohkale commented Apr 9, 2020

a) I felt it was related to the underlying issue. clarifying how directory.watch.added works. I.E. whether it is reversible.

Understood, I'll open a new issue for it.

b) My bad, didn't notice it was 2 years old.

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

No branches or pull requests

4 participants