diff --git a/src/init.c b/src/init.c index d92704cb..712cba11 100644 --- a/src/init.c +++ b/src/init.c @@ -14,15 +14,6 @@ #include #include -/* - * selects function for scandir. - * Select all files except hidden. - */ -static int selects(const struct dirent *dir) -{ - return dir->d_name[0] != '.'; -} - /* * Initialize backup catalog. */ @@ -31,14 +22,16 @@ do_init(void) { char path[MAXPGPATH]; char arclog_path_dir[MAXPGPATH]; - struct dirent **dp; 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); - if (results != 0) - elog(ERROR, "backup catalog already exist and it's not empty"); + int errno_tmp = errno; + elog(ERROR, "cannot open backup catalog directory \"%s\": %s", + backup_path, strerror(errno_tmp)); } /* create backup catalog root directory */