Skip to content

Commit 6cfabf1

Browse files
committed
requested changes from paulirwin at PR#1429
1 parent b3ce823 commit 6cfabf1

2 files changed

Lines changed: 19 additions & 25 deletions

File tree

src/Lucene.Net/Store/FSDirectory.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,33 +317,33 @@ public override void DeleteFile(string name)
317317
EnsureOpen();
318318
string file = Path.Combine(m_directory.FullName, name);
319319

320-
// LUCENENET specific: We need to explicitly throw when the file has already been deleted,
321-
// since FileInfo doesn't do that for us.
322-
// (An enhancement carried over from Lucene 8.2.0)
323-
if (!File.Exists(file))
324-
{
325-
throw new FileNotFoundException("Cannot delete " + file + " because it doesn't exist.");
326-
}
320+
// LUCENENET specific: We need to explicitly throw when the file has already been deleted,
321+
// since FileInfo doesn't do that for us.
322+
// (An enhancement carried over from Lucene 8.2.0)
323+
if (!File.Exists(file))
324+
{
325+
throw new FileNotFoundException("Cannot delete " + file + " because it doesn't exist.");
326+
}
327327

328-
// LUCENENET specific: Do NOT hold m_syncLock while deleting. On a network share (SMB),
328+
// LUCENENET NOTE: Do NOT hold m_syncLock while deleting. On a network share (SMB),
329329
// File.Delete can block for a long time (e.g. waiting for the server to break an
330330
// oplock/lease on a file this client still has open). Holding m_syncLock here would
331331
// block every concurrent Sync() and IndexOutput.Dispose() on this directory behind
332332
// a single stalled delete, freezing the whole writer. Only the m_staleFiles
333333
// bookkeeping below needs the lock (see remarks for the m_staleFiles field);
334334
// upstream Java likewise performs the delete without any directory-wide lock.
335-
try
336-
{
337-
File.Delete(file);
338-
if (File.Exists(file))
339-
{
340-
throw new IOException("Cannot delete " + file);
341-
}
342-
}
343-
catch (Exception e)
335+
try
336+
{
337+
File.Delete(file);
338+
if (File.Exists(file))
344339
{
345-
throw new IOException("Cannot delete " + file, e);
340+
throw new IOException("Cannot delete " + file);
346341
}
342+
}
343+
catch (Exception e)
344+
{
345+
throw new IOException("Cannot delete " + file, e);
346+
}
347347

348348
UninterruptableMonitor.Enter(m_syncLock);
349349
try

src/Lucene.Net/Store/MMapDirectory.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,7 @@ public override IndexInput OpenInput(string name, IOContext context)
194194
EnsureOpen();
195195
EnsureCanRead(name); // LUCENENET-specific: backported call site from Lucene 6.0.0
196196
var file = Path.Combine(Directory.FullName, name); // LUCENENET specific: changed to use string file name instead of allocating a FileInfo (#832)
197-
// LUCENENET specific: Add FileShare.Delete (a deliberate divergence from upstream Java's RandomAccessFile,
198-
// which omits it) to match SimpleFSDirectory, NIOFSDirectory and our other handles, giving Windows the same
199-
// delete-while-open semantics POSIX already provides so index files can be deleted while a read handle is
200-
// open (#1283). Without it, a pending delete of a still-mapped file on an SMB share can block inside
201-
// File.Delete while the server waits for this client's lease break, which cannot complete while mapped
202-
// views are active.
203-
var fc = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
197+
var fc = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
204198
return new MMapIndexInput(this, "MMapIndexInput(path=\"" + file + "\")", fc);
205199
}
206200

0 commit comments

Comments
 (0)