@@ -208,18 +208,15 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
208
208
*/
209
209
pgBackupGetPath (to_backup , control_file , lengthof (control_file ),
210
210
DATABASE_FILE_LIST );
211
- to_files = dir_read_file_list (from_database_path , /* Use from_database_path
212
- * so root path will be
213
- * equal with 'files' */
214
- control_file );
211
+ to_files = dir_read_file_list (NULL , control_file );
215
212
/* To delete from leaf, sort in reversed order */
216
213
parray_qsort (to_files , pgFileComparePathDesc );
217
214
/*
218
215
* Get list of files which need to be moved.
219
216
*/
220
217
pgBackupGetPath (from_backup , control_file , lengthof (control_file ),
221
218
DATABASE_FILE_LIST );
222
- files = dir_re
10000
ad_file_list (from_database_path , control_file );
219
+ files = dir_read_file_list (NULL , control_file );
223
220
/* sort by size for load balancing */
224
221
parray_qsort (files , pgFileCompareSize );
225
222
@@ -331,8 +328,18 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
331
328
332
329
if (parray_bsearch (files , file , pgFileComparePathDesc ) == NULL )
333
330
{
331
+ char to_file_path [MAXPGPATH ];
332
+ char * prev_path ;
333
+
334
+ /* We need full path, file object has relative path */
335
+ join_path_components (to_file_path , to_database_path , file -> path );
336
+ prev_path = file -> path ;
337
+ file -> path = to_file_path ;
338
+
334
339
pgFileDelete (file );
335
340
elog (VERBOSE , "Deleted \"%s\"" , file -> path );
341
+
342
+ file -> path = prev_path ;
336
343
}
337
344
}
338
345
@@ -378,13 +385,14 @@ merge_files(void *arg)
378
385
pgBackup * from_backup = argument -> from_backup ;
379
386
int i ,
380
387
num_files = parray_num (argument -> files );
381
- int to_root_len = strlen (argument -> to_root );
382
388
383
389
for (i = 0 ; i < num_files ; i ++ )
384
390
{
385
391
pgFile * file = (pgFile * ) parray_get (argument -> files , i );
386
392
pgFile * to_file ;
387
393
pgFile * * res_file ;
394
+ char from_file_path [MAXPGPATH ];
395
+ char * prev_file_path ;
388
396
389
397
if (!pg_atomic_test_set_flag (& file -> lock ))
390
398
continue ;
@@ -429,19 +437,23 @@ merge_files(void *arg)
429
437
continue ;
430
438
}
431
439
440
+ /* We need to make full path, file object has relative path */
441
+ join_path_components (from_file_path , argument -> from_root , file -> path );
442
+ prev_file_path = file -> path ;
443
+ file -> path = from_file_path ;
444
+
432
445
/*
433
446
* Move the file. We need to decompress it and compress again if
434
447
* necessary.
435
448
*/
436
- elog (VERBOSE , "Moving file \"%s\", is_datafile %d, is_cfs %d" ,
449
+ elog (VERBOSE , "Merging file \"%s\", is_datafile %d, is_cfs %d" ,
437
450
file -> path , file -> is_database , file -> is_cfs );
438
451
439
452
if (file -> is_datafile && !file -> is_cfs )
440
453
{
441
- char to_path_tmp [MAXPGPATH ]; /* Path of target file */
454
+ char to_file_path [MAXPGPATH ]; /* Path of target file */
442
455
443
- join_path_components (to_path_tmp , argument -> to_root ,
444
- file -> path + to_root_len + 1 );
456
+ join_path_components (to_file_path , argument -> to_root , prev_file_path );
445
457
446
458
/*
447
459
* We need more complicate algorithm if target file should be
@@ -453,7 +465,7 @@ merge_files(void *arg)
453
465
char tmp_file_path [MAXPGPATH ];
454
466
char * prev_path ;
455
467
456
- snprintf (tmp_file_path , MAXPGPATH , "%s_tmp" , to_path_tmp );
468
+ snprintf (tmp_file_path , MAXPGPATH , "%s_tmp" , to_file_path );
457
469
458
470
/* Start the magic */
459
471
@@ -479,7 +491,7 @@ merge_files(void *arg)
479
491
* need the file in directory to_root.
480
492
*/
481
493
prev_path = to_file -> path ;
482
- to_file -> path = to_path_tmp ;
494
+ to_file -> path = to_file_path ;
483
495
/* Decompress target file into temporary one */
484
496
restore_data_file (tmp_file_path , to_file , false, false,
485
497
parse_program_version (to_backup -> program_version ));
@@ -494,7 +506,7 @@ merge_files(void *arg)
494
506
false,
495
507
parse_program_version (from_backup -> program_version ));
496
508
497
- elog (VERBOSE , "Compress file and save it to the directory \"%s\"" ,
509
+ elog (VERBOSE , "Compress file and save it into the directory \"%s\"" ,
498
510
argument -> to_root );
499
511
500
512
/* Again we need to change path */
@@ -504,7 +516,7 @@ merge_files(void *arg)
504
516
file -> size = pgFileSize (file -> path );
505
517
/* Now we can compress the file */
506
518
backup_data_file (NULL , /* We shouldn't need 'arguments' here */
507
- to_path_tmp , file ,
519
+ to_file_path , file ,
508
520
to_backup -> start_lsn ,
509
521
to_backup -> backup_mode ,
510
522
to_backup -> compress_alg ,
@@ -523,7 +535,7 @@ merge_files(void *arg)
523
535
else
524
536
{
525
537
/* We can merge in-place here */
526
- restore_data_file (to_path_tmp , file ,
538
+ restore_data_file (to_file_path , file ,
527
539
from_backup -> backup_mode == BACKUP_MODE_DIFF_DELTA ,
528
540
true,
529
541
parse_program_version (from_backup -> program_version ));
@@ -532,8 +544,8 @@ merge_files(void *arg)
532
544
* We need to calculate write_size, restore_data_file() doesn't
533
545
* do that.
534
546
*/
535
- file -> write_size = pgFileSize (to_path_tmp );
536
- file -> crc = pgFileGetCRC (to_path_tmp , true, true, NULL );
547
+ file -> write_size = pgFileSize (to_file_path );
548
+ file -> crc = pgFileGetCRC (to_file_path , true, true, NULL );
537
549
}
538
550
}
539
551
else if (strcmp (file -> name , "pg_control" ) == 0 )
@@ -548,8 +560,11 @@ merge_files(void *arg)
548
560
file -> compress_alg = to_backup -> compress_alg ;
549
561
550
562
if (file -> write_size != BYTES_INVALID )
551
- elog (LOG , "Moved file \"%s\": " INT64_FORMAT " bytes" ,
563
+ elog (LOG , "Merged file \"%s\": " INT64_FORMAT " bytes" ,
552
564
file -> path , file -> write_size );
565
+
566
+ /* Restore relative path */
567
+ file -> path = prev_file_path ;
553
568
}
554
569
555
570
/* Data files merging is successful */
0 commit comments