Skip to content

Commit 114541d

Browse files
committed
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
1 parent d3aa114 commit 114541d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/test/perl/TestLib.pm

+23-4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ BEGIN
112112

113113
# Must be set early
114114
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
115+
if ($windows_os)
116+
{
117+
require Win32API::File;
118+
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
119+
}
115120
}
116121

117122
=pod
@@ -394,10 +399,24 @@ sub slurp_file
394399
{
395400
my ($filename) = @_;
396401
local $/;
397-
open(my $in, '<', $filename)
398-
or die "could not read \"$filename\": $!";
399-
my $contents = <$in>;
400-
close $in;
402+
my $contents;
403+
if (!$windows_os)
404+
{
405+
open(my $in, '<', $filename)
406+
or die "could not read \"$filename\": $!";
407+
$contents = <$in>;
408+
close $in;
409+
}
410+
else
411+
{
412+
my $fHandle = createFile($filename, "r", "rwd")
413+
or die "could not open \"$filename\": $^E";
414+
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
415+
or die "could not read \"$filename\": $^E\n";
416+
$contents = <$fh>;
417+
CloseHandle($fHandle)
418+
or die "could not close \"$filename\": $^E\n";
419+
}
401420
$contents =~ s/\r//g if $Config{osname} eq 'msys';
402421
return $contents;
403422
}

0 commit comments

Comments
 (0)