Skip to content

Commit 4b7a965

Browse files
committed
Add comments about FileShare modes
1 parent f8e6db3 commit 4b7a965

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/Lucene.Net/Store/MMapDirectory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,9 @@ private static SharedMapping CreateAttempt(string file, int chunkSizePower)
896896
// immediately recursively delete the directory. We need
897897
// FileShare.Delete in particular: on Windows, a delete
898898
// attempt against an open file fails unless the open
899-
// share-mode permits FILE_SHARE_DELETE.
899+
// share-mode permits FILE_SHARE_DELETE. In Java, FileChannel
900+
// uses read+write+delete mode by default and Lucene doesn't
901+
// override this.
900902
//
901903
// bufferSize: 1 because MemoryMappedFile uses only the
902904
// file handle and bypasses the FileStream buffer, so a

src/Lucene.Net/Store/NIOFSDirectory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public override IndexInput OpenInput(string name, IOContext context)
103103
{
104104
EnsureOpen();
105105
var path = Path.Combine(Directory.FullName, name); // LUCENENET specific: changed to use string file name instead of allocating a FileInfo (#832)
106+
// LUCENENET NOTE: FileShare Read+Write+Delete is correct and matches Java Lucene.
107+
// In Java, FileChannel defaults to this behavior, and Lucene does not override it.
106108
var fc = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
107109
return new NIOFSIndexInput("NIOFSIndexInput(path=\"" + path + "\")", fc, context);
108110
}
@@ -111,6 +113,8 @@ public override IndexInputSlicer CreateSlicer(string name, IOContext context)
111113
{
112114
EnsureOpen();
113115
var path = Path.Combine(Directory.FullName, name); // LUCENENET specific: changed to use string file name instead of allocating a FileInfo (#832)
116+
// LUCENENET NOTE: FileShare Read+Write+Delete is correct and matches Java Lucene.
117+
// In Java, FileChannel defaults to this behavior, and Lucene does not override it.
114118
var fc = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
115119
return new IndexInputSlicerAnonymousClass(context, path, fc);
116120
}

0 commit comments

Comments
 (0)