Re: Win32 tablespace - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Win32 tablespace
Date
Msg-id 200408080132.i781W3L22579@candle.pha.pa.us
Whole thread Raw
In response to Re: Win32 tablespace  (Andreas Pflug <pgadmin@pse-consulting.de>)
Responses Re: Win32 tablespace
List pgsql-patches
OK, got them all.  Thanks.  Patch attached.

Would someone retest on Win32?

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

Andreas Pflug wrote:
> Bruce Momjian wrote:
> > OK, applied.  I moved the funciton into port/dirmod.c and cleaned up the
> > interface for Win32.
> >
> > Would someone test this on Win32 in case I broke something?
>
> Yes, something's broken, see patch.
>
> Second, HAVE_SYMLINK must be defined somewhere (configure?).
>
> Third, a junction is a directory, not a file, so DROP tablespace must
> use rmdir, not unlink to remove the junction; see my original patch.
>
> Regards,
> Andreas
>
>


>
> ---------------------------(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
Index: configure
===================================================================
RCS file: /cvsroot/pgsql-server/configure,v
retrieving revision 1.381
diff -c -c -r1.381 configure
*** configure    4 Aug 2004 21:33:34 -0000    1.381
--- configure    8 Aug 2004 00:45:33 -0000
***************
*** 12060,12066 ****
  LIBOBJS="$LIBOBJS gettimeofday.$ac_objext"
  LIBOBJS="$LIBOBJS kill.$ac_objext"
  LIBOBJS="$LIBOBJS open.$ac_objext"
! LIBOBJS="$LIBOBJS rand.$ac_objext" ;;
  esac

  if test "$with_readline" = yes; then
--- 12060,12072 ----
  LIBOBJS="$LIBOBJS gettimeofday.$ac_objext"
  LIBOBJS="$LIBOBJS kill.$ac_objext"
  LIBOBJS="$LIBOBJS open.$ac_objext"
! LIBOBJS="$LIBOBJS rand.$ac_objext"
!
! cat >>confdefs.h <<\_ACEOF
! #define HAVE_SYMLINK 1
! _ACEOF
!
! ;;
  esac

  if test "$with_readline" = yes; then
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.371
diff -c -c -r1.371 configure.in
*** configure.in    4 Aug 2004 21:33:35 -0000    1.371
--- configure.in    8 Aug 2004 00:45:37 -0000
***************
*** 908,914 ****
  AC_LIBOBJ(gettimeofday)
  AC_LIBOBJ(kill)
  AC_LIBOBJ(open)
! AC_LIBOBJ(rand) ;;
  esac

  if test "$with_readline" = yes; then
--- 908,917 ----
  AC_LIBOBJ(gettimeofday)
  AC_LIBOBJ(kill)
  AC_LIBOBJ(open)
! AC_LIBOBJ(rand)
! AC_DEFINE([HAVE_SYMLINK], 1,
!           [Define to 1 if you have the `symlink' function.])
! ;;
  esac

  if test "$with_readline" = yes; then
Index: src/backend/commands/tablespace.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/tablespace.c,v
retrieving revision 1.7
diff -c -c -r1.7 tablespace.c
*** src/backend/commands/tablespace.c    1 Aug 2004 20:30:48 -0000    1.7
--- src/backend/commands/tablespace.c    8 Aug 2004 00:45:44 -0000
***************
*** 482,492 ****
--- 482,501 ----
                   errmsg("could not unlink file \"%s\": %m",
                          subfile)));

+ #ifndef WIN32
      if (unlink(location) < 0)
          ereport(ERROR,
                  (errcode_for_file_access(),
                   errmsg("could not unlink symbolic link \"%s\": %m",
                          location)));
+ #else
+     /* The junction is a directory, not a file */
+     if (rmdir(location) < 0)
+         ereport(ERROR,
+                 (errcode_for_file_access(),
+                  errmsg("could not remove junction dir \"%s\": %m",
+                          location)));
+ #endif

      pfree(subfile);
      pfree(location);
Index: src/port/dirmod.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/port/dirmod.c,v
retrieving revision 1.14
diff -c -c -r1.14 dirmod.c
*** src/port/dirmod.c    7 Aug 2004 21:48:09 -0000    1.14
--- src/port/dirmod.c    8 Aug 2004 00:45:52 -0000
***************
*** 153,161 ****
  {
      HANDLE dirhandle;
      DWORD len;
-     char *p = nativeTarget;
      char buffer[MAX_PATH*sizeof(WCHAR) + sizeof(REPARSE_JUNCTION_DATA_BUFFER)];
      char nativeTarget[MAX_PATH];
      REPARSE_JUNCTION_DATA_BUFFER *reparseBuf = (REPARSE_JUNCTION_DATA_BUFFER*)buffer;

      CreateDirectory(newpath, 0);
--- 153,161 ----
  {
      HANDLE dirhandle;
      DWORD len;
      char buffer[MAX_PATH*sizeof(WCHAR) + sizeof(REPARSE_JUNCTION_DATA_BUFFER)];
      char nativeTarget[MAX_PATH];
+     char *p = nativeTarget;
      REPARSE_JUNCTION_DATA_BUFFER *reparseBuf = (REPARSE_JUNCTION_DATA_BUFFER*)buffer;

      CreateDirectory(newpath, 0);
***************
*** 203,211 ****
                        NULL, GetLastError(),
                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                        (LPSTR)&msg, 0, NULL );
          ereport(ERROR, (errcode_for_file_access(),
              errmsg("Error setting junction for %s: %s", nativeTarget, msg)));
!
          LocalFree(msg);

          CloseHandle(dirhandle);
--- 203,214 ----
                        NULL, GetLastError(),
                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                        (LPSTR)&msg, 0, NULL );
+ #ifdef FRONTEND
+         fprintf(stderr, "Error setting junction for %s: %s", nativeTarget, msg);
+ #else
          ereport(ERROR, (errcode_for_file_access(),
              errmsg("Error setting junction for %s: %s", nativeTarget, msg)));
! #endif
          LocalFree(msg);

          CloseHandle(dirhandle);

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: Make psql version aware; hide tablespace from older versions
Next
From: Bruce Momjian
Date:
Subject: Re: dbsize modification to support tablespaces