[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH 2/2] Reimplement dpkg-divert in C



On Sat, 2009-10-17 at 14:58:55 +0700, Mikhail Gusarov wrote:
> Twas brillig at 02:05:47 17.10.2009 UTC+02 when guillem@debian.org did gyre and gimble:
>  GJ> Instead of inverting the list after the fact, just add to its tail
>  GJ> instead. OTOH I don't think this should be needed at all.
> 
> I have tried to replicate dpkg-divert.pl behaviour exactly, including
> sorting of diversions file. If it is not necessary, I could make a
> testsuite a bit smarter instead.

I mean that it should not be needed at all once the code uses the
divertdb infrastructure. But it seems the db parser is prepending the
diversions to the head of the list, so it will need to be changed to
append to the tail instead.

The behaviour should be preserved, yes, but the code layout does not
need to, just what fits best with the rest of the code base. In this
case duplicating part of the current infrastructure is not good. And
we might need to expose the functionality to write the db and add new
diversion from dpkg-divert to libdpkg at some point in the future.

>  >> +static int
>  >> +match_diversion(diversion *diversion, char *const *patterns)
>  >> +{
>  >> +        for (; *patterns; patterns++) {
>  >> +                if(!fnmatch(*patterns, diversion->contest, FNM_NOESCAPE))
>  >> +                        return 0;
>  >> +                if(!fnmatch(*patterns, diversion->altname, FNM_NOESCAPE))
>  >> +                        return 0;
>  >> +                if(!fnmatch(*patterns, diversion->package, FNM_NOESCAPE))
>  >> +                        return 0;
> 
>  GJ> Why the FNM_NOESCAPE?
> 
> To match Perl code - '\' is escaped there. Not that it really matters.

The --list option is supposed to be taking a glob as argument, the perl
code was trying to convert it into a regex. And there, all non word
characters get escaped to protect the regex. My take is that the coder
probably just didn't bother handling the escape case, which seems
useful to me now that we get it for free.

regards,
guillem


Reply to: