Skip to content

Commit 807cc27

Browse files
committed
Fix overwriting of 0-sized postgresql.auto.conf in remote mode, restore nonedata files asynchronously
1 parent a758d11 commit 807cc27

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/data.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ restore_non_data_file_internal(FILE *in, FILE *out, pgFile *file,
11451145

11461146
if (read_len > 0)
11471147
{
1148-
if (fio_fwrite(out, buf, read_len) != read_len)
1148+
if (fio_fwrite_async(out, buf, read_len) != read_len)
11491149
elog(ERROR, "Cannot write to \"%s\": %s", to_fullpath,
11501150
strerror(errno));
11511151
}

src/restore.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)