Logo Search packages:      
Sourcecode: langupdate version File versions  Download package

gboolean apt_init ( const gchar *  sourcelist,
const gchar *  suite_codename,
const gchar *  prefix,
gint  verbose 
)

initialise the apt cache

When installed this uses the emdebian cache for the current arch.

Definition at line 130 of file aptcache.cc.

References apt_quiet, and lu_get_aptstring().

Referenced by main().

{
      FILE * fout = NULL;
      gchar * config_str, * path, *quiet, * apt, * out, *errstr;
      MMap *Map = 0;
      GError * em_gerr = NULL;

      out = errstr = NULL;
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/", suite_codename,
                                           "/lists/partial", NULL);
      g_mkdir_with_parents (path, 0755);
      g_free (path);
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/", suite_codename,
                                           "/archives/partial", NULL);
      g_mkdir_with_parents (path, 0755);
      g_free (path);
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/status", NULL);
      fout = fopen (path, "a");
      fclose (fout);
      g_free (path);
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/", suite_codename,
                                           "/lists/lock", NULL);
      fout = fopen (path, "a");
      fclose (fout);
      g_free (path);
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/var/log/apt/", NULL);
      g_mkdir_with_parents (path, 0755);
      g_free (path);
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/", suite_codename,
                                           "/pkgcache.bin", NULL);
      fout = fopen (path, "a");
      fclose (fout);
      g_free (path);
      if (verbose <= 1)
            quiet = g_strdup (apt_quiet);
      else if (verbose >= 2)
            quiet = g_strndup(apt_quiet, 2);
      else
            quiet = g_strdup ("");
      apt = g_strconcat ("apt-get ", quiet, NULL);
      config_str = g_strconcat(apt, lu_get_aptstring(), " update", NULL);
      g_free (quiet);
      g_free (apt);
      g_spawn_command_line_sync (config_str, &out, &errstr, NULL, &em_gerr);
      if (em_gerr)
      {
            g_critical (em_gerr->message);
            g_message (_("Unable to execute command: %s\n%s"), config_str, out);
            if (errstr)
                  g_message (_("Error message was: %s"), errstr);
            g_clear_error (&em_gerr);
      }
      if (verbose >= 4)
            g_print ("%s: %s\n", PACKAGE, config_str);
      /* always initialise the config BEFORE changing values - init resets everything. */
      g_return_val_if_fail (pkgInitConfig(*_config), FALSE);
      g_return_val_if_fail (pkgInitSystem(*_config,_system), FALSE);
      if (verbose <= 1)
            _config->Set("quiet", 2);
      else
            _config->Set("quiet", 0);
      _config->Set("Apt::Architecture", HOST_CPU);
      _config->Set("help", true);
      _config->Set("APT::Get::List-Cleanup", "on");
      _config->Set("Apt::Install-Recommends","false");
      path = g_build_filename (prefix, "/var/lib/"PACKAGE, NULL);
      _config->Set("Dir",      path);
      _config->Set("Dir::Etc", path);
      g_free (path);
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/sources.list", NULL);
      _config->Set("Dir::Etc::SourceList", path);
      g_free (path);
      _config->Set("Dir::State", suite_codename);
      path = g_build_filename (prefix, "/var/lib/"PACKAGE"/status", NULL);
      _config->Set("Dir::State::Status", path);
      g_free (path);
      _config->Set("Dir::Cache", suite_codename);
      if (_config->FindB("APT::Cache::Generate",true) == false)
      {
            Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
                        FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
      }
      else
      {
            // Open the cache file
            SrcList = new pkgSourceList;
            if (SrcList->Read(sourcelist) == false)
            {
                  g_error ("%s: %s", PACKAGE, _("Failed to read sources"));
                  return false;
            }
            
            // Generate it and map it
            OpProgress Prog;
            pkgMakeStatusCache(*SrcList,Prog,&Map,true);
      }

      // Print any errors or warnings found during parsing
      if (_error->PendingError())
      {
            _error->DumpErrors();
            return FALSE;
      }
      pkgCache Cache(Map);
      LangCache = &Cache;

      // Print any errors or warnings found during parsing
      if (_error->empty() == false)
      {
            bool Errors = _error->PendingError();
            _error->DumpErrors();
            return Errors == true?100:0;
      }
      LoadPkgNames();
      LoadSourceNames(verbose);
      return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index