This class is now used purely for upgrading from prior versions of rbot the new registry is split into multiple DBHash objects, one per plugin
This class is now used purely for upgrading from prior versions of rbot the new registry is split into multiple DBHash objects, one per plugin
check for older versions of rbot with data formats that require updating NB this function is called early in init(), pretty much all you have to work with is @bot.botclass.
# File lib/rbot/registry/tc.rb, line 193 def upgrade_data if defined? DBHash oldreg = @bot.path 'registry.db' newreg = @bot.path 'plugin_registry.db' if File.exist?(oldreg) log _("upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format") old = ::BDB::Hash.open(oldreg, nil, "r+", 0600) new = TokyoCabinet::CIBDB.new new.open(name, TokyoCabinet::CIBDB::OREADER | TokyoCabinet::CIBDB::OCREAT | TokyoCabinet::CIBDB::OWRITER) old.each_key do |k| new.outlist k new.putlist k, (old.duplicates(k, false)) end old.close new.close File.rename(oldreg, oldreg + ".old") end else warning "Won't upgrade data: BDB not installed" end end
# File lib/rbot/registry/tc.rb, line 215 def upgrade_data2 oldreg = @bot.path 'plugin_registry.db' newdir = @bot.path 'registry' if File.exist?(oldreg) Dir.mkdir(newdir) unless File.exist?(newdir) env = BDB::Env.open(@bot.botclass, BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)# | BDB::TXN_NOSYNC) dbs = Hash.new log _("upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format") old = BDB::CIBtree.open(oldreg, nil, "r+", 0600, "env" => env) old.each {|k,v| prefix,key = k.split("/", 2) prefix.downcase! # subregistries were split with a +, now they are in separate folders if prefix.gsub!(/\+/, "/") # Ok, this code needs to be put in the db opening routines dirs = File.dirname("#{@bot.botclass}/registry/#{prefix}.db").split("/") dirs.length.times { |i| dir = dirs[0,i+1].join("/")+"/" unless File.exist?(dir) log _("creating subregistry directory #{dir}") Dir.mkdir(dir) end } end unless dbs.has_key?(prefix) log _("creating db #{@bot.botclass}/registry/#{prefix}.db") dbs[prefix] = TokyoCabinet::CIBDB.open("#{@bot.botclass}/registry/#{prefix}.db", TokyoCabinet::CIBDB::OREADER | TokyoCabinet::CIBDB::OCREAT | TokyoCabinet::CIBDB::OWRITER) end dbs[prefix][key] = v } old.close File.rename(oldreg, oldreg + ".old") dbs.each {|k,v| log _("closing db #{k}") v.close } env.close end end
Generated with the Darkfish Rdoc Generator 2.