Improve error message for cp or rm failur during create/drop database,
authorTom Lane
Wed, 10 Sep 2003 20:24:09 +0000 (20:24 +0000)
committerTom Lane
Wed, 10 Sep 2003 20:24:09 +0000 (20:24 +0000)
per recent discussions.

src/backend/commands/dbcommands.c

index 8a7db766455b38e54a573d9505e858e845a1f459..3227e300d2886c1c0679d32f7dc8d71449d45625 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.121 2003/08/04 02:39:58 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.122 2003/09/10 20:24:09 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -354,19 +354,40 @@ createdb(const CreatedbStmt *stmt)
                            nominal_loc, alt_loc)));
    }
 
-   /* Copy the template database to the new location */
+   /*
+    * Copy the template database to the new location
+    *
+    * XXX use of cp really makes this code pretty grotty, particularly
+    * with respect to lack of ability to report errors well.  Someday
+    * rewrite to do it for ourselves.
+    */
 #ifndef WIN32
    snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir);
    if (system(buf) != 0)
-#else
+   {
+       if (remove_dbdirs(nominal_loc, alt_loc))
+           ereport(ERROR,
+                   (errmsg("could not initialize database directory"),
+                    errdetail("Failing system command was: %s", buf),
+                    errhint("Look in the postmaster's stderr log for more information.")));
+       else
+           ereport(ERROR,
+                   (errmsg("could not initialize database directory; delete failed as well"),
+                    errdetail("Failing system command was: %s", buf),
+                    errhint("Look in the postmaster's stderr log for more information.")));
+   }
+#else  /* WIN32 */
    if (copydir(src_loc, target_dir) != 0)
-#endif
    {
+       /* copydir should already have given details of its troubles */
        if (remove_dbdirs(nominal_loc, alt_loc))
-           elog(ERROR, "could not initialize database directory");
+           ereport(ERROR,
+                   (errmsg("could not initialize database directory")));
        else
-           elog(ERROR, "could not initialize database directory; delete failed as well");
+           ereport(ERROR,
+                   (errmsg("could not initialize database directory; delete failed as well")));
    }
+#endif /* WIN32 */
 
    /*
     * Now OK to grab exclusive lock on pg_database.
@@ -935,9 +956,10 @@ remove_dbdirs(const char *nominal_loc, const char *alt_loc)
    if (system(buf) != 0)
    {
        ereport(WARNING,
-               (errcode_for_file_access(),
-                errmsg("could not remove database directory \"%s\": %m",
-                       target_dir)));
+               (errmsg("could not remove database directory \"%s\"",
+                       target_dir),
+                errdetail("Failing system command was: %s", buf),
+                errhint("Look in the postmaster's stderr log for more information.")));
        success = false;
    }