|
39 | 39 | * Portions Copyright (c) 1994, Regents of the University of California
|
40 | 40 | * Portions taken from FreeBSD.
|
41 | 41 | *
|
42 |
| - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.73 2005/01/08 22:51:12 tgl Exp $ |
| 42 | + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.74 2005/01/28 00:34:32 tgl Exp $ |
43 | 43 | *
|
44 | 44 | *-------------------------------------------------------------------------
|
45 | 45 | */
|
@@ -476,6 +476,9 @@ popen_check(const char *command, const char *mode)
|
476 | 476 | * this tries to build all the elements of a path to a directory a la mkdir -p
|
477 | 477 | * we assume the path is in canonical form, i.e. uses / as the separator
|
478 | 478 | * we also assume it isn't null.
|
| 479 | + * |
| 480 | + * note that on failure, the path arg has been modified to show the particular |
| 481 | + * directory level we had problems with. |
479 | 482 | */
|
480 | 483 | staticint
|
481 | 484 | mkdir_p(char*path,mode_tomode)
|
@@ -544,31 +547,25 @@ mkdir_p(char *path, mode_t omode)
|
544 | 547 | }
|
545 | 548 | if (last)
|
546 | 549 | (void)umask(oumask);
|
547 |
| -if (mkdir(path,last ?omode :S_IRWXU |S_IRWXG |S_IRWXO)<0) |
| 550 | + |
| 551 | +/* check for pre-existing directory; ok if it's a parent */ |
| 552 | +if (stat(path,&sb)==0) |
548 | 553 | {
|
549 |
| -if (errno==EEXIST||errno==EISDIR) |
550 |
| -{ |
551 |
| -if (stat(path,&sb)<0) |
552 |
| -{ |
553 |
| -retval=1; |
554 |
| -break; |
555 |
| -} |
556 |
| -elseif (!S_ISDIR(sb.st_mode)) |
557 |
| -{ |
558 |
| -if (last) |
559 |
| -errno=EEXIST; |
560 |
| -else |
561 |
| -errno=ENOTDIR; |
562 |
| -retval=1; |
563 |
| -break; |
564 |
| -} |
565 |
| -} |
566 |
| -else |
| 554 | +if (!S_ISDIR(sb.st_mode)) |
567 | 555 | {
|
| 556 | +if (last) |
| 557 | +errno=EEXIST; |
| 558 | +else |
| 559 | +errno=ENOTDIR; |
568 | 560 | retval=1;
|
569 | 561 | break;
|
570 | 562 | }
|
571 | 563 | }
|
| 564 | +elseif (mkdir(path,last ?omode :S_IRWXU |S_IRWXG |S_IRWXO)<0) |
| 565 | +{ |
| 566 | +retval=1; |
| 567 | +break; |
| 568 | +} |
572 | 569 | if (!last)
|
573 | 570 | *p='/';
|
574 | 571 | }
|
|