From 9cb4a28f471eed8095b49f40607b340550532254 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 10 Sep 2003 20:24:09 +0000 Subject: [PATCH] Improve error message for cp or rm failur during create/drop database, per recent discussions. --- src/backend/commands/dbcommands.c | 40 ++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 8a7db76645..3227e300d2 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -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; } -- 2.40.0