Thread: Re: [HACKERS] Win32 sysconfig -> pg_service.conf

Re: [HACKERS] Win32 sysconfig -> pg_service.conf

From
Bruce Momjian
Date:
On Win32, patch applied to return path if GetShortPathName() fails (no
short name, path does not exist), rather than returning nothing.

Backpatch to 8.1.X.

---------------------------------------------------------------------------

Andrew Dunstan wrote:
>
>
> David Fetter wrote:
>
> >>>doesn't report anything by way of --sysconfdir, which in turn means
> >>>that people have to do some fragile hackery in order even to see a
> >>>pg_service.conf file.  Can we put such a configuration directive
> >>>into the binary builds?  Is this known to work?
> >>>
> >>>
> >>In any case, the default is $prefix/etc which is probably not what
> >>you want anyway - why not set the PGSYSCONFDIR environment variable
> >>to point to where you put the service  file?
> >>
> >>
> >
> >Let's turn that question around.  Why *shouldn't* there be a default
> >built in?  "No default" seems like a pretty poor fall-through.
> >
> >
> >
> >
>
> On further investigation, this appears to be an artifact of the
> directory not existing, causing GetShortPathName to return an empty
> string, as noted in this comment:
>
>  * This can fail in 2 ways - if the path doesn't exist, or short names are
>  * disabled. In the first case, don't return any path.
>
> I think maybe we need a pg_config switch to allow us to fall back to
> GetFullPathName, which does not fail if the target doesn't exist. After
> all, it's cold comfort that libpq probably does the right thing if we
> don't have any reasonable way of finding out what that is.
>
> In the case of Windows binary packages, the place that actually works is
> apparently $bindir/../etc
>
> thoughts?
>
> cheers
>
> andrew
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

--
  Bruce Momjian   http://candle.pha.pa.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/bin/pg_config/pg_config.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_config/pg_config.c,v
retrieving revision 1.18
diff -c -c -r1.18 pg_config.c
*** src/bin/pg_config/pg_config.c    5 Mar 2006 15:58:50 -0000    1.18
--- src/bin/pg_config/pg_config.c    6 Jun 2006 19:03:53 -0000
***************
*** 35,45 ****
   * on Windows. We need them to use filenames without spaces, for which a
   * short filename is the safest equivalent, eg:
   *        C:/Progra~1/
-  *
-  * This can fail in 2 ways - if the path doesn't exist, or short names are
-  * disabled. In the first case, don't return any path. In the second case,
-  * we leave the path in the long form. In this case, it does still seem to
-  * fix elements containing spaces which is all we actually need.
   */
  static void
  cleanup_path(char *path)
--- 35,40 ----
***************
*** 47,64 ****
  #ifdef WIN32
      char       *ptr;

!     if (GetShortPathName(path, path, MAXPGPATH - 1) == 0)
!     {
!         /*
!          * Ignore ERROR_INVALID_PARAMETER as it almost certainly means that
!          * short names are disabled
!          */
!         if (GetLastError() != ERROR_INVALID_PARAMETER)
!         {
!             path[0] = '\0';
!             return;
!         }
!     }

      /* Replace '\' with '/' */
      for (ptr = path; *ptr; ptr++)
--- 42,53 ----
  #ifdef WIN32
      char       *ptr;

!     /*
!      *    GetShortPathName() will fail if the path does not exist, or short names
!      *    are disabled on this file system.  In both cases, we just return the
!      *    original path.
!      */
!     GetShortPathName(path, path, MAXPGPATH - 1);

      /* Replace '\' with '/' */
      for (ptr = path; *ptr; ptr++)

Re: [HACKERS] Win32 sysconfig -> pg_service.conf

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> On Win32, patch applied to return path if GetShortPathName() fails (no
> short name, path does not exist), rather than returning nothing.

Hm, are you sure GetShortPathName will never modify the path before
failing?  For instance, I'd be a bit worried about cases where it
successfully adjusts some components of the path before finding one that
doesn't exist.

            regards, tom lane

Re: [HACKERS] Win32 sysconfig -> pg_service.conf

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > On Win32, patch applied to return path if GetShortPathName() fails (no
> > short name, path does not exist), rather than returning nothing.
>
> Hm, are you sure GetShortPathName will never modify the path before
> failing?  For instance, I'd be a bit worried about cases where it
> successfully adjusts some components of the path before finding one that
> doesn't exist.

Good point.  Would someone test that?  Is GetFullPathName() the proper
direction?

--
  Bruce Momjian   http://candle.pha.pa.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +