提交 ce7300cd 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-7034] auto-recover from corrupt update data.

上级 62242627
......@@ -55,6 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Recover from a corrupted JSON update data file automatically
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-7034">issue 7034</a>)
<li class=bug>
Fixed the reported system reboot problem on installing JDK on Windows
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-7288">issue 7288</a>)
......
......@@ -26,15 +26,18 @@ package hudson.model;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.util.IOException2;
import hudson.util.IOUtils;
import hudson.util.QuotedStringTokenizer;
import hudson.util.TextFile;
import hudson.util.TimeUnit2;
import jenkins.model.Jenkins;
import net.sf.json.JSONException;
import org.kohsuke.stapler.Stapler;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.json.JSONObject;
......@@ -206,7 +209,12 @@ public class DownloadService extends PageDecorator {
public JSONObject getData() throws IOException {
TextFile df = getDataFile();
if(df.exists())
return JSONObject.fromObject(df.read());
try {
return JSONObject.fromObject(df.read());
} catch (JSONException e) {
df.delete(); // if we keep this file, it will cause repeated failures
throw new IOException2("Failed to parse "+df+" into JSON",e);
}
return null;
}
......
......@@ -36,6 +36,7 @@ import hudson.util.IOUtils;
import hudson.util.TextFile;
import hudson.util.VersionNumber;
import jenkins.model.Jenkins;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.TeeOutputStream;
......@@ -264,6 +265,10 @@ public class UpdateSite {
if(df.exists()) {
try {
return JSONObject.fromObject(df.read());
} catch (JSONException e) {
LOGGER.log(Level.SEVERE,"Failed to parse "+df,e);
df.delete(); // if we keep this file, it will cause repeated failures
return null;
} catch (IOException e) {
LOGGER.log(Level.SEVERE,"Failed to parse "+df,e);
df.delete(); // if we keep this file, it will cause repeated failures
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册