Skip to content

Commit c812fa3

Browse files
author
Michael Paquier
committed
Refactor code for file list creation
A lot of code in this area was duplicated, so better to remove that.
1 parent 0974550 commit c812fa3

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

backup.c

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ static bool dirExists(const char *path);
5858

5959
static void add_files(parray *files, const char *root, bool add_root, bool is_pgdata);
6060
static int strCompare(const void *str1, const void *str2);
61-
static void create_file_list(parray *files, const char *root, const char *prefix, bool is_append);
61+
static void create_file_list(parray *files,
62+
const char *root,
63+
const char *subdir,
64+
const char *prefix,
65+
bool is_append);
6266
static TimeLineID get_current_timeline(void);
6367

6468
/*
@@ -267,7 +271,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
267271
pg_stop_backup(&current);
268272

269273
/* create file list of non-snapshot objects */
270-
create_file_list(files, pgdata, NULL, false);
274+
create_file_list(files, pgdata, DATABASE_FILE_LIST, NULL, false);
271275

272276
/* backup files from snapshot volume */
273277
for (i = 0; i < parray_num(tblspcmp_list); i++)
@@ -310,7 +314,8 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
310314
/* backup files of DB cluster from snapshot volume */
311315
backup_files(mp, path, snapshot_files, prev_files, lsn, current.compress_data, NULL);
312316
/* create file list of snapshot objects (DB cluster) */
313-
create_file_list(snapshot_files, mp, NULL, true);
317+
create_file_list(snapshot_files, mp, DATABASE_FILE_LIST,
318+
NULL, true);
314319
/* remove the detected tablespace("PG-DATA") from tblspcmp_list */
315320
parray_rm(tblspcmp_list, "PG-DATA", strCompare);
316321
i--;
@@ -342,8 +347,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
342347
backup_files(mp, dest, snapshot_files, prev_files, lsn, current.compress_data, prefix);
343348

344349
/* create file list of snapshot objects (TABLESPACE) */
345-
create_file_list(snapshot_files, mp, prefix, true);
346-
/* remove the detected tablespace("PG-DATA") from tblspcmp_list */
350+
create_file_list(snapshot_files, mp, DATABASE_FILE_LIST,
351+
prefix, true);
352+
/*
353+
* Remove the detected tablespace("PG-DATA") from
354+
* tblspcmp_list.
355+
*/
347356
parray_rm(tblspcmp_list, spcname, strCompare);
348357
i--;
349358
break;
@@ -385,7 +394,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
385394
pg_stop_backup(&current);
386395

387396
/* create file list */
388-
create_file_list(files, pgdata, NULL, false);
397+
create_file_list(files, pgdata, DATABASE_FILE_LIST, NULL, false);
389398
}
390399

391400
/* print summary of size of backup mode files */
@@ -429,7 +438,6 @@ do_backup_arclog(parray *backup_list)
429438
int i;
430439
parray *files;
431440
parray *prev_files = NULL; /* file list of previous database backup */
432-
FILE *fp;
433441
char path[MAXPGPATH];
434442
char timeline_dir[MAXPGPATH];
435443
char prev_file_txt[MAXPGPATH];
@@ -513,19 +521,10 @@ do_backup_arclog(parray *backup_list)
513521
backup_files(arclog_path, path, files, prev_files, NULL,
514522
current.compress_data, NULL);
515523

516-
/* create file list */
517-
if (!check)
518-
{
519-
pgBackupGetPath(&current, path, lengthof(path), ARCLOG_FILE_LIST);
520-
fp = fopen(path, "wt");
521-
if (fp == NULL)
522-
elog(ERROR_SYSTEM, _("can't open file list \"%s\": %s"), path,
523-
strerror(errno));
524-
dir_print_file_list(fp, files, arclog_path, NULL);
525-
fclose(fp);
526-
}
524+
/* Create file list */
525+
create_file_list(files, arclog_path, ARCLOG_FILE_LIST, NULL, false);
527526

528-
/* print summary of size of backup files */
527+
/* Print summary of size of backup files */
529528
for (i = 0; i < parray_num(files); i++)
530529
{
531530
pgFile *file = (pgFile *) parray_get(files, i);
@@ -577,7 +576,6 @@ do_backup_srvlog(parray *backup_list)
577576
int i;
578577
parray *files;
579578
parray *prev_files = NULL; /* file list of previous database backup */
580-
FILE *fp;
581579
char path[MAXPGPATH];
582580
char prev_file_txt[MAXPGPATH];
583581
pgBackup *prev_backup;
@@ -623,16 +621,7 @@ do_backup_srvlog(parray *backup_list)
623621
backup_files(srvlog_path, path, files, prev_files, NULL, false, NULL);
624622

625623
/* create file list */
626-
if (!check)
627-
{
628-
pgBackupGetPath(&current, path, lengthof(path), SRVLOG_FILE_LIST);
629-
fp = fopen(path, "wt");
630-
if (fp == NULL)
631-
elog(ERROR_SYSTEM, _("can't open file list \"%s\": %s"), path,
632-
strerror(errno));
633-
dir_print_file_list(fp, files, srvlog_path, NULL);
634-
fclose(fp);
635-
}
624+
create_file_list(files, arclog_path, SRVLOG_FILE_LIST, NULL, false);
636625

637626
/* print summary of size of backup mode files */
638627
for (i = 0; i < parray_num(files); i++)
@@ -1548,18 +1537,22 @@ strCompare(const void *str1, const void *str2)
15481537
}
15491538

15501539
/*
1551-
* Output the list of backup files to backup catalog
1540+
* Output the list of files to backup catalog
15521541
*/
15531542
static void
1554-
create_file_list(parray *files, const char *root, const char *prefix, bool is_append)
1543+
create_file_list(parray *files,
1544+
const char *root,
1545+
const char *subdir,
1546+
const char *prefix,
1547+
bool is_append)
15551548
{
15561549
FILE *fp;
15571550
char path[MAXPGPATH];
15581551

15591552
if (!check)
15601553
{
15611554
/* output path is '$BACKUP_PATH/file_database.txt' */
1562-
pgBackupGetPath(&current, path, lengthof(path), DATABASE_FILE_LIST);
1555+
pgBackupGetPath(&current, path, lengthof(path), subdir);
15631556
fp = fopen(path, is_append ? "at" : "wt");
15641557
if (fp == NULL)
15651558
elog(ERROR_SYSTEM, _("can't open file list \"%s\": %s"), path,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy