[pacman-dev] [PATCH 1/2] skip unneeded parsing

jjacky i.am.jack.mail at gmail.com
Mon Jan 9 14:01:18 EST 2012


On 01/09/12 19:40, Dan McGee wrote:
> On Mon, Jan 9, 2012 at 12:09 PM, jjacky<i.am.jack.mail at gmail.com>  wrote:
>> parsing config file is a two-steps process, one for
>> "options" and one for the repos. in each of those,
>> there's no need to parse the other section(s), so we'll
>> skip it. (most notably, when parsing for "options" it
>> would read all included files for repos, while just
>> ignoring everything in them)
>>
>> Signed-off-by: Olivier Brunel<i.am.jack.mail at gmail.com>
>
> I think this will fail hard in the following scenario:
>
> pacman.conf follows:
> -----
> Include /etc/pacman.d/shared-options.conf
>
> [repo]
> ....
> -----
>
> Include directives can occur *anywhere*, not just inside sections.

hmm... so you mean there could be Include directives even before the 
very first section?

The way I read the man page was that Include directives, like everything 
else, are always in a section. In such cases, the Include directive 
would be in the "options" section so it would be parsed, but only when 
parsing for options, not when doing so for repos. And vice versa.

It would fail, however, with Include directives before any section is 
open, so not in any section, yes.

Oh, but yeah, it would also fail if an Include in the "options" section 
was to define some repos, or if an Include in a repo was to include a 
section "options" of its own, indeed.

My bad.

>
>> ---
>>   src/pacman/conf.c |    6 ++++++
>>   1 files changed, 6 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/pacman/conf.c b/src/pacman/conf.c
>> index 7ba2791..09749ea 100644
>> --- a/src/pacman/conf.c
>> +++ b/src/pacman/conf.c
>> @@ -755,6 +755,12 @@ static int _parseconfig(const char *file, struct
>> section_t *section,
>>                         continue;
>>                 }
>>
>> +               /* skip unnecessary parsing */
>> +               if ( (parse_options&&  !section->is_options)
>> +                               || (!parse_options&&  section->is_options) )
>> {
>> +                       continue;
>> +               }
>> +
>>                 /* directive */
>>                 /* strsep modifies the 'line' string: 'key \0 value' */
>>                 key = line;
>> --
>> 1.7.8.3
>>
>


More information about the pacman-dev mailing list