Fail scabbard create on invalid lmdb config
This change fails the creation of a Scabbard service with an
InvalidState error if the factory is not configured to use LMDB state
files, but finds that they exist.
@@ -413,6 +413,8 @@ impl ServiceFactory for ScabbardFactory {
}) as Box<dyn Fn() -> Result<(), InternalError> + Sync + Send>,
)
} else {
+ self.lmdb_state_check(circuit_id, &service_id)?;
+
match &self.store_factory_config {
#[cfg(feature = "postgres")]
ScabbardFactoryStorageConfig::Postgres { pool } => (
@@ -526,6 +528,28 @@ impl ServiceFactory for ScabbardFactory {
}
}
+impl ScabbardFactory {
+ /// Check that the LMDB files doesn't exist for the given service.
+ fn lmdb_state_check(
+ &self,
+ circuit_id: &str,
+ service_id: &str,
+ ) -> Result<(), FactoryCreateError> {
+ let path = self
+ .state_store_factory
+ .compute_path(circuit_id, service_id)
+ .map_err(|e| FactoryCreateError::Internal(e.to_string()))?;
+ if path.with_extension("lmdb").exists() {
+ return Err(InvalidStateError::with_message(format!(
+ "LMDB database files exist for {}::{}, but LMDB storage is not enabled",
+ circuit_id, service_id
+ ))
+ .into());
+ }
+ Ok(())
+ }
+}
+
/// Parse a service argument into a list. Check if the argument is in json or csv format
/// and return the list of strings. An error is returned if json fmt cannot be parsed.
fn parse_list(values_list: &str) -> Result<Vec<String>, String> {
