From 114541d58e5970e51b78b77b65de16210beaab43 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sun, 24 Nov 2019 18:25:22 -0500 Subject: [PATCH] Use native methods to open input in TestLib::slurp_file on Windows. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is hoped that this will avoid some errors that we have seen before, but lately with greater frequency, in buildfarm animals. For now apply only to master. If this proves effective it can be backpatched. Discussion: https://postgr.es/m/13900.1572839580@sss.pgh.pa.us Author: Juan José Santamaría Flecha --- src/test/perl/TestLib.pm | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 905d0d178f..a377cdb226 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -112,6 +112,11 @@ BEGIN # Must be set early $windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys'; + if ($windows_os) + { + require Win32API::File; + Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle)); + } } =pod @@ -394,10 +399,24 @@ sub slurp_file { my ($filename) = @_; local $/; - open(my $in, '<', $filename) - or die "could not read \"$filename\": $!"; - my $contents = <$in>; - close $in; + my $contents; + if (!$windows_os) + { + open(my $in, '<', $filename) + or die "could not read \"$filename\": $!"; + $contents = <$in>; + close $in; + } + else + { + my $fHandle = createFile($filename, "r", "rwd") + or die "could not open \"$filename\": $^E"; + OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r') + or die "could not read \"$filename\": $^E\n"; + $contents = <$fh>; + CloseHandle($fHandle) + or die "could not close \"$filename\": $^E\n"; + } $contents =~ s/\r//g if $Config{osname} eq 'msys'; return $contents; }