Matt Harrison <> wrote:
> I would like to be able to add file while the script is busy and
> have it append the new filename to its list. I've considered inotify
> type monitoring but I don't know much about it and if it could be
> made to fit this single-threaded script.
Inotify descriptors have an internal queue[1] so events can be
backlogged while your script is doing something else.
The sleepy_penguin[2] RubyGem provides inotify bindings that are
subclasses of Ruby IO objects, so you can IO.select on them in
an event loop (sleepy_penguin also provides an epoll wrapper).
sleepy_penguin is Linux-only and a fairly "raw" interface to the
underlying system calls. Cool.io (libev wrapper)[3] and EventMachine[4]
also support inotify and they may be more portable to systems without
inotify (using kqueue or stat() loops).
> I've also thought about re-reading the directory after each file
> operation is complete, and adding the previously unknown filenames
> to the list.
I had to do this once in a daemon since it ran on an NFS directory
since inotify doesn't work on NFS :<
[1] The inotify(7) manpage is a great resource for learning about
how it works.
[2]
http://bogomips.org/sleepy_penguin (disclaimer: I'm the author)
[3]
http://coolio.github.com/
[4]
http://rubyeventmachine.com/
--
Eric Wong