Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikaels2020-07-27 13:20:09 +0000
committerThomas Watson2020-07-27 13:23:08 +0000
commit5d23e0fa4b3831e10ffa789a93e07e41beb34296 (patch)
treeb318eecc10a40f3ed910f57ca481e17049d92ed6
parent792de56315e8b83b2076c35e684a5f932cf9f2e9 (diff)
downloadrt.equinox.framework-5d23e0fa4b3831e10ffa789a93e07e41beb34296.tar.gz
rt.equinox.framework-5d23e0fa4b3831e10ffa789a93e07e41beb34296.tar.xz
rt.equinox.framework-5d23e0fa4b3831e10ffa789a93e07e41beb34296.zip
Bug 563697 - Regression in canWrite() for unknown access to location
Restore explicit test file creation algorithm for canWrite() if Files.isWritable() returns false. Change-Id: I225a1a8a4f109a1962991595ee6d30d73cece8be Signed-off-by: mikaels <mikaels@comsol.se> Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java20
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java24
2 files changed, 41 insertions, 3 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 144571914..249397439 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
@@ -1287,7 +1287,25 @@ public class Main {
}
private static boolean canWrite(File installDir) {
- return installDir.isDirectory() && Files.isWritable(installDir.toPath());
+ if (!installDir.isDirectory())
+ return false;
+
+ if (Files.isWritable(installDir.toPath()))
+ return true;
+
+ 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("writableArea", ".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;
}
/**
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java
index d286110d5..6af3d74d6 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -170,7 +170,27 @@ public class StorageUtil {
}
public static boolean canWrite(File installDir) {
- return installDir.isDirectory() && Files.isWritable(installDir.toPath());
+ if (!installDir.isDirectory())
+ return false;
+
+ if (Files.isWritable(installDir.toPath()))
+ return true;
+
+ 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("writableArea", ".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;
}
public static URL encodeFileURL(File file) throws MalformedURLException {

Back to the top