Skip to content

Commit 52ee6bb

Browse files
authored
Remove adjust logic in MMapDirectory, #1090 (#1138)
1 parent 3729d32 commit 52ee6bb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Lucene.Net/Store/MMapDirectory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,15 @@ internal virtual ByteBuffer[] Map(MMapIndexInput input, FileStream fc, long offs
330330

331331
// LUCENENET: We get an UnauthorizedAccessException if we create a 0 byte file at the end of the range.
332332
// See: https://stackoverflow.com/a/5501331
333-
// We can fix this by moving back 1 byte on the offset if the bufSize is 0.
334-
int adjust = 0;
335-
if (bufSize == 0 && bufNr == (nrBuffers - 1) && (offset + bufferStart) > 0)
333+
// We can fix this by using an empty ByteBuffer if the buffer size is 0.
334+
if (bufSize == 0 && bufNr == (nrBuffers - 1))
336335
{
337-
adjust = 1;
336+
buffers[bufNr] = ByteBuffer.Allocate(0).AsReadOnlyBuffer();
337+
break;
338338
}
339339

340340
buffers[bufNr] = input.memoryMappedFile.CreateViewByteBuffer(
341-
offset: (offset + bufferStart) - adjust,
341+
offset: offset + bufferStart,
342342
size: bufSize,
343343
access: MemoryMappedFileAccess.Read);
344344
bufferStart += bufSize;

0 commit comments

Comments
 (0)