@@ -1515,8 +1515,8 @@ update_recovery_options(pgBackup *backup,
1515
1515
char postgres_auto_path [MAXPGPATH ];
1516
1516
char postgres_auto_path_tmp [MAXPGPATH ];
1517
1517
char path [MAXPGPATH ];
1518
- FILE * fp ;
1519
- FILE * fp_tmp ;
1518
+ FILE * fp = NULL ;
1519
+ FILE * fp_tmp = NULL ;
1520
1520
struct stat st ;
1521
1521
char current_time_str [100 ];
1522
1522
/* postgresql.auto.conf parsing */
@@ -1540,9 +1540,13 @@ update_recovery_options(pgBackup *backup,
1540
1540
strerror (errno ));
1541
1541
}
1542
1542
1543
- fp = fio_open_stream (postgres_auto_path , FIO_DB_HOST );
1544
- if (fp == NULL && errno != ENOENT )
1545
- elog (ERROR , "cannot open \"%s\": %s" , postgres_auto_path , strerror (errno ));
1543
+ /* Kludge for 0-sized postgresql.auto.conf file. TODO: make something more intelligent */
1544
+ if (st .st_size > 0 )
1545
+ {
1546
+ fp = fio_open_stream (postgres_auto_path , FIO_DB_HOST );
1547
+ if (fp == NULL && errno != ENOENT )
1548
+ elog (ERROR , "cannot open \"%s\": %s" , postgres_auto_path , strerror (errno ));
1549
+ }
1546
1550
1547
1551
sprintf (postgres_auto_path_tmp , "%s.tmp" , postgres_auto_path );
1548
1552
fp_tmp = fio_fopen (postgres_auto_path_tmp , "w" , FIO_DB_HOST );
@@ -1582,9 +1586,11 @@ update_recovery_options(pgBackup *backup,
1582
1586
if (fp )
1583
1587
fio_close_stream (fp );
1584
1588
1585
- /* TODO: detect remote error */
1586
- if (buf_len > 0 )
1587
- fio_fwrite (fp_tmp , buf , buf_len );
1589
+ /* Write data to postgresql.auto.conf.tmp */
1590
+ if (buf_len > 0 &&
1591
+ (fio_fwrite (fp_tmp , buf , buf_len ) != buf_len ))
1592
+ elog (ERROR , "Cannot write to \"%s\": %s" ,
1593
+ postgres_auto_path_tmp , strerror (errno ));
1588
1594
1589
1595
if (fio_fflush (fp_tmp ) != 0 ||
1590
1596
fio_fclose (fp_tmp ))
0 commit comments