Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions src/Lucene.Net/Store/FSDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,31 +317,37 @@ public override void DeleteFile(string name)
EnsureOpen();
string file = Path.Combine(m_directory.FullName, name);

// LUCENENET Specific: See remarks for m_staleFiles field.
UninterruptableMonitor.Enter(m_syncLock);
try
// LUCENENET specific: We need to explicitly throw when the file has already been deleted,
// since FileInfo doesn't do that for us.
// (An enhancement carried over from Lucene 8.2.0)
if (!File.Exists(file))
{
// LUCENENET specific: We need to explicitly throw when the file has already been deleted,
// since FileInfo doesn't do that for us.
// (An enhancement carried over from Lucene 8.2.0)
if (!File.Exists(file))
{
throw new FileNotFoundException("Cannot delete " + file + " because it doesn't exist.");
}
throw new FileNotFoundException("Cannot delete " + file + " because it doesn't exist.");
}

try
{
File.Delete(file);
if (File.Exists(file))
{
throw new IOException("Cannot delete " + file);
}
}
catch (Exception e)
// LUCENENET NOTE: Do NOT hold m_syncLock while deleting. On a network share (SMB),
// File.Delete can block for a long time (e.g. waiting for the server to break an
// oplock/lease on a file this client still has open). Holding m_syncLock here would
// block every concurrent Sync() and IndexOutput.Dispose() on this directory behind
// a single stalled delete, freezing the whole writer. Only the m_staleFiles
// bookkeeping below needs the lock (see remarks for the m_staleFiles field);
// upstream Java likewise performs the delete without any directory-wide lock.
try
{
File.Delete(file);
if (File.Exists(file))
{
throw new IOException("Cannot delete " + file, e);
throw new IOException("Cannot delete " + file);
}
}
catch (Exception e)
{
throw new IOException("Cannot delete " + file, e);
}

UninterruptableMonitor.Enter(m_syncLock);
try
{
m_staleFiles.Remove(name);
}
finally
Expand Down