Skip to content

Commit c731f91

Browse files
committed
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
1 parent 8e861ea commit c731f91

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

contrib/amcheck/t/001_verify_heapam.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use PostgresNode;
55
use TestLib;
66

7+
use Fcntl qw(:seek);
78
use Test::More tests => 80;
89

910
my ($node, $result);
@@ -124,7 +125,7 @@ sub corrupt_first_page
124125
# Corrupt some line pointers. The values are chosen to hit the
125126
# various line-pointer-corruption checks in verify_heapam.c
126127
# on both little-endian and big-endian architectures.
127-
seek($fh, 32, 0)
128+
seek($fh, 32, SEEK_SET)
128129
or BAIL_OUT("seek failed: $!");
129130
syswrite(
130131
$fh,

src/bin/pg_amcheck/t/003_check.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
use PostgresNode;
55
use TestLib;
6+
7+
use Fcntl qw(:seek);
68
use Test::More tests => 63;
79

810
my ($node, $port, %corrupt_page, %remove_relation);
@@ -84,7 +86,7 @@ sub corrupt_first_page
8486
# Corrupt some line pointers. The values are chosen to hit the
8587
# various line-pointer-corruption checks in verify_heapam.c
8688
# on both little-endian and big-endian architectures.
87-
seek($fh, 32, 0)
89+
seek($fh, 32, SEEK_SET)
8890
or BAIL_OUT("seek failed: $!");
8991
syswrite(
9092
$fh,

src/bin/pg_amcheck/t/004_verify_heapam.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use PostgresNode;
55
use TestLib;
66

7+
use Fcntl qw(:seek);
78
use Test::More;
89

910
# This regression test demonstrates that the pg_amcheck binary correctly
@@ -95,7 +96,7 @@ sub read_tuple
9596
{
9697
my ($fh, $offset) = @_;
9798
my ($buffer, %tup);
98-
seek($fh, $offset, 0)
99+
seek($fh, $offset, SEEK_SET)
99100
or BAIL_OUT("seek failed: $!");
100101
defined(sysread($fh, $buffer, HEAPTUPLE_PACK_LENGTH))
101102
or BAIL_OUT("sysread failed: $!");
@@ -172,7 +173,7 @@ sub write_tuple
172173
$tup->{c_va_extinfo},
173174
$tup->{c_va_valueid},
174175
$tup->{c_va_toastrelid});
175-
seek($fh, $offset, 0)
176+
seek($fh, $offset, SEEK_SET)
176177
or BAIL_OUT("seek failed: $!");
177178
defined(syswrite($fh, $buffer, HEAPTUPLE_PACK_LENGTH))
178179
or BAIL_OUT("syswrite failed: $!");

src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Config;
55
use File::Basename qw(basename dirname);
66
use File::Path qw(rmtree);
7+
use Fcntl qw(:seek);
78
use PostgresNode;
89
use TestLib;
910
use Test::More tests => 110;
@@ -555,7 +556,7 @@
555556
# induce corruption
556557
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
557558
open $file, '+<', "$pgdata/$file_corrupt1";
558-
seek($file, $pageheader_size, 0);
559+
seek($file, $pageheader_size, SEEK_SET);
559560
syswrite($file, "\0\0\0\0\0\0\0\0\0");
560561
close $file;
561562
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';
@@ -574,7 +575,7 @@
574575
for my $i (1 .. 5)
575576
{
576577
my $offset = $pageheader_size + $i * $block_size;
577-
seek($file, $offset, 0);
578+
seek($file, $offset, SEEK_SET);
578579
syswrite($file, "\0\0\0\0\0\0\0\0\0");
579580
}
580581
close $file;
@@ -591,7 +592,7 @@
591592
# induce corruption in a second file
592593
system_or_bail 'pg_ctl', '-D', $pgdata, 'stop';
593594
open $file, '+<', "$pgdata/$file_corrupt2";
594-
seek($file, $pageheader_size, 0);
595+
seek($file, $pageheader_size, SEEK_SET);
595596
syswrite($file, "\0\0\0\0\0\0\0\0\0");
596597
close $file;
597598
system_or_bail 'pg_ctl', '-D', $pgdata, 'start';

src/bin/pg_checksums/t/002_actions.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use warnings;
66
use PostgresNode;
77
use TestLib;
8+
9+
use Fcntl qw(:seek);
810
use Test::More tests => 63;
911

1012

@@ -50,7 +52,7 @@ sub check_relation_corruption
5052

5153
# Time to create some corruption
5254
open my $file, '+<', "$pgdata/$file_corrupted";
53-
seek($file, $pageheader_size, 0);
55+
seek($file, $pageheader_size, SEEK_SET);
5456
syswrite($file, "\0\0\0\0\0\0\0\0\0");
5557
close $file;
5658

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy