Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2010-05-18 20:01:47 +0000
committerPascal Rapicault2010-05-18 20:01:47 +0000
commit7525f5c2cbc21c977f012acd336265379a16974d (patch)
tree13ea1ae024b68b321a15feb00178d0243a2d744b
parent70a21bb153e8e5a85004b69cd382067f529e4cc2 (diff)
downloadrt.equinox.p2-7525f5c2cbc21c977f012acd336265379a16974d.tar.gz
rt.equinox.p2-7525f5c2cbc21c977f012acd336265379a16974d.tar.xz
rt.equinox.p2-7525f5c2cbc21c977f012acd336265379a16974d.zip
Bug 312284 - [repository] getting index file is guarded by a throwable
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java36
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/LocationProperties.java4
2 files changed, 29 insertions, 11 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
index db511d26a..9736154cf 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
@@ -638,17 +638,9 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
//add the repository first so that it will be enabled, but don't send add event until after the load
added = addRepository(location, true, false);
- // get the search order from the server, if it's available
- ByteArrayOutputStream index = new ByteArrayOutputStream();
- LocationProperties locationProperties = null;
- try {
- getTransport().download(getIndexFile(location), index, monitor);
- } catch (Throwable e) {
- // If any exceptions are thrown, just ignore the index file
- }
+ LocationProperties indexFile = loadIndexFile(location, monitor);
- locationProperties = LocationProperties.create(new ByteArrayInputStream(index.toByteArray()));
- String[] preferredOrder = getPreferredRepositorySearchOrder(locationProperties);
+ String[] preferredOrder = getPreferredRepositorySearchOrder(indexFile);
String[] suffixes = sortSuffixes(getAllSuffixes(), location, preferredOrder);
SubMonitor sub = SubMonitor.convert(monitor, NLS.bind(Messages.repoMan_adding, location), suffixes.length * 100);
@@ -694,6 +686,28 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
}
/**
+ * Fetches the p2.index file from the server. If the file could not be fetched
+ * a NullSafe version is returned.
+ */
+ private LocationProperties loadIndexFile(URI location, IProgressMonitor monitor) {
+ // get the search order from the server, if it's available
+ ByteArrayOutputStream index = new ByteArrayOutputStream();
+ LocationProperties locationProperties = LocationProperties.createEmptyIndexFile();
+ IStatus indexFileStatus = null;
+ try {
+ indexFileStatus = getTransport().download(getIndexFileURI(location), index, monitor);
+ } catch (URISyntaxException uriSyntaxException) {
+ LogHelper.log(new Status(IStatus.ERROR, Activator.ID, uriSyntaxException.getMessage(), uriSyntaxException));
+ indexFileStatus = null;
+ }
+
+ if (indexFileStatus != null && indexFileStatus.isOK())
+ locationProperties = LocationProperties.create(new ByteArrayInputStream(index.toByteArray()));
+
+ return locationProperties;
+ }
+
+ /**
* Basic sanity checking on location argument
*/
private URI checkValidLocation(URI location) {
@@ -1121,7 +1135,7 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
}
}
- private static URI getIndexFile(URI base) throws URISyntaxException {
+ private static URI getIndexFileURI(URI base) throws URISyntaxException {
final String name = INDEX_FILE;
String spec = base.toString();
if (spec.endsWith(name))
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/LocationProperties.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/LocationProperties.java
index 716f6d6a2..1b39fd416 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/LocationProperties.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/LocationProperties.java
@@ -51,6 +51,10 @@ public class LocationProperties {
private String[] artifactSearchOrder = new String[0]; // Version 1
private Map<String, Boolean> md5Hashes = null; // Version 1
+ public static LocationProperties createEmptyIndexFile() {
+ return new LocationProperties();
+ }
+
/**
* Creates a LocationProperties Object from an input stream. If the LocationProperties
* could be created, it is returned. If it could not be created, an empty LocationProperties

Back to the top