diff options
| author | Andrew MacBean <macbean@apache.org> | 2014-09-15 14:03:28 +0000 |
|---|---|---|
| committer | Andrew MacBean <macbean@apache.org> | 2014-09-15 14:03:28 +0000 |
| commit | c5c6fbdd6dc6f73321b4e5be840d7533cc932e69 (patch) | |
| tree | 99195b0ad2106ef438d605dac45b676729bf5ab0 /qpid/java | |
| parent | 0cf4fa0b2d77b8e0acc8f0e1ac904c84f6321f64 (diff) | |
| download | qpid-python-c5c6fbdd6dc6f73321b4e5be840d7533cc932e69.tar.gz | |
QPID-6095: [Java Broker] Deletion of an ERRORED JSON VHN with an invalid store path causes an exception
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1625035 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
2 files changed, 11 insertions, 25 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java index 1f5665a0a5..5001086010 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java @@ -90,7 +90,6 @@ public class JsonFileConfigStore implements DurableConfigurationStore private String _name; private FileLock _fileLock; private String _configFileName; - private String _backupFileName; private String _lockFileName; private static final Module _module; @@ -170,14 +169,12 @@ public class JsonFileConfigStore implements DurableConfigurationStore { _directoryName = fileFromSettings.getParent(); _configFileName = fileFromSettings.getName(); - _backupFileName = fileFromSettings.getName() + ".bak"; _lockFileName = fileFromSettings.getName() + ".lck"; } else { _directoryName = configurationStoreSettings.getStorePath(); _configFileName = _name + ".json"; - _backupFileName = _name + ".bak"; _lockFileName = _name + ".lck"; } @@ -187,21 +184,14 @@ public class JsonFileConfigStore implements DurableConfigurationStore if(!fileExists(_configFileName)) { - if(!fileExists(_backupFileName)) + File newFile = new File(_directoryName, _configFileName); + try { - File newFile = new File(_directoryName, _configFileName); - try - { - _objectMapper.writeValue(newFile, Collections.emptyMap()); - } - catch (IOException e) - { - throw new StoreException("Could not write configuration file " + newFile, e); - } + _objectMapper.writeValue(newFile, Collections.emptyMap()); } - else + catch (IOException e) { - renameFile(_backupFileName, _configFileName); + throw new StoreException("Could not write configuration file " + newFile, e); } } } @@ -399,12 +389,8 @@ public class JsonFileConfigStore implements DurableConfigurationStore File tmpFile = File.createTempFile("cfg","tmp", new File(_directoryName)); tmpFile.deleteOnExit(); _objectMapper.writeValue(tmpFile,data); - renameFile(_configFileName,_backupFileName); renameFile(tmpFile.getName(),_configFileName); tmpFile.delete(); - File backupFile = new File(_directoryName, _backupFileName); - backupFile.delete(); - } catch (IOException e) { @@ -581,11 +567,14 @@ public class JsonFileConfigStore implements DurableConfigurationStore @Override public void onDelete() { - if (_configFileName != null && _backupFileName != null) + if (_configFileName != null) { - renameFile(_configFileName,_backupFileName); + File configFile = new File(_directoryName, _configFileName); + if (!configFile.delete()) + { + _logger.info("Failed to delete JSON file config store: " + _configFileName); + } _configFileName = null; - _backupFileName = null; } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java index b652992021..72e14c7a4b 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java @@ -351,14 +351,11 @@ public class JsonFileConfigStoreTest extends QpidTestCase public void testStoreFileLifecycle() { File expectedJsonFile = new File(_storeLocation, _parent.getName() + ".json"); - File expectedJsonFileBak = new File(_storeLocation, _parent.getName() + ".bak"); assertFalse("JSON store should not exist", expectedJsonFile.exists()); - assertFalse("JSON backup should not exist", expectedJsonFileBak.exists()); _store.openConfigurationStore(_parent, false); assertTrue("JSON store should exist after open", expectedJsonFile.exists()); - assertFalse("JSON backup should not exist after open", expectedJsonFileBak.exists()); _store.closeConfigurationStore(); assertTrue("JSON store should exist after close", expectedJsonFile.exists()); |
