forked from I2P_Developers/i2p.i2p
* Updater: Fix plugin update checker (ticket #897)
* Utils: Reduce logging in wrapper log when extracting zip files
This commit is contained in:
@@ -30,14 +30,12 @@ import net.i2p.util.VersionComparator;
|
|||||||
* @since 0.7.12
|
* @since 0.7.12
|
||||||
*/
|
*/
|
||||||
class PluginUpdateChecker extends UpdateRunner {
|
class PluginUpdateChecker extends UpdateRunner {
|
||||||
private final ByteArrayOutputStream _baos;
|
|
||||||
private final String _appName;
|
private final String _appName;
|
||||||
private final String _oldVersion;
|
private final String _oldVersion;
|
||||||
|
|
||||||
public PluginUpdateChecker(RouterContext ctx, ConsoleUpdateManager mgr,
|
public PluginUpdateChecker(RouterContext ctx, ConsoleUpdateManager mgr,
|
||||||
List<URI> uris, String appName, String oldVersion ) {
|
List<URI> uris, String appName, String oldVersion ) {
|
||||||
super(ctx, mgr, uris);
|
super(ctx, mgr, uris, oldVersion);
|
||||||
_baos = new ByteArrayOutputStream(TrustedUpdate.HEADER_BYTES);
|
|
||||||
if (!uris.isEmpty())
|
if (!uris.isEmpty())
|
||||||
_currentURI = uris.get(0);
|
_currentURI = uris.get(0);
|
||||||
_appName = appName;
|
_appName = appName;
|
||||||
@@ -85,7 +83,10 @@ class PluginUpdateChecker extends UpdateRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
|
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining,
|
||||||
|
String url, String outputFile, boolean notModified) {
|
||||||
|
super.transferComplete(alreadyTransferred, bytesTransferred, bytesRemaining,
|
||||||
|
url, outputFile, notModified);
|
||||||
// super sets _newVersion if newer
|
// super sets _newVersion if newer
|
||||||
boolean newer = _newVersion != null;
|
boolean newer = _newVersion != null;
|
||||||
if (newer) {
|
if (newer) {
|
||||||
|
@@ -21,6 +21,7 @@ import net.i2p.update.*;
|
|||||||
import net.i2p.util.EepGet;
|
import net.i2p.util.EepGet;
|
||||||
import net.i2p.util.FileUtil;
|
import net.i2p.util.FileUtil;
|
||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
|
import net.i2p.util.Log;
|
||||||
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.SecureFile;
|
||||||
@@ -147,7 +148,7 @@ class PluginUpdateRunner extends UpdateRunner {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File tempDir = new File(_context.getTempDir(), "tmp" + _context.random().nextInt() + "-unzip");
|
File tempDir = new File(_context.getTempDir(), "tmp" + _context.random().nextInt() + "-unzip");
|
||||||
if (!FileUtil.extractZip(to, tempDir)) {
|
if (!FileUtil.extractZip(to, tempDir, Log.ERROR)) {
|
||||||
f.delete();
|
f.delete();
|
||||||
to.delete();
|
to.delete();
|
||||||
FileUtil.rmdir(tempDir, false);
|
FileUtil.rmdir(tempDir, false);
|
||||||
@@ -374,7 +375,7 @@ class PluginUpdateRunner extends UpdateRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally, extract the zip to the plugin directory
|
// Finally, extract the zip to the plugin directory
|
||||||
if (!FileUtil.extractZip(to, destDir)) {
|
if (!FileUtil.extractZip(to, destDir, Log.WARN)) {
|
||||||
to.delete();
|
to.delete();
|
||||||
statusDone("<b>" + _("Failed to install plugin in {0}", destDir.getAbsolutePath()) + "</b>");
|
statusDone("<b>" + _("Failed to install plugin in {0}", destDir.getAbsolutePath()) + "</b>");
|
||||||
return;
|
return;
|
||||||
|
@@ -39,9 +39,10 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
|
|||||||
protected boolean _isPartial;
|
protected boolean _isPartial;
|
||||||
/** set by the listeners on completion */
|
/** set by the listeners on completion */
|
||||||
protected String _newVersion;
|
protected String _newVersion;
|
||||||
// 56 byte header, only used for suds
|
/** 56 byte header, only used for suds */
|
||||||
private final ByteArrayOutputStream _baos;
|
protected final ByteArrayOutputStream _baos;
|
||||||
protected URI _currentURI;
|
protected URI _currentURI;
|
||||||
|
private final String _currentVersion;
|
||||||
|
|
||||||
private static final String SIGNED_UPDATE_FILE = "i2pupdate.sud";
|
private static final String SIGNED_UPDATE_FILE = "i2pupdate.sud";
|
||||||
|
|
||||||
@@ -49,7 +50,18 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
|
|||||||
protected static final long INACTIVITY_TIMEOUT = 5*60*1000;
|
protected static final long INACTIVITY_TIMEOUT = 5*60*1000;
|
||||||
protected static final long NOPROXY_INACTIVITY_TIMEOUT = 60*1000;
|
protected static final long NOPROXY_INACTIVITY_TIMEOUT = 60*1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses router version for partial checks
|
||||||
|
*/
|
||||||
public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris) {
|
public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris) {
|
||||||
|
this(ctx, mgr, uris, RouterVersion.VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param currentVersion used for partial checks
|
||||||
|
* @since 0.9.7
|
||||||
|
*/
|
||||||
|
public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris, String currentVersion) {
|
||||||
super("Update Runner");
|
super("Update Runner");
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
@@ -58,6 +70,7 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
|
|||||||
_urls = uris;
|
_urls = uris;
|
||||||
_baos = new ByteArrayOutputStream(TrustedUpdate.HEADER_BYTES);
|
_baos = new ByteArrayOutputStream(TrustedUpdate.HEADER_BYTES);
|
||||||
_updateFile = (new File(ctx.getTempDir(), "update" + ctx.random().nextInt() + ".tmp")).getAbsolutePath();
|
_updateFile = (new File(ctx.getTempDir(), "update" + ctx.random().nextInt() + ".tmp")).getAbsolutePath();
|
||||||
|
_currentVersion = currentVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////// begin UpdateTask methods
|
//////// begin UpdateTask methods
|
||||||
@@ -184,7 +197,7 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
|
|||||||
if (_isPartial) {
|
if (_isPartial) {
|
||||||
// Compare version with what we have now
|
// Compare version with what we have now
|
||||||
String newVersion = TrustedUpdate.getVersionString(new ByteArrayInputStream(_baos.toByteArray()));
|
String newVersion = TrustedUpdate.getVersionString(new ByteArrayInputStream(_baos.toByteArray()));
|
||||||
boolean newer = VersionComparator.comp(newVersion, RouterVersion.VERSION) > 0;
|
boolean newer = VersionComparator.comp(newVersion, _currentVersion) > 0;
|
||||||
if (newer) {
|
if (newer) {
|
||||||
_newVersion = newVersion;
|
_newVersion = newVersion;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -89,8 +89,19 @@ public class FileUtil {
|
|||||||
/**
|
/**
|
||||||
* As of release 0.7.12, any files inside the zip that have a .jar.pack or .war.pack suffix
|
* As of release 0.7.12, any files inside the zip that have a .jar.pack or .war.pack suffix
|
||||||
* are transparently unpacked to a .jar or .war file using unpack200.
|
* are transparently unpacked to a .jar or .war file using unpack200.
|
||||||
|
* Logs at WARN level to wrapper.log
|
||||||
*/
|
*/
|
||||||
public static boolean extractZip(File zipfile, File targetDir) {
|
public static boolean extractZip(File zipfile, File targetDir) {
|
||||||
|
return extractZip(zipfile, targetDir, Log.WARN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param logLevel Log.WARN, etc.
|
||||||
|
* @return true if it was copied successfully
|
||||||
|
* @since 0.9.7
|
||||||
|
*/
|
||||||
|
public static boolean extractZip(File zipfile, File targetDir, int logLevel) {
|
||||||
|
int files = 0;
|
||||||
ZipFile zip = null;
|
ZipFile zip = null;
|
||||||
try {
|
try {
|
||||||
byte buf[] = new byte[16*1024];
|
byte buf[] = new byte[16*1024];
|
||||||
@@ -107,6 +118,7 @@ public class FileUtil {
|
|||||||
if ( (parent != null) && (!parent.exists()) ) {
|
if ( (parent != null) && (!parent.exists()) ) {
|
||||||
boolean parentsOk = parent.mkdirs();
|
boolean parentsOk = parent.mkdirs();
|
||||||
if (!parentsOk) {
|
if (!parentsOk) {
|
||||||
|
if (logLevel <= Log.ERROR)
|
||||||
System.err.println("ERROR: Unable to create the parent dir for " + entry.getName() + ": [" + parent.getAbsolutePath() + "]");
|
System.err.println("ERROR: Unable to create the parent dir for " + entry.getName() + ": [" + parent.getAbsolutePath() + "]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -115,9 +127,10 @@ public class FileUtil {
|
|||||||
if (!target.exists()) {
|
if (!target.exists()) {
|
||||||
boolean created = target.mkdirs();
|
boolean created = target.mkdirs();
|
||||||
if (!created) {
|
if (!created) {
|
||||||
|
if (logLevel <= Log.ERROR)
|
||||||
System.err.println("ERROR: Unable to create the directory [" + entry.getName() + "]");
|
System.err.println("ERROR: Unable to create the directory [" + entry.getName() + "]");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else if (logLevel <= Log.INFO) {
|
||||||
System.err.println("INFO: Creating directory [" + entry.getName() + "]");
|
System.err.println("INFO: Creating directory [" + entry.getName() + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,6 +144,7 @@ public class FileUtil {
|
|||||||
target = new File(targetDir, entry.getName().substring(0, entry.getName().length() - ".pack".length()));
|
target = new File(targetDir, entry.getName().substring(0, entry.getName().length() - ".pack".length()));
|
||||||
jos = new JarOutputStream(new FileOutputStream(target));
|
jos = new JarOutputStream(new FileOutputStream(target));
|
||||||
unpack(in, jos);
|
unpack(in, jos);
|
||||||
|
if (logLevel <= Log.INFO)
|
||||||
System.err.println("INFO: File [" + entry.getName() + "] extracted and unpacked");
|
System.err.println("INFO: File [" + entry.getName() + "] extracted and unpacked");
|
||||||
} else {
|
} else {
|
||||||
fos = new FileOutputStream(target);
|
fos = new FileOutputStream(target);
|
||||||
@@ -138,21 +152,27 @@ public class FileUtil {
|
|||||||
while ( (read = in.read(buf)) != -1) {
|
while ( (read = in.read(buf)) != -1) {
|
||||||
fos.write(buf, 0, read);
|
fos.write(buf, 0, read);
|
||||||
}
|
}
|
||||||
|
if (logLevel <= Log.INFO)
|
||||||
System.err.println("INFO: File [" + entry.getName() + "] extracted");
|
System.err.println("INFO: File [" + entry.getName() + "] extracted");
|
||||||
}
|
}
|
||||||
|
files++;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
if (logLevel <= Log.ERROR) {
|
||||||
System.err.println("ERROR: Error extracting the zip entry (" + entry.getName() + ')');
|
System.err.println("ERROR: Error extracting the zip entry (" + entry.getName() + ')');
|
||||||
if (ioe.getMessage() != null && ioe.getMessage().indexOf("CAFED00D") >= 0)
|
if (ioe.getMessage() != null && ioe.getMessage().indexOf("CAFED00D") >= 0)
|
||||||
System.err.println("This may be caused by a packed library that requires Java 1.6, your Java version is: " +
|
System.err.println("This may be caused by a packed library that requires Java 1.6, your Java version is: " +
|
||||||
System.getProperty("java.version"));
|
System.getProperty("java.version"));
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Oracle unpack() should throw an IOE but other problems can happen, e.g:
|
// Oracle unpack() should throw an IOE but other problems can happen, e.g:
|
||||||
// java.lang.reflect.InvocationTargetException
|
// java.lang.reflect.InvocationTargetException
|
||||||
// Caused by: java.util.zip.ZipException: duplicate entry: xxxxx
|
// Caused by: java.util.zip.ZipException: duplicate entry: xxxxx
|
||||||
|
if (logLevel <= Log.ERROR) {
|
||||||
System.err.println("ERROR: Error extracting the zip entry (" + entry.getName() + ')');
|
System.err.println("ERROR: Error extracting the zip entry (" + entry.getName() + ')');
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
try { if (in != null) in.close(); } catch (IOException ioe) {}
|
try { if (in != null) in.close(); } catch (IOException ioe) {}
|
||||||
@@ -163,13 +183,17 @@ public class FileUtil {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
if (logLevel <= Log.ERROR) {
|
||||||
System.err.println("ERROR: Unable to extract the zip file");
|
System.err.println("ERROR: Unable to extract the zip file");
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (zip != null) {
|
if (zip != null) {
|
||||||
try { zip.close(); } catch (IOException ioe) {}
|
try { zip.close(); } catch (IOException ioe) {}
|
||||||
}
|
}
|
||||||
|
if (files > 0 && logLevel <= Log.WARN)
|
||||||
|
System.err.println("INFO: " + files + " files extracted to " + targetDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
2013-07-03 zzz
|
||||||
|
* Updater: Fix plugin update checker (ticket #897)
|
||||||
|
* Utils: Reduce logging in wrapper log when extracting zip files
|
||||||
|
|
||||||
2013-06-30 zzz
|
2013-06-30 zzz
|
||||||
* BuildHandler: Drop build request with bad flags
|
* BuildHandler: Drop build request with bad flags
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 14;
|
public final static long BUILD = 15;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "-rc";
|
public final static String EXTRA = "-rc";
|
||||||
|
Reference in New Issue
Block a user