Skip to content

Commit 9c4cdef

Browse files
committed
[Issue #113] bugfix: use rel_path attribute insead of path for sorting purposes and bsearch
1 parent dd124b3 commit 9c4cdef

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/dir.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pgFile *
187187
pgFileInit(const char *path, const char *rel_path)
188188
{
189189
pgFile *file;
190-
char *file_name;
190+
char *file_name = NULL;
191191

192192
file = (pgFile *) pgut_malloc(sizeof(pgFile));
193193
MemSet(file, 0, sizeof(pgFile));
@@ -414,6 +414,16 @@ pgFileComparePathWithExternalDesc(const void *f1, const void *f2)
414414
return -pgFileComparePathWithExternal(f1, f2);
415415
}
416416

417+
/*
418+
* Compare two pgFile with their rel_path and external_dir_num
419+
* in descending order of ASCII code.
420+
*/
421+
int
422+
pgFileCompareRelPathWithExternalDesc(const void *f1, const void *f2)
423+
{
424+
return -pgFileCompareRelPathWithExternal(f1, f2);
425+
}
426+
417427
/* Compare two pgFile with their linked directory path. */
418428
int
419429
pgFileCompareLinked(const void *f1, const void *f2)

src/merge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
236236
DATABASE_FILE_LIST);
237237
to_files = dir_read_file_list(NULL, NULL, control_file, FIO_BACKUP_HOST);
238238
/* To delete from leaf, sort in reversed order */
239-
parray_qsort(to_files, pgFileComparePathWithExternalDesc);
239+
parray_qsort(to_files, pgFileCompareRelPathWithExternalDesc);
240240
/*
241241
* Get list of files which need to be moved.
242242
*/
@@ -385,7 +385,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
385385
/*
386386
* Delete files which are not in from_backup file list.
387387
*/
388-
parray_qsort(files, pgFileComparePathWithExternalDesc);
388+
parray_qsort(files, pgFileCompareRelPathWithExternalDesc);
389389
for (i = 0; i < parray_num(to_files); i++)
390390
{
391391
pgFile *file = (pgFile *) parray_get(to_files, i);
@@ -398,7 +398,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
398398
continue;
399399
}
400400

401-
if (parray_bsearch(files, file, pgFileComparePathWithExternalDesc) == NULL)
401+
if (parray_bsearch(files, file, pgFileCompareRelPathWithExternalDesc) == NULL)
402402
{
403403
char to_file_path[MAXPGPATH];
404404
char *prev_path;
@@ -488,7 +488,7 @@ merge_files(void *arg)
488488
i + 1, num_files, file->path);
489489

490490
res_file = parray_bsearch(argument->to_files, file,
491-
pgFileComparePathWithExternalDesc);
491+
pgFileCompareRelPathWithExternalDesc);
492492
to_file = (res_file) ? *res_file : NULL;
493493

494494
join_path_components(to_file_path, argument->to_root, file->path);

src/pg_probackup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ extern int pgFileCompareName(const void *f1, const void *f2);
668668
extern int pgFileComparePath(const void *f1, const void *f2);
669669
extern int pgFileComparePathWithExternal(const void *f1, const void *f2);
670670
extern int pgFileCompareRelPathWithExternal(const void *f1, const void *f2);
671+
extern int pgFileCompareRelPathWithExternalDesc(const void *f1, const void *f2);
671672
extern int pgFileComparePathDesc(const void *f1, const void *f2);
672673
extern int pgFileComparePathWithExternalDesc(const void *f1, const void *f2);
673674
extern int pgFileCompareLinked(const void *f1, const void *f2);

0 commit comments

Comments
 (0)