Re: psql \ir filename normalization

Lists: pgsql-hackers
From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: psql \ir filename normalization
Date: 2011-11-15 23:54:30
Message-ID: CAK3UJRGTZv_rVLpEQ1oJ9Bfo3UTRRb=J=X90bvhUYBjVrs01oQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi all,

Commit c7f23494c1103f87bcf1ef7cbfcd626e73edb337 editorialized a bit on
Gurjeet Singh's patch to implement \ir for psql, particularly in
process_file(). Unfortunately, it looks like it broke the common case
of loading a .SQL file in psql's working directory. Consider the
following test case:

mkdir -p /tmp/psql_test/subdir/
mkdir -p /tmp/psql_test/path2/

echo "SELECT 'hello 1';" > /tmp/psql_test/hello.sql
echo "SELECT 'hello from parent';" > /tmp/psql_test/hello_parent.sql
echo "SELECT 'hello from absolute path';" >
/tmp/psql_test/path2/absolute_path.sql
echo -e "SELECT 'hello 2';\n\ir ../hello_parent.sql\n\ir
/tmp/psql_test/path2/absolute_path.sql" >
/tmp/psql_test/subdir/hello2.sql
echo -e "\ir hello.sql\n\ir subdir/hello2.sql" > /tmp/psql_test/load.sql

If you try to load in "load.sql" from any working directory other than
/tmp/psql_test/ , you should correctly see four output statements.
However, if you:
cd /tmp/psql_test/ && psql test -f load.sql

You will get:

psql:load.sql:1: /hello.sql: No such file or directory
psql:load.sql:2: /subdir/hello2.sql: No such file or directory

Attached is a patch which fixes this, by recycling the bit of
Gurjeet's code which used "last_slash". (I have a feeling there's a
simpler way to fix it which avoids the last_slash complications.)

Josh

Attachment Content-Type Size
psql_fix_ir.v2.diff application/octet-stream 1.5 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: Re: psql \ir filename normalization
Date: 2011-11-16 04:28:37
Message-ID: CA+TgmoZnszt86+GdFNk8VX5L8xDt4M+K+vUzdd=CV+_g_N14Zg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Nov 15, 2011 at 6:54 PM, Josh Kupershmidt <schmiddy(at)gmail(dot)com> wrote:
> Commit c7f23494c1103f87bcf1ef7cbfcd626e73edb337 editorialized a bit on
> Gurjeet Singh's patch to implement \ir for psql, particularly in
> process_file(). Unfortunately, it looks like it broke the common case
> of loading a .SQL file in psql's working directory. Consider the
> following test case:
>
> mkdir -p /tmp/psql_test/subdir/
> mkdir -p /tmp/psql_test/path2/
>
> echo "SELECT 'hello 1';" > /tmp/psql_test/hello.sql
> echo "SELECT 'hello from parent';" > /tmp/psql_test/hello_parent.sql
> echo "SELECT 'hello from absolute path';" >
> /tmp/psql_test/path2/absolute_path.sql
> echo -e "SELECT 'hello 2';\n\ir ../hello_parent.sql\n\ir
> /tmp/psql_test/path2/absolute_path.sql" >
> /tmp/psql_test/subdir/hello2.sql
> echo -e "\ir hello.sql\n\ir subdir/hello2.sql" > /tmp/psql_test/load.sql
>
>
> If you try to load in "load.sql" from any working directory other than
> /tmp/psql_test/ , you should correctly see four output statements.
> However, if you:
>  cd /tmp/psql_test/ && psql test -f load.sql
>
> You will get:
>
> psql:load.sql:1: /hello.sql: No such file or directory
> psql:load.sql:2: /subdir/hello2.sql: No such file or directory
>
> Attached is a patch which fixes this, by recycling the bit of
> Gurjeet's code which used "last_slash". (I have a feeling there's a
> simpler way to fix it which avoids the last_slash complications.)

Argh. The root of the problem here seems to be that
join_path_components() feels entitled to arbitrarily insert a pathname
separator at the front of the output string even if its first input
didn't begin with one originally. Lame!

While looking for other places where this behavior might cause a
problem, I noticed something else that doesn't seem right. On
REL9_1_STABLE, if I initdb and then change the first "all" on the
"local" line to "@foo", I get this:

LOG: could not open secondary authentication file "@foo" as
"/Users/rhaas/pgsql/x/foo": No such file or directory

...and then the server starts up. But on master, I get:

LOG: could not open secondary authentication file "@foo" as
"/Users/rhaas/pgsql/y/foo": No such file or directory
LOG: end-of-line before database specification
CONTEXT: line 84 of configuration file "/Users/rhaas/pgsql/y/pg_hba.conf"
LOG: invalid connection type "all"
CONTEXT: line 85 of configuration file "/Users/rhaas/pgsql/y/pg_hba.conf"
FATAL: could not load pg_hba.conf

...which doesn't look right.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: Re: psql \ir filename normalization
Date: 2011-11-21 18:05:07
Message-ID: 201111211805.pALI57V25371@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> Argh. The root of the problem here seems to be that
> join_path_components() feels entitled to arbitrarily insert a pathname
> separator at the front of the output string even if its first input
> didn't begin with one originally. Lame!

The attached patch fixes this report, I think.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
/rtmp/join text/x-diff 552 bytes

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: Re: psql \ir filename normalization
Date: 2011-11-21 18:45:18
Message-ID: CA+TgmoYnWag9yE+7OvQoqC6VY4fd2TGbU9=p+vo7ta+YWGA0iw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Nov 21, 2011 at 1:05 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Robert Haas wrote:
>> Argh.  The root of the problem here seems to be that
>> join_path_components() feels entitled to arbitrarily insert a pathname
>> separator at the front of the output string even if its first input
>> didn't begin with one originally.  Lame!
>
> The attached patch fixes this report, I think.

Looks sensible. Keep in mind we need to back-patch this.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: Re: psql \ir filename normalization
Date: 2011-11-21 19:30:37
Message-ID: 201111211930.pALJUb309517@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> On Mon, Nov 21, 2011 at 1:05 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > Robert Haas wrote:
> >> Argh. ?The root of the problem here seems to be that
> >> join_path_components() feels entitled to arbitrarily insert a pathname
> >> separator at the front of the output string even if its first input
> >> didn't begin with one originally. ?Lame!
> >
> > The attached patch fixes this report, I think.
>
> Looks sensible. Keep in mind we need to back-patch this.

Oh. Well, with no bug reports about it, does that make sense? Do we
have any code that relies on the old behavior?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: Re: psql \ir filename normalization
Date: 2011-11-21 19:50:48
Message-ID: CA+TgmoYAxBnKQTp2BYtk8Z+DTTSSVmHSnq4bMu6u8TG=L12RrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Nov 21, 2011 at 2:30 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Robert Haas wrote:
>> On Mon, Nov 21, 2011 at 1:05 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>> > Robert Haas wrote:
>> >> Argh. ?The root of the problem here seems to be that
>> >> join_path_components() feels entitled to arbitrarily insert a pathname
>> >> separator at the front of the output string even if its first input
>> >> didn't begin with one originally. ?Lame!
>> >
>> > The attached patch fixes this report, I think.
>>
>> Looks sensible.  Keep in mind we need to back-patch this.
>
> Oh.  Well, with no bug reports about it, does that make sense?  Do we
> have any code that relies on the old behavior?

Oh, wait a minute. I was thinking \ir was in 9.1, but it's not: it
was committed after the branch. So I guess this only needs to be
fixed in master, which is much less scary.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: Re: psql \ir filename normalization
Date: 2011-11-21 19:51:56
Message-ID: 201111211951.pALJpvn12154@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> On Mon, Nov 21, 2011 at 2:30 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > Robert Haas wrote:
> >> On Mon, Nov 21, 2011 at 1:05 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >> > Robert Haas wrote:
> >> >> Argh. ?The root of the problem here seems to be that
> >> >> join_path_components() feels entitled to arbitrarily insert a pathname
> >> >> separator at the front of the output string even if its first input
> >> >> didn't begin with one originally. ?Lame!
> >> >
> >> > The attached patch fixes this report, I think.
> >>
> >> Looks sensible. ?Keep in mind we need to back-patch this.
> >
> > Oh. ?Well, with no bug reports about it, does that make sense? ?Do we
> > have any code that relies on the old behavior?
>
> Oh, wait a minute. I was thinking \ir was in 9.1, but it's not: it
> was committed after the branch. So I guess this only needs to be
> fixed in master, which is much less scary.

Agreed. I realize it is wrong but I have no idea what impact fixing it
in back branches might have, or people who are relying on the broken
behavior in some way.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Subject: Re: psql \ir filename normalization
Date: 2011-11-26 14:27:31
Message-ID: 201111261427.pAQERVd23951@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Robert Haas wrote:
> > On Mon, Nov 21, 2011 at 2:30 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > > Robert Haas wrote:
> > >> On Mon, Nov 21, 2011 at 1:05 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > >> > Robert Haas wrote:
> > >> >> Argh. ?The root of the problem here seems to be that
> > >> >> join_path_components() feels entitled to arbitrarily insert a pathname
> > >> >> separator at the front of the output string even if its first input
> > >> >> didn't begin with one originally. ?Lame!
> > >> >
> > >> > The attached patch fixes this report, I think.
> > >>
> > >> Looks sensible. ?Keep in mind we need to back-patch this.
> > >
> > > Oh. ?Well, with no bug reports about it, does that make sense? ?Do we
> > > have any code that relies on the old behavior?
> >
> > Oh, wait a minute. I was thinking \ir was in 9.1, but it's not: it
> > was committed after the branch. So I guess this only needs to be
> > fixed in master, which is much less scary.
>
> Agreed. I realize it is wrong but I have no idea what impact fixing it
> in back branches might have, or people who are relying on the broken
> behavior in some way.

Patch applied.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +