You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2010/07/08 09:35:19 UTC

svn commit: r961612 - /lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java

Author: shaie
Date: Thu Jul  8 07:35:18 2010
New Revision: 961612

URL: http://svn.apache.org/viewvc?rev=961612&view=rev
Log:
LUCENE-2421: fix clearLock to not fail on file deletion

Modified:
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=961612&r1=961611&r2=961612&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java Thu Jul  8 07:35:18 2010
@@ -152,13 +152,20 @@ public class NativeFSLockFactory extends
     // 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();
     }
   }
 }