* Update Handler:

- Add option to download and verify only
      - Add distinct error message if version check fails
This commit is contained in:
zzz
2008-05-10 14:31:18 +00:00
parent 4c2c5ca232
commit 619b5c0e45
8 changed files with 55 additions and 25 deletions

View File

@ -49,9 +49,12 @@ public class ConfigUpdateHandler extends FormHandler {
if ("Check for update now".equals(_action)) {
NewsFetcher fetcher = NewsFetcher.getInstance(I2PAppContext.getGlobalContext());
fetcher.fetchNews();
if (fetcher.updateAvailable())
addFormNotice("Update available, click link on left");
else
if (fetcher.updateAvailable()) {
if ( (_updatePolicy == null) || (!_updatePolicy.equals("notify")) )
addFormNotice("Update available, attempting to download now");
else
addFormNotice("Update available, click link on left to download");
} else
addFormNotice("No update available");
}

View File

@ -102,10 +102,15 @@ public class ConfigUpdateHelper {
else
buf.append("<option value=\"notify\">Notify only</option>");
if ("install".equals(policy))
buf.append("<option value=\"install\" selected=\"true\">Download and install</option>");
if ("download".equals(policy))
buf.append("<option value=\"download\" selected=\"true\">Download and verify only</option>");
else
buf.append("<option value=\"install\">Download and install</option>");
buf.append("<option value=\"download\">Download and verify only</option>");
if ("install".equals(policy))
buf.append("<option value=\"install\" selected=\"true\">Download, verify, and restart</option>");
else
buf.append("<option value=\"install\">Download, verify, and restart</option>");
buf.append("</select>\n");
return buf.toString();

View File

@ -9,6 +9,7 @@ import java.util.StringTokenizer;
import net.i2p.I2PAppContext;
import net.i2p.crypto.TrustedUpdate;
import net.i2p.data.DataHelper;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.router.RouterVersion;
import net.i2p.util.EepGet;
@ -68,7 +69,10 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
private boolean shouldInstall() {
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY);
return ("install".equals(policy));
if ("notify".equals(policy))
return false;
File zip = new File(Router.UPDATE_FILE);
return !zip.exists();
}
private boolean shouldFetchNews() {

View File

@ -159,18 +159,23 @@ public class UpdateHandler {
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
_status = "<b>Update downloaded</b>";
TrustedUpdate up = new TrustedUpdate(_context);
boolean ok = up.migrateVerified(RouterVersion.VERSION, SIGNED_UPDATE_FILE, "i2pupdate.zip");
String err = up.migrateVerified(RouterVersion.VERSION, SIGNED_UPDATE_FILE, Router.UPDATE_FILE);
File f = new File(SIGNED_UPDATE_FILE);
f.delete();
if (ok) {
_log.log(Log.CRIT, "Update was VERIFIED, restarting to install it");
_status = "<b>Update verified</b><br />Restarting";
restart();
if (err == null) {
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY);
if ("install".equals(policy)) {
_log.log(Log.CRIT, "Update was VERIFIED, restarting to install it");
_status = "<b>Update verified</b><br />Restarting";
restart();
} else {
_log.log(Log.CRIT, "Update was VERIFIED, will be installed at next restart");
_status = "<b>Update downloaded</b><br />Click Restart to Install";
}
} else {
// One other possibility, the version in the file is not sufficient
// Perhaps need an int return code - but version problem unlikely?
_log.log(Log.CRIT, "Update was INVALID - signing key is not trusted or file is corrupt from " + url);
_status = "<b>Update signing key invalid or file is corrupt from " + url + "</b>";
err = err + " from " + url;
_log.log(Log.CRIT, err);
_status = "<b>" + err + "</b>";
System.setProperty(PROP_UPDATE_IN_PROGRESS, "false");
}
}