getFeeder: return a function which returns the next item from a folder.

Description Usage Arguments Details Value Author(s) See Also

View source: R/getFeeder.R

Description

The returned function maintains a queue of path names which is initialized with those files and folders already in incoming. Any files or folders subsequently added to incoming are added to the end of the queue. Items are typically email messages with attached data files or links to download them, or folders of data files already on the server.

Usage

1
2
getFeeder(incoming, tracing = FALSE, messages = c("close_write", "moved_to",
  "create"))

Arguments

incoming

the full path to the incoming folder(s). If this has more than one element, only the first is watched for new files, but files initially in all of them are queued.

tracing

boolean; if TRUE, each event on the incoming folder is printed. Default: FALSE.

messages:

list of inotifywait message to watch for. Default: c("close_write", "move_to", "create"). Other possible values: "move_from", "close_nowrite", "open", "access", "modify", "attrib", "delete", "delete_self", "move_self", "unmount". See man inotifywait for details.

Details

Algorithm:

  1. initialize file queue with list of files and folders in incoming.

  2. use inotifywait to watch incoming for new files, links, and folders.

There's a race condition in that files might be created after starting to watch incoming but before calling dir() to list existing items, so that we see them twice. Deal with this by keeping track of existing files. i.e. the queue looks like this:

1 —+ 2 | ... +— files existing before inotifywait is active n —+

n + 1 —+ n + 2 | n + 3 +— files created after inotifywait is active but before dir() ... | These files are seen twice: once from calling dir()... n + m —+

n + m + 1 –+ n + m + 2 | ... +— ... and this second time, from the inotifywait pipe n + 2m —+

n + 2m + 1 —+ n + 2m + 2 |— files created after dir() ... —+

m will usually be zero, but that can't be guaranteed. We retain the list of items 1..n + m, and check inotify events against it. The first item not in that list will be item n + 2m + 1, which is new.

Value

a function, f, with one optional parameter, quit, which defaults to FALSE. If quit == FALSE, then f returns the full path to the next available incoming item, or waits if there are none. If quit == FALSE, then f closes the inotifywait process, and any subsequent call to f will generate an error.

Author(s)

John Brzustowski jbrzusto@REMOVE_THIS_PART_fastmail.fm

See Also

server


jbrzusto/motusServer documentation built on May 19, 2019, 8:19 a.m.