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

Commit5ba397f

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 parentc53ff69 commit5ba397f

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
@@ -137,7 +137,7 @@ BEGIN
137137
if ($windows_os)
138138
{
139139
require Win32API::File;
140-
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer));
140+
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
141141
}
142142

143143
# Specifies whether to use Unix sockets for test setups. On
@@ -435,33 +435,33 @@ sub slurp_file
435435
my ($filename,$offset) =@_;
436436
local$/;
437437
my$contents;
438+
my$fh;
439+
440+
# On windows open file using win32 APIs, to allow us to set the
441+
# FILE_SHARE_DELETE flag ("d" below), otherwise other accesses to the file
442+
# may fail.
438443
if ($Config{osname}ne'MSWin32')
439444
{
440-
open(my$in,'<',$filename)
445+
open($fh,'<',$filename)
441446
ordie"could not read\"$filename\":$!";
442-
if (defined($offset))
443-
{
444-
seek($in,$offset, SEEK_SET)
445-
ordie"could not seek\"$filename\":$!";
446-
}
447-
$contents = <$in>;
448-
close$in;
449447
}
450448
else
451449
{
452450
my$fHandle = createFile($filename,"r","rwd")
453451
ordie"could not open\"$filename\": $^E";
454-
OsFHandleOpen(my$fh = IO::Handle->new(),$fHandle,'r')
452+
OsFHandleOpen($fh = IO::Handle->new(),$fHandle,'r')
455453
ordie"could not read\"$filename\": $^E\n";
456-
if (defined($offset))
457-
{
458-
setFilePointer($fh,$offset,qw(FILE_BEGIN))
459-
ordie"could not seek\"$filename\": $^E\n";
460-
}
461-
$contents = <$fh>;
462-
CloseHandle($fHandle)
463-
ordie"could not close\"$filename\": $^E\n";
464454
}
455+
456+
if (defined($offset))
457+
{
458+
seek($fh,$offset, SEEK_SET)
459+
ordie"could not seek\"$filename\":$!";
460+
}
461+
462+
$contents = <$fh>;
463+
close$fh;
464+
465465
$contents =~s/\r\n/\n/gif$Config{osname}eq'msys';
466466
return$contents;
467467
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp