From 929b2d34bd47d5320a5bc2ffeb5a66fb06ecc35f Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 26 Mar 2007 18:22:27 +0000
Subject: [PATCH] Fix for issue 1432 (Uninstall fails on windows due to lock on activation.jar).

---
 opends/src/server/org/opends/server/core/LockFileManager.java |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 108 insertions(+), 4 deletions(-)

diff --git a/opends/src/server/org/opends/server/core/LockFileManager.java b/opends/src/server/org/opends/server/core/LockFileManager.java
index b332d1b..e8b3b25 100644
--- a/opends/src/server/org/opends/server/core/LockFileManager.java
+++ b/opends/src/server/org/opends/server/core/LockFileManager.java
@@ -138,10 +138,11 @@
 
 
       // Open the file for reading and get the corresponding file channel.
-      FileChannel channel;
+      FileChannel channel = null;
+      RandomAccessFile raf = null;
       try
       {
-        RandomAccessFile raf = new RandomAccessFile(lockFile, "r");
+        raf = new RandomAccessFile(lockFile, "r");
         channel = raf.getChannel();
       }
       catch (Exception e)
@@ -154,6 +155,17 @@
         int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_OPEN;
         failureReason.append(getMessage(msgID, lockFile,
                                         stackTraceToSingleLineString(e)));
+
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
 
@@ -174,6 +186,26 @@
         int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_LOCK;
         failureReason.append(getMessage(msgID,
                                         stackTraceToSingleLineString(e)));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
 
@@ -184,6 +216,26 @@
       {
         int msgID = MSGID_FILELOCKER_LOCK_SHARED_NOT_GRANTED;
         failureReason.append(getMessage(msgID, lockFile));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
       else
@@ -263,10 +315,11 @@
 
 
       // Open the file read+write and get the corresponding file channel.
-      FileChannel channel;
+      FileChannel channel = null;
+      RandomAccessFile raf = null;
       try
       {
-        RandomAccessFile raf = new RandomAccessFile(lockFile, "rw");
+        raf = new RandomAccessFile(lockFile, "rw");
         channel = raf.getChannel();
       }
       catch (Exception e)
@@ -279,6 +332,16 @@
         int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_OPEN;
         failureReason.append(getMessage(msgID, lockFile,
                                         stackTraceToSingleLineString(e)));
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
 
@@ -299,6 +362,27 @@
         int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_LOCK;
         failureReason.append(getMessage(msgID, lockFile,
                                         stackTraceToSingleLineString(e)));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+
         return false;
       }
 
@@ -309,6 +393,26 @@
       {
         int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_NOT_GRANTED;
         failureReason.append(getMessage(msgID, lockFile));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
       else

--
Gitblit v1.10.0