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,8 +76,10 @@ public final class FileConfigStore implements ConfigStore {
final File replacementFile = fileFor(replacement);
if (!replacementFile.createNewFile())
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());
}
}
@Override