forked from I2P_Developers/i2p.i2p
Plugins: bugfix and defer update.
This commit is contained in:
@@ -2,7 +2,6 @@ package net.i2p.router.web;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ClassLoader;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
@@ -198,7 +197,30 @@ public class PluginStarter implements Runnable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do we need to extract an update?
|
||||||
|
File pluginUpdate = new File(ctx.getConfigDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName + "/app.xpi2p.zip" );
|
||||||
|
if(pluginUpdate.exists()) {
|
||||||
|
// Compare the start time of the router with the plugin.
|
||||||
|
List<RouterContext> contexts = RouterContext.listContexts();
|
||||||
|
if ( (contexts == null) || (contexts.isEmpty()) )
|
||||||
|
throw new IllegalStateException("No contexts. This is usually because the router is either starting up or shutting down.");
|
||||||
|
if(contexts.get(0).router().getWhenStarted() > pluginUpdate.lastModified()) {
|
||||||
|
if (!FileUtil.extractZip(pluginUpdate, pluginDir)) {
|
||||||
|
pluginUpdate.delete();
|
||||||
|
String foo = "Plugin '" + appName + "' failed to update! File '" + pluginUpdate +"' deleted. You may need to remove and install the plugin again.";
|
||||||
|
log.error(foo);
|
||||||
|
disablePlugin(appName);
|
||||||
|
throw new Exception(foo);
|
||||||
|
} else {
|
||||||
|
pluginUpdate.delete();
|
||||||
|
// Need to always log this, and log.logAlways() did not work for me.
|
||||||
|
System.err.println("INFO: Plugin updated: " + appName);
|
||||||
|
}
|
||||||
|
} // silently fail to update, because we have not restarted.
|
||||||
|
}
|
||||||
|
|
||||||
Properties props = pluginProperties(ctx, appName);
|
Properties props = pluginProperties(ctx, appName);
|
||||||
|
|
||||||
String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version");
|
String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version");
|
||||||
if (minVersion != null &&
|
if (minVersion != null &&
|
||||||
(new VersionComparator()).compare(CoreVersion.VERSION, minVersion) < 0) {
|
(new VersionComparator()).compare(CoreVersion.VERSION, minVersion) < 0) {
|
||||||
|
@@ -14,6 +14,7 @@ import net.i2p.util.FileUtil;
|
|||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
import net.i2p.util.OrderedProperties;
|
import net.i2p.util.OrderedProperties;
|
||||||
import net.i2p.util.SecureDirectory;
|
import net.i2p.util.SecureDirectory;
|
||||||
|
import net.i2p.util.SecureFile;
|
||||||
import net.i2p.util.SimpleScheduler;
|
import net.i2p.util.SimpleScheduler;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer;
|
||||||
import net.i2p.util.VersionComparator;
|
import net.i2p.util.VersionComparator;
|
||||||
@@ -333,7 +334,7 @@ public class PluginUpdateHandler extends UpdateHandler {
|
|||||||
}
|
}
|
||||||
String oldPubkey = oldProps.getProperty("key");
|
String oldPubkey = oldProps.getProperty("key");
|
||||||
String oldKeyName = oldProps.getProperty("signer");
|
String oldKeyName = oldProps.getProperty("signer");
|
||||||
String oldAppName = props.getProperty("name");
|
String oldAppName = oldProps.getProperty("name");
|
||||||
if ((!pubkey.equals(oldPubkey)) || (!signer.equals(oldKeyName)) || (!appName.equals(oldAppName))) {
|
if ((!pubkey.equals(oldPubkey)) || (!signer.equals(oldKeyName)) || (!appName.equals(oldAppName))) {
|
||||||
to.delete();
|
to.delete();
|
||||||
statusDone("<b>" + _("Signature of downloaded plugin does not match installed plugin") + "</b>");
|
statusDone("<b>" + _("Signature of downloaded plugin does not match installed plugin") + "</b>");
|
||||||
@@ -375,24 +376,25 @@ public class PluginUpdateHandler extends UpdateHandler {
|
|||||||
statusDone("<b>" + _("Plugin requires Jetty version {0} or lower", maxVersion) + "</b>");
|
statusDone("<b>" + _("Plugin requires Jetty version {0} or lower", maxVersion) + "</b>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
// not ready yet...
|
|
||||||
// do we defer extraction and installation?
|
// do we defer extraction and installation?
|
||||||
if (Boolean.valueOf(props.getProperty("router-restart-required")).booleanValue() && !Boolean.valueOf(props.getProperty("dont-start-at-install")).booleanValue()) {
|
if (Boolean.valueOf(props.getProperty("router-restart-required")).booleanValue()) {
|
||||||
// Yup!
|
// Yup!
|
||||||
if (!destDir.mkdir()) {
|
try {
|
||||||
|
if(!FileUtil.copy(to, (new SecureFile( new SecureFile(appDir.getCanonicalPath() +"/" + appName +"/"+ ZIP).getCanonicalPath())) , true, true)) {
|
||||||
|
to.delete();
|
||||||
|
statusDone("<b>" + _("Cannot copy plugin to directory {0}", destDir.getAbsolutePath()) + "</b>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
to.delete();
|
to.delete();
|
||||||
statusDone("<b>" + _("Cannot create plugin directory {0}", destDir.getAbsolutePath()) + "</b>");
|
_log.error("Error copying plugin {0}", t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!FileUtil.copy(to, destDir, true, true)) {
|
|
||||||
statusDone("<b>" + _("Cannot copy plugin to directory {0}", destDir.getAbsolutePath()) + "</b>");
|
|
||||||
}
|
|
||||||
// we don't need the original file anymore.
|
// we don't need the original file anymore.
|
||||||
to.delete();
|
to.delete();
|
||||||
statusDone("<b>" + _("Plugin will be installed on next restart.") + "</b>");
|
statusDone("<b>" + _("Plugin will be installed on next restart.") + "</b>");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
if (PluginStarter.isPluginRunning(appName, _context)) {
|
if (PluginStarter.isPluginRunning(appName, _context)) {
|
||||||
wasRunning = true;
|
wasRunning = true;
|
||||||
try {
|
try {
|
||||||
|
@@ -1,3 +1,9 @@
|
|||||||
|
2012-03-13 sponge
|
||||||
|
* Plugins:
|
||||||
|
- Fix a bug in the updater. It was not comparing the correct name.
|
||||||
|
- Plugin updates can now be deferred if router-restart-required is set.
|
||||||
|
The update happens at the next router restart.
|
||||||
|
|
||||||
2012-03-13 sponge
|
2012-03-13 sponge
|
||||||
* Plugins:
|
* Plugins:
|
||||||
- Handle 'file://' URLs for installation and updates.
|
- Handle 'file://' URLs for installation and updates.
|
||||||
|
Reference in New Issue
Block a user