Permalink
Browse files

Fix TC db close on cleanup

When closing the TC db on cleanup, we didn't remove it from the
environment. Override the #close() method to achieve that.
  • Loading branch information...
Oblomov committed Jul 11, 2011
1 parent 2a3bc07 commit 33c582acdb8c57f302145fc3dc01a1bf2d7c8478
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/rbot/registry/tc.rb
View
@@ -117,15 +117,19 @@ def initialize(bot, key, absfilename=false)
if absfilename && File.exist?(key)
# db already exists, use it
@db = DBTree.open_db(key)
+ @fname = key.dup
elsif absfilename
# create empty db
@db = DBTree.create_db(key)
+ @fname = key.dup
elsif File.exist? relfilename
# db already exists, use it
@db = DBTree.open_db relfilename
+ @fname = relfilename.dup
else
# create empty db
@db = DBTree.create_db relfilename
+ @fname = relfilename.dup
end
oldbasename = (absfilename ? key : relfilename).gsub(/\.tdb$/, ".db")
if File.exists? oldbasename and defined? BDB
@@ -155,6 +159,14 @@ def self.close_bot_registries
@@bot_registries.clear
end
+ def close
+ db = @@bot_registries.delete(@fname)
+ if db != @db
+ error "We think we have #{@db} from #{@fname}, TC pseudo-env gives us #{db}"
+ end
+ @db.close
+ end
+
def DBTree.create_db(name)
debug "DBTree: creating empty db #{name}"
if @@bot_registries.key? name

0 comments on commit 33c582a

Please sign in to comment.