From: graham.gower Date: Fri, 27 Nov 2009 00:42:00 +0000 (+0000) Subject: Provide error checking for users of pkg_extract_* functions. X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6afed21188df0c417349563621302ec85f44096f;p=oweals%2Fopkg-lede.git Provide error checking for users of pkg_extract_* functions. git-svn-id: http://opkg.googlecode.com/svn/trunk@391 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index 0fb3c85..572d8b7 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -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); diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index 49a48a0..a92a2ad 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -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; diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c index 8817591..594214b 100644 --- a/libopkg/opkg_install.c +++ b/libopkg/opkg_install.c @@ -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"); diff --git a/libopkg/opkg_remove.c b/libopkg/opkg_remove.c index f744585..f53ef00 100644 --- a/libopkg/opkg_remove.c +++ b/libopkg/opkg_remove.c @@ -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) diff --git a/libopkg/pkg.c b/libopkg/pkg.c index 278b727..58c133d 100644 --- a/libopkg/pkg.c +++ b/libopkg/pkg.c @@ -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);