Compare the digests of files and leave unchanged files entirely out of the

patch instead of creating empty JarDiff patches for them.
This commit is contained in:
Michael Bayne
2004-07-28 01:30:53 +00:00
parent dda8d015c4
commit 2dee599b11
@@ -1,5 +1,5 @@
//
// $Id: Differ.java,v 1.3 2004/07/13 17:45:40 mdb Exp $
// $Id: Differ.java,v 1.4 2004/07/28 01:30:53 mdb Exp $
package com.threerings.getdown.tools;
@@ -15,12 +15,15 @@ import java.util.ArrayList;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.security.MessageDigest;
import com.sun.javaws.jardiff.JarDiff;
import org.apache.commons.io.CopyUtils;
import com.samskivert.io.StreamUtil;
import com.threerings.getdown.data.Application;
import com.threerings.getdown.data.Digest;
import com.threerings.getdown.data.Resource;
/**
@@ -78,6 +81,7 @@ public class Differ
nrsrcs.addAll(napp.getCodeResources());
nrsrcs.addAll(napp.getResources());
MessageDigest md = Digest.getMessageDigest();
File patch = new File(nvdir, "patch" + overs + ".dat");
JarOutputStream jout = null;
try {
@@ -91,21 +95,36 @@ public class Differ
int oidx = orsrcs.indexOf(rsrc);
Resource orsrc = (oidx == -1) ?
null : (Resource)orsrcs.remove(oidx);
if (orsrc != null && rsrc.getPath().endsWith(".jar")) {
if (orsrc != null) {
// first see if they are the same
String odig = orsrc.computeDigest(md, null);
String ndig = rsrc.computeDigest(md, null);
if (odig.equals(ndig)) {
if (verbose) {
System.out.println(
"JarDiff: " + rsrc.getPath());
System.out.println("Unchanged: " + rsrc.getPath());
}
// by leaving it out, it will be left as is during
// the patching process
continue;
}
// otherwise potentially create a jar diff
if (rsrc.getPath().endsWith(".jar")) {
if (verbose) {
System.out.println("JarDiff: " + rsrc.getPath());
}
jout.putNextEntry(new ZipEntry(rsrc.getPath() + PATCH));
jarDiff(orsrc.getLocal(), rsrc.getLocal(), jout);
} else {
continue;
}
}
if (verbose) {
System.out.println("Addition: " + rsrc.getPath());
}
jout.putNextEntry(new ZipEntry(rsrc.getPath() + CREATE));
pipe(rsrc.getLocal(), jout);
}
}
// now any file remaining in orsrcs needs to be removed
for (int ii = 0; ii < orsrcs.size(); ii++) {