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(-)
v'߂+ZjrKj!qۊۦ`m$rz"ױ\{k^M:ㆿ?n)n遶ZbjrKj!s75(^rDzAH,G ~iϬZ~y"~b+vu*mjr~)^j[ '+"ǞyZ-z)yȚׯǨ{}-j~- ! Flj{HR:lj{}l{ $~ץ(K(b{ie]ֿ?w%jh[)ܖ^+"}aw^ozN[s<gtm4]4)ܖ^+"}a)ܖ^+"}aoz}g{i[-jrZvzkl[ןHg^~)HiHLL TD݉~w^}"Nןw!!HHLL R;v'yH!ןw! Fi S !݉Ȟz[-jhm曕hhbzh{lj2Xv'߂+Z+"}\o+sh}֭r){MtӮ8k+sh}֭so+sh}֭snzߟ箹-jrZvzkl[֭눧zz,ZC,HEWC,Hݕ42 ND _6k42ĄXx42āhZ^~)^XC~)^O*^ R6CJ45D9Z+{"w+fע~b @, PPF|PEW C,E@-A!)^ 42ٻ ,zU y"~^~)^i֭jky~.W+ajzzv*rםWzb~jبk! Z譲Z)ߢ*'{azj,ik^اךwzbEW-J뢿'KjD+z+uج)+!mpyڽbwH,D<E (Ӗ5݊+z۫۞jYb"wzzڲ+z۫NNG~)^~)^-v)ߊWW]_WW]zzb'~jبjwezb Z'ߊWʗ R6CJ4单-NGhfzjD++\y<zg[,7}njx!nׯzz-ׯzz-X z۫ON"~'~)^ƝWƬxR62+~)^w趋-jEW8^uz+$zߚvzڝ)bƬxR6-^" SnN"~'~)^Ɯr~)^ܩƥ&,zzrWH,D<@I_ۧz0zܩ{qMDCLOjDž `4NX߬jx!jOyߞ BTn}kz۫z)ߢ,a)^nzK"nnjx^^zW~g)_z۫Gv'Xwڱ(h{yᦜ^o_9o^o^