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

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: Use of 'cp -r' in CREATE DATABASE
Дата
Msg-id 200312120105.hBC15sr29145@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: Use of 'cp -r' in CREATE DATABASE  ("Nigel J. Andrews" <nandrews@investsystems.co.uk>)
Список 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("couldnot 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
logfor more information.")));    }#else   /* WIN32 */    if (copydir(src_loc, target_dir) != 0)    {        /* copydir
shouldalready 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@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Nigel J. Andrews"
Дата:
Сообщение: Re: Use of 'cp -r' in CREATE DATABASE
Следующее
От: "Andrew Dunstan"
Дата:
Сообщение: Re: Use of 'cp -r' in CREATE DATABASE