mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-11 19:20:40 +08:00
Replace magic constants for seek() calls in perl scripts
A couple of tests have been using 0 as magic constant while SEEK_SET can
be used instead. This makes the code easier to understand, and more
consistent with the changes done in 3c5b068
.
Per discussion with Andrew Dunstan.
Discussion: https://postgr.es/m/YHrc24AgJQ6tQ1q0@paquier.xyz
This commit is contained in:
parent
8e861eaae8
commit
c731f9187b
@ -4,6 +4,7 @@ use warnings;
|
|||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
|
|
||||||
|
use Fcntl qw(:seek);
|
||||||
use Test::More tests => 80;
|
use Test::More tests => 80;
|
||||||
|
|
||||||
my ($node, $result);
|
my ($node, $result);
|
||||||
@ -124,7 +125,7 @@ sub corrupt_first_page
|
|||||||
# Corrupt some line pointers. The values are chosen to hit the
|
# Corrupt some line pointers. The values are chosen to hit the
|
||||||
# various line-pointer-corruption checks in verify_heapam.c
|
# various line-pointer-corruption checks in verify_heapam.c
|
||||||
# on both little-endian and big-endian architectures.
|
# on both little-endian and big-endian architectures.
|
||||||
seek($fh, 32, 0)
|
seek($fh, 32, SEEK_SET)
|
||||||
or BAIL_OUT("seek failed: $!");
|
or BAIL_OUT("seek failed: $!");
|
||||||
syswrite(
|
syswrite(
|
||||||
$fh,
|
$fh,
|
||||||
|
@ -3,6 +3,8 @@ use warnings;
|
|||||||
|
|
||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
|
|
||||||
|
use Fcntl qw(:seek);
|
||||||
use Test::More tests => 63;
|
use Test::More tests => 63;
|
||||||
|
|
||||||
my ($node, $port, %corrupt_page, %remove_relation);
|
my ($node, $port, %corrupt_page, %remove_relation);
|
||||||
@ -84,7 +86,7 @@ sub corrupt_first_page
|
|||||||
# Corrupt some line pointers. The values are chosen to hit the
|
# Corrupt some line pointers. The values are chosen to hit the
|
||||||
# various line-pointer-corruption checks in verify_heapam.c
|
# various line-pointer-corruption checks in verify_heapam.c
|
||||||
# on both little-endian and big-endian architectures.
|
# on both little-endian and big-endian architectures.
|
||||||
seek($fh, 32, 0)
|
seek($fh, 32, SEEK_SET)
|
||||||
or BAIL_OUT("seek failed: $!");
|
or BAIL_OUT("seek failed: $!");
|
||||||
syswrite(
|
syswrite(
|
||||||
$fh,
|
$fh,
|
||||||
|
@ -4,6 +4,7 @@ use warnings;
|
|||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
|
|
||||||
|
use Fcntl qw(:seek);
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
||||||
# This regression test demonstrates that the pg_amcheck binary correctly
|
# This regression test demonstrates that the pg_amcheck binary correctly
|
||||||
@ -95,7 +96,7 @@ sub read_tuple
|
|||||||
{
|
{
|
||||||
my ($fh, $offset) = @_;
|
my ($fh, $offset) = @_;
|
||||||
my ($buffer, %tup);
|
my ($buffer, %tup);
|
||||||
seek($fh, $offset, 0)
|
seek($fh, $offset, SEEK_SET)
|
||||||
or BAIL_OUT("seek failed: $!");
|
or BAIL_OUT("seek failed: $!");
|
||||||
defined(sysread($fh, $buffer, HEAPTUPLE_PACK_LENGTH))
|
defined(sysread($fh, $buffer, HEAPTUPLE_PACK_LENGTH))
|
||||||
or BAIL_OUT("sysread failed: $!");
|
or BAIL_OUT("sysread failed: $!");
|
||||||
@ -172,7 +173,7 @@ sub write_tuple
|
|||||||
$tup->{c_va_extinfo},
|
$tup->{c_va_extinfo},
|
||||||
$tup->{c_va_valueid},
|
$tup->{c_va_valueid},
|
||||||
$tup->{c_va_toastrelid});
|
$tup->{c_va_toastrelid});
|
||||||
seek($fh, $offset, 0)
|
seek($fh, $offset, SEEK_SET)
|
||||||
or BAIL_OUT("seek failed: $!");
|
or BAIL_OUT("seek failed: $!");
|
||||||
defined(syswrite($fh, $buffer, HEAPTUPLE_PACK_LENGTH))
|
defined(syswrite($fh, $buffer, HEAPTUPLE_PACK_LENGTH))
|
||||||
or BAIL_OUT("syswrite failed: $!");
|
or BAIL_OUT("syswrite failed: $!");
|
||||||
|
@ -4,6 +4,7 @@ use Cwd;
|
|||||||
use Config;
|
use Config;
|
||||||
use File::Basename qw(basename dirname);
|
use File::Basename qw(basename dirname);
|
||||||
use File::Path qw(rmtree);
|
use File::Path qw(rmtree);
|
||||||
|
use Fcntl qw(:seek);
|
||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
use Test::More tests => 110;
|
use Test::More tests => 110;
|
||||||
@ -555,7 +556,7 @@ my $block_size = $node->safe_psql('postgres', 'SHOW block_size;');
|
|||||||
# induce corruption
|
# induce corruption
|
||||||
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
|
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
|
||||||
open $file, '+<', "$pgdata/$file_corrupt1";
|
open $file, '+<', "$pgdata/$file_corrupt1";
|
||||||
seek($file, $pageheader_size, 0);
|
seek($file, $pageheader_size, SEEK_SET);
|
||||||
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
||||||
close $file;
|
close $file;
|
||||||
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
|
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
|
||||||
@ -574,7 +575,7 @@ open $file, '+<', "$pgdata/$file_corrupt1";
|
|||||||
for my $i (1 .. 5)
|
for my $i (1 .. 5)
|
||||||
{
|
{
|
||||||
my $offset = $pageheader_size + $i * $block_size;
|
my $offset = $pageheader_size + $i * $block_size;
|
||||||
seek($file, $offset, 0);
|
seek($file, $offset, SEEK_SET);
|
||||||
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
||||||
}
|
}
|
||||||
close $file;
|
close $file;
|
||||||
@ -591,7 +592,7 @@ rmtree("$tempdir/backup_corrupt2");
|
|||||||
# induce corruption in a second file
|
# induce corruption in a second file
|
||||||
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
|
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
|
||||||
open $file, '+<', "$pgdata/$file_corrupt2";
|
open $file, '+<', "$pgdata/$file_corrupt2";
|
||||||
seek($file, $pageheader_size, 0);
|
seek($file, $pageheader_size, SEEK_SET);
|
||||||
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
||||||
close $file;
|
close $file;
|
||||||
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
|
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
|
||||||
|
@ -5,6 +5,8 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
|
|
||||||
|
use Fcntl qw(:seek);
|
||||||
use Test::More tests => 63;
|
use Test::More tests => 63;
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ sub check_relation_corruption
|
|||||||
|
|
||||||
# Time to create some corruption
|
# Time to create some corruption
|
||||||
open my $file, '+<', "$pgdata/$file_corrupted";
|
open my $file, '+<', "$pgdata/$file_corrupted";
|
||||||
seek($file, $pageheader_size, 0);
|
seek($file, $pageheader_size, SEEK_SET);
|
||||||
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
syswrite($file, "\0\0\0\0\0\0\0\0\0");
|
||||||
close $file;
|
close $file;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user