Re: BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Haribabu Kommi <kommi.haribabu@gmail.com>
Cc: henry_boehlert@agilent.com,
"pgsql-bugs@postgresql.org" <pgsql-bugs@postgresql.org>,
"pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2017-07-14T13:07:46Z
Lists: pgsql-bugs, pgsql-hackers
On 07/14/2017 05:27 AM, Haribabu Kommi wrote: > On Fri, Jul 14, 2017 at 2:54 AM, Heikki Linnakangas <hlinnaka@iki.fi> wrote: > >> On 05/03/2017 07:32 AM, Haribabu Kommi wrote: >> >>> [Adding -hackers mailing list] >>> >>> On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote: >>> >>>> Executing command pg_basebackup -D -F t writes its output to stdout, >>>> which >>>> is open in text mode, causing LF to be converted to CR LF thus corrupting >>>> the resulting archive. >>>> >>>> To write the tar to stdout, on Windows stdout's mode should be >>>> temporarily >>>> switched to binary. >>>> >>>> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx >>> >>> Thanks for reporting the issue. >>> With the attached patch, I was able to extract the tar file that gets >>> generated when the tar file is written into stdout. I tested the >>> the compressed tar also. >>> >>> This bug needs to be fixed in back branches also. >> >> Seems reasonable. One question: >> >> In the patch, you used "_setmode" function, while the calls in >> src/bin/pg_dump/pg_backup_archiver.c use "setmode". There are a few >> places in the backend that also use "_setmode". What's the difference? >> Should we change some of them to be consistent? > > Actually there is no functional difference between these two functions. > one is a POSIX variant and another one is ISO C++ variant [1]. The support > of POSIX variant is deprecated in windows, because of this reason we should > use the _setmode instead of setmode. > > I attached the patch to change the pg_dump code to use _setmode function > instead of _setmode to be consistent with other functions. Ok, committed and backpatched both patches. Thanks! - Heikki
Commits
-
Fix pg_basebackup output to stdout on Windows.
- 4b994a96c708 9.2.22 landed
- f3633689f25b 9.3.18 landed
- 240299806e90 9.4.13 landed
- f20d58a6f7b6 9.5.8 landed
- cedd25ae8877 9.6.4 landed
- 8046465c2ecf 10.0 landed