forked from I2P_Developers/i2p.i2p
configclients: Only save files that have changed when in split config
This commit is contained in:
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -256,12 +257,21 @@ public class ConfigClientsHandler extends FormHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveClientChanges2() throws IOException {
|
private void saveClientChanges2() throws IOException {
|
||||||
|
// will save if not split config
|
||||||
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
|
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
|
||||||
|
// will save if split config
|
||||||
|
List<ClientAppConfig> saveClients = new ArrayList<ClientAppConfig>(clients.size() + 1);
|
||||||
|
boolean isSplitConfig = ClientAppConfig.isSplitConfig(_context);
|
||||||
for (int cur = 0; cur < clients.size(); cur++) {
|
for (int cur = 0; cur < clients.size(); cur++) {
|
||||||
ClientAppConfig ca = clients.get(cur);
|
ClientAppConfig ca = clients.get(cur);
|
||||||
Object val = _settings.get(cur + ".enabled");
|
Object val = _settings.get(cur + ".enabled");
|
||||||
if (! (RouterConsoleRunner.class.getName().equals(ca.className)))
|
if (! (RouterConsoleRunner.class.getName().equals(ca.className))) {
|
||||||
ca.disabled = val == null;
|
boolean newval = val == null;
|
||||||
|
if (ca.disabled != newval) {
|
||||||
|
ca.disabled = newval;
|
||||||
|
saveClients.add(ca);
|
||||||
|
}
|
||||||
|
}
|
||||||
// edit of an existing entry
|
// edit of an existing entry
|
||||||
if (_context.getBooleanProperty(ConfigClientsHelper.PROP_ENABLE_CLIENT_CHANGE) ||
|
if (_context.getBooleanProperty(ConfigClientsHelper.PROP_ENABLE_CLIENT_CHANGE) ||
|
||||||
isAdvanced()) {
|
isAdvanced()) {
|
||||||
@ -277,6 +287,7 @@ public class ConfigClientsHandler extends FormHandler {
|
|||||||
ca.className = clss;
|
ca.className = clss;
|
||||||
ca.args = args;
|
ca.args = args;
|
||||||
ca.clientName = getJettyString("nofilter_name" + cur);
|
ca.clientName = getJettyString("nofilter_name" + cur);
|
||||||
|
saveClients.add(ca);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,12 +310,21 @@ public class ConfigClientsHandler extends FormHandler {
|
|||||||
if (name == null || name.trim().length() <= 0) name = "new client";
|
if (name == null || name.trim().length() <= 0) name = "new client";
|
||||||
ClientAppConfig ca = new ClientAppConfig(clss, name, args, 2*60*1000,
|
ClientAppConfig ca = new ClientAppConfig(clss, name, args, 2*60*1000,
|
||||||
_settings.get(newClient + ".enabled") == null); // true for disabled
|
_settings.get(newClient + ".enabled") == null); // true for disabled
|
||||||
ClientAppConfig.writeClientAppConfig(_context, ca);
|
clients.add(ca);
|
||||||
|
saveClients.add(ca);
|
||||||
addFormNotice(_t("New client added") + ": " + name + " (" + clss + ").");
|
addFormNotice(_t("New client added") + ": " + name + " (" + clss + ").");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Always save, as any of the disabled flags could have changed
|
if (isSplitConfig) {
|
||||||
ClientAppConfig.writeClientAppConfig(_context, clients);
|
// Only save what changed
|
||||||
|
// TODO this will lose other clients in the same file
|
||||||
|
for (ClientAppConfig ca : saveClients) {
|
||||||
|
ClientAppConfig.writeClientAppConfig(_context, ca);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Save all
|
||||||
|
ClientAppConfig.writeClientAppConfig(_context, clients);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,6 +112,19 @@ public class ClientAppConfig {
|
|||||||
uninstallargs = ua;
|
uninstallargs = ua;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only valid for the router's clients (not plugins).
|
||||||
|
* Only valid after getClientApps(ctx) has been called.
|
||||||
|
* @since 0.9.42
|
||||||
|
*/
|
||||||
|
public synchronized static boolean isSplitConfig(RouterContext ctx) {
|
||||||
|
File dir = new File(ctx.getConfigDir(), CLIENT_CONFIG_DIR);
|
||||||
|
return dir.exists() && !configFile(ctx).exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the old config file. Only valid if not a split config.
|
||||||
|
*/
|
||||||
public static File configFile(I2PAppContext ctx) {
|
public static File configFile(I2PAppContext ctx) {
|
||||||
String clientConfigFile = ctx.getProperty(PROP_CLIENT_CONFIG_FILENAME, DEFAULT_CLIENT_CONFIG_FILENAME);
|
String clientConfigFile = ctx.getProperty(PROP_CLIENT_CONFIG_FILENAME, DEFAULT_CLIENT_CONFIG_FILENAME);
|
||||||
File cfgFile = new File(clientConfigFile);
|
File cfgFile = new File(clientConfigFile);
|
||||||
@ -380,6 +393,10 @@ public class ClientAppConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This works for both split and non-split config.
|
||||||
|
* If this is the only config in the file, the file will be deleted;
|
||||||
|
* otherwise the file will be saved with the remaining configs.
|
||||||
|
*
|
||||||
* @return success
|
* @return success
|
||||||
* @throws IllegalArgumentException if cac has a null configfile
|
* @throws IllegalArgumentException if cac has a null configfile
|
||||||
* @since 0.9.42
|
* @since 0.9.42
|
||||||
|
Reference in New Issue
Block a user