Skip to content

Commit

Permalink
Change version comparison logic
Browse files Browse the repository at this point in the history
The central server sends a short version (e.g. 0.14), which the distributed server
then compares to its long version (e.g. 0.14.1). The problem is that 0.14 compares
as less than 0.14.1, so language packs are shown as unavailable. Instead,
when comparing two mismatched-length versions, only consider the shortest version
available -- thus 0.14 and 0.14.1 would compare equal. Then the languagepack versions
will be compared, which is the actual intent.
  • Loading branch information
MCGallaspy committed Oct 7, 2015
1 parent 306de74 commit 290b4fc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions kalite/updates/static/js/updates/update_languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ var installed_languages = [];
var downloading = false;

function version_comparison(v1, v2) {
// compare two version strings and return 1 if the first is higher than the second,
// -1 if the first is lower than the second, and 0 if they are equal
/*
compare two version strings and return 1 if the first is higher than the second,
-1 if the first is lower than the second, and 0 if they are equal.
:params v1, v2: Version strings expected format is either "N.N.N" or "N.N", where N is a positive integer.
If both strings have the same format, they're compared using a lexical order.
If one string is shorter than the other, then the other is truncated and then compared using lexical order.
*/
var v1parts = v1.split('.'), v2parts = v2.split('.');
var maxLen = Math.max(v1parts.length, v2parts.length);
var minLen = Math.min(v1parts.length, v2parts.length);
var part1, part2;
for(var i = 0; i < maxLen; i++) {
for(var i = 0; i < minLen; i++) {
part1 = parseInt(v1parts[i], 10) || 0;
part2 = parseInt(v2parts[i], 10) || 0;
if (part1 > part2) return 1;
Expand Down

0 comments on commit 290b4fc

Please sign in to comment.