Skip to content

Commit 093c7fe

Browse files
paulirwinmarionoack
authored andcommitted
Add comments about FileShare modes
1 parent 68f2872 commit 093c7fe

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
@@ -897,7 +897,9 @@ private static SharedMapping CreateAttempt(string file, int chunkSizePower)
897897
// immediately recursively delete the directory. We need
898898
// FileShare.Delete in particular: on Windows, a delete
899899
// attempt against an open file fails unless the open
900-
// share-mode permits FILE_SHARE_DELETE.
900+
// share-mode permits FILE_SHARE_DELETE. In Java, FileChannel
901+
// uses read+write+delete mode by default and Lucene doesn't
902+
// override this.
901903
//
902904
// bufferSize: 1 because MemoryMappedFile uses only the
903905
// 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
@@ -104,6 +104,8 @@ public override IndexInput OpenInput(string name, IOContext context)
104104
EnsureOpen();
105105
EnsureCanRead(name); // LUCENENET-specific: backported call site from Lucene 6.0.0
106106
var path = Path.Combine(Directory.FullName, name); // LUCENENET specific: changed to use string file name instead of allocating a FileInfo (#832)
107+
// LUCENENET NOTE: FileShare Read+Write+Delete is correct and matches Java Lucene.
108+
// In Java, FileChannel defaults to this behavior, and Lucene does not override it.
107109
var fc = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
108110
return new NIOFSIndexInput("NIOFSIndexInput(path=\"" + path + "\")", fc, context);
109111
}
@@ -113,6 +115,8 @@ public override IndexInputSlicer CreateSlicer(string name, IOContext context)
113115
EnsureOpen();
114116
EnsureCanRead(name); // LUCENENET-specific: this method is not in Lucene 6.0.0 but added to match OpenInput above
115117
var path = Path.Combine(Directory.FullName, name); // LUCENENET specific: changed to use string file name instead of allocating a FileInfo (#832)
118+
// LUCENENET NOTE: FileShare Read+Write+Delete is correct and matches Java Lucene.
119+
// In Java, FileChannel defaults to this behavior, and Lucene does not override it.
116120
var fc = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
117121
return new IndexInputSlicerAnonymousClass(context, path, fc);
118122
}

0 commit comments

Comments
 (0)