class Irc::Bot::Registry

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

Public Class Methods

new(bot) click to toggle source
# File lib/rbot/registry/bdb.rb, line 213
def initialize(bot)
  @bot = bot
  upgrade_data
  upgrade_data2
end

Public Instance Methods

upgrade_data() click to toggle source

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
def upgrade_data
  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 = BDB::CIBtree.open(newreg, nil, BDB::CREATE | BDB::EXCL, 0600)
    old.each {|k,v|
      new[k] = v
    }
    old.close
    new.close
    File.rename(oldreg, oldreg + ".old")
  end
end
upgrade_data2() click to toggle source
# File lib/rbot/registry/bdb.rb, line 238
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] = BDB::CIBtree.open("#{@bot.botclass}/registry/#{prefix}.db",
          nil, BDB::CREATE | BDB::EXCL,
          0600, "env" => env)
      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