[maemo-commits] [maemo-commits] r8184 - projects/haf/trunk/osso-application-installer/src

From: marivoll at stage.maemo.org marivoll at stage.maemo.org
Date: Mon Nov 20 19:01:30 EET 2006
Author: marivoll
Date: 2006-11-20 19:01:29 +0200 (Mon, 20 Nov 2006)
New Revision: 8184

Modified:
   projects/haf/trunk/osso-application-installer/src/apt-worker.cc
Log:
	* src/apt-worker.cc (handle_request): Dump errors after calling
	cache_init.
	(ensure_cache): New, to retry creating the cache when needed.  Use
	it everywhere instead of testing package_cache for NULLness.


Modified: projects/haf/trunk/osso-application-installer/src/apt-worker.cc
===================================================================
--- projects/haf/trunk/osso-application-installer/src/apt-worker.cc	2006-11-20 15:47:15 UTC (rev 8183)
+++ projects/haf/trunk/osso-application-installer/src/apt-worker.cc	2006-11-20 17:01:29 UTC (rev 8184)
@@ -524,7 +524,10 @@
   free_buf (reqbuf, stack_reqbuf);
 
   if (init_cache_after_request)
-    cache_init (false);
+    {
+      cache_init (false);
+      _error->DumpErrors ();
+    }
 }
 
 void read_certified_conf ();
@@ -597,6 +600,16 @@
     /var/lib/dpkg/status and the various Packages file from the
     repositories.
 
+    - ensure_cache
+
+    This function tries to make sure that there is a valid
+    PACKAGE_CACHE to work with.  It returns true when it succeeds and
+    PACKAGE_CACHE is non-NULL then.  The idea is that if the cache
+    couldn't be created in the past because of some transient error,
+    it might be able to create it now.  Thus, every command handler
+    that needs a cache should call ensure_cache.  When ensure_cache
+    actually does some work, it will send STATUS messages.
+
     - cache_reset ()
 
     This function resets the 'desired' state of the cache to be
@@ -974,6 +987,15 @@
   cache_reset ();
 }
 
+bool
+ensure_cache ()
+{
+  if (package_cache == NULL)
+    cache_init (true);
+
+  return package_cache != NULL;
+}
+
 /* Determine whether a package was installed automatically to satisfy
    a dependency.
 */
@@ -1269,7 +1291,7 @@
   const char *pattern = request.decode_string_in_place ();
   bool show_magic_sys = request.decode_int ();
 
-  if (package_cache == NULL)
+  if (!ensure_cache ())
     {
       response.encode_int (0);
       return;
@@ -1486,7 +1508,7 @@
   info.removable_status = status_unknown;
   info.remove_user_size_delta = 0;
 
-  if (package_cache)
+  if (ensure_cache ())
     {
       pkgDepCache &cache = *package_cache;
       pkgCache::PkgIterator pkg = cache.FindPkg (package);
@@ -1954,7 +1976,7 @@
   const char *package = request.decode_string_in_place ();
   int result_code = rescode_failure;
 
-  if (package_cache)
+  if (ensure_cache ())
     {
       mark_named_package_for_install (package);
       result_code = operation (true);
@@ -1984,7 +2006,7 @@
       DBG ("https_proxy: %s", https_proxy);
     }
 
-  if (package_cache)
+  if (ensure_cache ())
     {
       mark_named_package_for_install (package);
       result_code = operation (false);
@@ -1999,7 +2021,7 @@
 {
   const char *package = request.decode_string_in_place ();
 
-  if (package_cache)
+  if (ensure_cache ())
     {
       pkgDepCache &cache = *package_cache;
       pkgCache::PkgIterator pkg = cache.FindPkg (package);
@@ -2029,7 +2051,7 @@
   const char *package = request.decode_string_in_place ();
   int result_code = rescode_failure;
 
-  if (package_cache)
+  if (ensure_cache ())
     {
       pkgDepCache &cache = *package_cache;
       pkgCache::PkgIterator pkg = cache.FindPkg (package);
@@ -2135,7 +2157,7 @@
 static void
 encode_upgrades ()
 {
-  if (package_cache)
+  if (ensure_cache ())
     {
       pkgDepCache &cache = *package_cache;
 
@@ -2429,7 +2451,8 @@
 
   // As a special case, we try to init the cache again.  Chances are
   // good that it will now succeed because there might be more space
-  // available now.
+  // available now.  We don't use ensure_cache for this since we want
+  // it to happen silently.
 
   if (package_cache == NULL)
     need_cache_init ();
@@ -2525,7 +2548,7 @@
 static bool
 check_dependency (string &package, string &version, unsigned int op)
 {
-  if (package_cache == NULL)
+  if (!ensure_cache ())
     return false;
 
   pkgDepCache &cache = (*package_cache);
@@ -2759,7 +2782,7 @@
   const char *installed_version = NULL;
   int installed_size = 0;
 
-  if (package_cache)
+  if (ensure_cache ())
     {
       pkgDepCache &cache = *package_cache;
       pkgCache::PkgIterator pkg = cache.FindPkg (section.FindS ("Package"));


More information about the maemo-commits mailing list