diff options
-rw-r--r-- | bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java index df507e5fb..4e083955a 100644 --- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java +++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Anton Leherbauer (Wind River Systems) - bug 301226 *******************************************************************************/ package org.eclipse.equinox.launcher; @@ -202,6 +203,9 @@ public class Main { private static final String PROP_COMMANDS = "eclipse.commands"; //$NON-NLS-1$ private static final String PROP_ECLIPSESECURITY = "eclipse.security"; //$NON-NLS-1$ + // Suffix for location properties - see LocationManager. + private static final String READ_ONLY_AREA_SUFFIX = ".readOnly"; //$NON-NLS-1$ + // Data mode constants for user, configuration and data locations. private static final String NONE = "@none"; //$NON-NLS-1$ private static final String NO_DEFAULT = "@noDefault"; //$NON-NLS-1$ @@ -557,6 +561,10 @@ public class Main { if (!checkVersion(System.getProperty("java.version"), System.getProperty(PROP_REQUIRED_JAVA_VERSION))) //$NON-NLS-1$ return; + // verify configuration location is writable + if (!checkConfigurationLocation(configurationLocation)) + return; + setSecurityPolicy(bootPath); // splash handling is done here, because the default case needs to know // the location of the boot plugin we are going to use @@ -652,6 +660,41 @@ public class Main { } /** + * Checks whether the given location can be created and is writable. + * If the system property "osgi.configuration.area.readOnly" is set + * the check always succeeds. + * <p>Will set PROP_EXITCODE/PROP_EXITDATA accordingly if check fails.</p> + * + * @param locationUrl configuration area URL, may be <code>null</code> + * @return a boolean indicating whether the checking passed + */ + private boolean checkConfigurationLocation(URL locationUrl) { + if (locationUrl == null || !"file".equals(locationUrl.getProtocol())) //$NON-NLS-1$ + return true; + if (Boolean.valueOf(System.getProperty(PROP_CONFIG_AREA + READ_ONLY_AREA_SUFFIX)).booleanValue()) { + // user wants readonly config area + return true; + } + File configDir = new File(locationUrl.getFile()).getAbsoluteFile(); + if (!configDir.exists()) { + configDir.mkdirs(); + if (!configDir.exists()) { + System.getProperties().put(PROP_EXITCODE, "15"); //$NON-NLS-1$ + System.getProperties().put(PROP_EXITDATA, "<title>Invalid Configuration Location</title>The configuration area at '" + configDir + //$NON-NLS-1$ + "' could not be created. Please choose a writable location using the '-configuration' command line option."); //$NON-NLS-1$ + return false; + } + } + if (!canWrite(configDir)) { + System.getProperties().put(PROP_EXITCODE, "15"); //$NON-NLS-1$ + System.getProperties().put(PROP_EXITDATA, "<title>Invalid Configuration Location</title>The configuration area at '" + configDir + //$NON-NLS-1$ + "' is not writable. Please choose a writable location using the '-configuration' command line option."); //$NON-NLS-1$ + return false; + } + return true; + } + + /** * Returns a string representation of the given URL String. This converts * escaped sequences (%..) in the URL into the appropriate characters. * NOTE: due to class visibility there is a copy of this method |