3737 *
3838 *
3939 * IDENTIFICATION
40- * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.68 2010/01/06 23:23:51 momjian Exp $
40+ * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.69 2010/01/07 04:05:39 momjian Exp $
4141 *
4242 *-------------------------------------------------------------------------
4343 */
@@ -89,7 +89,7 @@ static void write_version_file(const char *path);
8989 * Each database using a table space is isolated into its own name space
9090 * by a subdirectory named for the database OID. On first creation of an
9191 * object in the tablespace, create the subdirectory. If the subdirectory
92- * already exists,just fall through quietly.
92+ * already exists, fall through quietly.
9393 *
9494 * isRedo indicates that we are creating an object during WAL replay.
9595 * In this case we will cope with the possibility of the tablespace
@@ -137,29 +137,32 @@ TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo)
137137 */
138138if (stat (dir ,& st )== 0 && S_ISDIR (st .st_mode ))
139139{
140- /*need not do anything */
140+ /*Directory was created. */
141141}
142142else
143143{
144- /*OK, go for it */
144+ /*Directory creation failed? */
145145if (mkdir (dir ,S_IRWXU )< 0 )
146146{
147147char * parentdir ;
148148
149+ /* Failure other than not exists? */
149150if (errno != ENOENT || !isRedo )
150151ereport (ERROR ,
151152(errcode_for_file_access (),
152153errmsg ("could not create directory \"%s\": %m" ,
153154dir )));
154- /*Try to make parent directory too */
155+ /*Parent directory must be missing */
155156parentdir = pstrdup (dir );
156157get_parent_directory (parentdir );
158+ /* Can't create parent either? */
157159if (mkdir (parentdir ,S_IRWXU )< 0 )
158160ereport (ERROR ,
159161(errcode_for_file_access (),
160162errmsg ("could not create directory \"%s\": %m" ,
161163parentdir )));
162164pfree (parentdir );
165+ /* Create database directory */
163166if (mkdir (dir ,S_IRWXU )< 0 )
164167ereport (ERROR ,
165168(errcode_for_file_access (),
@@ -179,7 +182,7 @@ TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo)
179182}
180183else
181184{
182- /*be paranoid */
185+ /*Is it not a directory? */
183186if (!S_ISDIR (st .st_mode ))
184187ereport (ERROR ,
185188(errcode (ERRCODE_WRONG_OBJECT_TYPE ),