Provide error checking for users of pkg_extract_* functions.
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Fri, 27 Nov 2009 00:42:00 +0000 (00:42 +0000)
committergraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Fri, 27 Nov 2009 00:42:00 +0000 (00:42 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@391 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/opkg_cmd.c
libopkg/opkg_download.c
libopkg/opkg_install.c
libopkg/opkg_remove.c
libopkg/pkg.c

index 0fb3c8591a716479d0ca0f295927b38864e08905..572d8b7cb90793475bf519064e4802a37f082885 100644 (file)
@@ -538,7 +538,7 @@ static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv)
 
           opkg_message(conf, OPKG_DEBUG2, "Debug install_cmd: %s  \n",arg );
           err = opkg_prepare_url_for_install(conf, arg, &argv[i]);
-          if (err != EINVAL && err != 0)
+          if (err)
               return err;
      }
      pkg_info_preinstall_check(conf);
@@ -574,7 +574,7 @@ static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv)
               char *arg = argv[i];
 
                err = opkg_prepare_url_for_install(conf, arg, &arg);
-               if (err != EINVAL && err != 0)
+               if (err)
                    return err;
          }
          pkg_info_preinstall_check(conf);
index 49a48a08631cdbfa308026c615abd962dfa1453d..a92a2ad11d0987300a12c95566b57c30440bd46f 100644 (file)
@@ -306,7 +306,7 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
 
      if (!pkg->architecture) {
          opkg_message(conf, OPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
-         return -EINVAL;
+         return -1;
      }
 
      pkg->dest = conf->default_dest;
index 881759179b8043ce0a18877c7e4d090ba14623e5..594214bc8adfe6575fe8b6eb6ba8afd807ccdee9 100644 (file)
@@ -146,9 +146,13 @@ check_conflicts_for(opkg_conf_t *conf, pkg_t *pkg)
 static int
 update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
 {
-     str_list_t *new_list = pkg_get_installed_files(conf, new_pkg);
+     str_list_t *new_list, *old_list;
      str_list_elt_t *iter, *niter;
 
+     new_list = pkg_get_installed_files(conf, new_pkg);
+     if (new_list == NULL)
+            return -1;
+
      for (iter = str_list_first(new_list), niter = str_list_next(new_list, iter); 
              iter; 
              iter = niter, niter = str_list_next(new_list, niter)) {
@@ -159,8 +163,14 @@ update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
          if (!owner || (owner == old_pkg))
               file_hash_set_file_owner(conf, new_file, new_pkg);
      }
+
      if (old_pkg) {
-         str_list_t *old_list = pkg_get_installed_files(conf, old_pkg);
+         old_list = pkg_get_installed_files(conf, old_pkg);
+         if (old_list == NULL) {
+                 pkg_free_installed_files(new_pkg);
+                 return -1;
+         }
+
          for (iter = str_list_first(old_list), niter = str_list_next(old_list, iter); 
                   iter; 
                   iter = niter, niter = str_list_next(old_list, niter)) {
@@ -756,6 +766,9 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
      int clashes = 0;
 
      files_list = pkg_get_installed_files(conf, pkg);
+     if (files_list == NULL)
+            return -1;
+
      for (iter = str_list_first(files_list), niter = str_list_next(files_list, iter); 
              iter; 
              iter = niter, niter = str_list_next(files_list, iter)) {
@@ -829,6 +842,9 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
      return clashes;
 }
 
+/*
+ * XXX: This function sucks, as does the below comment.
+ */
 static int
 check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 {
@@ -845,9 +861,10 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 
      char *root_filename = NULL;
 
-     int clashes = 0;
-
      files_list = pkg_get_installed_files(conf, pkg);
+     if (files_list == NULL)
+            return -1;
+
      for (iter = str_list_first(files_list), niter = str_list_next(files_list, iter); 
              iter; 
              iter = niter, niter = str_list_next(files_list, niter)) {
@@ -888,7 +905,7 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
      }
      pkg_free_installed_files(pkg);
 
-     return clashes;
+     return 0;
 }
 
 static int
@@ -931,12 +948,15 @@ remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
      str_list_elt_t *nf;
      hash_table_t new_files_table;
 
-     if (old_pkg == NULL) {
-         return 0;
-     }
-
      old_files = pkg_get_installed_files(conf, old_pkg);
+     if (old_files == NULL)
+         return -1;
+
      new_files = pkg_get_installed_files(conf, pkg);
+     if (new_files == NULL) {
+          pkg_free_installed_files(old_pkg);
+         return -1;
+     }
 
      new_files_table.entries = NULL;
      hash_table_init("new_files" , &new_files_table, 20);
@@ -1403,7 +1423,11 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
 #endif
 
      if (pkg->tmp_unpack_dir == NULL) {
-         unpack_pkg_control_files(conf, pkg);
+         if (unpack_pkg_control_files(conf, pkg) == -1) {
+              opkg_message(conf, OPKG_ERROR, "Failed to unpack control"
+                             " files from %s.\n", pkg->local_filename);
+              return -1;
+         }
      }
 
      /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
@@ -1473,7 +1497,11 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
               } else {
                    opkg_message(conf, OPKG_INFO,
                                 "  removing obsolesced files\n");
-                   remove_obsolesced_files(conf, pkg, old_pkg);
+                   if (remove_obsolesced_files(conf, pkg, old_pkg)) {
+                       opkg_message(conf, OPKG_ERROR, "Failed to determine "
+                                       "obsolete files from previously "
+                                       "installed %s\n", old_pkg->name);
+                   }
               }
 
                /* removing files from old package, to avoid ghost files */ 
@@ -1484,17 +1512,33 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
 
          opkg_message(conf, OPKG_INFO,
                       "  installing maintainer scripts\n");
-         install_maintainer_scripts(conf, pkg, old_pkg);
+         if (install_maintainer_scripts(conf, pkg, old_pkg)) {
+               opkg_message(conf, OPKG_ERROR, "Failed to extract maintainer"
+                              " scripts for %s. Package debris may remain!\n",
+                              pkg->name);
+               goto pkg_is_hosed;
+         }
 
          /* the following just returns 0 */
          remove_disappeared(conf, pkg);
 
          opkg_message(conf, OPKG_INFO,
                       "  installing data files\n");
-         install_data_files(conf, pkg);
 
-/* read comments from function for detail but I will execute this here as all other tests are ok.*/
+         if (install_data_files(conf, pkg)) {
+               opkg_message(conf, OPKG_ERROR, "Failed to extract data files "
+                              "for %s. Package debris may remain!\n",
+                              pkg->name);
+               goto pkg_is_hosed;
+         }
+
          err = check_data_file_clashes_change(conf, pkg, old_pkg);
+         if (err) {
+               opkg_message(conf, OPKG_ERROR,
+                               "check_data_file_clashes_change() failed for "
+                              "for files belonging to %s.\n",
+                              pkg->name);
+         }
 
          opkg_message(conf, OPKG_INFO,
                       "  resolving conf files\n");
@@ -1537,6 +1581,7 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      UNWIND_REMOVE_INSTALLED_REPLACEES:
          pkg_remove_installed_replacees_unwind(conf, replacees);
 
+pkg_is_hosed:
          opkg_message(conf, OPKG_INFO,
                       "Failed.\n");
 
index f744585a413edc51ce3d1f2dcb77712597fb2b93..f53ef00fbe40631d78e4ed4739f6d1d99ce5ef47 100644 (file)
@@ -329,8 +329,14 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
      pkg_t *owner;
      int rootdirlen = 0;
 
-     str_list_init(&installed_dirs);
      installed_files = pkg_get_installed_files(conf, pkg);
+     if (installed_files == NULL) {
+            opkg_message(conf, OPKG_ERROR, "Failed to determine installed "
+                    "files for %s. None removed.\n", pkg->name);
+            return;
+     }
+
+     str_list_init(&installed_dirs);
 
      /* don't include trailing slash */
      if (conf->offline_root)
index 278b7271d8893717cad42f48d8301296af9c9c47..58c133d0a00d8fd8e989cce82bf4f16abb70e33f 100644 (file)
@@ -309,8 +309,11 @@ pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename)
        }
 
        err = pkg_extract_control_file_to_stream(pkg, control_file);
-       if (err)
+       if (err) {
+               opkg_message(conf, OPKG_ERROR, "Failed to extract control file"
+                               " from %s\n", filename);
                goto err2;
+       }
 
        rewind(control_file);
 
@@ -1152,12 +1155,14 @@ pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg)
          err = pkg_extract_data_file_names_to_stream(pkg, list_file);
          if (err) {
               opkg_message(conf, OPKG_ERROR, "%s: Error extracting file list "
-                              "from %s: %s\n", __FUNCTION__,
-                              pkg->local_filename, strerror(err));
+                              "from %s\n", __FUNCTION__,
+                              pkg->local_filename);
               fclose(list_file);
               unlink(list_file_name);
               free(list_file_name);
-              return pkg->installed_files;
+              str_list_deinit(pkg->installed_files);
+              pkg->installed_files = NULL;
+              return NULL;
          }
          rewind(list_file);
      } else {
@@ -1436,7 +1441,8 @@ pkg_info_preinstall_check(opkg_conf_t *conf)
          str_list_t *installed_files = pkg_get_installed_files(conf, pkg); /* this causes installed_files to be cached */
          str_list_elt_t *iter, *niter;
          if (installed_files == NULL) {
-              opkg_message(conf, OPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
+              opkg_message(conf, OPKG_ERROR, "Failed to determine installed "
+                              "files for pkg %s.\n", pkg->name);
               break;
          }
          for (iter = str_list_first(installed_files), niter = str_list_next(installed_files, iter);