diff options
author | John Arthorne | 2008-11-21 22:23:56 +0000 |
---|---|---|
committer | John Arthorne | 2008-11-21 22:23:56 +0000 |
commit | 2da0e0c3273d024526e9c0742efe3313ec3d23ba (patch) | |
tree | 3d18d21c194f5c9fa02c22698afa402cb172a5c3 /bundles/org.eclipse.equinox.p2.metadata.repository | |
parent | f8bb9a4e5a661dc362692af7a69f7f2ca9d5593b (diff) | |
download | rt.equinox.p2-2da0e0c3273d024526e9c0742efe3313ec3d23ba.tar.gz rt.equinox.p2-2da0e0c3273d024526e9c0742efe3313ec3d23ba.tar.xz rt.equinox.p2-2da0e0c3273d024526e9c0742efe3313ec3d23ba.zip |
Bug 255858 [composite repo] Error reading update site
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.metadata.repository')
4 files changed, 33 insertions, 25 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java index e2a966b56..09b2adb3c 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CacheManager.java @@ -13,7 +13,7 @@ package org.eclipse.equinox.internal.p2.metadata.repository; import java.io.*; import java.net.URI; import java.net.URL; -import java.util.EventObject; +import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.*; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -35,10 +35,11 @@ import org.osgi.framework.ServiceReference; */ public class CacheManager { private static SynchronousProvisioningListener busListener; - private static final String CONTENT_FILENAME = "content"; //$NON-NLS-1$ private static final String JAR_EXTENSION = ".jar"; //$NON-NLS-1$ private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ + private final HashSet knownPrefixes = new HashSet(5); + /** * Returns a hash of the URL. */ @@ -50,15 +51,17 @@ public class CacheManager { * Returns a local cache file with the contents of the given remote location, * or <code>null</code> if a local cache could not be created. * - * @param repositoryLocation - * @param monitor - a progress monitor + * @param repositoryLocation The remote location to be cached + * @param prefix The prefix to use when creating the cache file + * @param monitor a progress monitor * @return A {@link File} object pointing to the cache file or <code>null</code> * if the location is not a repository. * @throws IOException * @throws ProvisionException */ - public File createCache(URI repositoryLocation, IProgressMonitor monitor) throws IOException, ProvisionException { - File cacheFile = getCache(repositoryLocation); + public File createCache(URI repositoryLocation, String prefix, IProgressMonitor monitor) throws IOException, ProvisionException { + knownPrefixes.add(prefix); + File cacheFile = getCache(repositoryLocation, prefix); URI jarLocation = URLMetadataRepository.getActualLocation(repositoryLocation, JAR_EXTENSION); URI xmlLocation = URLMetadataRepository.getActualLocation(repositoryLocation, XML_EXTENSION); AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); @@ -69,14 +72,14 @@ public class CacheManager { long lastModifiedRemote = getTransport().getLastModified(jarLocation); URI remoteFile; if (lastModifiedRemote != 0) { - cacheFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + JAR_EXTENSION); + cacheFile = new File(dataAreaFile, prefix + hashCode + JAR_EXTENSION); remoteFile = jarLocation; } else { lastModifiedRemote = getTransport().getLastModified(xmlLocation); if (lastModifiedRemote == 0) // no jar or xml file found return null; - cacheFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + XML_EXTENSION); + cacheFile = new File(dataAreaFile, prefix + hashCode + XML_EXTENSION); remoteFile = xmlLocation; } cacheFile.getParentFile().mkdirs(); @@ -98,25 +101,29 @@ public class CacheManager { * @param repositoryLocation */ void deleteCache(URI repositoryLocation) { - File cacheFile = getCache(repositoryLocation); - if (cacheFile != null) - safeDelete(cacheFile); + for (Iterator it = knownPrefixes.iterator(); it.hasNext();) { + String prefix = (String) it.next(); + File cacheFile = getCache(repositoryLocation, prefix); + if (cacheFile != null) + safeDelete(cacheFile); + } } /** - * Determines the local filepath of the repository's cache file. - * @param repositoryLocation + * Determines the local file path of the repository's cache file. + * @param repositoryLocation The location to compute the cache for + * @param prefix The prefix to use for this location * @return A {@link File} pointing to the cache file or <code>null</code> if * the cache file does not exist. */ - private File getCache(URI repositoryLocation) { + private File getCache(URI repositoryLocation, String prefix) { AgentLocation agentLocation = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); URL dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ File dataAreaFile = URLUtil.toFile(dataArea); int hashCode = computeHash(repositoryLocation); - File cacheFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + JAR_EXTENSION); + File cacheFile = new File(dataAreaFile, prefix + hashCode + JAR_EXTENSION); if (!cacheFile.exists()) { - cacheFile = new File(dataAreaFile, CONTENT_FILENAME + hashCode + XML_EXTENSION); + cacheFile = new File(dataAreaFile, prefix + hashCode + XML_EXTENSION); if (!cacheFile.exists()) return null; } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java index 08842222c..161d381fc 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java @@ -16,7 +16,8 @@ import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.core.helpers.*; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO.CompositeRepositoryState; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; @@ -35,7 +36,6 @@ public class CompositeMetadataRepository extends AbstractMetadataRepository impl static final private Integer REPOSITORY_VERSION = new Integer(1); static final public String XML_EXTENSION = ".xml"; //$NON-NLS-1$ static final private String JAR_EXTENSION = ".jar"; //$NON-NLS-1$ - static final public String CONTENT_FILENAME = "compositeContent"; //$NON-NLS-1$ private ArrayList childrenURIs = new ArrayList(); @@ -129,15 +129,15 @@ public class CompositeMetadataRepository extends AbstractMetadataRepository impl private static File getActualLocation(URI location, String extension) { File spec = URIUtil.toFile(location); String path = spec.getAbsolutePath(); - if (path.endsWith(CONTENT_FILENAME + extension)) { + if (path.endsWith(CompositeMetadataRepositoryFactory.CONTENT_FILENAME + extension)) { //todo this is the old code that doesn't look right // return new File(spec + extension); return spec; } if (path.endsWith("/")) //$NON-NLS-1$ - path += CONTENT_FILENAME; + path += CompositeMetadataRepositoryFactory.CONTENT_FILENAME; else - path += "/" + CONTENT_FILENAME; //$NON-NLS-1$ + path += "/" + CompositeMetadataRepositoryFactory.CONTENT_FILENAME; //$NON-NLS-1$ return new File(path + extension); } @@ -195,7 +195,7 @@ public class CompositeMetadataRepository extends AbstractMetadataRepository impl public static URI getActualLocationURI(URI base, String extension) { if (extension == null) extension = XML_EXTENSION; - return URIUtil.append(base, CONTENT_FILENAME + extension); + return URIUtil.append(base, CompositeMetadataRepositoryFactory.CONTENT_FILENAME + extension); } //TODO this should never be called. What do we do? diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory.java index 56c65f951..682089d6d 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory.java @@ -29,6 +29,7 @@ public class CompositeMetadataRepositoryFactory extends MetadataRepositoryFactor private static final String JAR_EXTENSION = ".jar"; //$NON-NLS-1$ private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ + public static final String CONTENT_FILENAME = "compositeContent"; //$NON-NLS-1$ public IMetadataRepository create(URI location, String name, String type, Map properties) { return new CompositeMetadataRepository(location, name, properties); @@ -56,7 +57,7 @@ public class CompositeMetadataRepositoryFactory extends MetadataRepositoryFactor throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, null)); } //file is not local, create a cache of the repository metadata - localFile = Activator.getCacheManager().createCache(location, monitor); + localFile = Activator.getCacheManager().createCache(location, CONTENT_FILENAME, monitor); if (localFile == null) { //there is no remote file in either form String msg = NLS.bind(Messages.io_failedRead, location); @@ -102,7 +103,7 @@ public class CompositeMetadataRepositoryFactory extends MetadataRepositoryFactor if (localFile.getAbsolutePath().endsWith(JAR_EXTENSION)) { jarStream = new JarInputStream(inStream); JarEntry jarEntry = jarStream.getNextJarEntry(); - String entryName = CompositeMetadataRepository.CONTENT_FILENAME + CompositeMetadataRepository.XML_EXTENSION; + String entryName = CONTENT_FILENAME + CompositeMetadataRepository.XML_EXTENSION; while (jarEntry != null && (!entryName.equals(jarEntry.getName()))) { jarEntry = jarStream.getNextJarEntry(); } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java index db3bb8277..9457ee32b 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/metadata/repository/SimpleMetadataRepositoryFactory.java @@ -56,7 +56,7 @@ public class SimpleMetadataRepositoryFactory extends MetadataRepositoryFactory { throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, null)); } //file is not local, create a cache of the repository metadata - localFile = Activator.getCacheManager().createCache(location, monitor); + localFile = Activator.getCacheManager().createCache(location, URLMetadataRepository.CONTENT_FILENAME, monitor); if (localFile == null) { //there is no remote file in either form String msg = NLS.bind(Messages.io_failedRead, location); |