diff --git a/src/dir.c b/src/dir.c index 2f6d8090..8732e712 100644 --- a/src/dir.c +++ b/src/dir.c @@ -187,7 +187,7 @@ pgFile * pgFileInit(const char *path, const char *rel_path) { pgFile *file; - char *file_name; + char *file_name = NULL; file = (pgFile *) pgut_malloc(sizeof(pgFile)); MemSet(file, 0, sizeof(pgFile)); @@ -414,6 +414,16 @@ pgFileComparePathWithExternalDesc(const void *f1, const void *f2) return -pgFileComparePathWithExternal(f1, f2); } +/* + * Compare two pgFile with their rel_path and external_dir_num + * in descending order of ASCII code. + */ +int +pgFileCompareRelPathWithExternalDesc(const void *f1, const void *f2) +{ + return -pgFileCompareRelPathWithExternal(f1, f2); +} + /* Compare two pgFile with their linked directory path. */ int pgFileCompareLinked(const void *f1, const void *f2) diff --git a/src/merge.c b/src/merge.c index e3358bd9..2d00fa78 100644 --- a/src/merge.c +++ b/src/merge.c @@ -236,7 +236,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup) DATABASE_FILE_LIST); to_files = dir_read_file_list(NULL, NULL, control_file, FIO_BACKUP_HOST); /* To delete from leaf, sort in reversed order */ - parray_qsort(to_files, pgFileComparePathWithExternalDesc); + parray_qsort(to_files, pgFileCompareRelPathWithExternalDesc); /* * Get list of files which need to be moved. */ @@ -385,7 +385,7 @@ delete_source_backup: /* * Delete files which are not in from_backup file list. */ - parray_qsort(files, pgFileComparePathWithExternalDesc); + parray_qsort(files, pgFileCompareRelPathWithExternalDesc); for (i = 0; i < parray_num(to_files); i++) { pgFile *file = (pgFile *) parray_get(to_files, i); @@ -398,7 +398,7 @@ delete_source_backup: continue; } - if (parray_bsearch(files, file, pgFileComparePathWithExternalDesc) == NULL) + if (parray_bsearch(files, file, pgFileCompareRelPathWithExternalDesc) == NULL) { char to_file_path[MAXPGPATH]; char *prev_path; @@ -488,7 +488,7 @@ merge_files(void *arg) i + 1, num_files, file->path); res_file = parray_bsearch(argument->to_files, file, - pgFileComparePathWithExternalDesc); + pgFileCompareRelPathWithExternalDesc); to_file = (res_file) ? *res_file : NULL; join_path_components(to_file_path, argument->to_root, file->path); diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 40b8ccb0..690e4d33 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -668,6 +668,7 @@ extern int pgFileCompareName(const void *f1, const void *f2); extern int pgFileComparePath(const void *f1, const void *f2); extern int pgFileComparePathWithExternal(const void *f1, const void *f2); extern int pgFileCompareRelPathWithExternal(const void *f1, const void *f2); +extern int pgFileCompareRelPathWithExternalDesc(const void *f1, const void *f2); extern int pgFileComparePathDesc(const void *f1, const void *f2); extern int pgFileComparePathWithExternalDesc(const void *f1, const void *f2); extern int pgFileCompareLinked(const void *f1, const void *f2);