diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-10 00:01:31 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-10 00:01:52 -0600 |
commit | 951afaa9b29637d1abb3b6a60f9fdeb6bc27bb1c (patch) | |
tree | 84ea22e6f15f3a313b8c981196b6122c8e0656f9 /app | |
parent | 5ce7eba2bf8b1b879581d32c327bdec6cd251718 (diff) |
ConfigStore: Add a rename method and implement it
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/wireguard/android/configStore/ConfigStore.java | 8 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/configStore/ConfigStore.java b/app/src/main/java/com/wireguard/android/configStore/ConfigStore.java index 1d6d29ea..3995376c 100644 --- a/app/src/main/java/com/wireguard/android/configStore/ConfigStore.java +++ b/app/src/main/java/com/wireguard/android/configStore/ConfigStore.java @@ -43,6 +43,14 @@ public interface ConfigStore { 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}. * * @param name The identifier for the configuration in persistent storage (i.e. the name of diff --git a/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java b/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java index 68dfb485..4bc7a17e 100644 --- a/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java +++ b/app/src/main/java/com/wireguard/android/configStore/FileConfigStore.java @@ -70,6 +70,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 public Config save(final String name, final Config config) throws IOException { Log.d(TAG, "Saving configuration for tunnel " + name); final File file = fileFor(name); |