diff options
author | Pascal Rapicault (Ericsson) | 2013-02-11 18:15:56 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-02-11 18:15:56 +0000 |
commit | 870db778ee068a39da1deea111af23f08dde2bc5 (patch) | |
tree | 0d174839b8df97cd753d5b72bfab8d792676bf88 | |
parent | 73c99f4c4246af7389fc140fc243ccf531acad68 (diff) | |
download | rt.equinox.p2-870db778ee068a39da1deea111af23f08dde2bc5.tar.gz rt.equinox.p2-870db778ee068a39da1deea111af23f08dde2bc5.tar.xz rt.equinox.p2-870db778ee068a39da1deea111af23f08dde2bc5.zip |
Bug 399988 - [shared][director] Provides clean error message whenv20130211-181556
install is readonly
3 files changed, 39 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java index df28b5156..11df4dda8 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java @@ -1050,7 +1050,14 @@ public class DirectorApplication implements IApplication, ProvisioningListener { performHelpInfo(); else { initializeServices(); + if (!(printIUList || printRootIUList || printTags)) { + if (!canInstallInDestination()) { + printMessage(NLS.bind(Messages.Cant_write_in_destination, destination.getAbsolutePath())); + return EXIT_ERROR; + } + } initializeRepositories(); + if (revertToPreviousState != NOTHING_TO_REVERT_TO) { revertToPreviousState(); } else if (!(rootsToInstall.isEmpty() && rootsToUninstall.isEmpty())) @@ -1326,4 +1333,33 @@ public class DirectorApplication implements IApplication, ProvisioningListener { System.out.println(tags.get(timestamp)); } } + + private boolean canInstallInDestination() { + //When we are provisioning what we are running. We can always install. + if (targetAgentIsSelfAndUp) + return true; + return canWrite(destination); + } + + private static boolean canWrite(File installDir) { + if (installDir.canWrite() == false) + return false; + + if (!installDir.isDirectory()) + return false; + + File fileTest = null; + try { + // we use the .dll suffix to properly test on Vista virtual directories + // on Vista you are not allowed to write executable files on virtual directories like "Program Files" + fileTest = File.createTempFile("writtableArea", ".dll", installDir); //$NON-NLS-1$ //$NON-NLS-2$ + } catch (IOException e) { + //If an exception occured while trying to create the file, it means that it is not writtable + return false; + } finally { + if (fileTest != null) + fileTest.delete(); + } + return true; + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java index 5427148d4..57a4058d4 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java @@ -86,6 +86,8 @@ public class Messages extends NLS { public static String unableToWriteLogFile; public static String Unmatched_iu_profile_property_key_value; + public static String Cant_write_in_destination; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties index fbe7512c3..6a3289d38 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties @@ -73,3 +73,4 @@ File_does_not_exist=File does not exist: {0}. Cannot_set_iu_profile_property_iu_does_not_exist=Unable to set IU profile properties because the following IU does not exist: {0}. Unmatched_iu_profile_property_key_value=Unmatched IU profile property key/value pair: {0}. Bad_format=Bad format ({0}) in IU profile properties file: {1}. +Cant_write_in_destination=The operation you've requested can not be performed because the folder {0} is read only.
\ No newline at end of file |