aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_dump/pg_backup_directory.c')
-rw-r--r--src/bin/pg_dump/pg_backup_directory.c36
1 files changed, 2 insertions, 34 deletions
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index b2a841bb0ff..21b00792a8a 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -41,6 +41,7 @@
#include "common/file_utils.h"
#include "compress_io.h"
+#include "dumputils.h"
#include "parallel.h"
#include "pg_backup_utils.h"
@@ -156,41 +157,8 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
if (AH->mode == archModeWrite)
{
- struct stat st;
- bool is_empty = false;
-
/* we accept an empty existing directory */
- if (stat(ctx->directory, &st) == 0 && S_ISDIR(st.st_mode))
- {
- DIR *dir = opendir(ctx->directory);
-
- if (dir)
- {
- struct dirent *d;
-
- is_empty = true;
- while (errno = 0, (d = readdir(dir)))
- {
- if (strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0)
- {
- is_empty = false;
- break;
- }
- }
-
- if (errno)
- pg_fatal("could not read directory \"%s\": %m",
- ctx->directory);
-
- if (closedir(dir))
- pg_fatal("could not close directory \"%s\": %m",
- ctx->directory);
- }
- }
-
- if (!is_empty && mkdir(ctx->directory, 0700) < 0)
- pg_fatal("could not create directory \"%s\": %m",
- ctx->directory);
+ create_or_open_dir(ctx->directory);
}
else
{ /* Read Mode */