Add copydir() function because xcopy doesn't work in XP without a
authorBruce Momjian
Thu, 15 May 2003 17:59:17 +0000 (17:59 +0000)
committerBruce Momjian
Thu, 15 May 2003 17:59:17 +0000 (17:59 +0000)
window.

configure
configure.in
src/backend/commands/dbcommands.c
src/port/copydir.c [new file with mode: 0644]

index 1a09a8226870da9508f5ba331c4d7a6489e07787..bd84605af0ff807d0bbb51294ec31e37db4cf8a1 100755 (executable)
--- a/configure
+++ b/configure
@@ -11395,8 +11395,9 @@ LIBOBJS="$LIBOBJS qsort.$ac_objext" ;;
 esac
 
 # Win32 can't to rename or unlink on an open file
-case $host_os in win32*|mingw*)
-LIBOBJS="$LIBOBJS dirmod.$ac_objext" ;;
+case $host_os in mingw*)
+LIBOBJS="$LIBOBJS dirmod.$ac_objext"
+LIBOBJS="$LIBOBJS copydir.$ac_objext" ;;
 esac
 
 if test "$with_readline" = yes; then
index 774f439829bd2da4e2071f156fd061e3d02de4c3..670e5960d7e4c00a8932cd2bedf0d2e0edf7ccd5 100644 (file)
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.250 2003/05/15 16:35:27 momjian Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.251 2003/05/15 17:59:17 momjian Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -863,8 +863,9 @@ AC_LIBOBJ(qsort) ;;
 esac
 
 # Win32 can't to rename or unlink on an open file
-case $host_os in win32*|mingw*)
-AC_LIBOBJ(dirmod) ;;
+case $host_os in mingw*)
+AC_LIBOBJ(dirmod)
+AC_LIBOBJ(copydir) ;;
 esac
 
 if test "$with_readline" = yes; then
index 1c3b554c291c9f1134b1db13db02c9b4de497ff4..bd436878189a6cf49dfd6a7dcb88e291ad09b60f 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.114 2003/05/07 03:47:08 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.115 2003/05/15 17:59:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -311,11 +311,10 @@ createdb(const CreatedbStmt *stmt)
    /* Copy the template database to the new location */
 #ifndef WIN32
    snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir);
+   if (system(buf) != 0)
 #else
-   snprintf(buf, sizeof(buf), "xcopy /e /i /q '%s' '%s'", src_loc, target_dir);
+   if (copydir(src_loc, target_dir) != 0)
 #endif
-
-   if (system(buf) != 0)
    {
        if (remove_dbdirs(nominal_loc, alt_loc))
            elog(ERROR, "CREATE DATABASE: could not initialize database directory");
diff --git a/src/port/copydir.c b/src/port/copydir.c
new file mode 100644 (file)
index 0000000..cd39f4d
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * While "xcopy /e /i /q" works fine for copying directories, on Windows XP
+ * it requires an Window handle which prevents it from working when invoked
+ * as a service.
+ */
+
+#include "postgres.h"
+
+int
+copydir(char *fromdir,char *todir)
+{
+   DIR        *xldir;
+   struct dirent *xlde;
+   char        fromfl[MAXPGPATH];
+   char        tofl[MAXPGPATH];
+
+   if (mkdir(todir) != 0)
+   {
+       elog(ERROR, "could not make directory '%s'",todir);
+       return 1;
+   }
+   xldir = opendir(fromdir);
+   if (xldir == NULL)
+   {
+       closedir(xldir);
+       elog(ERROR, "could not open directory '%s'",fromdir);
+       return 1;
+   }
+
+   while ((xlde = readdir(xldir)) != NULL)
+   {
+           snprintf(fromfl, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
+           snprintf(tofl, MAXPGPATH, "%s/%s", todir, xlde->d_name);
+           if (CopyFile(fromfl,tofl,TRUE) < 0)
+           {
+               closedir(xldir);
+               elog(ERROR,"could not create file %s\n",todir);
+               return 1;
+           }
+   }
+
+   closedir(xldir);
+   return 0;
+}