W3cubDocs

/Nim

Module fsmonitor

This module allows you to monitor files or directories for changes using asyncio.

Warning: This module will likely disappear soon and be moved into a new Nimble package.

Windows support is not yet implemented.

Note: This module uses inotify on Linux (Other Unixes are not yet supported). inotify was merged into the 2.6.13 Linux kernel, this module will therefore not work with any Linux kernel prior to that, unless it has been patched to support inotify.

Imports

posix, inotify, os, asyncio, tables

Types

FSMonitor = ref FSMonitorObj
MonitorEventType = enum
  MonitorAccess,              ## File was accessed.
  MonitorAttrib,              ## Metadata changed.
  MonitorCloseWrite,          ## Writable file was closed.
  MonitorCloseNoWrite,        ## Non-writable file closed.
  MonitorCreate,              ## Subfile was created.
  MonitorDelete,              ## Subfile was deleted.
  MonitorDeleteSelf,          ## Watched file/directory was itself deleted.
  MonitorModify,              ## File was modified.
  MonitorMoveSelf,            ## Self was moved.
  MonitorMoved,               ## File was moved.
  MonitorOpen,                ## File was opened.
  MonitorAll                  ## Filter for all event types.
Monitor event type
MonitorEvent = object
  case kind*: MonitorEventType
  of MonitorMoveSelf, MonitorMoved:
      oldPath*: string         ## Old absolute location
      newPath*: string         ## New absolute location
    
  else:
      fullname*: string        ## Absolute filename of the file/directory affected.
    
  name*: string                ## Non absolute filepath of the file/directory
              ## affected relative to the directory watched.
              ## "" if this event refers to the file/directory
              ## watched.
  wd*: cint                    ## Watch descriptor.
Type of the event.

Procs

proc newMonitor(): FSMonitor {.raises: [OSError], tags: [].}
Creates a new file system monitor.
proc add(monitor: FSMonitor; target: string; filters = {MonitorAll}): cint {.discardable,
    raises: [OSError], tags: [].}
Adds target which may be a directory or a file to the list of watched paths of monitor. You can specify the events to report using the filters parameter.
proc del(monitor: FSMonitor; wd: cint) {.raises: [OSError], tags: [].}

Removes watched directory or file as specified by wd from monitor.

If wd is not a part of monitor an EOS error is raised.

proc register(d: Dispatcher; monitor: FSMonitor;
             handleEvent: proc (m: FSMonitor; ev: MonitorEvent) {.closure.}) {.
    raises: [], tags: [].}
Registers monitor with dispatcher d.

© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/fsmonitor.html