I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 6e4df883 authored by zzz's avatar zzz
Browse files

- Force news refetch after URL change

parent 7ab95d01
No related branches found
No related tags found
No related merge requests found
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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment