Re: [pgsql-hackers-win32] Data directory with trailing [back]slash - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [pgsql-hackers-win32] Data directory with trailing [back]slash
Date
Msg-id 200407110257.i6B2vZb22729@candle.pha.pa.us
Whole thread Raw
In response to Re: [pgsql-hackers-win32] Data directory with trailing [back]slash  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-patches
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
Index: src/port/path.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/port/path.c,v
retrieving revision 1.21
diff -c -c -r1.21 path.c
*** src/port/path.c    10 Jul 2004 22:58:42 -0000    1.21
--- src/port/path.c    11 Jul 2004 02:50:49 -0000
***************
*** 389,395 ****
  trim_trailing_separator(char *path)
  {
      char *p = path + strlen(path);
!
      /* trim off trailing slashes */
      if (p > path)
          for (p--; p > path && IS_DIR_SEP(*p); p--)
--- 389,414 ----
  trim_trailing_separator(char *path)
  {
      char *p = path + strlen(path);
!
! #ifdef WIN32
!     /* Skip over network and drive specifiers for win32 */
!     if (strlen(path) >= 2)
!     {
!         if (IS_DIR_SEP(path[0]) && IS_DIR_SEP(path[1]))
!         {
!             path += 2;
!             while (*path && !IS_DIR_SEP(*path))
!                 path++;
!         }
!         else if (isalpha(path[0]) && path[1] == ':')
!         {
!             path++;
!             if (IS_DIR_SEP(path[1]))
!                 path++;
!         }
!     }
! #endif
!
      /* trim off trailing slashes */
      if (p > path)
          for (p--; p > path && IS_DIR_SEP(*p); p--)

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Updated ALTER TABLE ... SET TABLESPACE patch
Next
From: Bruce Momjian
Date:
Subject: Re: pg_dump --clean w/ <= 7.2 server