Обсуждение: relative_path() seems overly complicated and buggy

Поиск
Список
Период
Сортировка

relative_path() seems overly complicated and buggy

От
Tom Lane
Дата:
There's at least one bug in path.c's relative_path(): it will think
"/foo/a/b" is equal to "/foo/ab" because it skips directory separators
independently in the two strings.  The code is sufficiently complex that
I have little faith in it not having any other bugs, either.

I believe that it's unnecessary for relative_path to be so tense
about trying to implement platform-weirdness-aware comparison of paths.
It is not called on arbitrary paths, but only on the compiled-in
paths that were generated by configure.  Therefore it is reasonable
to assume that the common prefix we are trying to identify is spelled
exactly the same in both paths.

What I'd like to do is simplify it to just check for exact equality
up through the last directory separator in bin_path.  Any objections?
        regards, tom lane


Re: relative_path() seems overly complicated and buggy

От
Bruce Momjian
Дата:
Tom Lane wrote:
> There's at least one bug in path.c's relative_path(): it will think
> "/foo/a/b" is equal to "/foo/ab" because it skips directory separators
> independently in the two strings.  The code is sufficiently complex that
> I have little faith in it not having any other bugs, either.
> 
> I believe that it's unnecessary for relative_path to be so tense
> about trying to implement platform-weirdness-aware comparison of paths.
> It is not called on arbitrary paths, but only on the compiled-in
> paths that were generated by configure.  Therefore it is reasonable
> to assume that the common prefix we are trying to identify is spelled
> exactly the same in both paths.
> 
> What I'd like to do is simplify it to just check for exact equality
> up through the last directory separator in bin_path.  Any objections?

If you can simplify it, feel free.   I found that code much more complex
than I liked but couldn't simplify it.  Originally I thought that would
be used in more generic places but that hasn't happened.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: relative_path() seems overly complicated and buggy

От
Bruce Momjian
Дата:
Bruce Momjian wrote:
> Tom Lane wrote:
> > There's at least one bug in path.c's relative_path(): it will think
> > "/foo/a/b" is equal to "/foo/ab" because it skips directory separators
> > independently in the two strings.  The code is sufficiently complex that
> > I have little faith in it not having any other bugs, either.
> > 
> > I believe that it's unnecessary for relative_path to be so tense
> > about trying to implement platform-weirdness-aware comparison of paths.
> > It is not called on arbitrary paths, but only on the compiled-in
> > paths that were generated by configure.  Therefore it is reasonable
> > to assume that the common prefix we are trying to identify is spelled
> > exactly the same in both paths.
> > 
> > What I'd like to do is simplify it to just check for exact equality
> > up through the last directory separator in bin_path.  Any objections?
> 
> If you can simplify it, feel free.   I found that code much more complex
> than I liked but couldn't simplify it.  Originally I thought that would
> be used in more generic places but that hasn't happened.

Let me try to clean it up first by using canonicalize_path() and
comparing the result.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: relative_path() seems overly complicated and buggy

От
Tom Lane
Дата:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Bruce Momjian wrote:
>> Tom Lane wrote:
>>> What I'd like to do is simplify it to just check for exact equality
>>> up through the last directory separator in bin_path.  Any objections?
>> 
>> If you can simplify it, feel free.   I found that code much more complex
>> than I liked but couldn't simplify it.  Originally I thought that would
>> be used in more generic places but that hasn't happened.

> Let me try to clean it up first by using canonicalize_path() and
> comparing the result.

I already checked in the simplification.
        regards, tom lane