Data directory with trailing [back]slash
Hi!
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/
but it does work with
postmaster -D d:\pgdata
or
postmaster -D d:/pgdata/
This is because of the stat() call in postmaster.c in checkDataDir() -
stat() clearly does not work with trainling slash/backslash. I changed
the code to:
strcpy(path, checkdir);
#ifdef WIN32
if (path[strlen(path)-1] == '\\' || path[strlen(path)-1] == '/')
path[strlen(path)-1] = 0;
#endif
if (stat(path, &stat_buf) == -1)
{
if (errno == ENOENT)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("data directory \"%s\"
does not exist",
path)));
else
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not read permissions of directory
\"%s\": %m",
path)));
}
It seems to work on my system. I'm not sure if this is a good place to
do it, though, or if it should be changed at a different place. (with
this fix it will use duplicate path separators elsewhere, but from what
I can see this appears to work just fine).
If this seems like a good idea, please apply from code above. If not,
please direct me to a better plavce to work :-)
This is all required for the win32 installer, because Windows Installer
automatically adds trailing backslashes to all paths.
//Magnus
"Magnus Hagander" <mha@sollentuna.net> writes:
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/
Sounds like canonicalize_path() needs to be applied a bit sooner than
it is.
BTW I think canonicalize_path() is a few bricks shy of a load yet:
I'm not sure it works well with Windows drive-letters, and it definitely
will strip significant slashes when given input like '/' or 'C:\'.
Feel free to fix those problems while at it...
regards, tom lane
Why isn't the path being canonicalised, which should remove the trailing
slash.
cheers
andrew
Magnus Hagander wrote:
Show quoted text
Hi!
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/but it does work with
postmaster -D d:\pgdata
or
postmaster -D d:/pgdata/This is because of the stat() call in postmaster.c in checkDataDir() -
stat() clearly does not work with trainling slash/backslash. I changed
the code to:strcpy(path, checkdir);
#ifdef WIN32
if (path[strlen(path)-1] == '\\' || path[strlen(path)-1] == '/')
path[strlen(path)-1] = 0;
#endif
if (stat(path, &stat_buf) == -1)
{
if (errno == ENOENT)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("data directory \"%s\"
does not exist",
path)));
else
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not read permissions of directory
\"%s\": %m",
path)));
}It seems to work on my system. I'm not sure if this is a good place to
do it, though, or if it should be changed at a different place. (with
this fix it will use duplicate path separators elsewhere, but from what
I can see this appears to work just fine).If this seems like a good idea, please apply from code above. If not,
please direct me to a better plavce to work :-)This is all required for the win32 installer, because Windows Installer
automatically adds trailing backslashes to all paths.//Magnus
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
Tom Lane wrote:
"Magnus Hagander" <mha@sollentuna.net> writes:
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/Sounds like canonicalize_path() needs to be applied a bit sooner than
it is.BTW I think canonicalize_path() is a few bricks shy of a load yet:
I'm not sure it works well with Windows drive-letters, and it definitely
will strip significant slashes when given input like '/' or 'C:\'.
Feel free to fix those problems while at it...
Or use the attached patch, which I think does it right.
cheers
andrew
Attachments:
canon.patchtext/x-patch; name=canon.patchDownload+23-0
OK, I have fixed the problem. While your patch got close, it is best to
fix the problem in trim_trailing_separator() rather than above.
Tom already fixed the Unix case by preventing a path of '/' from being
stripped. This patch prevents c:/ and //network/ from being stripped
too. (Tom already mentioned Win32 would need work.)
---------------------------------------------------------------------------
Andrew Dunstan wrote:
Tom Lane wrote:
"Magnus Hagander" <mha@sollentuna.net> writes:
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/Sounds like canonicalize_path() needs to be applied a bit sooner than
it is.BTW I think canonicalize_path() is a few bricks shy of a load yet:
I'm not sure it works well with Windows drive-letters, and it definitely
will strip significant slashes when given input like '/' or 'C:\'.
Feel free to fix those problems while at it...Or use the attached patch, which I think does it right.
cheers
andrew
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
--
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, Pennsylvania 19073
Attachments:
/bjm/difftext/plainDownload+21-21
I am now confused about the original report. I don't see how my fix
would correct the reported problem. trim_trailing_separator() would
have handled d:\pgdata\ and d:\pgdata just fine. The fix only corrects
d:\.
Magnus, does current CVS fix the problem?
---------------------------------------------------------------------------
Andrew Dunstan wrote:
Tom Lane wrote:
"Magnus Hagander" <mha@sollentuna.net> writes:
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/Sounds like canonicalize_path() needs to be applied a bit sooner than
it is.BTW I think canonicalize_path() is a few bricks shy of a load yet:
I'm not sure it works well with Windows drive-letters, and it definitely
will strip significant slashes when given input like '/' or 'C:\'.
Feel free to fix those problems while at it...Or use the attached patch, which I think does it right.
cheers
andrew
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
--
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, Pennsylvania 19073
I think this still is not fixed. I think we need to add a call to
trim_trailing_separator() in checkDataDir(). Magnus, can you confirm
this will fix it?
---------------------------------------------------------------------------
Bruce Momjian wrote:
I am now confused about the original report. I don't see how my fix
would correct the reported problem. trim_trailing_separator() would
have handled d:\pgdata\ and d:\pgdata just fine. The fix only corrects
d:\.Magnus, does current CVS fix the problem?
---------------------------------------------------------------------------
Andrew Dunstan wrote:
Tom Lane wrote:
"Magnus Hagander" <mha@sollentuna.net> writes:
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/Sounds like canonicalize_path() needs to be applied a bit sooner than
it is.BTW I think canonicalize_path() is a few bricks shy of a load yet:
I'm not sure it works well with Windows drive-letters, and it definitely
will strip significant slashes when given input like '/' or 'C:\'.
Feel free to fix those problems while at it...Or use the attached patch, which I think does it right.
cheers
andrew
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match-- 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, Pennsylvania 19073---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
--
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, Pennsylvania 19073
OK, I found the problem. While we did canonicalize_path for client apps
like initdb, we didn't do it for server-side paths, for the most part.
This applied patch does canonicalize_path for -D, GUC variables, and
environment variables supplying paths. This should fix the Win32
problem you saw.
Are there other places where paths come into the system?
---------------------------------------------------------------------------
Bruce Momjian wrote:
I think this still is not fixed. I think we need to add a call to
trim_trailing_separator() in checkDataDir(). Magnus, can you confirm
this will fix it?---------------------------------------------------------------------------
Bruce Momjian wrote:
I am now confused about the original report. I don't see how my fix
would correct the reported problem. trim_trailing_separator() would
have handled d:\pgdata\ and d:\pgdata just fine. The fix only corrects
d:\.Magnus, does current CVS fix the problem?
---------------------------------------------------------------------------
Andrew Dunstan wrote:
Tom Lane wrote:
"Magnus Hagander" <mha@sollentuna.net> writes:
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/Sounds like canonicalize_path() needs to be applied a bit sooner than
it is.BTW I think canonicalize_path() is a few bricks shy of a load yet:
I'm not sure it works well with Windows drive-letters, and it definitely
will strip significant slashes when given input like '/' or 'C:\'.
Feel free to fix those problems while at it...Or use the attached patch, which I think does it right.
cheers
andrew
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match-- 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, Pennsylvania 19073---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)-- 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, Pennsylvania 19073---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
--
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, Pennsylvania 19073
Oops, path patch attached.
---------------------------------------------------------------------------
Bruce Momjian wrote:
I think this still is not fixed. I think we need to add a call to
trim_trailing_separator() in checkDataDir(). Magnus, can you confirm
this will fix it?---------------------------------------------------------------------------
Bruce Momjian wrote:
I am now confused about the original report. I don't see how my fix
would correct the reported problem. trim_trailing_separator() would
have handled d:\pgdata\ and d:\pgdata just fine. The fix only corrects
d:\.Magnus, does current CVS fix the problem?
---------------------------------------------------------------------------
Andrew Dunstan wrote:
Tom Lane wrote:
"Magnus Hagander" <mha@sollentuna.net> writes:
It's not possible to start the postmaster on win32 with:
postmaster -D d:\pgdata\
or
postmaster -D d:/pgdata/Sounds like canonicalize_path() needs to be applied a bit sooner than
it is.BTW I think canonicalize_path() is a few bricks shy of a load yet:
I'm not sure it works well with Windows drive-letters, and it definitely
will strip significant slashes when given input like '/' or 'C:\'.
Feel free to fix those problems while at it...Or use the attached patch, which I think does it right.
cheers
andrew
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match-- 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, Pennsylvania 19073---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)-- 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, Pennsylvania 19073---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
--
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, Pennsylvania 19073