From: Ronan Desplanques <desplanq...@adacore.com> 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. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnat/a-direct.adb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/gcc/ada/libgnat/a-direct.adb b/gcc/ada/libgnat/a-direct.adb index 4b08d41337d..f7a1d5dfd6d 100644 --- a/gcc/ada/libgnat/a-direct.adb +++ b/gcc/ada/libgnat/a-direct.adb @@ -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; -- 2.42.0