#include #include #include #include #include #include #include #include #include #include #include #include #include #include "apt.h" int aptBackend::opencache (void) { if (pkgInitConfig (*_config) == false) return 0; if (pkgInitSystem (*_config, _system) == false) return 0; FileFd *fd = new FileFd (_config->FindFile ("Dir::Cache::pkgcache"), FileFd::ReadOnly); MMap *map = new MMap (*fd, MMap::Public|MMap::ReadOnly); if (_error->PendingError () == true) { _error->DumpErrors (); return 0; } pkgCache *cgCache = new pkgCache (map); if (0 == cgCache) return 0; if (_error->PendingError () == true) { _error->DumpErrors (); return 0; } return 1; } aptBackend aptB; aptBackend::ret_vector aptBackend::getPackages (void) { aptB.opencache (); char id_buf[30]; char size_buf[30]; aptBackend::pack_vector packages; pkgCache *cgCache = 0; pkgCache &cache = *cgCache; pkgRecords Recs (cache); for (pkgCache::PkgIterator I = cache.PkgBegin(); !I.end(); I++) { aptB.avail = false; for (pkgCache::VerIterator V = I.VersionList(); V.end() == false; V++) { pkgRecords::Parser &P = Recs.Lookup (V.FileList ()); aptB.name = I.Name(); aptB.filename = V.FileList ().File ().FileName (); aptB.isize = V->Size; sprintf (size_buf, "%d", aptB.isize); aptB.size = size_buf; aptB.iid = I->ID; sprintf (id_buf, "%d", aptB.iid); aptB.id = id_buf; aptB.version = V.VerStr (); aptB.shortDesc = P.ShortDesc ().c_str (); aptB.longDesc = P.LongDesc ().c_str (); for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++) { // dep = (aptDep*) g_malloc0(sizeof(aptDep)); /* ********* FIXME ********** dep->id = D.TargetPkg ()->ID; pack->depends = dep; pack->depends=g_list_prepend(pack->depends, dep); * ********************************************** */ } packages.push_back (aptB.name); packages.push_back (aptB.filename); packages.push_back (aptB.size); packages.push_back (aptB.id); packages.push_back (aptB.version); packages.push_back (aptB.shortDesc); packages.push_back (aptB.longDesc); aptB.avail = true; } if (!aptB.avail) { aptB.name = I.Name (); aptB.filename = ""; aptB.size = ""; aptB.iid = I->ID; sprintf (id_buf, "%d", aptB.iid); aptB.id = id_buf; aptB.version = ""; aptB.depends = "0"; packages.push_back (aptB.name); packages.push_back (aptB.filename); packages.push_back (aptB.size); packages.push_back (aptB.id); packages.push_back (aptB.version); packages.push_back (aptB.depends); } } /* ret = (aptPackageRet*)g_malloc0(sizeof(aptPackageRet)); ret->list = list; ret->map = packmap; return ret; */ return packages; } void aptBackend::show (void) { aptB.opencache (); pkgCache *cgCache = 0; pkgCache &cache = *cgCache; string s = ""; pkgRecords Recs(cache); for (pkgCache::PkgIterator I = cache.PkgBegin(); !I.end(); I++) { for (pkgCache::VerIterator V = I.VersionList(); V.end() == false; V++) { pkgRecords::Parser &P = Recs.Lookup(V.FileList()); cout << I.Name() << " " << I->ID << " " << I.Section() << " " << V.FileList().File()->Size << " " << V.VerStr() << " " << P.LongDesc() << " " << endl; for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++) cout << " Depends: " << D.TargetPkg().Name() << ' ' << D.TargetVer() << " " << D.TargetPkg()->ID << endl; } cout << "---------" << endl; } }