[metasrv] fix: get_sled_db() should not panic while holding a lock
@@ -63,9 +63,14 @@ pub fn init_sled_db(path: String) {
}
pub fn get_sled_db() -> sled::Db {
- let x = GLOBAL_SLED.as_ref().lock().unwrap();
- let y = x.as_ref().expect(
- "init_sled_db() or init_temp_sled_db() has to be called before using get_sled_db()",
- );
- y.db.clone()
+ {
+ let guard = GLOBAL_SLED.as_ref().lock().unwrap();
+ let glb_opt = guard.as_ref();
+ match glb_opt {
+ None => {}
+ Some(g) => return g.db.clone(),
+ }
+ }
+
+ panic!("init_sled_db() or init_temp_sled_db() has to be called before using get_sled_db()");
}
