Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Cannot initdb in cvs tip

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org,PostgreSQL Win32 port list <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-20 18:36:14
Message-ID: 200407201836.i6KIaER11446@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-hackers-win32pgsql-patches
Seems it might be time to address this and get it fixed.  Win32 doesn't
clean up the directory structure under /data and leave /data unchanged,
and there is no way to do this with a system() command on Win32.

I resisted adding a C version of rmtree during Win32 development because
I was concerned about disturbing the Unix behavior, but at this point I
think we should just move ahead and add a /port function for this and
remove the system() backend and initdb calls to 'rm' for directories.

---------------------------------------------------------------------------

Andrew Dunstan wrote:
> John Hansen said:
> > On Sun, 2004-06-20 at 08:04, Dave Page wrote:
> >> > > although it says it's clearing the contents of the directory, in
> >> > > actual fact it leaves the directory structure in place, thus a
> >> > > subsequent initdb will not run without a manual clearup.
> >> >
> >> > Hm.  The rmtree() function in initdb.c is responsible for
> >> > this, and I see it has WIN32-specific behavior, which is
> >> > evidently wrong.
> >> > Can you recommend a fix?
> >>
> >> The current solution does an "rmdir /q /s $PGDATA" if the datadir was
> >> created, and "del /q /s $PGDATA" if the directory already existed. The
> >> second case  will not work, as del will not remove directories.
> >> AFAICS, there is no easy way to do this using system() as rmdir won't
> >> accept wildcards, so we can't do "del $PGDATA/* && rmdir $PGDATA/*".
> >>
> >> It seems to me that the simple answer is to put Andrew's recursive
> >> unlink code back in (as he suggested), which Bruce removed as rm etc.
> >> were being used in commands/dbcommands.c (which should work fine under
> >> Windows). Patch below....
> >>
> >
> > you could of course rmdir /s /q $PGDATA && mkdir $PGDATA if the purpose
> > is to leave the directory intact if it already existed prior to
> > install.
> >
> 
> No we can't. This was discussed months ago, IIRC. The user might very well
> not have the privileges necessary to delete the directory, and might not
> have the privileges to recreate it if they do.
> 
> The direct recursive delete is not a lot of code, and I must confess I
> *hate* having C programs calling system() for such tasks. One of my goals
> in rewriting initdb in C was to avoid any calls at all to any external
> program other than postgres itself.
> 
> cheers
> 
> andrew
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
> 

-- 
  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

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2004-07-20 20:11:30
Subject: pg_config
Previous:From: Simon RiggsDate: 2004-07-20 17:27:58
Subject: Re: [HACKERS] Point in Time Recovery

pgsql-patches by date

Next:From: Bruce MomjianDate: 2004-07-20 19:00:22
Subject: Re: pg_dump --clean w/ <= 7.2 server
Previous:From: Bruce MomjianDate: 2004-07-20 18:17:41
Subject: Re: logfile subprocess and Fancy File Functions

pgsql-hackers-win32 by date

Next:From: Magnus HaganderDate: 2004-07-20 20:40:32
Subject: win2k, service, pg_ctl, popen, etc
Previous:From: Magnus HaganderDate: 2004-07-20 14:56:36
Subject: Re: psql_service v0.11

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group