new method to test if a particular file is or is related to the target of a lock
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / NativeLock.java
index 8a0124c..ccaa407 100644 (file)
@@ -70,16 +70,19 @@ public class NativeLock extends Lock {
   }
 
   public void release(boolean closeChannel) {
+    if (lock==null)
+      return;
     try {
       // channel.close should be called before release() for rigourous locking.
-      if (rafile!=null && rafile.getFD().valid() && rafile.getChannel()!=null && lock.isValid()) {
+      if (lock.isValid() && rafile!=null && rafile.getFD().valid() && rafile.getChannel()!=null) {
         if (closeChannel && rafile.getChannel().isOpen()) {
             rafile.close();
             rafile=null; 
+        } else {
+          // just release the lock without doing anything to the channe;l
+          if (lock!=null && lock.isValid())
+            lock.release();
         }
-        if (lock!=null && lock.isValid())
-          lock.release();
-        
       }
     } catch (IOException e) {
       log.warn("Whilst releasing lock",e);
@@ -169,4 +172,10 @@ public class NativeLock extends Lock {
     return null;
   }
 
+  public boolean isTargetLockFile(File afile) {
+    if (isLocked() && target.equals(afile))
+      return true;
+    return false;
+  }
+
 }