Skip to content

An Ada 2012 library for monitoring filesystem events using Linux' inotify API

License

Notifications You must be signed in to change notification settings

onox/inotify-ada

Repository files navigation

Build status Alire crate License GitHub release IRC Gitter chat

inotify-ada

An Ada 2012 library to monitor filesystem events using Linux' inotify API.

Usage

with Ada.Command_Line;
with Ada.Text_IO;

with Inotify.Recursive;

procedure Example is
   Instance : Inotify.Recursive.Recursive_Instance;

   procedure Handle_Event
     (Subject      : Inotify.Watch;
      Event        : Inotify.Event_Kind;
      Is_Directory : Boolean;
      Name         : String)
   is
      Kind : constant String := (if Is_Directory then "directory" else "file");
   begin
      Ada.Text_IO.Put_Line (Event'Image & " " & Instance.Name (Subject));
      Ada.Text_IO.Put_Line ("  [" & Kind & "] '" & Name & "'");
   end Handle_Event;
begin
   Instance.Add_Watch
     (Path => Ada.Command_Line.Argument (1),
      Mask => (Modified | Closed_Write | Closed_No_Write => True, others => False));

   while Instance.Has_Watches loop
      Instance.Process_Events (Handle_Event'Access);
   end loop;
end Example;

An optional second access-to-procedure parameter can be added to Process_Events to handle move events. See examples/monitor.adb.

Dependencies

In order to build the library, you need to have:

  • An Ada 2012 compiler implementing GNAT.OS_Lib

  • Alire and (optionally) make

Using the library

Use the library in your crates as follows:

alr with inotify

Installing the tools

A tool to monitor a folder for any event can be build and run with:

$ alr run --args="path/to/folder"

Alternatively, it can be build and installed with:

$ make
$ make PREFIX=~/.local install

Run inotify-ada path/to/folder to monitor the folder for events.

Contributing

Please read the contributing guidelines before opening issues or pull requests.

License

This library is distributed under the terms of the Apache License 2.0.