Skip to content

Commit e3b9fd4

Browse files
author
itagaki.takahiro
committed
Use join_path_components() if possible.
git-svn-id: http://pg-rman.googlecode.com/svn/trunk@27 182aca00-e38e-11de-a668-6fd11605f5ce
1 parent 1824440 commit e3b9fd4

File tree

7 files changed

+49
-59
lines changed

7 files changed

+49
-59
lines changed

backup.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ do_backup_arclog(parray *backup_list)
314314
* We do this after create file list, because copy_file() update
315315
* pgFile->write_size to actual size.
316316
*/
317-
snprintf(timeline_dir, lengthof(timeline_dir), "%s/%s", backup_path,
318-
TIMELINE_HISTORY_DIR);
317+
join_path_components(timeline_dir, backup_path, TIMELINE_HISTORY_DIR);
319318
for (i = 0; i < parray_num(files); i++)
320319
{
321320
pgFile *file = (pgFile *) parray_get(files, i);
@@ -875,8 +874,7 @@ backup_files(const char *from_root,
875874
{
876875
char dirpath[MAXPGPATH];
877876

878-
snprintf(dirpath, lengthof(dirpath), "%s/%s", to_root,
879-
file->path + strlen(from_root) + 1);
877+
join_path_components(dirpath, to_root, file->path + strlen(from_root) + 1);
880878
if (!check)
881879
dir_create_dir(dirpath, DIR_PERMISSION);
882880
if (verbose)

catalog.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ catalog_lock(void)
3737
int ret;
3838
char id_path[MAXPGPATH];
3939

40-
snprintf(id_path, lengthof(id_path), "%s/%s", backup_path,
41-
PG_RMAN_INI_FILE);
40+
join_path_components(id_path, backup_path, PG_RMAN_INI_FILE);
4241
lock_fd = open(id_path, O_RDWR);
4342
if (lock_fd == -1)
4443
elog(errno == ENOENT ? ERROR_CORRUPTED : ERROR_SYSTEM,
@@ -81,8 +80,8 @@ catalog_unlock(void)
8180
pgBackup *
8281
catalog_get_backup(time_t timestamp)
8382
{
84-
pgBackup tmp;
85-
char ini_path[MAXPGPATH];
83+
pgBackup tmp;
84+
char ini_path[MAXPGPATH];
8685

8786
tmp.start_time = timestamp;
8887
pgBackupGetPath(&tmp, ini_path, lengthof(ini_path), BACKUP_INI_FILE);
@@ -120,18 +119,18 @@ parray *
120119
catalog_get_backup_list(const pgBackupRange *range)
121120
{
122121
const pgBackupRange range_all = { 0, 0 };
123-
DIR *date_dir = NULL;
124-
struct dirent *date_ent = NULL;
125-
DIR *time_dir = NULL;
126-
struct dirent *time_ent = NULL;
127-
char date_path[MAXPGPATH];
128-
parray *backups = NULL;
129-
pgBackup *backup = NULL;
130-
struct tm *tm;
131-
char begin_date[100];
132-
char begin_time[100];
133-
char end_date[100];
134-
char end_time[100];
122+
DIR *date_dir = NULL;
123+
struct dirent *date_ent = NULL;
124+
DIR *time_dir = NULL;
125+
struct dirent *time_ent = NULL;
126+
char date_path[MAXPGPATH];
127+
parray *backups = NULL;
128+
pgBackup *backup = NULL;
129+
struct tm *tm;
130+
char begin_date[100];
131+
char begin_time[100];
132+
char end_date[100];
133+
char end_time[100];
135134

136135
if (range == NULL)
137136
range = &range_all;
@@ -172,7 +171,7 @@ catalog_get_backup_list(const pgBackupRange *range)
172171
continue;
173172

174173
/* open subdirectory (date directory) and search time directory */
175-
snprintf(date_path, MAXPGPATH, "%s/%s", backup_path, date_ent->d_name);
174+
join_path_components(date_path, backup_path, date_ent->d_name);
176175
time_dir = opendir(date_path);
177176
if (time_dir == NULL)
178177
{
@@ -291,8 +290,8 @@ catalog_get_last_arclog_backup(parray *backup_list)
291290
pgBackup *
292291
catalog_get_last_srvlog_backup(parray *backup_list)
293292
{
294-
int i;
295-
pgBackup *backup = NULL;
293+
int i;
294+
pgBackup *backup = NULL;
296295

297296
/* backup_list is sorted in order of descending ID */
298297
for (i = 0; i < parray_num(backup_list); i++)
@@ -311,9 +310,9 @@ catalog_get_last_srvlog_backup(parray *backup_list)
311310
int
312311
pgBackupCreateDir(pgBackup *backup)
313312
{
314-
int i;
315-
char path[MAXPGPATH];
316-
char *subdirs[] = { DATABASE_DIR, ARCLOG_DIR, SRVLOG_DIR, NULL };
313+
int i;
314+
char path[MAXPGPATH];
315+
char *subdirs[] = { DATABASE_DIR, ARCLOG_DIR, SRVLOG_DIR, NULL };
317316

318317
pgBackupGetPath(backup, path, lengthof(path), NULL);
319318
dir_create_dir(path, DIR_PERMISSION);
@@ -377,8 +376,8 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
377376
void
378377
pgBackupWriteIni(pgBackup *backup)
379378
{
380-
FILE *fp = NULL;
381-
char ini_path[MAXPGPATH];
379+
FILE *fp = NULL;
380+
char ini_path[MAXPGPATH];
382381

383382
pgBackupGetPath(backup, ini_path, lengthof(ini_path), BACKUP_INI_FILE);
384383
fp = fopen(ini_path, "wt");
@@ -561,8 +560,8 @@ pgBackupCompareIdDesc(const void *l, const void *r)
561560
void
562561
pgBackupGetPath(const pgBackup *backup, char *path, size_t len, const char *subdir)
563562
{
564-
char datetime[20];
565-
struct tm *tm;
563+
char datetime[20];
564+
struct tm *tm;
566565

567566
/* generate $BACKUP_PATH/date/time path */
568567
tm = localtime(&backup->start_time);

data.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ backup_data_file(const char *from_root, const char *to_root,
307307
if (check)
308308
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
309309
else
310-
snprintf(to_path, lengthof(to_path), "%s/%s",
311-
to_root, file->path + strlen(from_root) + 1);
310+
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
312311
out = fopen(to_path, "w");
313312
if (out == NULL)
314313
{
@@ -594,8 +593,7 @@ restore_data_file(const char *from_root,
594593
* modified pages for incremental restore. If the file is not exists,
595594
* re-open it with "w" to create an empty file.
596595
*/
597-
snprintf(to_path, lengthof(to_path), "%s/%s", to_root,
598-
file->path + strlen(from_root) + 1);
596+
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
599597
out = fopen(to_path, "r+");
600598
if (out == NULL && errno == ENOENT)
601599
out = fopen(to_path, "w");
@@ -783,8 +781,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
783781
if (check)
784782
snprintf(to_path, lengthof(to_path), "%s/tmp", backup_path);
785783
else
786-
snprintf(to_path, lengthof(to_path), "%s/%s", to_root,
787-
file->path + strlen(from_root) + 1);
784+
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
788785
out = fopen(to_path, "w");
789786
if (out == NULL)
790787
{

dir.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
246246

247247
strncpy(dname, file->path, lengthof(dname));
248248
dnamep = dirname(dname);
249-
snprintf(absolute, lengthof(absolute), "%s/%s", dname, linked);
249+
join_path_components(absolute, dname, linked);
250250
file = pgFileNew(absolute, omit_symlink);
251251
}
252252
else
@@ -329,7 +329,7 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
329329
strcmp(dent->d_name, "..") == 0)
330330
continue;
331331

332-
snprintf(child, lengthof(child), "%s/%s", file->path, dent->d_name);
332+
join_path_components(child, file->path, dent->d_name);
333333
dir_list_file(files, child, exclude, omit_symlink, true);
334334
}
335335
if (errno && errno != ENOENT)
@@ -438,9 +438,9 @@ dir_print_file_list(FILE *out, const parray *files, const char *root)
438438
parray *
439439
dir_read_file_list(const char *root, const char *file_txt)
440440
{
441-
FILE *fp;
441+
FILE *fp;
442442
parray *files;
443-
char buf[MAXPGPATH * 2];
443+
char buf[MAXPGPATH * 2];
444444

445445
fp = fopen(file_txt, "rt");
446446
if (fp == NULL)
@@ -508,9 +508,8 @@ dir_read_file_list(const char *root, const char *file_txt)
508508
void
509509
dir_copy_files(const char *from_root, const char *to_root)
510510
{
511-
int i;
512-
parray *files;
513-
files = parray_new();
511+
int i;
512+
parray *files = parray_new();
514513

515514
/* don't copy root directory */
516515
dir_list_file(files, from_root, NULL, true, false);
@@ -522,8 +521,7 @@ dir_copy_files(const char *from_root, const char *to_root)
522521
if (S_ISDIR(file->mode))
523522
{
524523
char to_path[MAXPGPATH];
525-
snprintf(to_path, lengthof(to_path), "%s/%s", to_root,
526-
file->path + strlen(from_root) + 1);
524+
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
527525
if (verbose && !check)
528526
printf(_("create directory \"%s\"\n"),
529527
file->path + strlen(from_root) + 1);

init.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ do_init(void)
3232
dir_create_dir(backup_path, DIR_PERMISSION);
3333

3434
/* create directories for backup of online files */
35-
snprintf(path, lengthof(path), "%s/%s", backup_path, RESTORE_WORK_DIR);
35+
join_path_components(path, backup_path, RESTORE_WORK_DIR);
3636
dir_create_dir(path, DIR_PERMISSION);
3737
snprintf(path, lengthof(path), "%s/%s/%s", backup_path, RESTORE_WORK_DIR,
3838
PG_XLOG_DIR);
@@ -42,18 +42,18 @@ do_init(void)
4242
dir_create_dir(path, DIR_PERMISSION);
4343

4444
/* create directory for timeline history files */
45-
snprintf(path, lengthof(path), "%s/%s", backup_path, TIMELINE_HISTORY_DIR);
45+
join_path_components(path, backup_path, TIMELINE_HISTORY_DIR);
4646
dir_create_dir(path, DIR_PERMISSION);
4747

4848
/* read postgresql.conf */
4949
if (pgdata)
5050
{
51-
snprintf(path, lengthof(path), "%s/%s", pgdata, "postgresql.conf");
51+
join_path_components(path, pgdata, "postgresql.conf");
5252
parse_postgresql_conf(path, &log_directory, &archive_command);
5353
}
5454

5555
/* create pg_rman.ini */
56-
snprintf(path, lengthof(path), "%s/%s", backup_path, PG_RMAN_INI_FILE);
56+
join_path_components(path, backup_path, PG_RMAN_INI_FILE);
5757
fp = fopen(path, "wt");
5858
if (fp == NULL)
5959
elog(ERROR_SYSTEM, _("can't create pg_rman.ini: %s"), strerror(errno));
@@ -112,14 +112,14 @@ do_init(void)
112112
else
113113
{
114114
srvlog_path = pgut_malloc(MAXPGPATH);
115-
snprintf(srvlog_path, MAXPGPATH, "%s/%s", pgdata, log_directory);
115+
join_path_components(srvlog_path, pgdata, log_directory);
116116
}
117117
}
118118
else if (pgdata)
119119
{
120120
/* default: log_directory = 'pg_log' */
121121
srvlog_path = pgut_malloc(MAXPGPATH);
122-
snprintf(srvlog_path, MAXPGPATH, "%s/%s", pgdata, "pg_log");
122+
join_path_components(srvlog_path, pgdata, "pg_log");
123123
}
124124
}
125125
if (srvlog_path)

pg_rman.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ main(int argc, char *argv[])
140140
{
141141
char path[MAXPGPATH];
142142

143-
snprintf(path, lengthof(path), "%s/%s", backup_path, PG_RMAN_INI_FILE);
143+
join_path_components(path, backup_path, PG_RMAN_INI_FILE);
144144
pgut_readopt(path, options, ERROR_ARGS);
145145
}
146146

restore.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ do_restore(const char *target_time,
128128
* restore timeline history files and get timeline branches can reach
129129
* recovery target point.
130130
*/
131-
snprintf(timeline_dir, lengthof(timeline_dir), "%s/%s", backup_path,
132-
TIMELINE_HISTORY_DIR);
131+
join_path_components(timeline_dir, backup_path, TIMELINE_HISTORY_DIR);
133132
if (verbose && !check)
134133
printf(_("restoring timeline history files\n"));
135134
dir_copy_files(timeline_dir, arclog_path);
@@ -254,7 +253,7 @@ do_restore(const char *target_time,
254253
if (verbose)
255254
printf(_("searching online WAL...\n"));
256255

257-
snprintf(xlogpath, lengthof(xlogpath), "%s/%s", pgdata, PG_XLOG_DIR);
256+
join_path_components(xlogpath, pgdata, PG_XLOG_DIR);
258257
search_next_wal(xlogpath, &needId, &needSeg, timelines);
259258

260259
if (verbose)
@@ -489,8 +488,7 @@ restore_archive_logs(pgBackup *backup)
489488
elog(ERROR_INTERRUPTED, _("interrupted during restore WAL"));
490489

491490
/* print progress */
492-
snprintf(path, lengthof(path), "%s/%s", arclog_path,
493-
file->path + strlen(base_path) + 1);
491+
join_path_components(path, arclog_path, file->path + strlen(base_path) + 1);
494492
if (verbose && !check)
495493
printf(_("(%d/%lu) %s "), i + 1, (unsigned long) parray_num(files),
496494
file->path + strlen(base_path) + 1);
@@ -669,7 +667,7 @@ restore_online_files(void)
669667
else if(S_ISREG(file->mode))
670668
{
671669
char to_root[MAXPGPATH];
672-
snprintf(to_root, lengthof(to_root), "%s/%s", pgdata, PG_XLOG_DIR);
670+
join_path_components(to_root, pgdata, PG_XLOG_DIR);
673671
if (verbose && !check)
674672
printf(_("restore \"%s\"\n"),
675673
file->path + strlen(root_backup) + 1);
@@ -940,7 +938,7 @@ search_next_wal(const char *path, uint32 *needId, uint32 *needSeg, parray *timel
940938
pgTimeLine *timeline = (pgTimeLine *) parray_get(timelines, i);
941939

942940
XLogFileName(xlogfname, timeline->tli, *needId, *needSeg);
943-
snprintf(xlogpath, lengthof(xlogpath), "%s/%s", path, xlogfname);
941+
join_path_components(xlogpath, path, xlogfname);
944942

945943
if (stat(xlogpath, &st) == 0)
946944
break;

0 commit comments

Comments
 (0)