From 27a9539d7786583fd0315c964b2484554aec5a48 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 18 Jan 2011 19:20:56 +0100 Subject: [PATCH] TokyoCabinet pseudo-environment TokyoCabinet does not have an environment feature to automatically manage databases, and in particular there is no simple way to close all open registries on exit. While we do close main registries for all plugins, this is not usually done for sub-registries. Rather than shifting the chore of their management to each plugin, we set up a list of all opened registries, updating it manually and releasing it on shutdown. --- lib/rbot/registry/tc.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rbot/registry/tc.rb b/lib/rbot/registry/tc.rb index c114a1be..4d7393cf 100644 --- a/lib/rbot/registry/tc.rb +++ b/lib/rbot/registry/tc.rb @@ -91,12 +91,21 @@ module Irc module ::TokyoCabinet class CIBDB < TokyoCabinet::BDB + # Since TokyoCabinet does not have the concept of an environment, we have to do the + # database management ourselves. In particular, we have to keep a list of open + # registries to be sure we to close all of them on exit + @@bot_registries=[] + def self.close_bot_registries + @@bot_registries.each { |reg| reg.close } + end + def open(path, omode) res = super if res self.setcmpfunc(Proc.new do |a, b| a.downcase <=> b.downcase end) + @@bot_registries << res end res end @@ -171,7 +180,7 @@ module Irc end def DBTree.cleanup_env() - # no-op + CIBDB.close_bot_registries end end -- 2.32.0.93.g670b81a890