mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
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:
parent
f5bcd398ad
commit
8ca03aa414
@ -84,8 +84,6 @@ static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
|
|||||||
|
|
||||||
static char *prependDirectory(ArchiveHandle *AH, const char *relativeFilename);
|
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
|
* Init routine required by ALL formats. This is a global routine
|
||||||
@ -148,8 +146,9 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
|
|||||||
|
|
||||||
if (AH->mode == archModeWrite)
|
if (AH->mode == archModeWrite)
|
||||||
{
|
{
|
||||||
/* Create the directory, errors are caught there */
|
if (mkdir(ctx->directory, 0700) < 0)
|
||||||
createDirectory(ctx->directory);
|
exit_horribly(modulename, "could not create directory \"%s\": %s\n",
|
||||||
|
ctx->directory, strerror(errno));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* Read Mode */
|
{ /* Read Mode */
|
||||||
@ -628,34 +627,6 @@ _EndBlobs(ArchiveHandle *AH, TocEntry *te)
|
|||||||
ctx->blobsTocFH = NULL;
|
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 *
|
static char *
|
||||||
prependDirectory(ArchiveHandle *AH, const char *relativeFilename)
|
prependDirectory(ArchiveHandle *AH, const char *relativeFilename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user