Method: Debian::AptPkg::PkgCache.packages

Defined in:
ext/apt_pkg/pkgcache.cpp

.packagesArray?

A list of Debian::AptPkg::Package objects stored in the cache Raise ‘Debian::AptPkg::InitError` when config, system, cache is not configured.

Debian::AptPkg::PkgCache.packages

Returns:

  • (Array, nil)

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/apt_pkg/pkgcache.cpp', line 101

static VALUE
packages(int argc, VALUE *argv, VALUE self)
{
  if (!config_system_initialized()) {
    rb_raise(e_mDebianAptPkgInitError, "System not initialized");
  }
  VALUE result = rb_ary_new();
  pkgCacheFile CacheFile;
  if (CacheFile.GetPkgCache() == 0) {
    return Qnil;
  }
  for (pkgCache::PkgIterator Pkg = CacheFile.GetPkgCache()->PkgBegin(); not Pkg.end(); ++Pkg) {
    VALUE current_version;
    if (Pkg->CurrentVer == 0) {
      current_version = Qnil;
    } else {
      current_version = rb_struct_new(rb_cVersion,
          rb_str_new2(Pkg.CurrentVer().ParentPkg().Name()),
          rb_str_new2(Pkg.CurrentVer().VerStr()),
          rb_str_new2(Pkg.CurrentVer().Section()),
          rb_str_new2(Pkg.CurrentVer().Arch()),
          INT2FIX(Pkg.CurrentVer()->Size),
          INT2FIX(Pkg.CurrentVer()->InstalledSize),
          INT2FIX(Pkg.CurrentVer()->Hash),
          INT2FIX(Pkg.CurrentVer()->ID),
          INT2FIX(Pkg.CurrentVer()->Priority)
          );
    }
    VALUE rb_cPackage_args[7];
    rb_cPackage_args[0] = INT2FIX(Pkg->ID);
    rb_cPackage_args[1] = rb_str_new2(Pkg.Name());
    rb_cPackage_args[2] = rb_str_new2(Pkg.FullName().c_str());
    rb_cPackage_args[3] = rb_str_new2(Pkg.Arch());
    rb_cPackage_args[4] = INT2BOOL((Pkg->Flags & pkgCache::Flag::Essential) != 0);
    rb_cPackage_args[5] = INT2BOOL((Pkg->Flags & pkgCache::Flag::Important) != 0);
    rb_cPackage_args[6] = current_version;
    rb_ary_push(result, rb_class_new_instance(7,
          rb_cPackage_args,
          rb_cPackage
          ));
  }
  return result;
}