Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6485b9f

Browse files
author
Artur Zakirov
committed
Check if restore destination exists
1 parent38407a0 commit6485b9f

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

‎dir.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,3 +725,41 @@ dir_copy_files(const char *from_root, const char *to_root)
725725
parray_walk(files,pgFileFree);
726726
parray_free(files);
727727
}
728+
729+
/*
730+
* Check if directory empty.
731+
*/
732+
bool
733+
dir_is_empty(constchar*path)
734+
{
735+
DIR*dir;
736+
structdirent*dir_ent;
737+
738+
dir=opendir(path);
739+
if (dir==NULL)
740+
{
741+
/* Directory in path doesn't exist */
742+
if (errno==ENOENT)
743+
return true;
744+
elog(ERROR,"cannot open directory \"%s\": %s",path,strerror(errno));
745+
}
746+
747+
errno=0;
748+
while ((dir_ent=readdir(dir)))
749+
{
750+
/* Skip entries point current dir or parent dir */
751+
if (strcmp(dir_ent->d_name,".")==0||
752+
strcmp(dir_ent->d_name,"..")==0)
753+
continue;
754+
755+
/* Directory is not empty */
756+
closedir(dir);
757+
return false;
758+
}
759+
if (errno)
760+
elog(ERROR,"cannot read directory \"%s\": %s",path,strerror(errno));
761+
762+
closedir(dir);
763+
764+
return true;
765+
}

‎pg_probackup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ extern parray *dir_read_file_list(const char *root, const char *file_txt);
322322

323323
externintdir_create_dir(constchar*path,mode_tmode);
324324
externvoiddir_copy_files(constchar*from_root,constchar*to_root);
325+
externbooldir_is_empty(constchar*path);
325326

326327
externpgFile*pgFileNew(constchar*path,boolomit_symlink);
327328
externvoidpgFileDelete(pgFile*file);

‎restore.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ do_restore(time_t backup_id,
4646
inti;
4747
intbase_index;/* index of base (full) backup */
4848
intret;
49-
TimeLineIDcur_tli;
5049
parray*backups;
5150

52-
parray*files;
5351
parray*timelines;
5452
pgBackup*base_backup=NULL;
5553
pgBackup*dest_backup=NULL;
@@ -85,9 +83,6 @@ do_restore(time_t backup_id,
8583
if (!backups)
8684
elog(ERROR,"cannot process any more.");
8785

88-
cur_tli=get_current_timeline(true);
89-
elog(LOG,"current instance timeline ID = %u",cur_tli);
90-
9186
if (target_tli)
9287
{
9388
elog(LOG,"target timeline ID = %u",target_tli);
@@ -148,27 +143,9 @@ do_restore(time_t backup_id,
148143
base_backup_found:
149144
base_index=i;
150145

151-
/*
152-
* Clear restore destination, but don't remove $PGDATA.
153-
* To remove symbolic link, get file list with "omit_symlink = false".
154-
*/
155-
if (!check)
156-
{
157-
elog(LOG,"----------------------------------------");
158-
elog(LOG,"clearing restore destination");
159-
160-
files=parray_new();
161-
dir_list_file(files,pgdata, false, false, false);
162-
parray_qsort(files,pgFileComparePathDesc);/* delete from leaf */
163-
164-
for (i=0;i<parray_num(files);i++)
165-
{
166-
pgFile*file= (pgFile*)parray_get(files,i);
167-
pgFileDelete(file);
168-
}
169-
parray_walk(files,pgFileFree);
170-
parray_free(files);
171-
}
146+
/* Check if restore destination empty */
147+
if (!dir_is_empty(pgdata))
148+
elog(ERROR,"restore destination is not empty");
172149

173150
print_backup_lsn(base_backup);
174151

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp