An Ada 2012 library to monitor filesystem events using Linux' inotify API.
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
.
In order to build the library, you need to have:
-
An Ada 2012 compiler implementing
GNAT.OS_Lib
-
Alire and (optionally)
make
Use the library in your crates as follows:
alr with inotify
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.
Please read the contributing guidelines before opening issues or pull requests.
This library is distributed under the terms of the Apache License 2.0.