Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2001-10-02 21:09:26 +0000
committerJohn Arthorne2001-10-02 21:09:26 +0000
commitc1a6440ba99fc8267c4b4abab1ea193e06293111 (patch)
tree9c826a9557958aeaf31f83c7517b70713f81abe6
parent2dac7075e068ac74a3682a24271ef0b0609e9053 (diff)
downloadeclipse.platform.runtime-203.tar.gz
eclipse.platform.runtime-203.tar.xz
eclipse.platform.runtime-203.zip
1GET4T6: ITPCORE:WIN2000 - Prevent a workspace being opened twicev203
-rw-r--r--bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java52
-rw-r--r--bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java3
-rw-r--r--bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties20
3 files changed, 65 insertions, 10 deletions
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java
index 800d3fdcf..cfc7c0927 100644
--- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java
+++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java
@@ -13,6 +13,7 @@ import org.eclipse.core.runtime.*;
import org.eclipse.core.internal.runtime.*;
import org.eclipse.core.internal.plugins.*;
import java.io.*;
+import java.io.FileOutputStream;
import java.net.*;
import java.util.*;
@@ -42,6 +43,9 @@ public final class InternalPlatform {
private static boolean splashDown = false;
private static boolean cacheRegistry = false;
+ private static File lockFile = null;
+ private static RandomAccessFile lockRAF = null;
+
// default plugin data
private static final String PI_XML = "org.apache.xerces";
private static final String PLUGINSDIR = "plugins/";
@@ -166,6 +170,50 @@ private static String findPlugin(LaunchInfo.VersionedIdentifier[] list, String n
}
return result == null ? null : result.toString();
}
+/**
+ * Closes the open lock file handle, and makes a silent best
+ * attempt to delete the file.
+ */
+private static synchronized void clearLockFile() {
+ try {
+ if (lockRAF != null) {
+ lockRAF.close();
+ lockRAF = null;
+ }
+ } catch (IOException e) {
+ }
+ if (lockFile != null) {
+ lockFile.delete();
+ lockFile = null;
+ }
+}
+/**
+ * Creates a lock file in the meta-area that indicates the meta-area
+ * is in use, preventing other eclipse instances from concurrently
+ * using the same meta-area.
+ */
+private static synchronized void createLockFile() throws CoreException {
+ String lockLocation = metaArea.getLocation().append(PlatformMetaArea.F_LOCK_FILE).toOSString();
+ lockFile = new File(lockLocation);
+ boolean success = false;
+ //if the lock file already exists, try to delete,
+ //assume failure means another eclipse has it open
+ if (lockFile.exists())
+ lockFile.delete();
+ if (lockFile.exists()) {
+ String message = Policy.bind("meta.inUse", lockLocation);
+ throw new CoreException(new Status(IStatus.ERROR, Platform.PI_RUNTIME, Platform.FAILED_WRITE_METADATA, message, null));
+ }
+ try {
+ //open the lock file so other instances can't co-exist
+ lockRAF = new RandomAccessFile(lockFile, "rw");
+ lockRAF.writeByte(0);
+ success = true;
+ } catch (IOException e) {
+ String message = Policy.bind("meta.failCreateLock", lockLocation);
+ throw new CoreException(new Status(IStatus.ERROR, Platform.PI_RUNTIME, Platform.FAILED_WRITE_METADATA, message, e));
+ }
+}
/**
* Creates and remembers a spoofed up class loader which loads the
@@ -473,6 +521,7 @@ public static IPlatformRunnable loaderGetRunnable(String pluginId, String classN
public static void loaderShutdown() {
assertInitialized();
registry.shutdown(null);
+ clearLockFile();
if (DEBUG_PLUGINS) {
// We are debugging so output the registry in XML
// format.
@@ -523,6 +572,7 @@ public static void loaderShutdown() {
public static void loaderStartup(URL[] pluginPath, String locationString, Properties bootOptions, String[] args) throws CoreException {
processCommandLine(args);
setupMetaArea(locationString);
+ createLockFile();
adapterManager = new AdapterManager();
loadOptions(bootOptions);
createXMLClassLoader();
@@ -787,7 +837,7 @@ private static void setupMetaArea(String locationString) throws CoreException {
if (location.toFile().exists()) {
if (!location.toFile().isDirectory()) {
String message = Policy.bind("meta.notDir", location.toString());
- throw new CoreException(new Status(IStatus.ERROR, Platform.PI_RUNTIME, 13, message, null));
+ throw new CoreException(new Status(IStatus.ERROR, Platform.PI_RUNTIME, Platform.FAILED_WRITE_METADATA, message, null));
}
}
metaArea = new PlatformMetaArea(location);
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java
index 2ba0f023b..7ccb175ce 100644
--- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java
+++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java
@@ -21,7 +21,8 @@ public class PlatformMetaArea {
/* package */ static final String F_LOG = ".log";
/* package */ static final String F_BACKUP = ".bak";
/* package */ static final String F_OPTIONS = ".options";
- /* package */ static final String F_KEYRING = ".keyring";
+ /* package */ static final String F_KEYRING = ".keyring";
+ /* package */ static final String F_LOCK_FILE = ".lock";
/**
*
*/
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties
index 1738bb5d6..77b6d35b4 100644
--- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties
+++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties
@@ -42,23 +42,27 @@ parse.unsatisfiedOptPrereq = Optional prerequisite constraint from {0} to {1} ig
parse.prereqOptLoop = Optional prerequisite from {0} to {1} produced loop. Prerequisite ignored.
### metadata
-meta.unableToWriteRegistry = Unable to write plug-in registry to cache.
meta.appNotInit = The application has not been initialized.
-meta.pluginProblems = Problems occurred when invoking code from plug-in: {0}.
-meta.notDir = Specified platform location {0} is not a directory.
-meta.readPlatformMeta = Could not read platform metadata: {0}.
-meta.writePlatformMeta = Could not write platform metadata: {0}.
meta.couldNotCreate = Error trying to create the platform metadata area: {0}.
+meta.failCreateLock = Unable to create platform lock file: {0}.
+meta.inUse = \nThe platform metadata area is already in use by another platform instance, or there was a failure\n\
+ in deleting the old lock file. If no other platform instances are running, delete the \n\
+ lock file ({0}) and try starting the platform again.
+meta.notDir = Specified platform location {0} is not a directory.
+meta.pluginProblems = Problems occurred when invoking code from plug-in: {0}.
meta.readonly = The platform metadata area could not be written: {0}.
+meta.readPlatformMeta = Could not read platform metadata: {0}.
+meta.registryCacheWriteProblems = Trouble writing to the registry cache file.
+meta.registryCacheReadProblems = Trouble reading from the registry cache file.
+meta.regCacheIOException = IOException encountered while writing {0}.
+meta.unableToWriteRegistry = Unable to write plug-in registry to cache.
meta.unableToCreateCache = Unable to create output stream for registry cache.
meta.unableToReadCache = Unable to create input stream for registry cache.
meta.unableToCreateRegDebug = Unable to create output stream for registry debug information.
meta.unableToWriteDebugRegistry = Unable to write plug-in registry to debug file.
meta.unableToReadAuthorization = Unable to read authorization database: {0}.
meta.unableToWriteAuthorization = Unable to write to authorization database: {0}.
-meta.registryCacheWriteProblems = Trouble writing to the registry cache file.
-meta.registryCacheReadProblems = Trouble reading from the registry cache file.
-meta.regCacheIOException = IOException encountered while writing {0}.
+meta.writePlatformMeta = Could not write platform metadata: {0}.
### URL
url.badVariant=Unsupported "platform:" protocol variation {0}.

Back to the top