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

Commitc4465cd

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 parent919c08d commitc4465cd

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
@@ -472,33 +472,33 @@ sub slurp_file
472472
my ($filename,$offset) =@_;
473473
local$/;
474474
my$contents;
475+
my$fh;
476+
477+
# On windows open file using win32 APIs, to allow us to set the
478+
# FILE_SHARE_DELETE flag ("d" below), otherwise other accesses to the file
479+
# may fail.
475480
if ($Config{osname}ne'MSWin32')
476481
{
477-
open(my$in,'<',$filename)
482+
open($fh,'<',$filename)
478483
or croak"could not read\"$filename\":$!";
479-
if (defined($offset))
480-
{
481-
seek($in,$offset, SEEK_SET)
482-
or croak"could not seek\"$filename\":$!";
483-
}
484-
$contents = <$in>;
485-
close$in;
486484
}
487485
else
488486
{
489487
my$fHandle = createFile($filename,"r","rwd")
490488
or croak"could not open\"$filename\": $^E";
491-
OsFHandleOpen(my$fh = IO::Handle->new(),$fHandle,'r')
489+
OsFHandleOpen($fh = IO::Handle->new(),$fHandle,'r')
492490
or croak"could not read\"$filename\": $^E\n";
493-
if (defined($offset))
494-
{
495-
setFilePointer($fh,$offset,qw(FILE_BEGIN))
496-
or croak"could not seek\"$filename\": $^E\n";
497-
}
498-
$contents = <$fh>;
499-
CloseHandle($fHandle)
500-
or croak"could not close\"$filename\": $^E\n";
501491
}
492+
493+
if (defined($offset))
494+
{
495+
seek($fh,$offset, SEEK_SET)
496+
or croak"could not seek\"$filename\":$!";
497+
}
498+
499+
$contents = <$fh>;
500+
close$fh;
501+
502502
$contents =~s/\r\n/\n/gif$Config{osname}eq'msys';
503503
return$contents;
504504
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp