Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

make migration version safe

regerfb8ae14b217c
diff --git a/source/net/yacy/migration.java b/source/net/yacy/migration.java
index 2f2765e4f..38878edc8 100644
--- a/source/net/yacy/migration.java
+++ b/source/net/yacy/migration.java
@@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import net.yacy.cora.order.Base64Order;
@@ -47,26 +48,34 @@ import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.LukeResponse.FieldInfo;
public class migration {
- //SVN constants
- public static final int USE_WORK_DIR=1389; //wiki & messages in DATA/WORK
- public static final int TAGDB_WITH_TAGHASH=1635; //tagDB keys are tagHashes instead of plain tagname.
- public static final int NEW_OVERLAYS=4422;
- public static final int IDX_HOST=7724; // api for index retrieval: host index
-
- public static void migrate(final Switchboard sb, final int fromRev, final int toRev){
- if(fromRev < toRev){
- if(fromRev < TAGDB_WITH_TAGHASH){
+ //SVN constants (version & revision format = v.vvv0rrrr)
+ public static final double TAGDB_WITH_TAGHASH=0.43101635; //tagDB keys are tagHashes instead of plain tagname.
+ public static final double NEW_OVERLAYS =0.56504422;
+ public static final double IDX_HOST_VER =0.99007724; // api for index retrieval: host index
+
+ /**
+ * Migrates older configuratin to current version
+ * @param sb
+ * @param fromVer the long version & revision (example 1.83009123)
+ * @param toRev to current version
+ */
+ public static void migrate(final Switchboard sb, final double fromVer, final double toVer){
+ if(fromVer < toVer){
+ if(fromVer < TAGDB_WITH_TAGHASH){
migrateBookmarkTagsDB(sb);
}
- if(fromRev < NEW_OVERLAYS){
+ if(fromVer < NEW_OVERLAYS){
migrateDefaultFiles(sb);
}
- ConcurrentLog.info("MIGRATION", "Migrating from "+ fromRev + " to " + toRev);
- presetPasswords(sb);
- migrateSwitchConfigSettings(sb);
- migrateWorkFiles(sb);
+ // use String.format to cut-off small rounding errors
+ ConcurrentLog.info("MIGRATION", "Migrating from "+ String.format(Locale.US, "%.8f",fromVer) + " to " + String.format(Locale.US, "%.8f",toVer));
+ if (fromVer < 0.47d) {
+ presetPasswords(sb);
+ migrateSwitchConfigSettings(sb);
+ migrateWorkFiles(sb);
+ }
}
- installSkins(sb); // FIXME: yes, bad fix for quick release 0.47
+ if (fromVer < 0.431d) installSkins(sb);
// ssl/https support currently on hardcoded default port 8443 (v1.67/9563)
// make sure YaCy can start (disable ssl/https support if port is used)
diff --git a/source/net/yacy/peers/Protocol.java b/source/net/yacy/peers/Protocol.java
index 72a707f56..9724d17e9 100644
--- a/source/net/yacy/peers/Protocol.java
+++ b/source/net/yacy/peers/Protocol.java
@@ -1722,7 +1722,7 @@ public final class Protocol {
Base64Order.enhancedCoder,
6);
// check if the host supports this protocol
- if ( target.getRevision() < migration.IDX_HOST ) {
+ if ( target.getVersion()< migration.IDX_HOST_VER ) {
// if the protocol is not supported then we just return an empty host reference container
return index;
}
diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java
index 6d6a715eb..361f18c54 100644
--- a/source/net/yacy/yacy.java
+++ b/source/net/yacy/yacy.java
@@ -65,6 +65,7 @@ import net.yacy.cora.federate.yacy.CacheStrategy;
import net.yacy.cora.order.Digest;
import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.crawler.retrieval.Response;
+import net.yacy.peers.Seed;
import net.yacy.server.serverSwitch;
@@ -234,14 +235,25 @@ public final class yacy {
// hardcoded, forced, temporary value-migration
sb.setConfig("htTemplatePath", "htroot/env/templates");
- int oldRev;
+ double oldVer;
try {
- oldRev = Integer.parseInt(sb.getConfig("svnRevision", "0"));
+ String tmpversion = sb.getConfig(Seed.VERSION, "");
+ if (tmpversion.isEmpty()) { // before 1.83009737 only the svnRevision nr was in config (like 9737)
+ tmpversion = yacyBuildProperties.getVersion();
+ int oldRev = Integer.parseInt(sb.getConfig("svnRevision", "0"));
+ if (oldRev > 1) {
+ oldVer = Double.parseDouble(tmpversion) + oldRev / 100000000.0;
+ } else {
+ oldVer = Double.parseDouble(yacyBuildProperties.getLongVersion()); // failsafe (assume current version = no migration)
+ }
+ } else {
+ oldVer = Double.parseDouble(tmpversion);
+ }
} catch (final NumberFormatException e) {
- oldRev = 0;
+ oldVer = 0.0d;
}
- final int newRev = Integer.parseInt(yacyBuildProperties.getSVNRevision());
- sb.setConfig("svnRevision", yacyBuildProperties.getSVNRevision());
+ final double newRev = Double.parseDouble(yacyBuildProperties.getLongVersion());
+ sb.setConfig(Seed.VERSION, yacyBuildProperties.getLongVersion());
sb.setConfig("applicationRoot", appHome.toString());
sb.setConfig("dataRoot", dataHome.toString());
@@ -296,7 +308,7 @@ public final class yacy {
shareDumpDefaultPath = new File(shareDefaultPath, "dump");
mkdirIfNeseccary(shareDumpDefaultPath);
- migration.migrate(sb, oldRev, newRev);
+ migration.migrate(sb, oldVer, newRev);
// delete old release files
final int deleteOldDownloadsAfterDays = (int) sb.getConfigLong("update.deleteOld", 30);
@@ -338,22 +350,22 @@ public final class yacy {
final File locale_source = sb.getAppPath("locale.source", "locales");
final String lang = sb.getConfig("locale.language", "");
if (!lang.equals("") && !lang.equals("default")) { //locale is used
- String currentRev = "";
+ String currentRev = null;
try{
final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang+"/version" ))));
- currentRev = br.readLine();
+ currentRev = br.readLine(); // may return null
br.close();
}catch(final IOException e){
//Error
}
- if (!currentRev.equals(sb.getConfig("svnRevision", ""))) try { //is this another version?!
+ if (currentRev == null || !currentRev.equals(sb.getConfig(Seed.VERSION, ""))) try { //is this another version?!
final File sourceDir = new File(sb.getConfig(SwitchboardConstants.HTROOT_PATH, SwitchboardConstants.HTROOT_PATH_DEFAULT));
final File destDir = new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang);
if (Translator.translateFilesRecursive(sourceDir, destDir, new File(locale_source, lang + ".lng"), "html,template,inc", "locale")){ //translate it
//write the new Versionnumber
final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
- bw.write(sb.getConfig("svnRevision", "Error getting Version"));
+ bw.write(sb.getConfig(Seed.VERSION, "Error getting Version"));
bw.close();
}
} catch (final IOException e) {}