Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMengxin Zhu2011-12-19 03:28:35 +0000
committerMengxin Zhu2011-12-19 03:28:35 +0000
commit4174108261eddcb3cd45006d5f1f7631e4a2a2d9 (patch)
tree754cd68cb333e74611344f6a7e86ada63da5d9ce
parent8f29ae39f0a2e4692730b8a79f998f605d565e2f (diff)
downloadrt.equinox.p2-4174108261eddcb3cd45006d5f1f7631e4a2a2d9.tar.gz
rt.equinox.p2-4174108261eddcb3cd45006d5f1f7631e4a2a2d9.tar.xz
rt.equinox.p2-4174108261eddcb3cd45006d5f1f7631e4a2a2d9.zip
Bug 366781 - isReadOnly(File) doesn't work on Windows.v20111219-0328
It wants to determine whether new files can be created under the given file that actually denotes a folder. There's no more elegant way besides creating a temporary file for testing. Signed-off-by: Mengxin Zhu <kane.zhu@windriver.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
index 3f9a1c511..f86e1f5cf 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
@@ -88,12 +88,18 @@ public class Activator implements BundleActivator {
private boolean isReadOnly(File file) {
if (file == null)
return true; // If we've reached the root, then return true
- else if (file.canWrite())
- return false; // If we can write to this area, then it's not read-only
- else if (file.exists())
- return true; // if we can't write && file exists, then this is a read only area
- else
- return isReadOnly(file.getParentFile());
+ if (file.exists()) {
+ try {
+ // on Vista/Windows 7 you are not allowed to write executable files on virtual directories like "Program Files"
+ File tmpTestFile = File.createTempFile(".artifactlocktest", ".dll", file); //$NON-NLS-1$ //$NON-NLS-2$
+ tmpTestFile.delete();
+ return false;
+ } catch (IOException e) {
+ return true; // permission issue to create new file, so it's readonly
+ }
+ }
+
+ return isReadOnly(file.getParentFile());
}
private File getLockFile(URI repositoryLocation) throws IOException {

Back to the top