FileConfigStore: cleanup on rename problem

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-01-10 23:26:12 +01:00
parent f8ee7dcce9
commit 7a618c1463

View File

@ -76,9 +76,11 @@ public final class FileConfigStore implements ConfigStore {
final File replacementFile = fileFor(replacement); final File replacementFile = fileFor(replacement);
if (!replacementFile.createNewFile()) if (!replacementFile.createNewFile())
throw new IOException("Configuration for " + replacement + " already exists"); throw new IOException("Configuration for " + replacement + " already exists");
if (!file.renameTo(replacementFile)) if (!file.renameTo(replacementFile)) {
replacementFile.delete();
throw new IOException("Cannot rename configuration file " + file.getName()); 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 {