Skip to content

Commit eff788e

Browse files
committed
---
yaml --- r: 6033 b: refs/heads/tswast-patch-1 c: eefd171 h: refs/heads/master i: 6031: 9ec4f28
1 parent d180300 commit eff788e

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 716c2eb7df6bdcde8e50139b45a9875168cf6680
60+
refs/heads/tswast-patch-1: eefd171cb3573b493f259a84ee23b1351af21229
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.common.base.Strings;
2222

23+
import java.io.BufferedInputStream;
2324
import java.io.BufferedOutputStream;
2425
import java.io.BufferedReader;
2526
import java.io.File;
@@ -31,6 +32,7 @@
3132
import java.io.InputStream;
3233
import java.io.InputStreamReader;
3334
import java.io.OutputStream;
35+
import java.math.BigInteger;
3436
import java.net.HttpURLConnection;
3537
import java.net.MalformedURLException;
3638
import java.net.URL;
@@ -42,6 +44,8 @@
4244
import java.nio.file.Paths;
4345
import java.nio.file.SimpleFileVisitor;
4446
import java.nio.file.attribute.BasicFileAttributes;
47+
import java.security.MessageDigest;
48+
import java.security.NoSuchAlgorithmException;
4549
import java.util.Locale;
4650
import java.util.zip.ZipEntry;
4751
import java.util.zip.ZipInputStream;
@@ -59,6 +63,7 @@ public class LocalGcdHelper {
5963
public static final int PORT = 8080;
6064
private static final String GCD = "gcd-v1beta2-rev1-2.1.2b";
6165
private static final String GCD_FILENAME = GCD + ".zip";
66+
private static final String MD5_CHECKSUM = "d84384cdfa8658e1204f4f8be51300e8";
6267
private static final URL GCD_URL;
6368

6469
static {
@@ -69,7 +74,6 @@ public class LocalGcdHelper {
6974
}
7075
}
7176

72-
7377
private static class ProcessStreamReader extends Thread {
7478

7579
private final Process process;
@@ -134,7 +138,7 @@ public void start() throws IOException, InterruptedException {
134138

135139
// check if we already have a local copy of the gcd utility and download it if not.
136140
File gcdZipFile = new File(System.getProperty("java.io.tmpdir"), GCD_FILENAME);
137-
if (!gcdZipFile.exists()) {
141+
if (!gcdZipFile.exists() || !MD5_CHECKSUM.equals(md5(gcdZipFile))) {
138142
ReadableByteChannel rbc = Channels.newChannel(GCD_URL.openStream());
139143
FileOutputStream fos = new FileOutputStream(gcdZipFile);
140144
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
@@ -188,6 +192,22 @@ public void start() throws IOException, InterruptedException {
188192
processReader = ProcessStreamReader.start(temp, "Dev App Server is now running");
189193
}
190194

195+
private static String md5(File gcdZipFile) throws IOException {
196+
try {
197+
MessageDigest md5 = MessageDigest.getInstance("MD5");
198+
try (InputStream is = new BufferedInputStream(new FileInputStream(gcdZipFile))) {
199+
byte[] bytes = new byte[4 * 1024 * 1024];
200+
int len;
201+
while ((len = is.read(bytes)) >= 0) {
202+
md5.update(bytes, 0, len);
203+
}
204+
}
205+
return String.format("%032x",new BigInteger(1, md5.digest()));
206+
} catch (NoSuchAlgorithmException e) {
207+
throw new IOException(e);
208+
}
209+
}
210+
191211
private static boolean isWindows() {
192212
return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).indexOf("windows") > -1;
193213
}

0 commit comments

Comments
 (0)