| From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> | 
|---|---|
| To: | Andrew Dunstan <andrew(at)dunslane(dot)net> | 
| Cc: | PostgreSQL Win32 port list <pgsql-hackers-win32(at)postgresql(dot)org>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org> | 
| Subject: | Re: [pgsql-hackers-win32] initdb in C | 
| Date: | 2003-11-08 17:38:37 | 
| Message-ID: | 200311081738.hA8Hcbj21209@candle.pha.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers pgsql-hackers-win32 pgsql-patches | 
Andrew Dunstan wrote:
> >Good. I can do rmdir() in C in port/dirmod.c if we need it.  Right now
> >we are doing system(rm/rmdir) in dbcommands.c so we should consistent. 
> >Let's stay with system(rm/rmdir) and if it doesn't work as we expect, we
> >can add your rmdir() code and put it in port/dirmod.c.
> >  
> >
> 
> In view of Peter's email of a few minutes ago I think we need to do that.
Again, recreate is only Win32.  I just figured out how to do this on
Win32.  We have to use 'del' rather than 'rmdir' to keep the directory:
New code is:
	/*
	 * delete a directory tree recursively
	 * assumes path points to a valid directory
	 * deletes everything under path
	 * if rmtopdir is true deletes the directory too
	 *
	 */
	static bool
	rmtree(char *path, bool rmtopdir)
	{
	    char        buf[MAXPGPATH + 64];
	
	#ifndef WIN32
	    /* doesn't handle .* files */
	    snprintf(buf, sizeof(buf), "rm -rf '%s%s'", path,
	            rmtopdir ? "" : "/*");
	#else
		snprintf(buf, sizeof(buf), "%s /s /q \"%s\"",
	    	    rmtopdir ? "rmdir" : "del", path);
	#endif
	
	    return !system(buf);
	}
> >        printf("\n"
> >                   "Success. You can now start the database server using:\n\n"
> >                   "    %s/postmaster -D %s%s%s\n"
> >                   "or\n"
> >                   "    %s/pg_ctl -D %s%s%s -l logfile start\n\n",
> >                        pgpath, QUOTE_PATH, pg_data, QUOTE_PATH,
> >                        pgpath, QUOTE_PATH, pg_data, QUOTE_PATH);
> >
> >(I also merged multiple \n into a single line.)  My logic was that
> >spaces in directory names are much more common on WIN32, so we should
> >display the quotes only on WIN32.  Perhaps you read "\"" as "\\"?
> >  
> >
> 
> Yes, I did. Sorry about that. But we also need to quote the path (the 
> most obvious place to put it after all is "C:\Program 
> Files\PostgreSQL"). In fact, that's more important than the data 
> location. Unfortunately, the Windows command processor barfs on multiple 
> quotes strings ;-(
I ran some tests using XP "CMD" and found:
	"C:\test"
and
	"\test"
works but:
"test"
does not work.  Since I see that the output always has a leading path, I
have modified the code to do:
    printf("\nSuccess. You can now start the database server using:\n\n"
           "    %s%s%s/postmaster -D %s%s%s\n"
           "or\n"
           "    %s%s%s/pg_ctl -D %s%s%s -l logfile start\n\n",
            QUOTE_PATH, pgpath, QUOTE_PATH, QUOTE_PATH, pg_data, QUOTE_PATH,
            QUOTE_PATH, pgpath, QUOTE_PATH, QUOTE_PATH, pg_data, QUOTE_PATH);
I am attaching the updated initdb.c file.
-- 
  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
| Attachment | Content-Type | Size | 
|---|---|---|
| unknown_filename | text/plain | 49.2 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruce Momjian | 2003-11-08 17:39:41 | Re: initdb in C | 
| Previous Message | Tom Lane | 2003-11-08 17:27:57 | Re: initdb in C | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruce Momjian | 2003-11-08 17:39:41 | Re: initdb in C | 
| Previous Message | Tom Lane | 2003-11-08 17:27:57 | Re: initdb in C | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruce Momjian | 2003-11-08 17:39:41 | Re: initdb in C | 
| Previous Message | Tom Lane | 2003-11-08 17:27:57 | Re: initdb in C |