more fixes for clientdocument/simpleclient. Testign the vamsasArchive reader and...
[vamsas.git] / src / org / vamsas / client / simpleclient / SessionFile.java
index 0ff306e..0eabf6d 100644 (file)
@@ -46,17 +46,27 @@ public class SessionFile {
         fileLock.release();
     fileLock = null;
     if (sessionFile != null) {
-      if (sessionFile.exists()) {
-        // TODO: see if we need to loop-wait for locks or they just block until
-        // lock is made...
-        do {
-          if (fileLock!=null)
-            fileLock.release();
-          fileLock = new Lock(sessionFile); // TODO: wait around if we can't get the lock.
-        } while (!fileLock.isLocked());
-        // fileLock = new Lock(sessionFile);
-        return fileLock.isLocked();
+      if (!sessionFile.exists()) {
+        // create new file
+        try {
+          if (!sessionFile.createNewFile()) {
+            log.error("Failed to create file prior to locking: "+sessionFile);
+            return false;
+          }
+        } catch (IOException e) {
+          log.error("Exception when trying to create file "+sessionFile, e);
+          return false;
+        }
       }
+      // TODO: see if we need to loop-wait for locks or they just block until
+      // lock is made...
+      do {
+        if (fileLock!=null)
+          fileLock.release();
+          fileLock = new Lock(sessionFile); // TODO: wait around if we can't get the lock.
+      } while (!fileLock.isLocked());
+      // fileLock = new Lock(sessionFile);
+      return fileLock.isLocked();    
     } else
       log.error("lockFile called for non-initialised SessionFile!");