forked from I2P_Developers/i2p.i2p
- Force news refetch after URL change
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.crypto.TrustedUpdate;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.FileUtil;
|
||||
@ -78,7 +77,7 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
if (_action == null)
|
||||
return;
|
||||
if (_action.equals(_("Check for updates"))) {
|
||||
NewsFetcher fetcher = NewsFetcher.getInstance(I2PAppContext.getGlobalContext());
|
||||
NewsFetcher fetcher = NewsFetcher.getInstance(_context);
|
||||
fetcher.fetchNews();
|
||||
if (fetcher.shouldFetchUnsigned())
|
||||
fetcher.fetchUnsignedHead();
|
||||
@ -100,6 +99,7 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
String oldURL = ConfigUpdateHelper.getNewsURL(_context);
|
||||
if ( (oldURL == null) || (!_newsURL.equals(oldURL)) ) {
|
||||
_context.router().setConfigSetting(PROP_NEWS_URL, _newsURL);
|
||||
NewsFetcher.getInstance(_context).invalidateNews();
|
||||
addFormNotice(_("Updating news URL to") + " " + _newsURL);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
||||
private String _updateVersion;
|
||||
private String _unsignedUpdateVersion;
|
||||
private String _lastModified;
|
||||
private boolean _invalidated;
|
||||
private File _newsFile;
|
||||
private File _tempFile;
|
||||
private static NewsFetcher _instance;
|
||||
@ -134,6 +135,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
||||
}
|
||||
|
||||
private boolean shouldFetchNews() {
|
||||
if (_invalidated)
|
||||
return true;
|
||||
updateLastFetched();
|
||||
String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY,
|
||||
ConfigUpdateHandler.DEFAULT_REFRESH_FREQUENCY);
|
||||
@ -155,6 +158,16 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
||||
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() {
|
||||
String newsURL = ConfigUpdateHelper.getNewsURL(_context);
|
||||
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);
|
||||
if (get.fetch()) {
|
||||
_lastModified = get.getLastModified();
|
||||
_invalidated = false;
|
||||
} else {
|
||||
// backup news location - always proxied
|
||||
_tempFile.delete();
|
||||
|
Reference in New Issue
Block a user