@@ -1515,8 +1515,8 @@ update_recovery_options(pgBackup *backup,
15151515 char postgres_auto_path [MAXPGPATH ];
15161516 char postgres_auto_path_tmp [MAXPGPATH ];
15171517 char path [MAXPGPATH ];
1518- FILE * fp ;
1519- FILE * fp_tmp ;
1518+ FILE * fp = NULL ;
1519+ FILE * fp_tmp = NULL ;
15201520 struct stat st ;
15211521 char current_time_str [100 ];
15221522 /* postgresql.auto.conf parsing */
@@ -1540,9 +1540,13 @@ update_recovery_options(pgBackup *backup,
15401540 strerror (errno ));
15411541 }
15421542
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+ }
15461550
15471551 sprintf (postgres_auto_path_tmp , "%s.tmp" , postgres_auto_path );
15481552 fp_tmp = fio_fopen (postgres_auto_path_tmp , "w" , FIO_DB_HOST );
@@ -1582,9 +1586,11 @@ update_recovery_options(pgBackup *backup,
15821586 if (fp )
15831587 fio_close_stream (fp );
15841588
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 ));
15881594
15891595 if (fio_fflush (fp_tmp ) != 0 ||
15901596 fio_fclose (fp_tmp ))
0 commit comments