]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix filesystem entry filtering
authorRonan Desplanques <desplanques@adacore.com>
Tue, 19 Sep 2023 07:45:16 +0000 (09:45 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 10 Oct 2023 12:12:28 +0000 (14:12 +0200)
This patch fixes the behavior of Ada.Directories.Search when being
requested to filter out regular files or directories. One of the
configurations in which that behavior was incorrect was that when the
caller requested only the regular and special files but not the
directories, the directories would still be returned.

gcc/ada/

* libgnat/a-direct.adb: Fix filesystem entry filtering.

gcc/ada/libgnat/a-direct.adb

index 4b08d41337dda385c8512522962c81251626ad07..f7a1d5dfd6d62ba5309162a42e9c604495773bce 100644 (file)
@@ -1414,24 +1414,26 @@ package body Ada.Directories is
 
                   elsif Exists = 1 then
                      if Is_Regular_File_Attr (Path_C'Address, Attr'Access) = 1
-                       and then Filter (Ordinary_File)
                      then
-                        Found := True;
-                        Kind := Ordinary_File;
-                        Size :=
-                          File_Size
-                            (File_Length_Attr
-                               (-1, Path_C'Address, Attr'Access));
+                        if Filter (Ordinary_File) then
+                           Found := True;
+                           Kind := Ordinary_File;
+                           Size :=
+                             File_Size
+                               (File_Length_Attr
+                                  (-1, Path_C'Address, Attr'Access));
 
+                        end if;
                      elsif Is_Directory_Attr (Path_C'Address, Attr'Access) = 1
-                       and then Filter (File_Kind'First)
                      then
-                        Found := True;
-                        Kind := File_Kind'First;
-                        --  File_Kind'First is used instead of Directory due
-                        --  to a name overload issue with the procedure
-                        --  parameter Directory.
-                        Size := 0;
+                        if Filter (File_Kind'First) then
+                           Found := True;
+                           Kind := File_Kind'First;
+                           --  File_Kind'First is used instead of Directory due
+                           --  to a name overload issue with the procedure
+                           --  parameter Directory.
+                           Size := 0;
+                        end if;
 
                      elsif Filter (Special_File) then
                         Found := True;