Skip to content

Commit 7eeb7a1

Browse files
committed
Fix directory check. Now pg_probackup init uses postgresql cross platform function pg_check_dir to ensure that backup catalog is empty
1 parent fa35f2e commit 7eeb7a1

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/init.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
#include <dirent.h>
1515
#include <sys/stat.h>
1616

17-
/*
18-
* selects function for scandir.
19-
* Select all files except hidden.
20-
*/
21-
static int selects(const struct dirent *dir)
22-
{
23-
return dir->d_name[0] != '.';
24-
}
25-
2617
/*
2718
* Initialize backup catalog.
2819
*/
@@ -31,14 +22,16 @@ do_init(void)
3122
{
3223
char path[MAXPGPATH];
3324
char arclog_path_dir[MAXPGPATH];
34-
struct dirent **dp;
3525
int results;
3626

37-
if (access(backup_path, F_OK) == 0)
27+
results = pg_check_dir(backup_path);
28+
if (results == 4) /* exists and not empty*/
29+
elog(ERROR, "backup catalog already exist and it's not empty");
30+
else if (results == -1) /*trouble accessing directory*/
3831
{
39-
results = scandir(backup_path, &dp, selects, NULL);
40-
if (results != 0)
41-
elog(ERROR, "backup catalog already exist and it's not empty");
32+
int errno_tmp = errno;
33+
elog(ERROR, "cannot open backup catalog directory \"%s\": %s",
34+
backup_path, strerror(errno_tmp));
4235
}
4336

4437
/* create backup catalog root directory */

0 commit comments

Comments
 (0)