pg_dump: Simplify mkdir() error checking

mkdir() can check for errors itself.  We don't need to code that
ourselves again.
This commit is contained in:
Peter Eisentraut 2012-07-20 22:34:11 +03:00
parent f5bcd398ad
commit 8ca03aa414
1 changed files with 3 additions and 32 deletions

View File

@ -84,8 +84,6 @@ static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
static char *prependDirectory(ArchiveHandle *AH, const char *relativeFilename);
static void createDirectory(const char *dir);
/*
* Init routine required by ALL formats. This is a global routine
@ -148,8 +146,9 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
if (AH->mode == archModeWrite)
{
/* Create the directory, errors are caught there */
createDirectory(ctx->directory);
if (mkdir(ctx->directory, 0700) < 0)
exit_horribly(modulename, "could not create directory \"%s\": %s\n",
ctx->directory, strerror(errno));
}
else
{ /* Read Mode */
@ -628,34 +627,6 @@ _EndBlobs(ArchiveHandle *AH, TocEntry *te)
ctx->blobsTocFH = NULL;
}
static void
createDirectory(const char *dir)
{
struct stat st;
/* the directory must not exist yet. */
if (stat(dir, &st) == 0)
{
if (S_ISDIR(st.st_mode))
exit_horribly(modulename,
"cannot create directory %s, it exists already\n",
dir);
else
exit_horribly(modulename,
"cannot create directory %s, a file with this name "
"exists already\n", dir);
}
/*
* Now we create the directory. Note that for some race condition we could
* also run into the situation that the directory has been created just
* between our two calls.
*/
if (mkdir(dir, 0700) < 0)
exit_horribly(modulename, "could not create directory %s: %s\n",
dir, strerror(errno));
}
static char *
prependDirectory(ArchiveHandle *AH, const char *relativeFilename)