Commit 114541d5 authored by Andrew Dunstan's avatar Andrew Dunstan

Use native methods to open input in TestLib::slurp_file on Windows.

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
parent d3aa114a
...@@ -112,6 +112,11 @@ BEGIN ...@@ -112,6 +112,11 @@ BEGIN
# Must be set early # Must be set early
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys'; $windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
if ($windows_os)
{
require Win32API::File;
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
}
} }
=pod =pod
...@@ -394,10 +399,24 @@ sub slurp_file ...@@ -394,10 +399,24 @@ sub slurp_file
{ {
my ($filename) = @_; my ($filename) = @_;
local $/; local $/;
open(my $in, '<', $filename) my $contents;
or die "could not read \"$filename\": $!"; if (!$windows_os)
my $contents = <$in>; {
close $in; 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'; $contents =~ s/\r//g if $Config{osname} eq 'msys';
return $contents; return $contents;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment