]> granicus.if.org Git - postgresql/commitdiff
Open output file before sleeping in pg_recvlogical.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 16 May 2014 07:10:45 +0000 (10:10 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 16 May 2014 07:10:45 +0000 (10:10 +0300)
Let's complain about e.g an invalid path or permission problem sooner rather
than later. Before this patch, we would only try to open the output file
after receiving the first decoded message from the server.

src/bin/pg_basebackup/pg_recvlogical.c

index 9058c3daa704b30e6c523b95546bc8d2874f96f9..a58530372e1fc5038fd9c3d31dc959fcaf48a104 100644 (file)
@@ -315,6 +315,23 @@ StreamLog(void)
                }
                output_reopen = false;
 
+               /* open the output file, if not open yet */
+               if (outfd == -1)
+               {
+                       if (strcmp(outfile, "-") == 0)
+                               outfd = fileno(stdout);
+                       else
+                               outfd = open(outfile, O_CREAT | O_APPEND | O_WRONLY | PG_BINARY,
+                                                        S_IRUSR | S_IWUSR);
+                       if (outfd == -1)
+                       {
+                               fprintf(stderr,
+                                               _("%s: could not open log file \"%s\": %s\n"),
+                                               progname, outfile, strerror(errno));
+                               goto error;
+                       }
+               }
+
                r = PQgetCopyData(conn, &copybuf, 1);
                if (r == 0)
                {
@@ -479,23 +496,6 @@ StreamLog(void)
                        output_written_lsn = Max(temp, output_written_lsn);
                }
 
-               /* open the output file, if not open yet */
-               if (outfd == -1)
-               {
-                       if (strcmp(outfile, "-") == 0)
-                               outfd = fileno(stdout);
-                       else
-                               outfd = open(outfile, O_CREAT | O_APPEND | O_WRONLY | PG_BINARY,
-                                                        S_IRUSR | S_IWUSR);
-                       if (outfd == -1)
-                       {
-                               fprintf(stderr,
-                                               _("%s: could not open log file \"%s\": %s\n"),
-                                               progname, outfile, strerror(errno));
-                               goto error;
-                       }
-               }
-
                bytes_left = r - hdr_len;
                bytes_written = 0;