#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"
| static GList * | apt_list = NULL |
| the list of packages in the cache | |
| static pkgCache * | LangCache = 0 |
| static pkgSourceList * | SrcList = 0 |
| static bool | LoadPkgNames (void) |
| gboolean | apt_init (const gchar *sourcelist, const gchar *suite_codename, gboolean verbose) |
| initialise the apt cache | |
| gint | check_pkg_name (gconstpointer a, gconstpointer b) |
| gboolean | aptcache_lookup (const gchar *pkg) |
| gboolean apt_init | ( | const gchar * | sourcelist, | |
| const gchar * | suite_codename, | |||
| gboolean | verbose | |||
| ) |
initialise the apt cache
When installed this uses the emdebian cache for the current arch.
00079 { 00080 FILE * fout = NULL; 00081 gchar * pkg, * config_str, * path; 00082 MMap *Map = 0; 00083 GError * em_gerr = NULL; 00084 pkgSourceList *SrcList = 0; 00085 gboolean All = _config->FindB("APT::Cache::AllNames","false"); 00086 00087 path = g_strconcat ("/var/lib/langupdate/", suite_codename, "/lists/partial", NULL); 00088 g_mkdir_with_parents (path, 0755); 00089 g_free (path); 00090 path = g_strconcat ("/var/lib/langupdate/", suite_codename, "/archives/partial", NULL); 00091 g_mkdir_with_parents (path, 0755); 00092 g_free (path); 00093 fout = fopen ("/var/lib/langupdate/status", "a"); 00094 fclose (fout); 00095 path = g_strconcat ("/var/lib/langupdate/", suite_codename, "/lists/lock", NULL); 00096 fout = fopen (path, "a"); 00097 fclose (fout); 00098 g_free (path); 00099 config_str = g_strconcat("apt-get ", lu_get_aptstring(), " update", NULL); 00100 g_spawn_command_line_sync (config_str, NULL, NULL, NULL, &em_gerr); 00101 /* always initialise the config BEFORE changing values - init resets everything. */ 00102 g_return_val_if_fail (pkgInitConfig(*_config), FALSE); 00103 g_return_val_if_fail (pkgInitSystem(*_config,_system), FALSE); 00104 if (verbose) 00105 _config->Set("quiet", 2); 00106 else 00107 _config->Set("quiet", 0); 00108 #ifdef FOREIGN 00109 _config->Set("Apt::Architecture", "arm"); 00110 #endif 00111 _config->Set("help", true); 00112 _config->Set("APT::Get::List-Cleanup", "off"); 00113 _config->Set("Apt::Install-Recommends","false"); 00114 _config->Set("Dir", "/var/lib/langupdate"); 00115 _config->Set("Dir::Etc", "/var/lib/langupdate"); 00116 _config->Set("Dir::Etc::SourceList", "/var/lib/langupdate/sources.list"); 00117 _config->Set("Dir::State", suite_codename); 00118 _config->Set("Dir::State::Status", "/var/lib/langupdate/status"); 00119 _config->Set("Dir::Cache", suite_codename); 00120 #ifdef FOREIGN 00121 if (verbose) 00122 _config->Dump(); 00123 #endif 00124 if (_config->FindB("APT::Cache::Generate",true) == false) 00125 Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"), 00126 FileFd::ReadOnly),MMap::Public|MMap::ReadOnly); 00127 else 00128 { 00129 // Open the cache file 00130 SrcList = new pkgSourceList; 00131 if (SrcList->Read(sourcelist) == false) 00132 { 00133 g_error (_("Failed to read sources")); 00134 return false; 00135 } 00136 00137 // Generate it and map it 00138 OpProgress Prog; 00139 pkgMakeStatusCache(*SrcList,Prog,&Map,true); 00140 } 00141 00142 // Print any errors or warnings found during parsing 00143 if (_error->PendingError()) 00144 { 00145 _error->DumpErrors(); 00146 return FALSE; 00147 } 00148 pkgCache Cache(Map); 00149 LangCache = &Cache; 00150 00151 // Print any errors or warnings found during parsing 00152 if (_error->empty() == false) 00153 { 00154 bool Errors = _error->PendingError(); 00155 _error->DumpErrors(); 00156 return Errors == true?100:0; 00157 } 00158 LoadPkgNames(); 00159 return TRUE; 00160 }
| gboolean aptcache_lookup | ( | const gchar * | pkg | ) |
lookup the package name against the cache.
00179 { 00180 GList * available = NULL; 00181 00182 available = g_list_find_custom (apt_list, pkg, check_pkg_name); 00183 if (g_list_length (available)) 00184 return TRUE; 00185 return FALSE; 00186 }
| gint check_pkg_name | ( | gconstpointer | a, | |
| gconstpointer | b | |||
| ) |
| static bool LoadPkgNames | ( | void | ) | [static] |
00058 { 00059 pkgCache &Cache = *LangCache; 00060 pkgCache::PkgIterator I = Cache.PkgBegin(); 00061 bool All = _config->FindB("APT::Cache::AllNames","false"); 00062 for (;I.end() != true; I++) 00063 { 00064 gchar * str; 00065 if (All == false && I->VersionList == 0) 00066 continue; 00067 str = g_strdup(I.Name()); 00068 apt_list = g_list_prepend(apt_list, str); 00069 } 00070 return true; 00071 }
GList* apt_list = NULL [static] |
the list of packages in the cache
pkgCache* LangCache = 0 [static] |
pkgSourceList* SrcList = 0 [static] |
1.5.4