pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Daniel Watzinger <daniel.watzinger@gmail.com>
To: pgsql-hackers@postgresql.org
Subject: pg_dump/pg_restore: Fix stdin/stdout handling of custom format on Win32
Date: Fri, 16 Dec 2022 16:09:21 +0100
Message-ID: <b1448cd7-871e-20e3-8398-895e2d1d3bf9@gmail.com> (raw )
Hi there,
first-time contributor here. I certainly hope I got the patch
creation and email workflow right. Let me know if anything can be
improved as I`m eager to learn. Regression tests (check) were
successful on native Win32 MSVC as well as Debian. Here comes the
patch and corresponding commit text.
During archive initialization pg_backup_custom.c determines if the file
pointer it should read from or write to is seekable. pg_dump
uses this information to rewrite the custom output format's TOC
enriched with known offsets into the archive on close. pg_restore uses
seeking to speed up file operations when searching for specific
blocks within the archive.
The seekable property of a file pointer is currently checked by
invoking ftello and subsequently fseeko. Both calls succeed
on Windows platforms if the underlying file descriptor represents a
terminal handle or an anonymous or named pipe. Obviously, these type
of devices do not support seeking. In the case of pg_dump, this
leads to the TOC being appended to the end of the output when attempting
to rewrite known offsets. Furthermore, pg_restore may try to seek to
known file offsets if the custom format archive's TOC supports it
and subsequently fails to locate blocks.
This commit improves the detection of the seekable property by checking
a descriptor's file type (st_mode) and filtering character special
devices and pipes. The current customized implementation of fstat on
Windows platforms (_pgfstat64) erroneously marks terminal and pipe
handles as regular files (_S_IFREG). This was improved on by
utilizing WinAPI functionality (GetFileType) to correctly distinguish
and flag descriptors based on their native OS handle's file type.
Daniel
---
src/bin/pg_dump/pg_backup_archiver.c | 12 +++++
src/include/port/win32_port.h | 6 +++
src/port/win32stat.c | 68 ++++++++++++++++++++--------
3 files changed, 67 insertions(+), 19 deletions(-)
Attachments:
[application/x-patch] v1-0001-pg_dump-pg_restore-Fix-stdin-stdout-handling-of-c.patch (1.8K, ../b1448cd7-871e-20e3-8398-895e2d1d3bf9@gmail.com/2-v1-0001-pg_dump-pg_restore-Fix-stdin-stdout-handling-of-c.patch)
download | inline diff:
v'ß+ZþÊÜý¸§þºj¦ÚrK©j·!÷«q¿ìÏÛéÛ¦§ú`m§$º«r¯z·"×±íþÚÑý\{¾¼áÖøk^Ú×M:㿲·?n)ÿ¦né¶êZÈb½êÜûïþÊÜý¸§þºj¦ÚrK©j·!÷«s7ó¯·ó5ñº(È^rDzAH,Gé¦
~Ûi¢Ï¬¶»¶ËZ¶Ë~ûð¡yÉ"~Øb²+µêæv¥uë®*m¢¿þø¬jÛr~)^éú·º¹ßj[ûï¿
'í+"±©îǦåyÈZ§-z»)yÈׯǨ®©{ÿ¢}û-j×âéè~- ! FËl¶j{äHR:Ël¶j{êÞ¶êç}©l{ïÂ
ç$¶~×¥(®K(Øb±ø¥{ûi¢Àµée¡ú]÷àÖ¿²·?w%¹×¿¦íÿ§ßjh®Ø[þÊÜþ)Üç^þ+·ü"}©¢»aw^Çoz÷N[s§<÷gtm¾4×]4ëþÊÜþ)Üç^þ+·ü"}©¢»aûïþÊÜþ)Üç^þ+·ü"}©¢»aßozû}½×g±µêç{i[-jÞ¸rìµÈZ®v¦zËk¹Ëlµ«[¹ø×Hg^~)ÞHi¦HLL TDéÝÿ¢~w^}"Nù×w!!Hé¦HLL R;ç§v'þùÝyôH!Ñù×w! Fi S !ÑùéÝÿÈÝz·è®[-jÛhmæëhêh®ØîËb¢zh{ljË2X§Ìv'ß+ZþÊÜþ+·ü"}¬µ«\oû+súh®ßð}ö²Ör)Ý{ºçÞãMôí¦ô÷ÍÚïtÓ®8kû+súh®ßð}ö²Ösï¾oû+súh®ßð}ö²Ösnz߶箹¦-jÞ¸rìµÈZ®v¦zËk¹Ëlµ«[¹ø§¶²Öë§µø¥zz,¶»¶ËZµ»C,HEWC,H¶
©ÝçâéèÀ42ÄÄ ÑNDÀ ã_6káÀ42ÄX¥x42Äëh±øZÙ^~)^XäC~)^O*^ R6CJ4åø5D9Z²Ñ+®þº{"w²+¶Ëf¡×¢~b Õ@,Ç ÐËPPFî|P²þøEW ²C,E@-A!)^ 42ÄÙ» ,·«®zU ºÞ¶êç×ð¡yÉ"~Ø^~)^¬iÖjËky©~Ê.W¬²+ajÆÞzzÞv*Þr×¶W zÛb§~æjبØk¢è!Û ÐË¥ö¢ÊéZµè²ËZ¶)ߢ¹¶*'{azj,µªi®k«^Á¬ÚÞ¶êçØ§²×wçâäò¥àzÑbäò¥èEW¾«-ºè¬´¶¬´J뢿¾ÿâ'¾ëKjËD®º+z+uêí¡Ø¬¶)àº+!mëpyéÚ½©bwêÞ¶êç¡ñH,DØ<E
(Ó5©ÝÛ+zÛ«Û¶jYb«®þ"w±ê²çzËzÒÚ²Ñ+®ëzÛ«ÃNNGø~)^~)^-v)ßW§ W§¢Ë]¢ë_W§ W§¢Ë]zºÆzÑbâ'~æjبjwezbçâ
«Zú'ßWÊ R6CJ4å«-ºè¬NGçh²f©zºåjËD®º+ú·º¹õûï¬Â+\
ø¥y<©zg¦±ë[¹ý,7¨}»nçì¶jx!Ñnçìµ×¯øzz¹û-ׯøzz¹û-X§
zÛ«O¿N¬¥ç"~'~)^ÆÉW¿ùƬxR62+êÞ¶êç~)^wè¶-jØEW¹ÿ¿ù8^²øuø¥z+²$zß©v©zÚ©è)¨ºÊb¥ï¿ùƬxR6òë-^" S¾n·ïþN¬¥ç"~'~)^Æ
ªÚr׫~)^úܩƥ&§,ôÝzøzÚrì¢W¾ÿç±áH,DØ<@¿ùIî±ç_¨Û§z0ø¥zÜ©{ïþq«ÄMÄDCLOjÇ
±`ñ4£NX߬¶jx!ÑùºÞjOyö®ß®¹è BTþën®}kzÛ«ø¥z)ߢÚ,µ«a)^nçþé¬zÖîK"Íênçþnçì¶jx^ù»²×^¼éèù»²ÚÝzðW§£æî~Ëg)ä_zÛ«G§v'ÿXwÛöÚ±ç(h{ñ½ôÕçyá¦ç^¶o_9oßåý^ãúo^Þ
view thread (12+ messages) latest in thread
Message-ID: <b1448cd7-871e-20e3-8398-895e2d1d3bf9@gmail.com>
Permalink: ../b1448cd7-871e-20e3-8398-895e2d1d3bf9@gmail.com/
Also on: postgresql.org/message-id/b1448cd7-871e-20e3-8398-895e2d1d3bf9@gmail.com
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: daniel.watzinger@gmail.com
Subject: Re: pg_dump/pg_restore: Fix stdin/stdout handling of custom format on Win32
In-Reply-To: <b1448cd7-871e-20e3-8398-895e2d1d3bf9@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox