Commit 786c2b9
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
- Store
- Lucene.Net.Tests.Misc/Store
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
0 commit comments