ConfigStore: Add a rename method and implement it
Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
parent
5ce7eba2bf
commit
951afaa9b2
@ -42,6 +42,14 @@ public interface ConfigStore {
|
|||||||
*/
|
*/
|
||||||
Config load(final String name) throws Exception;
|
Config load(final String name) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename the configuration for the tunnel given by {@code name}.
|
||||||
|
*
|
||||||
|
* @param name The identifier for the existing configuration in persistent storage.
|
||||||
|
* @param replacement The new identifier for the configuration in persistent storage.
|
||||||
|
*/
|
||||||
|
void rename(String name, String replacement) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the configuration for an existing tunnel given by {@code name}.
|
* Save the configuration for an existing tunnel given by {@code name}.
|
||||||
*
|
*
|
||||||
|
@ -69,6 +69,17 @@ public final class FileConfigStore implements ConfigStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rename(final String name, final String replacement) throws IOException {
|
||||||
|
Log.d(TAG, "Renaming configuration for tunnel " + name + " to " + replacement);
|
||||||
|
final File file = fileFor(name);
|
||||||
|
final File replacementFile = fileFor(replacement);
|
||||||
|
if (!replacementFile.createNewFile())
|
||||||
|
throw new IOException("Configuration for " + replacement + " already exists");
|
||||||
|
if (!file.renameTo(replacementFile))
|
||||||
|
throw new IOException("Cannot rename configuration file " + file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Config save(final String name, final Config config) throws IOException {
|
public Config save(final String name, final Config config) throws IOException {
|
||||||
Log.d(TAG, "Saving configuration for tunnel " + name);
|
Log.d(TAG, "Saving configuration for tunnel " + name);
|
||||||
|
Loading…
Reference in New Issue
Block a user