- Force news refetch after URL change

This commit is contained in:
zzz
2011-05-23 19:19:07 +00:00
parent 7ab95d0144
commit 6e4df8830a
2 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,5 @@
package net.i2p.router.web; package net.i2p.router.web;
import net.i2p.I2PAppContext;
import net.i2p.crypto.TrustedUpdate; import net.i2p.crypto.TrustedUpdate;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.util.FileUtil; import net.i2p.util.FileUtil;
@ -78,7 +77,7 @@ public class ConfigUpdateHandler extends FormHandler {
if (_action == null) if (_action == null)
return; return;
if (_action.equals(_("Check for updates"))) { if (_action.equals(_("Check for updates"))) {
NewsFetcher fetcher = NewsFetcher.getInstance(I2PAppContext.getGlobalContext()); NewsFetcher fetcher = NewsFetcher.getInstance(_context);
fetcher.fetchNews(); fetcher.fetchNews();
if (fetcher.shouldFetchUnsigned()) if (fetcher.shouldFetchUnsigned())
fetcher.fetchUnsignedHead(); fetcher.fetchUnsignedHead();
@ -100,6 +99,7 @@ public class ConfigUpdateHandler extends FormHandler {
String oldURL = ConfigUpdateHelper.getNewsURL(_context); String oldURL = ConfigUpdateHelper.getNewsURL(_context);
if ( (oldURL == null) || (!_newsURL.equals(oldURL)) ) { if ( (oldURL == null) || (!_newsURL.equals(oldURL)) ) {
_context.router().setConfigSetting(PROP_NEWS_URL, _newsURL); _context.router().setConfigSetting(PROP_NEWS_URL, _newsURL);
NewsFetcher.getInstance(_context).invalidateNews();
addFormNotice(_("Updating news URL to") + " " + _newsURL); addFormNotice(_("Updating news URL to") + " " + _newsURL);
} }
} }

View File

@ -33,6 +33,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
private String _updateVersion; private String _updateVersion;
private String _unsignedUpdateVersion; private String _unsignedUpdateVersion;
private String _lastModified; private String _lastModified;
private boolean _invalidated;
private File _newsFile; private File _newsFile;
private File _tempFile; private File _tempFile;
private static NewsFetcher _instance; private static NewsFetcher _instance;
@ -134,6 +135,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
} }
private boolean shouldFetchNews() { private boolean shouldFetchNews() {
if (_invalidated)
return true;
updateLastFetched(); updateLastFetched();
String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY, String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY,
ConfigUpdateHandler.DEFAULT_REFRESH_FREQUENCY); ConfigUpdateHandler.DEFAULT_REFRESH_FREQUENCY);
@ -155,6 +158,16 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
return false; return false;
} }
} }
/**
* Call this when changing news URLs to force an update next time the timer fires.
* @since 0.8.7
*/
void invalidateNews() {
_lastModified = null;
_invalidated = true;
}
public void fetchNews() { public void fetchNews() {
String newsURL = ConfigUpdateHelper.getNewsURL(_context); String newsURL = ConfigUpdateHelper.getNewsURL(_context);
boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue(); boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
@ -172,6 +185,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
get.addStatusListener(this); get.addStatusListener(this);
if (get.fetch()) { if (get.fetch()) {
_lastModified = get.getLastModified(); _lastModified = get.getLastModified();
_invalidated = false;
} else { } else {
// backup news location - always proxied // backup news location - always proxied
_tempFile.delete(); _tempFile.delete();