Re: Use of 'cp -r' in CREATE DATABASE

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
Cc: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Use of 'cp -r' in CREATE DATABASE
Date: 2003-12-12 01:05:54
Message-ID: 200312120105.hBC15sr29145@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Nigel J. Andrews wrote:
> On Thu, 11 Dec 2003, Alvaro Herrera wrote:
>
> > On Thu, Dec 11, 2003 at 06:36:05PM -0500, Bruce Momjian wrote:
> > > Our dbcommands.c has for create database:
> > >
> > > snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir);
> > >
> > [...]
> > >
> > > I think we should switch to -R in our code.
> >
> > But you will have to write special code for Win32, won't you?
> > Maybe it would be better to avoid using system commands
> > altogether and copy the whole thing using syscalls ...
>
> That was my immediate thought. Unfortunately that means reinventing the
> wheel; or grabbing it from BSD or somewhere and distributing it with
> postgresql.

We already have in dbcommands.c:

#ifndef WIN32
snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir);
if (system(buf) != 0)
{
if (remove_dbdirs(nominal_loc, alt_loc))
ereport(ERROR,
(errmsg("could not initialize database directory"),
errdetail("Failing system command was: %s", buf),
errhint("Look in the postmaster's stderr log for more information.")));
else
ereport(ERROR,
(errmsg("could not initialize database directory; delete failed as well"),
errdetail("Failing system command was: %s", buf),
errhint("Look in the postmaster's stderr log for more information.")));
}
#else /* WIN32 */
if (copydir(src_loc, target_dir) != 0)
{
/* copydir should already have given details of its troubles */
if (remove_dbdirs(nominal_loc, alt_loc))
ereport(ERROR,
(errmsg("could not initialize database directory")));
else
ereport(ERROR,
(errmsg("could not initialize database directory; delete failed as well")));
}
#endif /* WIN32 */

so Win32 is already handled by copydir. One reason we didn't implement
this in C is because there might be some OS-specific handling for copy.
copydir() is in port/copydir.c and is for Win32 alone.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-12-12 01:41:36 Re: Use of 'cp -r' in CREATE DATABASE
Previous Message Nigel J. Andrews 2003-12-12 00:45:21 Re: Use of 'cp -r' in CREATE DATABASE