Class | Irc::Bot::Registry |
In: |
lib/rbot/registry/bdb.rb
lib/rbot/registry/tc.rb |
Parent: | Object |
# File lib/rbot/registry/bdb.rb, line 213 213: def initialize(bot) 214: @bot = bot 215: upgrade_data 216: upgrade_data2 217: end
# File lib/rbot/registry/tc.rb, line 184 184: def initialize(bot) 185: @bot = bot 186: upgrade_data 187: upgrade_data2 188: end
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 193: def upgrade_data 194: if defined? DBHash 195: oldreg = @bot.path 'registry.db' 196: newreg = @bot.path 'plugin_registry.db' 197: if File.exist?(oldreg) 198: log _("upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format") 199: old = ::BDB::Hash.open(oldreg, nil, "r+", 0600) 200: new = TokyoCabinet::CIBDB.new 201: new.open(name, TokyoCabinet::CIBDB::OREADER | TokyoCabinet::CIBDB::OCREAT | TokyoCabinet::CIBDB::OWRITER) 202: old.each_key do |k| 203: new.outlist k 204: new.putlist k, (old.duplicates(k, false)) 205: end 206: old.close 207: new.close 208: File.rename(oldreg, oldreg + ".old") 209: end 210: else 211: warning "Won't upgrade data: BDB not installed" 212: end 213: end
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/bdb.rb, line 222 222: def upgrade_data 223: oldreg = @bot.path 'registry.db' 224: newreg = @bot.path 'plugin_registry.db' 225: if File.exist?(oldreg) 226: log _("upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format") 227: old = BDB::Hash.open(oldreg, nil, "r+", 0600) 228: new = BDB::CIBtree.open(newreg, nil, BDB::CREATE | BDB::EXCL, 0600) 229: old.each {|k,v| 230: new[k] = v 231: } 232: old.close 233: new.close 234: File.rename(oldreg, oldreg + ".old") 235: end 236: end
# File lib/rbot/registry/bdb.rb, line 238 238: def upgrade_data2 239: oldreg = @bot.path 'plugin_registry.db' 240: newdir = @bot.path 'registry' 241: if File.exist?(oldreg) 242: Dir.mkdir(newdir) unless File.exist?(newdir) 243: env = BDB::Env.open(@bot.botclass, BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)# | BDB::TXN_NOSYNC) 244: dbs = Hash.new 245: log _("upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format") 246: old = BDB::CIBtree.open(oldreg, nil, "r+", 0600, "env" => env) 247: old.each {|k,v| 248: prefix,key = k.split("/", 2) 249: prefix.downcase! 250: # subregistries were split with a +, now they are in separate folders 251: if prefix.gsub!(/\+/, "/") 252: # Ok, this code needs to be put in the db opening routines 253: dirs = File.dirname("#{@bot.botclass}/registry/#{prefix}.db").split("/") 254: dirs.length.times { |i| 255: dir = dirs[0,i+1].join("/")+"/" 256: unless File.exist?(dir) 257: log _("creating subregistry directory #{dir}") 258: Dir.mkdir(dir) 259: end 260: } 261: end 262: unless dbs.has_key?(prefix) 263: log _("creating db #{@bot.botclass}/registry/#{prefix}.db") 264: dbs[prefix] = BDB::CIBtree.open("#{@bot.botclass}/registry/#{prefix}.db", 265: nil, BDB::CREATE | BDB::EXCL, 266: 0600, "env" => env) 267: end 268: dbs[prefix][key] = v 269: } 270: old.close 271: File.rename(oldreg, oldreg + ".old") 272: dbs.each {|k,v| 273: log _("closing db #{k}") 274: v.close 275: } 276: env.close 277: end 278: end
# File lib/rbot/registry/tc.rb, line 215 215: def upgrade_data2 216: oldreg = @bot.path 'plugin_registry.db' 217: newdir = @bot.path 'registry' 218: if File.exist?(oldreg) 219: Dir.mkdir(newdir) unless File.exist?(newdir) 220: env = BDB::Env.open(@bot.botclass, BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)# | BDB::TXN_NOSYNC) 221: dbs = Hash.new 222: log _("upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format") 223: old = BDB::CIBtree.open(oldreg, nil, "r+", 0600, "env" => env) 224: old.each {|k,v| 225: prefix,key = k.split("/", 2) 226: prefix.downcase! 227: # subregistries were split with a +, now they are in separate folders 228: if prefix.gsub!(/\+/, "/") 229: # Ok, this code needs to be put in the db opening routines 230: dirs = File.dirname("#{@bot.botclass}/registry/#{prefix}.db").split("/") 231: dirs.length.times { |i| 232: dir = dirs[0,i+1].join("/")+"/" 233: unless File.exist?(dir) 234: log _("creating subregistry directory #{dir}") 235: Dir.mkdir(dir) 236: end 237: } 238: end 239: unless dbs.has_key?(prefix) 240: log _("creating db #{@bot.botclass}/registry/#{prefix}.db") 241: dbs[prefix] = TokyoCabinet::CIBDB.open("#{@bot.botclass}/registry/#{prefix}.db", 242: TokyoCabinet::CIBDB::OREADER | TokyoCabinet::CIBDB::OCREAT | TokyoCabinet::CIBDB::OWRITER) 243: end 244: dbs[prefix][key] = v 245: } 246: old.close 247: File.rename(oldreg, oldreg + ".old") 248: dbs.each {|k,v| 249: log _("closing db #{k}") 250: v.close 251: } 252: env.close 253: end 254: end