* Update: Files listed in deletelist.txt will be deleted

This commit is contained in:
zzz
2011-11-28 18:00:36 +00:00
parent 1339209fa9
commit bf461ee77e
3 changed files with 69 additions and 8 deletions

View File

@@ -664,8 +664,9 @@
<target name="preppkg-base" depends="build, preplicenses, prepConsoleDocs, prepthemeupdates, prepCertificates"> <target name="preppkg-base" depends="build, preplicenses, prepConsoleDocs, prepthemeupdates, prepCertificates">
<!-- if updater200 was run previously, it left *.pack files in pkg-temp --> <!-- if updater200 was run previously, it left *.pack files in pkg-temp -->
<!-- Also remove deletelist.txt used for updater only -->
<delete> <delete>
<fileset dir="pkg-temp" includes="**/*.jar.pack **/*.war.pack" /> <fileset dir="pkg-temp" includes="**/*.jar.pack **/*.war.pack deletelist.txt" />
</delete> </delete>
<copy file="build/i2p.jar" todir="pkg-temp/lib/" /> <copy file="build/i2p.jar" todir="pkg-temp/lib/" />
<copy file="build/i2ptunnel.jar" todir="pkg-temp/lib/" /> <copy file="build/i2ptunnel.jar" todir="pkg-temp/lib/" />
@@ -889,6 +890,7 @@
<exec executable="echo" osfamily="unix" failifexecutionfails="true" output="pkg-temp/history.txt" append="true"> <exec executable="echo" osfamily="unix" failifexecutionfails="true" output="pkg-temp/history.txt" append="true">
<arg value="EARLIER HISTORY IS AVAILABLE IN THE SOURCE PACKAGE" /> <arg value="EARLIER HISTORY IS AVAILABLE IN THE SOURCE PACKAGE" />
</exec> </exec>
<copy file="installer/resources/deletelist.txt" todir="pkg-temp/" />
<!-- May be pointless now, people with split directories will never see this, <!-- May be pointless now, people with split directories will never see this,
and for flat installs we don't want to overwrite news more recent than the update package. and for flat installs we don't want to overwrite news more recent than the update package.
<copy file="installer/resources/news.xml" todir="pkg-temp/docs/" /> <copy file="installer/resources/news.xml" todir="pkg-temp/docs/" />

View File

@@ -0,0 +1,3 @@
# Files listed here will be deleted after the update is extracted
# expired cert
certificates/r31453.ovh.net

View File

@@ -8,8 +8,11 @@ package net.i2p.router;
* *
*/ */
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@@ -1371,6 +1374,7 @@ public class Router implements RouterClock.ClockShiftListener {
} }
public static final String UPDATE_FILE = "i2pupdate.zip"; public static final String UPDATE_FILE = "i2pupdate.zip";
private static final String DELETE_FILE = "deletelist.txt";
/** /**
* Unzip update file found in the router dir OR base dir, to the base dir * Unzip update file found in the router dir OR base dir, to the base dir
@@ -1411,6 +1415,7 @@ public class Router implements RouterClock.ClockShiftListener {
// and we will die with NCDFE. // and we will die with NCDFE.
// Ideally, do not use I2P classes at all, new or not. // Ideally, do not use I2P classes at all, new or not.
try { try {
// TODO move deleteListedFiles() here after a few releases
if (ok) if (ok)
System.out.println("INFO: Update installed"); System.out.println("INFO: Update installed");
else else
@@ -1444,13 +1449,23 @@ public class Router implements RouterClock.ClockShiftListener {
} }
System.exit(EXIT_HARD_RESTART); System.exit(EXIT_HARD_RESTART);
} else { } else {
// Remove extracted libjbigi.so and libjcpuid.so files if we have a newer jbigi.jar, deleteJbigiFiles();
// so the new ones will be extracted. // Here so it may be used in the 0.8.12 update
// We do this after the restart, not after the extract, because it's safer, and // TODO move up in a few releases so it is only run after an update
// because people may upgrade their jbigi.jar file manually. deleteListedFiles();
}
}
// Copied from NativeBigInteger, which we can't access here or the /**
// libs will get loaded. * Remove extracted libjbigi.so and libjcpuid.so files if we have a newer jbigi.jar,
* so the new ones will be extracted.
* We do this after the restart, not after the extract, because it's safer, and
* because people may upgrade their jbigi.jar file manually.
*
* Copied from NativeBigInteger, which we can't access here or the
* libs will get loaded.
*/
private void deleteJbigiFiles() {
String osArch = System.getProperty("os.arch"); String osArch = System.getProperty("os.arch");
boolean isX86 = osArch.contains("86") || osArch.equals("amd64"); boolean isX86 = osArch.contains("86") || osArch.equals("amd64");
String osName = System.getProperty("os.name").toLowerCase(); String osName = System.getProperty("os.name").toLowerCase();
@@ -1495,6 +1510,47 @@ public class Router implements RouterClock.ClockShiftListener {
} }
} }
} }
/**
* Delete all files listed in the delete file.
* Format: One file name per line, comment lines start with '#'.
* All file names must be relative to $I2P, absolute file names not allowed.
* We probably can't remove old jars this way.
* Fails silently.
* Use no new I2P classes here so it may be called after zip extraction.
* @since 0.8.12
*/
private void deleteListedFiles() {
File deleteFile = new File(_context.getBaseDir(), DELETE_FILE);
if (!deleteFile.exists())
return;
// this is similar to FileUtil.readTextFile() but we can't use any I2P classes here
FileInputStream fis = null;
try {
fis = new FileInputStream(deleteFile);
BufferedReader in = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
String line;
while ( (line = in.readLine()) != null) {
String fl = line.trim();
if (fl.startsWith("..") || fl.startsWith("#") || fl.length() == 0)
continue;
File df = new File(fl);
if (df.isAbsolute())
continue;
df = new File(_context.getBaseDir(), fl);
if (df.exists() && !df.isDirectory()) {
if (df.delete())
System.out.println("INFO: File [" + fl + "] deleted");
}
}
fis.close();
fis = null;
if (deleteFile.delete())
System.out.println("INFO: File [" + DELETE_FILE + "] deleted");
} catch (IOException ioe) {
} finally {
if (fis != null) try { fis.close(); } catch (IOException ioe) {}
}
} }
/******* /*******