From 47840115c51c3f4b57f703e09758fadc483475fd Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 25 Aug 2021 11:58:02 +0200 Subject: [PATCH] Fix iteration with cursors in search command (#807) --- src/alr/alr-commands-search.adb | 51 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/alr/alr-commands-search.adb b/src/alr/alr-commands-search.adb index 976ac3bd..f0dbfd3a 100644 --- a/src/alr/alr-commands-search.adb +++ b/src/alr/alr-commands-search.adb @@ -1,6 +1,6 @@ +with Alire.Crates.Containers; with Alire.Externals; with Alire.Index.Search; -with Alire.Crates.Containers; with Alire.Releases.Containers; with Alire.Solutions; with Alire.Solver; @@ -217,42 +217,45 @@ package body Alr.Commands.Search is Busy.Step; end List_Crate; + I : Alire.Crates.Containers.Maps.Cursor := + Alire.Index.All_Crates.First; + -- Cursor-based iteration because external detection during listing + -- may cause addition of new crates, and that triggers tampering + -- checks in some compiler versions. + + use Alire.Crates.Containers.Maps; begin if Cmd.List then - - -- List releases - Trace.Detail ("Searching..."); - declare - I : Alire.Crates.Containers.Maps.Cursor := - Alire.Index.All_Crates.First; - use Alire.Crates.Containers.Maps; - begin - -- Cursor-based iteration because external detection during - -- listing may cause addition of new crates, and this triggers - -- tampering checks in some compiler versions. - - while Has_Element (I) loop - List_Crate (Element (I)); - Next (I); - end loop; - end; else + Trace.Detail ("Searching " & Utils.Quote (Argument (1)) & "..."); + end if; - -- Search into releases + while Has_Element (I) loop declare - Pattern : constant String := Argument (1); + Crate : Alire.Crates.Crate renames Element (I); + Pattern : constant String := (if Cmd.List + then "" + else Argument (1)); begin - Trace.Detail ("Searching " & Utils.Quote (Pattern) & "..."); + if Cmd.List then + + -- List all releases + List_Crate (Crate); + + else - for Crate of Alire.Index.All_Crates.all loop + -- Search into release names if Utils.Contains (+Crate.Name, Pattern) then List_Crate (Crate); end if; - end loop; + + end if; end; - end if; + + Next (I); + end loop; end; if Found = 0 then -- 2.39.5