Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2016-12-18 04:42:49 -0500
committerPascal Rapicault2017-03-29 10:14:30 -0400
commitf6f9c5732002a7bbe4a692eb55449e5c00002cbe (patch)
treeca0a4a0cfe66b04739a43cb0cd275da3adf99695
parent7c9545086de9dda759cf3bc776ef4046513540b8 (diff)
downloadrt.equinox.p2-f6f9c5732002a7bbe4a692eb55449e5c00002cbe.tar.gz
rt.equinox.p2-f6f9c5732002a7bbe4a692eb55449e5c00002cbe.tar.xz
rt.equinox.p2-f6f9c5732002a7bbe4a692eb55449e5c00002cbe.zip
Bug 509401 - Don't hide I/O problems in ChecksumProducer's computeMD5(File)
If caller doesn't care about I/O problems during checksum calculation, neither should computeMD5 method. The only two callers, RecreateRepositoryApplication and PublisherHelper, now catch such exceptions (to preserve original behavior) and log them to make troubleshooting easier. Change-Id: I1e82ac45cc958f4ffc3ed969a50cfa68aec3c8fc Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java23
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java11
3 files changed, 35 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java
index 96d9ff973..c02dc4925 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2016 IBM Corporation and others.
+ * Copyright (c) 2007, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,9 +15,14 @@
package org.eclipse.equinox.spi.p2.publisher;
import java.io.File;
+import java.io.IOException;
import java.util.*;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
import org.eclipse.equinox.internal.p2.metadata.BasicVersion;
+import org.eclipse.equinox.internal.p2.publisher.Activator;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumProducer;
import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
@@ -106,11 +111,17 @@ public class PublisherHelper {
if (pathOnDisk != null) {
descriptor.setProperty(IArtifactDescriptor.ARTIFACT_SIZE, Long.toString(pathOnDisk.length()));
descriptor.setProperty(IArtifactDescriptor.DOWNLOAD_SIZE, Long.toString(pathOnDisk.length()));
- }
- if (info == null || (info.getArtifactOptions() & IPublisherInfo.A_NO_MD5) == 0) {
- String md5 = ChecksumProducer.computeMD5(pathOnDisk);
- if (md5 != null)
- descriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5);
+ if (info == null || (info.getArtifactOptions() & IPublisherInfo.A_NO_MD5) == 0) {
+ try {
+ String md5 = ChecksumProducer.computeMD5(pathOnDisk);
+ if (md5 != null)
+ descriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5);
+ } catch (IOException e) {
+ // don't care if failed to compute checksum
+ // TODO provide message?
+ LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "", e));
+ }
+ }
}
}
return result;
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java
index 8932e357c..fbd0cb0bf 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,10 +13,12 @@
package org.eclipse.equinox.p2.internal.repository.tools;
import java.io.File;
+import java.io.IOException;
import java.net.URI;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
+import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumProducer;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
@@ -118,9 +120,15 @@ public class RecreateRepositoryApplication extends AbstractApplication {
newDescriptor.setProperty(IArtifactDescriptor.ARTIFACT_SIZE, size);
newDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_SIZE, size);
- String md5 = ChecksumProducer.computeMD5(artifactFile);
- if (md5 != null)
- newDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5);
+ try {
+ String md5 = ChecksumProducer.computeMD5(artifactFile);
+ if (md5 != null)
+ newDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5);
+ } catch (IOException e) {
+ // don't care if failed to compute checksum
+ // TODO provide message?
+ LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "", e));
+ }
File temp = new File(artifactFile.getParentFile(), artifactFile.getName() + ".pack.gz"); //$NON-NLS-1$
if (temp.exists()) {
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java
index 4296a53fa..fc8cabec6 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java
@@ -18,9 +18,12 @@ import java.security.NoSuchAlgorithmException;
public class ChecksumProducer {
- public static String computeMD5(File file) {
- if (file == null || file.isDirectory() || !file.exists())
- return null;
+ /**
+ * @param file should not be <code>null</code>
+ * @return MD5 checksum of the file or <code>null</code> in case of NoSuchAlgorithmException
+ * @throws IOException
+ */
+ public static String computeMD5(File file) throws IOException {
InputStream fis = null;
try {
MessageDigest md5Checker = MessageDigest.getInstance("MD5"); //$NON-NLS-1$
@@ -41,8 +44,6 @@ public class ChecksumProducer {
return buf.toString();
} catch (NoSuchAlgorithmException e) {
return null;
- } catch (IOException e) {
- return null;
} finally {
if (fis != null)
try {

Back to the top