Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2f74db1

Browse files
committed
Fix TestLib::slurp_file() with offset on windows.
3c5b068 used setFilePointer() to set the position of the filehandle, butpassed the wrong filehandle, always leaving the position at 0. Instead of justfixing that, remove use of setFilePointer(), we have a perl fd at this point,so we can just use perl's seek().Additionally, the perl filehandle wasn't closed, just the windows filehandle.Reviewed-By: Andrew Dunstan <andrew@dunslane.net>Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/20211003173038.64mmhgxctfqn7wl6@alap3.anarazel.deBackpatch: 9.6-, like3c5b068
1 parent8162464 commit2f74db1

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

‎src/test/perl/TestLib.pm

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ BEGIN
149149
{
150150
require Win32API::File;
151151
Win32API::File->import(
152-
qw(createFile OsFHandleOpen CloseHandle setFilePointer));
152+
qw(createFile OsFHandleOpen CloseHandle));
153153
}
154154

155155
# Specifies whether to use Unix sockets for test setups. On
@@ -492,33 +492,33 @@ sub slurp_file
492492
my ($filename,$offset) =@_;
493493
local$/;
494494
my$contents;
495+
my$fh;
496+
497+
# On windows open file using win32 APIs, to allow us to set the
498+
# FILE_SHARE_DELETE flag ("d" below), otherwise other accesses to the file
499+
# may fail.
495500
if ($Config{osname}ne'MSWin32')
496501
{
497-
open(my$in,'<',$filename)
502+
open($fh,'<',$filename)
498503
or croak"could not read\"$filename\":$!";
499-
if (defined($offset))
500-
{
501-
seek($in,$offset, SEEK_SET)
502-
or croak"could not seek\"$filename\":$!";
503-
}
504-
$contents = <$in>;
505-
close$in;
506504
}
507505
else
508506
{
509507
my$fHandle = createFile($filename,"r","rwd")
510508
or croak"could not open\"$filename\": $^E";
511-
OsFHandleOpen(my$fh = IO::Handle->new(),$fHandle,'r')
509+
OsFHandleOpen($fh = IO::Handle->new(),$fHandle,'r')
512510
or croak"could not read\"$filename\": $^E\n";
513-
if (defined($offset))
514-
{
515-
setFilePointer($fh,$offset,qw(FILE_BEGIN))
516-
or croak"could not seek\"$filename\": $^E\n";
517-
}
518-
$contents = <$fh>;
519-
CloseHandle($fHandle)
520-
or croak"could not close\"$filename\": $^E\n";
521511
}
512+
513+
if (defined($offset))
514+
{
515+
seek($fh,$offset, SEEK_SET)
516+
or croak"could not seek\"$filename\":$!";
517+
}
518+
519+
$contents = <$fh>;
520+
close$fh;
521+
522522
$contents =~s/\r\n/\n/gif$Config{osname}eq'msys';
523523
return$contents;
524524
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp