diff --git a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java index c264e61d33..846ee90b92 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java @@ -133,8 +133,10 @@ public class ConsoleUpdateManager implements UpdateManager { } PluginUpdateHandler puh = new PluginUpdateHandler(_context, this); register((Checker)puh, PLUGIN, HTTP, 0); - register((Checker)puh, PLUGIN_INSTALL, HTTP, 0); - register((Updater)puh, PLUGIN_INSTALL, HTTP, 0); + register((Updater)puh, PLUGIN, HTTP, 0); + // Don't do this until we can prevent it from retrying the same thing again... + // handled inside P.U.H. for now + //register((Updater)puh, PLUGIN, FILE, 0); new NewsTimerTask(_context, this); _context.simpleScheduler().addPeriodicEvent(new TaskCleaner(), TASK_CLEANER_TIME); } @@ -414,15 +416,21 @@ public class ConsoleUpdateManager implements UpdateManager { * @return true if task started */ public boolean installPlugin(String name, URI uri) { + // We must have a name and install it in _available or else + // update_fromCheck() will fail. + // It's not removed from _available on success, as we lose the name. if (name == null) name = Long.toString(_context.random().nextLong()); List uris = Collections.singletonList(uri); - UpdateItem item = new UpdateItem(PLUGIN_INSTALL, name); - VersionAvailable va = new VersionAvailable("", "", HTTP, uris); - _available.putIfAbsent(item, va); + UpdateItem item = new UpdateItem(PLUGIN, name); + VersionAvailable va = _available.get(item); + if (va == null) { + va = new VersionAvailable("", "", HTTP, uris); + _available.putIfAbsent(item, va); + } if (_log.shouldLog(Log.WARN)) _log.warn("Install plugin: " + name + ' ' + va); - return update(PLUGIN_INSTALL, name); + return update(PLUGIN, name); } /** @@ -492,7 +500,11 @@ public class ConsoleUpdateManager implements UpdateManager { _log.warn("No version available for: " + type + ' ' + id); return false; } - List sorted = new ArrayList(_registeredUpdaters); + List sorted = new ArrayList(4); + for (RegisteredUpdater ru : _registeredUpdaters) { + if (ru.type == type) + sorted.add(ru); + } Collections.sort(sorted); return retry(ui, va.sourceMap, sorted, maxTime) != null; } @@ -573,7 +585,7 @@ public class ConsoleUpdateManager implements UpdateManager { * * @param newsSource who told us * @param id plugin name for plugins, ignored otherwise - * @param updateSourcew Where to get the new version + * @param updateSources Where to get the new version * @param newVersion The new version available * @param minVersion The minimum installed version to be able to update to newVersion * @return true if it's newer @@ -638,10 +650,8 @@ public class ConsoleUpdateManager implements UpdateManager { // fall through case ROUTER_SIGNED: - case ROUTER_SIGNED_PACK200: if (shouldInstall() && !(isUpdateInProgress(ROUTER_SIGNED) || - isUpdateInProgress(ROUTER_SIGNED_PACK200) || isUpdateInProgress(ROUTER_UNSIGNED))) { update_fromCheck(type, id, DEFAULT_MAX_TIME); } @@ -673,7 +683,6 @@ public class ConsoleUpdateManager implements UpdateManager { switch (task.getType()) { case NEWS: case ROUTER_SIGNED: - case ROUTER_SIGNED_PACK200: case ROUTER_UNSIGNED: // ConfigUpdateHandler, SummaryHelper, SummaryBarRenderer handle status display break; @@ -766,8 +775,9 @@ public class ConsoleUpdateManager implements UpdateManager { * If the return value is false, caller must call notifyTaskFailed() or notifyComplete() * again. * + * @param must be an Updater, not a Checker * @param actualVersion may be higher (or lower?) than the version requested - * @param file a valid format for the task's UpdateType + * @param file a valid format for the task's UpdateType, or null if it did the installation itself * @return true if valid, false if corrupt */ public boolean notifyComplete(UpdateTask task, String actualVersion, File file) { @@ -781,7 +791,6 @@ public class ConsoleUpdateManager implements UpdateManager { break; case ROUTER_SIGNED: - case ROUTER_SIGNED_PACK200: rv = handleSudFile(task.getURI(), actualVersion, file); if (rv) notifyDownloaded(task.getType(), task.getID(), actualVersion); @@ -795,12 +804,10 @@ public class ConsoleUpdateManager implements UpdateManager { } break; - case PLUGIN: -/// FIXME probably handled in PluginUpdateRunner?????????? - rv = handlePluginFile(task.getURI(), actualVersion, file); - break; - - default: + case PLUGIN: // file handled in PluginUpdateRunner + default: // assume Updater installed it + rv = true; + notifyInstalled(task.getType(), task.getID(), actualVersion); break; } if (rv) @@ -881,7 +888,6 @@ public class ConsoleUpdateManager implements UpdateManager { break; case ROUTER_SIGNED: - case ROUTER_SIGNED_PACK200: String URLs = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL, ConfigUpdateHandler.DEFAULT_UPDATE_URL); StringTokenizer tok = new StringTokenizer(URLs, " ,\r\n"); List rv = new ArrayList(); diff --git a/apps/routerconsole/java/src/net/i2p/router/update/NewsHandler.java b/apps/routerconsole/java/src/net/i2p/router/update/NewsHandler.java index d54948a848..0f955aec6f 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/NewsHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/NewsHandler.java @@ -35,7 +35,7 @@ class NewsHandler extends UpdateHandler implements Checker { */ public UpdateTask check(UpdateType type, UpdateMethod method, String id, String currentVersion, long maxTime) { - if ((type != ROUTER_SIGNED && type != ROUTER_SIGNED_PACK200 && type != NEWS) || + if ((type != ROUTER_SIGNED && type != NEWS) || method != HTTP) return null; List updateSources = new ArrayList(2); diff --git a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateHandler.java index 12847fc8e2..64304bd3bc 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateHandler.java @@ -64,7 +64,7 @@ class PluginUpdateHandler implements Checker, Updater { @Override public UpdateTask update(UpdateType type, UpdateMethod method, List updateSources, String appName, String newVersion, long maxTime) { - if ((type != UpdateType.PLUGIN && type != UpdateType.PLUGIN_INSTALL) || + if (type != UpdateType.PLUGIN || method != UpdateMethod.HTTP || updateSources.isEmpty()) return null; Properties props = PluginStarter.pluginProperties(_context, appName); diff --git a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java index 6265496379..559fa58ca5 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java @@ -48,6 +48,7 @@ class PluginUpdateRunner extends UpdateRunner { private final URI _uri; private final String _xpi2pURL; private boolean _updated; + private String _errMsg = ""; private static final String XPI2P = "app.xpi2p"; private static final String ZIP = XPI2P + ".zip"; @@ -68,7 +69,7 @@ class PluginUpdateRunner extends UpdateRunner { @Override public UpdateType getType() { - return _oldVersion.equals("") ? UpdateType.PLUGIN_INSTALL : UpdateType.PLUGIN; + return UpdateType.PLUGIN; } @Override @@ -85,7 +86,7 @@ class PluginUpdateRunner extends UpdateRunner { updateStatus("" + _("Attempting to install from file {0}", _xpi2pURL) + ""); // strip off "file://" String xpi2pfile = _xpi2pURL.substring(7); - if(xpi2pfile.length() == 0) { // This is actually what String.isEmpty() does, so it should be safe. + if(xpi2pfile.length() == 0) { statusDone("" + _("No file specified {0}", _xpi2pURL) + ""); } else { // copy the contents of from to _updateFile @@ -114,8 +115,10 @@ class PluginUpdateRunner extends UpdateRunner { _log.error("Error downloading plugin", t); } } - if (!_updated) - _mgr.notifyTaskFailed(this, "", null); + if (_updated) + _mgr.notifyComplete(this, _newVersion, null); + else + _mgr.notifyTaskFailed(this, _errMsg, null); } @Override @@ -240,6 +243,9 @@ class PluginUpdateRunner extends UpdateRunner { statusDone("" + _("Plugin {0} has mismatched versions", appName) + ""); return; } + // set so notifyComplete() will work + _appName = appName; + _newVersion = version; String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version"); if (minVersion != null && @@ -414,6 +420,8 @@ class PluginUpdateRunner extends UpdateRunner { } private void statusDone(String msg) { + // if we fail, we will pass this back in notifyTaskFailed() + _errMsg = msg; updateStatus(msg); } diff --git a/apps/routerconsole/java/src/net/i2p/router/update/UpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/update/UpdateHandler.java index 3ff73e4d31..1ba0ceb546 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/UpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/UpdateHandler.java @@ -38,7 +38,7 @@ class UpdateHandler implements Updater { */ public UpdateTask update(UpdateType type, UpdateMethod method, List updateSources, String id, String newVersion, long maxTime) { - if ((type != UpdateType.ROUTER_SIGNED && type != UpdateType.ROUTER_SIGNED_PACK200) || + if (type != UpdateType.ROUTER_SIGNED || method != UpdateMethod.HTTP || updateSources.isEmpty()) return null; UpdateRunner update = new UpdateRunner(_context, _mgr, updateSources); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java index 6d70a9dbf0..09d4d0666e 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java @@ -151,13 +151,16 @@ public class PluginStarter implements Runnable { if (log.shouldLog(Log.WARN)) log.warn("Updating plugin: " + appName); + // non-blocking mgr.update(PLUGIN, appName, 30*60*1000); int loop = 0; do { + // only wait for 4 minutes, then we will + // keep going try { Thread.sleep(5*1000); } catch (InterruptedException ie) {} - if (loop++ > 40) break; + if (loop++ > 48) break; } while (mgr.isUpdateInProgress(PLUGIN, appName)); if (mgr.getUpdateAvailable(PLUGIN, appName) != null) diff --git a/build.xml b/build.xml index f4831bceaa..be60da6920 100644 --- a/build.xml +++ b/build.xml @@ -416,7 +416,7 @@ - + diff --git a/core/java/src/net/i2p/update/UpdateManager.java b/core/java/src/net/i2p/update/UpdateManager.java index 5f609f5475..edb39cc3c0 100644 --- a/core/java/src/net/i2p/update/UpdateManager.java +++ b/core/java/src/net/i2p/update/UpdateManager.java @@ -38,7 +38,7 @@ public interface UpdateManager { * @param newsSource who told us * @param id plugin name for plugins, ignored otherwise * @param method How to get the new version - * @param updateSourcew Where to get the new version + * @param updateSources Where to get the new version * @param newVersion The new version available * @param minVersion The minimum installed version to be able to update to newVersion * @return true if we didn't know already diff --git a/core/java/src/net/i2p/update/UpdateMethod.java b/core/java/src/net/i2p/update/UpdateMethod.java index a5aee879ff..cb2154387a 100644 --- a/core/java/src/net/i2p/update/UpdateMethod.java +++ b/core/java/src/net/i2p/update/UpdateMethod.java @@ -6,11 +6,14 @@ package net.i2p.update; * @since 0.9.4 */ public enum UpdateMethod { - METHOD_DUMMY, + METHOD_DUMMY, // Internal use only HTTP, // .i2p or via outproxy HTTP_CLEARNET, // direct non-.i2p HTTPS_CLEARNET, // direct non-.i2p TORRENT, - GNUTELLA, IMULE, TAHOE_LAFS, - DEBIAN + GNUTELLA, + IMULE, + TAHOE_LAFS, + DEBIAN, + FILE // local file } diff --git a/core/java/src/net/i2p/update/UpdateType.java b/core/java/src/net/i2p/update/UpdateType.java index dd2daa7a46..eea76eb15b 100644 --- a/core/java/src/net/i2p/update/UpdateType.java +++ b/core/java/src/net/i2p/update/UpdateType.java @@ -6,13 +6,14 @@ package net.i2p.update; * @since 0.9.4 */ public enum UpdateType { - TYPE_DUMMY, + TYPE_DUMMY, // Internal use only NEWS, ROUTER_SIGNED, - ROUTER_SIGNED_PACK200, // unused, use ROUTER_SIGNED for both ROUTER_UNSIGNED, - PLUGIN, PLUGIN_INSTALL, - GEOIP, BLOCKLIST, RESEED, + PLUGIN, + GEOIP, + BLOCKLIST, + RESEED, HOMEPAGE, ADDRESSBOOK }