From 662059f219758b0348e7679b4cb5eee0e520df0e Mon Sep 17 00:00:00 2001 From: Shai Erera Date: Thu, 8 Jul 2010 07:55:32 +0000 Subject: [PATCH] LUCENE-2421: merge 3x to trunk git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@961618 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/store/NativeFSLockFactory.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java b/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java index ab78a0873a5..19a3c62cc09 100755 --- a/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java +++ b/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java @@ -152,13 +152,20 @@ public class NativeFSLockFactory extends FSLockFactory { // they are locked, but, still do this in case people // really want to see the files go away: if (lockDir.exists()) { + + // Try to release the lock first - if it's held by another process, this + // method should not silently fail. + // NOTE: makeLock fixes the lock name by prefixing it w/ lockPrefix. + // Therefore it should be called before the code block next which prefixes + // the given name. + makeLock(lockName).release(); + if (lockPrefix != null) { lockName = lockPrefix + "-" + lockName; } - File lockFile = new File(lockDir, lockName); - if (lockFile.exists() && !lockFile.delete()) { - throw new IOException("Cannot delete " + lockFile); - } + + // As mentioned above, we don't care if the deletion of the file failed. + new File(lockDir, lockName).delete(); } } }