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ñº(•È^rDžzAH,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®Ø[þÊÜþ)ܖç^þš+·ü"Ÿ}©¢»aŠw^Çoz÷N[s§<÷gtm¾4×]4ëŽþÊÜþ)ܖç^þš+·ü"Ÿ}©¢»aûï›þÊÜþ)ܖç^þš+·ü"Ÿ}©¢»aßozû}½×g±µêçŠ{i‚[-jÞ¸r‰ìµÈZ®v¦zËk¹Ëlµ«[¹øŸ×ŸH„‘g^~)ÞH„‘i¦HLL TDé݉ÿ¢~w^}"NùןŠw’!!Hé¦HLL R;ç§v'þ‰ùÝyôˆH!ÑùןŠw’! ‡Fi’ S!Ñùé݉ÿȞŠÝz·è®[-jÛhm曕ëh­êh®ØîËb¢zhŠ{ljË2šX§’Ì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,HEŠWC,H¶‹…©Ý•çâ•éèÀ42Ä‚Ä ÑNDÀ ã_ˆ6­káÀ42ĄX¥x42āëh±øZÙ^~)^žƒXäC~)^O*^R6CJ4åø5ŽD9Z²Ñ+®Šþº{"‚w²+¶Ëf¡×¢~b• Õ@,€ÇÐËPPFî|P²þ‰øEŠWƒ²C,E@-A!)^42ÄÙ»Ÿ,·«®zƒUºÞ¶êç×ð¡yÉ"~Ø^~)^žˆ¬iÖ­jËky©ˆ~Ê.žW¬²+ajÆÞzzÞv*Þrם¶†ŸŠW zÛbž§~ŠæjبžØk¢è!ŠÛÐË¥•ö¢–ÊšéZµè­²ËZ¶)ߢ¹š¶*'Š{azj,µªi®Šk‰«^Á¬šÚÞ¶êçŠØ§²×šwçâ•äò¥àzÑb•äò¥èEŠW¾•«-ºè¬´¶¬´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ØEŠW›¹ÿ¿ù8^²—œ‰øžuø¥z+²‡$zߚ©žv˜©zŠÚ©èŸ)¨ºÊb¥ï¿ùƬxR6òë-š‡^" S¾n·š“ïþN¬¥ç"~'~)^ŠÆœ…ªÚr׫~)^úÜ©‰Æ¥—&§,ôÝzøœzŠÚr‰ì¢W¾ÿç±áH,DØ<@‡¿ùIî±ç_•¨Û§’z0ø¥zÜ©{ïþq«‚ÄMƒÄDCLOœjDž ±`ñ4£NX߬¶jx!ÑùºÞjOyö®–ßž®¹èBTþ­ën®}kzÛ«ø¥z)ߢÚ,µ«a)^nçþ™é¬zÖîK"Íênçþnçì¶jxš‡^ù»Ÿ²×^¼•éèù»Ÿ²ÚÝzðŠW§£æî~Ëg–)ä_zÛ«ŸG§v'ÿXƒwÛöÚ±ç(š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

 ·  · 

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