mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-12-11 11:41:33 +02:00
Fix directory check. Now pg_probackup init uses postgresql cross platform function pg_check_dir to ensure that backup catalog is empty
This commit is contained in:
parent
fa35f2e09c
commit
7eeb7a110b
21
src/init.c
21
src/init.c
@ -14,15 +14,6 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* selects function for scandir.
|
|
||||||
* Select all files except hidden.
|
|
||||||
*/
|
|
||||||
static int selects(const struct dirent *dir)
|
|
||||||
{
|
|
||||||
return dir->d_name[0] != '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize backup catalog.
|
* Initialize backup catalog.
|
||||||
*/
|
*/
|
||||||
@ -31,14 +22,16 @@ do_init(void)
|
|||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
char arclog_path_dir[MAXPGPATH];
|
char arclog_path_dir[MAXPGPATH];
|
||||||
struct dirent **dp;
|
|
||||||
int results;
|
int results;
|
||||||
|
|
||||||
if (access(backup_path, F_OK) == 0)
|
results = pg_check_dir(backup_path);
|
||||||
|
if (results == 4) /* exists and not empty*/
|
||||||
|
elog(ERROR, "backup catalog already exist and it's not empty");
|
||||||
|
else if (results == -1) /*trouble accessing directory*/
|
||||||
{
|
{
|
||||||
results = scandir(backup_path, &dp, selects, NULL);
|
int errno_tmp = errno;
|
||||||
if (results != 0)
|
elog(ERROR, "cannot open backup catalog directory \"%s\": %s",
|
||||||
elog(ERROR, "backup catalog already exist and it's not empty");
|
backup_path, strerror(errno_tmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create backup catalog root directory */
|
/* create backup catalog root directory */
|
||||||
|
Loading…
Reference in New Issue
Block a user