From e43dfb47a2cbb8994030814b65c679af6f3857e3 Mon Sep 17 00:00:00 2001 From: Yura Sokolov Date: Mon, 19 Dec 2022 06:01:57 +0300 Subject: [PATCH] do_init: use pioIsDirEmpty for existance check --- src/init.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/init.c b/src/init.c index 638096af..bd9a857f 100644 --- a/src/init.c +++ b/src/init.c @@ -19,19 +19,16 @@ int do_init(CatalogState *catalogState) { pioDrive_i backup_location = pioDriveForLocation(FIO_BACKUP_HOST); - int results; + bool empty; err_i err; - results = pg_check_dir(catalogState->catalog_path); + empty = $i(pioIsDirEmpty, backup_location,.path = catalogState->catalog_path, + .err = &err); - if (results == 4) /* exists and not empty*/ + if ($haserr(err)) + ft_logerr(FT_FATAL, $errmsg(err), "cannot open backup catalog directory"); + if (!empty) elog(ERROR, "backup catalog already exist and it's not empty"); - else if (results == -1) /*trouble accessing directory*/ - { - int errno_tmp = errno; - elog(ERROR, "cannot open backup catalog directory \"%s\": %s", - catalogState->catalog_path, strerror(errno_tmp)); - } /* create backup catalog root directory */ err = $i(pioMakeDir, backup_location, .path = catalogState->catalog_path,