Patch to copy dirs

Поиск
Список
Период
Сортировка
Искать

Patch to copy dirs

От:
Bruce Momjian <pgman@candle.pha.pa.us>
Дата:
It turns out that while xcopy works for Win32, you can't run it as a
service because you don't have a window.  This patch adds a Win32
version of 'cp' as copydir.

Applied.

-- 
  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.259
diff -c -c -r1.259 configure
*** configure	15 May 2003 16:35:23 -0000	1.259
--- configure	15 May 2003 17:53:31 -0000
***************
*** 11395,11402 ****
  esac
  
  # Win32 can't to rename or unlink on an open file
! case $host_os in win32*|mingw*)
! LIBOBJS="$LIBOBJS dirmod.$ac_objext" ;;
  esac
  
  if test "$with_readline" = yes; then
--- 11395,11403 ----
  esac
  
  # Win32 can't to rename or unlink on an open file
! case $host_os in mingw*)
! LIBOBJS="$LIBOBJS dirmod.$ac_objext"
! LIBOBJS="$LIBOBJS copydir.$ac_objext" ;;
  esac
  
  if test "$with_readline" = yes; then
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.250
diff -c -c -r1.250 configure.in
*** configure.in	15 May 2003 16:35:27 -0000	1.250
--- configure.in	15 May 2003 17:53:32 -0000
***************
*** 863,870 ****
  esac
  
  # Win32 can't to rename or unlink on an open file
! case $host_os in win32*|mingw*)
! AC_LIBOBJ(dirmod) ;;
  esac
  
  if test "$with_readline" = yes; then
--- 863,871 ----
  esac
  
  # Win32 can't to rename or unlink on an open file
! case $host_os in mingw*)
! AC_LIBOBJ(dirmod)
! AC_LIBOBJ(copydir) ;;
  esac
  
  if test "$with_readline" = yes; then
Index: src/backend/commands/dbcommands.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/dbcommands.c,v
retrieving revision 1.114
diff -c -c -r1.114 dbcommands.c
*** src/backend/commands/dbcommands.c	7 May 2003 03:47:08 -0000	1.114
--- src/backend/commands/dbcommands.c	15 May 2003 17:53:34 -0000
***************
*** 311,321 ****
  	/* 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)
  	{
  		if (remove_dbdirs(nominal_loc, alt_loc))
  			elog(ERROR, "CREATE DATABASE: could not initialize database directory");
--- 311,320 ----
  	/* 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
! 	if (copydir(src_loc, target_dir) != 0)
  #endif
  	{
  		if (remove_dbdirs(nominal_loc, alt_loc))
  			elog(ERROR, "CREATE DATABASE: could not initialize database directory");
/*
 *	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;
}
FAQ