Skip to content

Commit 09aad5a

Browse files
committed
Add copydir() function because xcopy doesn't work in XP without a
window.
1 parent bee0ac6 commit 09aad5a

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

configure

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11395,8 +11395,9 @@ LIBOBJS="$LIBOBJS qsort.$ac_objext" ;;
1139511395
esac
1139611396
1139711397
# Win32 can't to rename or unlink on an open file
11398-
case $host_os in win32*|mingw*)
11399-
LIBOBJS="$LIBOBJS dirmod.$ac_objext" ;;
11398+
case $host_os in mingw*)
11399+
LIBOBJS="$LIBOBJS dirmod.$ac_objext"
11400+
LIBOBJS="$LIBOBJS copydir.$ac_objext" ;;
1140011401
esac
1140111402
1140211403
if test "$with_readline" = yes; then

configure.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.250 2003/05/15 16:35:27 momjian Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.251 2003/05/15 17:59:17 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -863,8 +863,9 @@ AC_LIBOBJ(qsort) ;;
863863
esac
864864

865865
# Win32 can't to rename or unlink on an open file
866-
case $host_os in win32*|mingw*)
867-
AC_LIBOBJ(dirmod) ;;
866+
case $host_os in mingw*)
867+
AC_LIBOBJ(dirmod)
868+
AC_LIBOBJ(copydir) ;;
868869
esac
869870

870871
if test "$with_readline" = yes; then

src/backend/commands/dbcommands.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.114 2003/05/07 03:47:08 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.115 2003/05/15 17:59:17 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -311,11 +311,10 @@ createdb(const CreatedbStmt *stmt)
311311
/* Copy the template database to the new location */
312312
#ifndef WIN32
313313
snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir);
314+
if (system(buf) != 0)
314315
#else
315-
snprintf(buf, sizeof(buf), "xcopy /e /i /q '%s' '%s'", src_loc, target_dir);
316+
if (copydir(src_loc, target_dir) != 0)
316317
#endif
317-
318-
if (system(buf) != 0)
319318
{
320319
if (remove_dbdirs(nominal_loc, alt_loc))
321320
elog(ERROR, "CREATE DATABASE: could not initialize database directory");

src/port/copydir.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* While "xcopy /e /i /q" works fine for copying directories, on Windows XP
3+
* it requires an Window handle which prevents it from working when invoked
4+
* as a service.
5+
*/
6+
7+
#include "postgres.h"
8+
9+
int
10+
copydir(char *fromdir,char *todir)
11+
{
12+
DIR *xldir;
13+
struct dirent *xlde;
14+
char fromfl[MAXPGPATH];
15+
char tofl[MAXPGPATH];
16+
17+
if (mkdir(todir) != 0)
18+
{
19+
elog(ERROR, "could not make directory '%s'",todir);
20+
return 1;
21+
}
22+
xldir = opendir(fromdir);
23+
if (xldir == NULL)
24+
{
25+
closedir(xldir);
26+
elog(ERROR, "could not open directory '%s'",fromdir);
27+
return 1;
28+
}
29+
30+
while ((xlde = readdir(xldir)) != NULL)
31+
{
32+
snprintf(fromfl, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
33+
snprintf(tofl, MAXPGPATH, "%s/%s", todir, xlde->d_name);
34+
if (CopyFile(fromfl,tofl,TRUE) < 0)
35+
{
36+
closedir(xldir);
37+
elog(ERROR,"could not create file %s\n",todir);
38+
return 1;
39+
}
40+
}
41+
42+
closedir(xldir);
43+
return 0;
44+
}

0 commit comments

Comments
 (0)