1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-03-31 23:09:30 +02:00

dir_is_empty() should be aware about MyLocation

This commit is contained in:
Arthur Zakirov 2019-04-23 12:00:53 +03:00
parent 99c55b6cff
commit 5dfa59fa9e
5 changed files with 10 additions and 10 deletions

View File

@ -489,7 +489,7 @@ pgBackupCreateDir(pgBackup *backup)
pgBackupGetPath(backup, path, lengthof(path), NULL);
if (!dir_is_empty(path))
if (!dir_is_empty(path, FIO_BACKUP_HOST))
elog(ERROR, "backup destination is not empty \"%s\"", path);
fio_mkdir(path, DIR_PERMISSION, FIO_BACKUP_HOST);

View File

@ -1277,7 +1277,7 @@ check_tablespace_mapping(pgBackup *backup)
elog(ERROR, "tablespace directory is not an absolute path: %s\n",
linked_path);
if (!dir_is_empty(linked_path))
if (!dir_is_empty(linked_path, FIO_DB_HOST))
elog(ERROR, "restore tablespace destination is not empty: \"%s\"",
linked_path);
}
@ -1619,12 +1619,12 @@ dir_read_file_list(const char *root, const char *external_prefix,
* Check if directory empty.
*/
bool
dir_is_empty(const char *path)
dir_is_empty(const char *path, fio_location location)
{
DIR *dir;
struct dirent *dir_ent;
dir = opendir(path);
dir = fio_opendir(path, location);
if (dir == NULL)
{
/* Directory in path doesn't exist */
@ -1634,7 +1634,7 @@ dir_is_empty(const char *path)
}
errno = 0;
while ((dir_ent = readdir(dir)))
while ((dir_ent = fio_readdir(dir)))
{
/* Skip entries point current dir or parent dir */
if (strcmp(dir_ent->d_name, ".") == 0 ||
@ -1642,13 +1642,13 @@ dir_is_empty(const char *path)
continue;
/* Directory is not empty */
closedir(dir);
fio_closedir(dir);
return false;
}
if (errno)
elog(ERROR, "cannot read directory \"%s\": %s", path, strerror(errno));
closedir(dir);
fio_closedir(dir);
return true;
}

View File

@ -359,7 +359,7 @@ validate_wal(pgBackup *backup, const char *archivedir,
* If recovery target is provided, ensure that archive files exist in
* archive directory.
*/
if (dir_is_empty(archivedir))
if (dir_is_empty(archivedir, FIO_BACKUP_HOST))
elog(ERROR, "WAL archive is empty. You cannot restore backup to a recovery target without WAL archive.");
/*

View File

@ -583,7 +583,7 @@ extern void makeExternalDirPathByNum(char *ret_path, const char *pattern_path,
extern bool backup_contains_external(const char *dir, parray *dirs_list);
extern int dir_create_dir(const char *path, mode_t mode);
extern bool dir_is_empty(const char *path);
extern bool dir_is_empty(const char *path, fio_location location);
extern bool fileExists(const char *path, fio_location location);
extern size_t pgFileSize(const char *path);

View File

@ -64,7 +64,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
elog(ERROR,
"required parameter not specified: PGDATA (-D, --pgdata)");
/* Check if restore destination empty */
if (!dir_is_empty(instance_config.pgdata))
if (!dir_is_empty(instance_config.pgdata, FIO_DB_HOST))
elog(ERROR, "restore destination is not empty: \"%s\"",
instance_config.pgdata);
}