Further juicy goodness.

This commit is contained in:
Michael Bayne
2004-07-06 09:46:35 +00:00
parent 3795d51e15
commit e884648bf8
3 changed files with 54 additions and 21 deletions
@@ -1,5 +1,5 @@
// //
// $Id: Application.java,v 1.4 2004/07/06 05:13:35 mdb Exp $ // $Id: Application.java,v 1.5 2004/07/06 09:46:35 mdb Exp $
package com.threerings.getdown.data; package com.threerings.getdown.data;
@@ -256,7 +256,7 @@ public class Application
args[idx++] = processArg((String)iter.next()); args[idx++] = processArg((String)iter.next());
} }
Log.info("Running " + StringUtil.join(args, "\n")); Log.info("Running " + StringUtil.join(args, "\n "));
return Runtime.getRuntime().exec(args, null); return Runtime.getRuntime().exec(args, null);
} }
@@ -306,11 +306,25 @@ public class Application
"Attempting recovery..."); "Attempting recovery...");
} }
// if we failed to load the digest, try to redownload the digest // if we have no version, then we are running in unversioned mode
// file and give it another good college try; this time we allow // so we need to download our digest.txt file on every invocation
// exceptions to propagate up to the caller as there is nothing if (_version == -1) {
// else we can do to recover // make a note of the old meta-digest, if this changes we need
if (_digest == null) { // to revalidate all of our resources as one or more of them
// have also changed
String olddig = (_digest == null) ? "" : _digest.getMetaDigest();
downloadControlFile(Digest.DIGEST_FILE);
_digest = new Digest(_appdir);
if (!olddig.equals(_digest.getMetaDigest())) {
Log.info("Unversioned digest changed. Revalidating...");
clearValidationMarkers();
}
} else if (_digest == null) {
// if we failed to load the digest, try to redownload the
// digest file and give it another good college try; this time
// we allow exceptions to propagate up to the caller as there
// is nothing else we can do to recover
downloadControlFile(Digest.DIGEST_FILE); downloadControlFile(Digest.DIGEST_FILE);
_digest = new Digest(_appdir); _digest = new Digest(_appdir);
} }
@@ -391,6 +405,22 @@ public class Application
} }
} }
/** Clears all validation marker files. */
protected void clearValidationMarkers ()
{
clearValidationMarkers(_codes.iterator());
clearValidationMarkers(_resources.iterator());
}
/** Clears all validation marker files for the resources in the
* supplied iterator. */
protected void clearValidationMarkers (Iterator iter)
{
while (iter.hasNext()) {
((Resource)iter.next()).clearMarker();
}
}
/** /**
* Downloads a new copy of the specified control file and, if the * Downloads a new copy of the specified control file and, if the
* download is successful, moves it over the old file on the * download is successful, moves it over the old file on the
@@ -1,5 +1,5 @@
// //
// $Id: Digest.java,v 1.2 2004/07/02 15:22:49 mdb Exp $ // $Id: Digest.java,v 1.3 2004/07/06 09:46:35 mdb Exp $
package com.threerings.getdown.data; package com.threerings.getdown.data;
@@ -39,13 +39,12 @@ public class Digest
throws IOException throws IOException
{ {
// parse and validate our digest file contents // parse and validate our digest file contents
String metaDigest = "";
StringBuffer data = new StringBuffer(); StringBuffer data = new StringBuffer();
List pairs = ConfigUtil.parsePairs(new File(appdir, DIGEST_FILE)); List pairs = ConfigUtil.parsePairs(new File(appdir, DIGEST_FILE));
for (Iterator iter = pairs.iterator(); iter.hasNext(); ) { for (Iterator iter = pairs.iterator(); iter.hasNext(); ) {
String[] pair = (String[])iter.next(); String[] pair = (String[])iter.next();
if (pair[0].equals(DIGEST_FILE)) { if (pair[0].equals(DIGEST_FILE)) {
metaDigest = pair[1]; _metaDigest = pair[1];
break; break;
} }
_digests.put(pair[0], pair[1]); _digests.put(pair[0], pair[1]);
@@ -56,21 +55,20 @@ public class Digest
MessageDigest md = getMessageDigest(); MessageDigest md = getMessageDigest();
byte[] contents = data.toString().getBytes("UTF-8"); byte[] contents = data.toString().getBytes("UTF-8");
String md5 = StringUtil.hexlate(md.digest(contents)); String md5 = StringUtil.hexlate(md.digest(contents));
if (!md5.equals(metaDigest)) { if (!md5.equals(_metaDigest)) {
String err = MessageUtil.tcompose( String err = MessageUtil.tcompose(
"m.invalid_digest_file", metaDigest, md5); "m.invalid_digest_file", _metaDigest, md5);
throw new IOException(err); throw new IOException(err);
} }
} }
// /** /**
// * Returns the stored digest value for the file with the supplied * Returns the digest for the digest file.
// * path, or null if no digest exists for a file with that path. */
// */ public String getMetaDigest ()
// public String getDigest (String path) {
// { return _metaDigest;
// return (String)_digests.get(path); }
// }
/** /**
* Computes the MD5 hash of the specified resource and compares it * Computes the MD5 hash of the specified resource and compares it
@@ -145,4 +143,5 @@ public class Digest
} }
protected HashMap _digests = new HashMap(); protected HashMap _digests = new HashMap();
protected String _metaDigest = "";
} }
@@ -1,5 +1,5 @@
// //
// $Id: Resource.java,v 1.4 2004/07/06 05:13:36 mdb Exp $ // $Id: Resource.java,v 1.5 2004/07/06 09:46:35 mdb Exp $
package com.threerings.getdown.data; package com.threerings.getdown.data;
@@ -78,6 +78,10 @@ public class Resource
*/ */
public boolean isMarkedValid () public boolean isMarkedValid ()
{ {
if (!_local.exists()) {
clearMarker();
return false;
}
return _marker.exists(); return _marker.exists();
} }