aptcache.cc File Reference


Detailed Description

Query the apt cache.

Author:
Neil Williams <codehelp@debian.org>

Definition in file aptcache.cc.

#include "config.h"
#include <iostream>
#include <string>
#include <apt-pkg/init.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/error.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/pkgcachegen.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/policy.h>
#include <apt-pkg/pkgsystem.h>
#include <glib.h>
#include <glib/gi18n.h>
#include "langupdate.h"

Go to the source code of this file.
static GList * apt_list = NULL
 the list of packages in the cache
static GHashTable * src_table = NULL
 Hash table of source packages.
static const gchar * apt_quiet = "-q -q"
 support full quiet mode for apt
static pkgCache * LangCache = 0
static pkgSourceList * SrcList = 0
static bool LoadPkgNames (void)
static bool LoadSourceNames (gint verbose)
void lu_clear_caches (void)
gboolean apt_init (const gchar *sourcelist, const gchar *suite_codename, gint verbose)
gint check_pkg_name (gconstpointer a, gconstpointer b)
gboolean aptcache_lookup (const gchar *pkg)
gchar * lu_get_sourcepkg (const gchar *binary)


Function Documentation

gboolean aptcache_lookup ( const gchar *  pkg  ) 

lookup the package name against the cache.

Definition at line 257 of file aptcache.cc.

00258 {
00259     GList * available = NULL;
00260 
00261     available = g_list_find_custom (apt_list, pkg, check_pkg_name);
00262     if (g_list_length (available))
00263         return TRUE;
00264     return FALSE;
00265 }

gint check_pkg_name ( gconstpointer  a,
gconstpointer  b 
)

compare package names.

Definition at line 248 of file aptcache.cc.

00249 {
00250     gchar * test, * avail;
00251     test =  (gchar*)a;
00252     avail = (gchar*)b;
00253     return g_strcmp0 (test, avail);
00254 }

static bool LoadSourceNames ( gint  verbose  )  [static]

Bug:
Work out how to get the complete SrcList into a HashTable instead of spawning all the time.

Definition at line 79 of file aptcache.cc.

00080 {
00081     gchar * apt, *config_str, *out, *src, *bin;
00082     gchar ** lines, **name;
00083     guint c;
00084     GList * p;
00085 
00086     pkgSrcRecords SrcRecs(*SrcList);
00087     pkgSrcRecords::Parser *Parse;
00088     src_table = g_hash_table_new (g_str_hash, g_str_equal);
00089 
00090     p = NULL;
00091     for (p = apt_list; p != NULL; p=p->next)
00092     {
00093         bin = g_strdup ((gchar*)p->data);
00094         while ((Parse = SrcRecs.Find(bin, false)) != 0)
00095         {
00096             string aptstr;
00097 
00098             /* never gets executed - FIXME */
00099             if (verbose >= 4)
00100                 g_message ("Inside SrcRecs.Find - not using workaround.");
00101             aptstr = Parse->AsStr();
00102             src = g_strdup(aptstr.data());
00103             g_hash_table_insert (src_table, bin, src);
00104         }
00105     }
00106     if (g_hash_table_size (src_table) > 0)
00107         return true;
00108     /* remove this broken workaround */
00109     p = NULL;
00110     for (p = apt_list; p != NULL; p=p->next)
00111     {
00112         bin = g_strdup ((gchar*)p->data);
00113         apt = g_strconcat ("apt-cache ", NULL);
00114         config_str = g_strconcat(apt, lu_get_aptstring(), " show ", bin, NULL);
00115         g_spawn_command_line_sync (config_str, &out, NULL, NULL, NULL);
00116         g_free (apt);
00117         g_free (config_str);
00118         lines = g_strsplit (out, "\n", -1);
00119         for (c = 0; c <= g_strv_length(lines); c++)
00120         {
00121             if (!lines[c])
00122                 continue;
00123             if (g_str_has_prefix (lines[c], "Source: "))
00124             {
00125                 name = g_strsplit (lines[c], ":", -1);
00126                 src = g_strdup (name[1]);
00127                 src = g_strstrip (src);
00128                 if (verbose >= 4)
00129                     g_printerr ("DEBUG:Adding %s (%s)\n", bin, src);
00130                 g_hash_table_insert (src_table, bin, src);
00131                 g_strfreev (name);
00132             }
00133         }
00134         g_strfreev (lines);
00135     }
00136     return true;
00137 }

void lu_clear_caches ( void   ) 

clear the source package table

Definition at line 140 of file aptcache.cc.

00141 {
00142     g_hash_table_destroy (src_table);
00143 }

gchar* lu_get_sourcepkg ( const gchar *  binary  ) 

get the equivalent source package name for the supplied binary

Definition at line 268 of file aptcache.cc.

00269 {
00270     gchar * src;
00271 
00272     src = NULL;
00273     src = (gchar*)g_hash_table_lookup (src_table, binary);
00274     return src;
00275 }


Generated on Sun Jan 18 17:25:32 2009 for langupdate by  doxygen 1.5.6