diff options
author | Pascal Rapicault | 2015-04-28 14:58:09 +0000 |
---|---|---|
committer | Pascal Rapicault | 2015-04-28 16:13:48 +0000 |
commit | 9b1fa1cad604207e24f41d6affcb28aa7c011ffb (patch) | |
tree | b0b19aadc828e96bf5705174886a894891caa50a /bundles/org.eclipse.equinox.p2.repository/src | |
parent | 60c11f0bbcbb5ed7ec2a7dc58625330b49b714da (diff) | |
download | rt.equinox.p2-9b1fa1cad604207e24f41d6affcb28aa7c011ffb.tar.gz rt.equinox.p2-9b1fa1cad604207e24f41d6affcb28aa7c011ffb.tar.xz rt.equinox.p2-9b1fa1cad604207e24f41d6affcb28aa7c011ffb.zip |
Bug 464614 - Use XZ as compression formats of metadata filesI20150429-0800I20150428-2000
Change-Id: I4107f2f4fff7ae827f5587dfb8e6b42ba2cf638a
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository/src')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java index 95afb681f..97c239d24 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java @@ -86,6 +86,57 @@ public class CacheManager { return repositoryLocation.hashCode(); } + public File createCacheFromFile(URI remoteFile, IProgressMonitor monitor) throws ProvisionException, IOException { + if (!isURL(remoteFile)) { + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, NLS.bind(Messages.CacheManager_CannotLoadNonUrlLocation, remoteFile), null)); + } + + SubMonitor submonitor = SubMonitor.convert(monitor, 1000); + try { + File cacheFile = getCacheFile(remoteFile); + + boolean stale = true; + long lastModified = cacheFile.lastModified(); + long lastModifiedRemote = 0L; + + // bug 269588 - server may return 0 when file exists, so extra flag is needed + try { + lastModifiedRemote = transport.getLastModified(remoteFile, submonitor.newChild(1)); + if (lastModifiedRemote <= 0) + LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "Server returned lastModified <= 0 for " + remoteFile)); //$NON-NLS-1$ + } catch (AuthenticationFailedException e) { + // it is not meaningful to continue - the credentials are for the server + // do not pass the exception - it gives no additional meaningful user information + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_AUTHENTICATION, NLS.bind(Messages.CacheManager_AuthenticationFaileFor_0, remoteFile), null)); + } catch (CoreException e) { + // give up on a timeout - if we did not get a 404 on the jar, we will just prolong the pain + // by (almost certainly) also timing out on the xml. + if (e.getStatus() != null && e.getStatus().getException() != null) { + Throwable ex = e.getStatus().getException(); + if (ex.getClass() == java.net.SocketTimeoutException.class) + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, NLS.bind(Messages.CacheManager_FailedCommunicationWithRepo_0, remoteFile), ex)); + } + } catch (OperationCanceledException e) { + // must pass this on + throw e; + } catch (Exception e) { + // not ideal, just skip the jar on error, and try the xml instead - report errors for + // the xml. + } + + stale = lastModifiedRemote != lastModified; + if (!stale) + return cacheFile; + + // The cache is stale or missing, so we need to update it from the remote location + updateCache(cacheFile, remoteFile, lastModifiedRemote, submonitor); + return cacheFile; + } finally { + submonitor.done(); + } + + } + /** * 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. @@ -264,6 +315,12 @@ public class CacheManager { return files; } + private File getCacheFile(URI url) { + File dataAreaFile = getCacheDirectory(); + int hashCode = computeHash(url); + return new File(dataAreaFile, Integer.toString(hashCode)); + } + private static boolean isURL(URI location) { try { new URL(location.toASCIIString()); |