mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Add copydir() function because xcopy doesn't work in XP without a
window.
This commit is contained in:
@ -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);
|
||||
#else
|
||||
snprintf(buf, sizeof(buf), "xcopy /e /i /q '%s' '%s'", src_loc, target_dir);
|
||||
#endif
|
||||
|
||||
if (system(buf) != 0)
|
||||
#else
|
||||
if (copydir(src_loc, target_dir) != 0)
|
||||
#endif
|
||||
{
|
||||
if (remove_dbdirs(nominal_loc, alt_loc))
|
||||
elog(ERROR, "CREATE DATABASE: could not initialize database directory");
|
||||
|
44
src/port/copydir.c
Normal file
44
src/port/copydir.c
Normal file
@ -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;
|
||||
}
|
Reference in New Issue
Block a user