text stringlengths 0 234 |
|---|
use Ada.Streams; |
function Convert is new Ada.Unchecked_Conversion |
(Source => Stream_Element_Array, Target => Inotify_Event); |
function Convert is new Ada.Unchecked_Conversion |
(Source => Interfaces.C.unsigned, Target => Event_Bits); |
Event_In_Bytes : constant Stream_Element_Offset |
:= Inotify_Event'Size / System.Storage_Unit; |
Length : Stream_Element_Offset; |
Buffer : Stream_Element_Array (1 .. 4096) |
with Alignment => 4; |
function Find_Move (Cookie : Interfaces.C.unsigned) return Move_Vectors.Cursor is |
Cursor : Move_Vectors.Cursor := Move_Vectors.No_Element; |
procedure Reverse_Iterate (Position : Move_Vectors.Cursor) is |
use type Interfaces.C.unsigned; |
begin |
if Cookie = Object.Moves (Position).Key then |
Cursor := Position; |
end if; |
end Reverse_Iterate; |
begin |
Object.Moves.Reverse_Iterate (Reverse_Iterate'Access); |
return Cursor; |
end Find_Move; |
use type Ada.Containers.Count_Type; |
begin |
if Object.Watches.Is_Empty then |
return; |
end if; |
Length := Stream_Element_Offset (GNAT.OS_Lib.Read |
(Object.Instance, Buffer'Address, Buffer'Length)); |
if Length = -1 then |
raise Read_Error; |
end if; |
if Length = 0 then |
return; |
end if; |
declare |
Index : Stream_Element_Offset := Buffer'First; |
begin |
Object.Defer_Remove := True; |
while Index < Buffer'First + Length loop |
declare |
Event : constant Inotify_Event |
:= Convert (Buffer (Index .. Index + Event_In_Bytes - 1)); |
Mask : constant Event_Bits := Convert (Event.Mask); |
Name_Length : constant Stream_Element_Offset |
:= Stream_Element_Offset (Event.Length); |
begin |
if Mask.Queue_Overflowed then |
raise Queue_Overflow_Error; |
end if; |
pragma Assert (Event.Watch /= -1); |
if Mask.Ignored then |
Object.Watches.Exclude (Event.Watch); |
else |
declare |
Directory : constant String := Object.Watches.Element (Event.Watch); |
begin |
if Name_Length > 0 then |
declare |
subtype Name_Array is Interfaces.C.char_array |
(1 .. Interfaces.C.size_t (Event.Length)); |
subtype Name_Buffer is Stream_Element_Array |
(1 .. Name_Length); |
function Convert is new Ada.Unchecked_Conversion |
(Source => Name_Buffer, Target => Name_Array); |
Name_Index : constant Stream_Element_Offset |
:= Index + Event_In_Bytes; |
Name : constant String := Interfaces.C.To_Ada (Convert |
(Buffer (Name_Index .. Name_Index + Name_Length - 1))); |
begin |
Handle |
((Watch => Event.Watch), Mask.Event, |
Mask.Is_Directory, Directory & "/" & Name); |
case Mask.Event is |
when Moved_From => |
if Object.Moves.Length = Object.Moves.Capacity then |
Object.Moves.Delete_First; |
end if; |
Object.Moves.Append ((Event.Cookie, |
(From => SU.To_Unbounded_String (Directory & "/" & Name), |
To => <>))); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.