diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2019-11-24 18:25:22 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2019-11-24 18:25:22 -0500 |
commit | 114541d58e5970e51b78b77b65de16210beaab43 (patch) | |
tree | a20887e5065ea94899c2c497accca860ddacb3f9 /src | |
parent | d3aa114ac4de9ecc558ba77ed5c85e2ad9ad01d4 (diff) | |
download | postgresql-114541d58e5970e51b78b77b65de16210beaab43.tar.gz postgresql-114541d58e5970e51b78b77b65de16210beaab43.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/test/perl/TestLib.pm | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 905d0d178ff..a377cdb226a 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; } |