Skip to content

Commit

Permalink
Rewrite pkgng/pkgdb, load all data once into @db
Browse files Browse the repository at this point in the history
Issue:	#41
  • Loading branch information
bdrewery committed Jul 17, 2013
1 parent cef1c50 commit ab2939f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/pkgtools/pkgdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ def PkgDB.finalizer

def initialize(*args)
@db = nil
if with_pkgng?
@db_driver = "pkg"
return
end
@lock_file = Process.euid == 0 ? LOCK_FILE : nil
@db_version = DB_VERSION
ObjectSpace.define_finalizer(self, PkgDB.finalizer)
Expand Down Expand Up @@ -325,6 +329,8 @@ def set_origin(pkgname, origin)
@db[':mtime'] = Marshal.dump(Time.now)
@db[':origins'] = @installed_ports.join(' ')

return true if with_pkgng?

close_db
rescue => e
raise e if e.class == PkgDB::NeedsPkgNGSupport
Expand Down Expand Up @@ -383,6 +389,7 @@ def up_to_date?
end

def check_db
return true if with_pkgng?
return true if up_to_date? || File.writable?(db_dir)

if $sudo
Expand Down Expand Up @@ -577,9 +584,11 @@ def open_db
retried = false

begin
open_db_for_read!
if not with_pkgng?
open_db_for_read!

check_db_version or raise TypeError, 'database version mismatch/bump detected'
check_db_version or raise TypeError, 'database version mismatch/bump detected'
end

s = @db[':pkgnames']
s.is_a?(String) or raise TypeError, "pkgnames - not a string (#{s.class})"
Expand Down
2 changes: 1 addition & 1 deletion lib/pkgtools/pkgtools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ def config_include?(key, p)

def init_pkgtools_global
# initialize pkgdb first - PortsDB uses PkgDB.instance.db_dir.
$portsdb = PortsDB.instance.setup
$pkgdb = PkgDB.instance.setup
$pkgdb_dir = $pkgdb.db_dir
$portsdb = PortsDB.instance.setup
$ports_dir = $portsdb.ports_dir
$packages_base = ENV['PACKAGES'] || File.join($ports_dir, 'packages')
$packages_dir = File.join($packages_base, 'All')
Expand Down

0 comments on commit ab2939f

Please sign in to comment.