aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/TestLib.pm
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2021-04-16 16:54:04 -0400
committerAndrew Dunstan <andrew@dunslane.net>2021-04-16 17:38:08 -0400
commitd380ec9891db13d8a4fc8a40adc68880a88ecb31 (patch)
tree3c69bbf2483df492285eb876812099579500812b /src/test/perl/TestLib.pm
parent26cf32455c501f01d3b73dcf680072169749c980 (diff)
downloadpostgresql-d380ec9891db13d8a4fc8a40adc68880a88ecb31.tar.gz
postgresql-d380ec9891db13d8a4fc8a40adc68880a88ecb31.zip
Allow TestLib::slurp_file to skip contents, and use as needed
In order to avoid getting old logfile contents certain functions in PostgresNode were doing one of two things. On Windows it rotated the logfile and restarted the server, while elsewhere it truncated the log file. Both of these are unnecessary. We borrow from the buildfarm which does this instead: note the size of the logfile before we start, and then when fetching the logfile skip to that position before accumulating contents. This is spelled differently on Windows but the effect is the same. This is largely centralized in TestLib's slurp_file function, which has a new optional parameter, the offset to skip to before starting to reading the file. Code in the client becomes much neater. Backpatch to all live branches. Michael Paquier, slightly modified by me. Discussion: https://postgr.es/m/YHajnhcMAI3++pJL@paquier.xyz
Diffstat (limited to 'src/test/perl/TestLib.pm')
-rw-r--r--src/test/perl/TestLib.pm16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index 4cb3c765d93..63975db5e76 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -13,7 +13,7 @@ use warnings;
use Config;
use Cwd;
use Exporter 'import';
-use Fcntl qw(:mode);
+use Fcntl qw(:mode :seek);
use File::Basename;
use File::Find;
use File::Spec;
@@ -82,7 +82,7 @@ BEGIN
if ($windows_os)
{
require Win32API::File;
- Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
+ Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer));
}
}
@@ -259,13 +259,18 @@ sub slurp_dir
sub slurp_file
{
- my ($filename) = @_;
+ my ($filename, $offset) = @_;
local $/;
my $contents;
if ($Config{osname} ne 'MSWin32')
{
open(my $in, '<', $filename)
or die "could not read \"$filename\": $!";
+ if (defined($offset))
+ {
+ seek($in, $offset, SEEK_SET)
+ or die "could not seek \"$filename\": $!";
+ }
$contents = <$in>;
close $in;
}
@@ -275,6 +280,11 @@ sub slurp_file
or die "could not open \"$filename\": $^E";
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
or die "could not read \"$filename\": $^E\n";
+ if (defined($offset))
+ {
+ setFilePointer($fh, $offset, qw(FILE_BEGIN))
+ or die "could not seek \"$filename\": $^E\n";
+ }
$contents = <$fh>;
CloseHandle($fHandle)
or die "could not close \"$filename\": $^E\n";