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 / FileLock.java
index 9201702..40ee9cf 100644 (file)
@@ -64,7 +64,7 @@ public class FileLock extends Lock {
     super(lockfile);
     // try and get a lock.
     try {
-      _lock = new File(lockfile.getParentFile(), lockfile.getName()+"."+_LockSuffix);
+      _lock = make_lockForTarget(lockfile);
       if (!ensureLockFile(block)) {
         log.debug("Couldn't get lock on "+_lock);
         tidy();
@@ -87,7 +87,14 @@ public class FileLock extends Lock {
           + lockfile.getAbsolutePath(),e);
     }
   }
-  
+  /**
+   * 
+   * @param lockfile target of lock
+   * @return file object that will be locked for lockfile
+   */
+  private File make_lockForTarget(File lockfile) {
+    return new File(lockfile.getParentFile(), lockfile.getName()+"."+_LockSuffix);
+  }
   private boolean openRaFile() throws IOException {
     if (target==null)
       return false;
@@ -208,4 +215,12 @@ public class FileLock extends Lock {
     log.debug("Failed to getRaChannel on target "+target);
     return null;
   }
+  public boolean isTargetLockFile(File afile) {
+    if (isLocked())
+    {
+      if (target.equals(afile) || make_lockForTarget(target).equals(afile))
+        return true;
+    }
+    return false;
+  }
 }