Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8ca03aa

Browse files
committed
pg_dump: Simplify mkdir() error checking
mkdir() can check for errors itself. We don't need to code that ourselves again.
1 parent f5bcd39 commit 8ca03aa

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

src/bin/pg_dump/pg_backup_directory.c

+3-32
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
8484

8585
static char *prependDirectory(ArchiveHandle *AH, const char *relativeFilename);
8686

87-
static void createDirectory(const char *dir);
88-
8987

9088
/*
9189
* Init routine required by ALL formats. This is a global routine
@@ -148,8 +146,9 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
148146

149147
if (AH->mode == archModeWrite)
150148
{
151-
/* Create the directory, errors are caught there */
152-
createDirectory(ctx->directory);
149+
if (mkdir(ctx->directory, 0700) < 0)
150+
exit_horribly(modulename, "could not create directory \"%s\": %s\n",
151+
ctx->directory, strerror(errno));
153152
}
154153
else
155154
{ /* Read Mode */
@@ -628,34 +627,6 @@ _EndBlobs(ArchiveHandle *AH, TocEntry *te)
628627
ctx->blobsTocFH = NULL;
629628
}
630629

631-
static void
632-
createDirectory(const char *dir)
633-
{
634-
struct stat st;
635-
636-
/* the directory must not exist yet. */
637-
if (stat(dir, &st) == 0)
638-
{
639-
if (S_ISDIR(st.st_mode))
640-
exit_horribly(modulename,
641-
"cannot create directory %s, it exists already\n",
642-
dir);
643-
else
644-
exit_horribly(modulename,
645-
"cannot create directory %s, a file with this name "
646-
"exists already\n", dir);
647-
}
648-
649-
/*
650-
* Now we create the directory. Note that for some race condition we could
651-
* also run into the situation that the directory has been created just
652-
* between our two calls.
653-
*/
654-
if (mkdir(dir, 0700) < 0)
655-
exit_horribly(modulename, "could not create directory %s: %s\n",
656-
dir, strerror(errno));
657-
}
658-
659630

660631
static char *
661632
prependDirectory(ArchiveHandle *AH, const char *relativeFilename)

0 commit comments

Comments
 (0)