1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Version check now sees 1.0.4-pre.1 as older than 1.0.4, but 1.0.4-abd332 as newer.

This commit is contained in:
Fabian Schlenz 2016-09-02 16:38:00 +02:00
parent 71fb63443b
commit 11b5dc66e5
2 changed files with 28 additions and 6 deletions

View File

@ -102,8 +102,8 @@ public class Utils {
logger.debug("Comparing versions {} and {}.", v1, v2); logger.debug("Comparing versions {} and {}.", v1, v2);
if (v1.equals(v2)) return VERSIONS_EQUAL; if (v1.equals(v2)) return VERSIONS_EQUAL;
String[] v1_p = v1.split("-"); String[] v1_p = v1.split("-", 2);
String[] v2_p = v2.split("-"); String[] v2_p = v2.split("-", 2);
logger.trace("Parts to compare without suffixes: {} and {}.", v1_p[0], v2_p[0]); logger.trace("Parts to compare without suffixes: {} and {}.", v1_p[0], v2_p[0]);
@ -134,13 +134,34 @@ public class Utils {
return VERSION_2_NEWER; return VERSION_2_NEWER;
} }
// startsWith
if (v1_p.length>1 && v2_p.length==1) { if (v1_p.length>1 && v2_p.length==1) {
logger.debug("v1 has a suffix, v2 not - so v2 is newer."); logger.debug("v1 has a suffix, v2 not.");
if (v1_p[1].startsWith("pre")) {
logger.debug("v1 is a pre version, so v1 is newer");
return VERSION_2_NEWER; return VERSION_2_NEWER;
} else if (v1_p.length==1 && v2_p.length>1) { } else {
logger.debug("v1 has no suffix, but v2 has - so v1 is newer.");
return VERSION_1_NEWER; return VERSION_1_NEWER;
} }
} else if (v1_p.length==1 && v2_p.length>1) {
logger.debug("v1 has no suffix, but v2 has");
if (v2_p[1].startsWith("pre")) {
logger.debug("v2 is a pre version, so v1 is better");
return VERSION_1_NEWER;
} else {
return VERSION_2_NEWER;
}
} else if (v1_p.length>1 && v2_p.length>1) {
logger.debug("Both have a suffix");
if (v1_p[1].startsWith("pre") && !v2_p[1].startsWith("pre")) {
logger.debug("v1 is a 'pre' version, v2 not.");
return VERSION_2_NEWER;
} else if (!v1_p[1].startsWith("pre") && v2_p[1].startsWith("pre")) {
logger.debug("v2 is a 'pre' version, v2 not.");
return VERSION_1_NEWER;
}
return VERSIONS_EQUAL;
}
logger.debug("We couldn't find a real difference, so we're assuming the versions are equal-ish."); logger.debug("We couldn't find a real difference, so we're assuming the versions are equal-ish.");
return VERSIONS_EQUAL; return VERSIONS_EQUAL;
} }

View File

@ -11,5 +11,6 @@ public class CompareVersionsTest {
assertEquals(Utils.compareVersions("1.0.4", "1.0.4-pre.1"), Utils.VERSION_1_NEWER); assertEquals(Utils.compareVersions("1.0.4", "1.0.4-pre.1"), Utils.VERSION_1_NEWER);
assertEquals(Utils.compareVersions("1.0.4", "1.0.4"), Utils.VERSIONS_EQUAL); assertEquals(Utils.compareVersions("1.0.4", "1.0.4"), Utils.VERSIONS_EQUAL);
assertEquals(Utils.compareVersions("1.0.4-pre.2", "1.0.4-pre.1"), Utils.VERSIONS_EQUAL); assertEquals(Utils.compareVersions("1.0.4-pre.2", "1.0.4-pre.1"), Utils.VERSIONS_EQUAL);
assertEquals(Utils.compareVersions("1.0.4", "1.0.4-abcdef-dirty"), Utils.VERSION_2_NEWER);
} }
} }