Обсуждение: Data directory with trailing [back]slash

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

Data directory with trailing [back]slash

От
"Magnus Hagander"
Дата:
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

Re: Data directory with trailing [back]slash

От
Tom Lane
Дата:
"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

Re: Data directory with trailing [back]slash

От
Andrew Dunstan
Дата:
Why isn't the path being canonicalised, which should remove the trailing
slash.

cheers

andrew

Magnus Hagander wrote:

>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?
>
>               http://www.postgresql.org/docs/faqs/FAQ.html
>
>
>