To be safe, if we had a version file before and the latest version is
newer, overwrite with the newer version.
This commit is contained in:
@@ -36,6 +36,7 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@@ -1014,12 +1015,13 @@ public class Application
|
|||||||
if (_version != -1) {
|
if (_version != -1) {
|
||||||
File vfile = getLocalPath(VERSION_FILE);
|
File vfile = getLocalPath(VERSION_FILE);
|
||||||
FileInputStream fin = null;
|
FileInputStream fin = null;
|
||||||
|
long fileVersion = -1;
|
||||||
try {
|
try {
|
||||||
fin = new FileInputStream(vfile);
|
fin = new FileInputStream(vfile);
|
||||||
BufferedReader bin = new BufferedReader(new InputStreamReader(fin));
|
BufferedReader bin = new BufferedReader(new InputStreamReader(fin));
|
||||||
String vstr = bin.readLine();
|
String vstr = bin.readLine();
|
||||||
if (!StringUtil.isBlank(vstr)) {
|
if (!StringUtil.isBlank(vstr)) {
|
||||||
_targetVersion = Long.parseLong(vstr);
|
_targetVersion = fileVersion = Long.parseLong(vstr);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("Unable to read version file: " + e.getMessage());
|
log.info("Unable to read version file: " + e.getMessage());
|
||||||
@@ -1029,12 +1031,18 @@ public class Application
|
|||||||
|
|
||||||
if (_latest != null) {
|
if (_latest != null) {
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
|
PrintStream out = null;
|
||||||
try {
|
try {
|
||||||
in = _latest.openStream();
|
in = _latest.openStream();
|
||||||
BufferedReader bin = new BufferedReader(new InputStreamReader(in));
|
BufferedReader bin = new BufferedReader(new InputStreamReader(in));
|
||||||
for (String[] pair : ConfigUtil.parsePairs(bin, false)) {
|
for (String[] pair : ConfigUtil.parsePairs(bin, false)) {
|
||||||
if (pair[0].equals("version")) {
|
if (pair[0].equals("version")) {
|
||||||
_targetVersion = Math.max(Long.parseLong(pair[1]), _targetVersion);
|
_targetVersion = Math.max(Long.parseLong(pair[1]), _targetVersion);
|
||||||
|
if (fileVersion != -1 && _targetVersion > fileVersion) {
|
||||||
|
// replace the file with the newest version
|
||||||
|
out = new PrintStream(new FileOutputStream(vfile));
|
||||||
|
out.println(_targetVersion);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1042,6 +1050,7 @@ public class Application
|
|||||||
log.warning("Unable to retrieve version from latest config file.", e);
|
log.warning("Unable to retrieve version from latest config file.", e);
|
||||||
} finally {
|
} finally {
|
||||||
StreamUtil.close(in);
|
StreamUtil.close(in);
|
||||||
|
StreamUtil.close(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user