Skip to content

Commit 786c2b9

Browse files
paulirwinclaude
andcommitted
Finish port of WindowsDirectory using P/Invoke (#1342)
Complete the previously-excluded WindowsDirectory port from Lucene 4.8.1, replacing the original Java + C++/JNI native layer with Win32 P/Invoke (CreateFileW with FILE_FLAG_RANDOM_ACCESS, ReadFile with positioned NativeOverlapped reads, GetFileInformationByHandle, and SafeFileHandle for the handle lifecycle). Modernized to current Lucene.NET conventions (ReadInternal(Span<byte>), Position, DirectoryInfo/string ctors, Dispose pattern) to match SimpleFSDirectory. The read handle uses FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE. Upstream 4.8.1 used only READ | WRITE; FILE_SHARE_DELETE is added to match the SimpleFSDirectory read-path behavior from #1283 so an open read handle does not block deletion of the underlying file on Windows. The type is guarded to Windows via a runtime Constants.WINDOWS check (throwing PlatformNotSupportedException) and [SupportedOSPlatform("windows")] (under FEATURE_SUPPORTEDOSPLATFORMATTRIBUTE). Enabled AllowUnsafeBlocks in Lucene.Net.Misc for the fixed read buffer, and narrowed the Store compile exclusion to only the still-unfinished NativeUnixDirectory/NativePosixUtil. Added test coverage (the original Lucene type had none): TestWindowsDirectory runs the full BaseDirectoryTestCase suite (Windows-gated), plus bespoke tests for random-access positioned reads, independent clone reads, read-past-EOF, clone dispose not closing the shared handle, and concurrent multi-threaded clone reads. A cross-platform fixture verifies the platform guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 80b2a66 commit 786c2b9

3 files changed

Lines changed: 560 additions & 135 deletions

File tree

src/Lucene.Net.Misc/Lucene.Net.Misc.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@
3636
<PackageTags>$(PackageTags);miscellaneous</PackageTags>
3737
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
3838
<NoWarn>$(NoWarn);1591;1573</NoWarn>
39+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3940
</PropertyGroup>
4041

4142

4243

4344
<ItemGroup>
44-
<Compile Remove="Store\*" />
45+
<!-- LUCENENET TODO: The Unix/POSIX native directory port (NativeUnixDirectory) is not yet
46+
complete and is excluded from compilation. See GH-1342. WindowsDirectory has been ported. -->
47+
<Compile Remove="Store\NativeUnixDirectory.cs" />
48+
<Compile Remove="Store\NativePosixUtil.cs" />
4549
</ItemGroup>
4650

4751
<ItemGroup>

0 commit comments

Comments
 (0)