|
9 | 9 | *
|
10 | 10 | *
|
11 | 11 | * IDENTIFICATION
|
12 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.81 2001/10/25 05:49:24 momjian Exp $ |
| 12 | + * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.82 2002/02/23 20:55:46 tgl Exp $ |
13 | 13 | *
|
14 | 14 | *-------------------------------------------------------------------------
|
15 | 15 | */
|
@@ -164,10 +164,21 @@ createdb(const char *dbname, const char *dbpath,
|
164 | 164 | * Compute nominal location (where we will try to access the
|
165 | 165 | * database), and resolve alternate physical location if one is
|
166 | 166 | * specified.
|
| 167 | + * |
| 168 | + * If an alternate location is specified but is the same as the |
| 169 | + * normal path, just drop the alternate-location spec (this seems |
| 170 | + * friendlier than erroring out). We must test this case to avoid |
| 171 | + * creating a circular symlink below. |
167 | 172 | */
|
168 | 173 | nominal_loc = GetDatabasePath(dboid);
|
169 | 174 | alt_loc = resolve_alt_dbpath(dbpath, dboid);
|
170 | 175 |
|
| 176 | + if (alt_loc && strcmp(alt_loc, nominal_loc) == 0) |
| 177 | + { |
| 178 | + alt_loc = NULL; |
| 179 | + dbpath = NULL; |
| 180 | + } |
| 181 | + |
171 | 182 | if (strchr(nominal_loc, '\''))
|
172 | 183 | elog(ERROR, "database path may not contain single quotes");
|
173 | 184 | if (alt_loc && strchr(alt_loc, '\''))
|
@@ -198,7 +209,9 @@ createdb(const char *dbname, const char *dbpath,
|
198 | 209 | if (mkdir(target_dir, S_IRWXU) != 0)
|
199 | 210 | elog(ERROR, "CREATE DATABASE: unable to create database directory '%s': %m",
|
200 | 211 | target_dir);
|
201 |
| - rmdir(target_dir); |
| 212 | + if (rmdir(target_dir) != 0) |
| 213 | + elog(ERROR, "CREATE DATABASE: unable to remove temp directory '%s': %m", |
| 214 | + target_dir); |
202 | 215 |
|
203 | 216 | /* Make the symlink, if needed */
|
204 | 217 | if (alt_loc)
|
@@ -548,6 +561,9 @@ resolve_alt_dbpath(const char *dbpath, Oid dboid)
|
548 | 561 | }
|
549 | 562 |
|
550 | 563 | len = strlen(prefix) + 6 + sizeof(Oid) * 8 + 1;
|
| 564 | + if (len >= MAXPGPATH - 100) |
| 565 | + elog(ERROR, "Alternate path is too long"); |
| 566 | + |
551 | 567 | ret = palloc(len);
|
552 | 568 | snprintf(ret, len, "%s/base/%u", prefix, dboid);
|
553 | 569 |
|
|
0 commit comments