because of the file_hash_set_file_owner may break the file list of pkgs
[project/opkg-lede.git] / libopkg / opkg_install.c
index 8625f6214dffecab9afb5fddf4caad408b6a4c84..15a5ecc96918f7c255d2f31d7d75feef4ba1680b 100644 (file)
@@ -138,7 +138,7 @@ int opkg_install_from_file(opkg_conf_t *conf, const char *filename)
 
 opkg_error_t opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name)
 {
-     int cmp, err;
+     int cmp, err = 0;
      pkg_t *old, *new;
      char *old_version, *new_version;
 
@@ -432,9 +432,11 @@ static int 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(new_pkg);
-     str_list_elt_t *iter;
+     str_list_elt_t *iter, *niter;
 
-     for (iter = str_list_first(new_list); iter; iter = str_list_next(new_list, iter)) {
+     for (iter = str_list_first(new_list), niter = str_list_next(new_list, iter); 
+             iter; 
+             iter = niter, niter = str_list_next(new_list, niter)) {
          char *new_file = (char *)iter->data;
          pkg_t *owner = file_hash_get_file_owner(conf, new_file);
          if (!new_file)
@@ -444,7 +446,9 @@ static int update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_p
      }
      if (old_pkg) {
          str_list_t *old_list = pkg_get_installed_files(old_pkg);
-         for (iter = str_list_first(old_list); iter; iter = str_list_next(old_list, iter)) {
+         for (iter = str_list_first(old_list), niter = str_list_next(old_list, iter); 
+                  iter; 
+                  iter = niter, niter = str_list_next(old_list, niter)) {
               char *old_file = (char *)iter->data;
               pkg_t *owner = file_hash_get_file_owner(conf, old_file);
               if (owner == old_pkg) {
@@ -832,7 +836,7 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      char *list_file_name, *sig_file_name, *lists_dir;
 
      /* check to ensure the package has come from a repository */
-     if (pkg->src)
+     if (conf->check_signature && pkg->src)
      {
        sprintf_alloc (&lists_dir, "%s",
                      (conf->restrict_to_default_dest)
@@ -1217,12 +1221,14 @@ static int check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
        other package.
      */
      str_list_t *files_list;
-     str_list_elt_t *iter;
+     str_list_elt_t *iter, *niter;
 
      int clashes = 0;
 
      files_list = pkg_get_installed_files(pkg);
-     for (iter = str_list_first(files_list); iter; iter = str_list_next(files_list, iter)) {
+     for (iter = str_list_first(files_list), niter = str_list_next(files_list, iter); 
+             iter; 
+             iter = niter, niter = str_list_next(files_list, iter)) {
          char *root_filename;
          char *filename = (char *) iter->data;
          root_filename = root_filename_alloc(conf, filename);
@@ -1304,25 +1310,33 @@ static int check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *
        @@@ To change after 1.0 release.
      */
      str_list_t *files_list;
-     str_list_elt_t *iter;
+     str_list_elt_t *iter, *niter;
+
+     char *root_filename = NULL;
 
      int clashes = 0;
 
      files_list = pkg_get_installed_files(pkg);
-     for (iter = str_list_first(files_list); iter; iter = str_list_next(files_list, iter)) {
-         char *root_filename;
+     for (iter = str_list_first(files_list), niter = str_list_next(files_list, iter); 
+             iter; 
+             iter = niter, niter = str_list_next(files_list, niter)) {
          char *filename = (char *) iter->data;
+          if (root_filename) {
+              free(root_filename);
+              root_filename = NULL;
+          }
          root_filename = root_filename_alloc(conf, filename);
          if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
               pkg_t *owner;
 
+              owner = file_hash_get_file_owner(conf, filename);
+
               if (conf->force_overwrite) {
                    /* but we need to change who owns this file */
                    file_hash_set_file_owner(conf, filename, pkg);
                    continue;
               }
 
-              owner = file_hash_get_file_owner(conf, filename);
 
               /* Pre-existing files are OK if owned by a package replaced by new pkg. */
               if (owner) {
@@ -1336,7 +1350,10 @@ static int check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *
               }
 
          }
-         free(root_filename);
+     }
+     if (root_filename) {
+         free(root_filename);
+         root_filename = NULL;
      }
      pkg_free_installed_files(pkg);
 
@@ -1377,7 +1394,7 @@ static int remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
      str_list_elt_t *of;
      str_list_t *new_files;
      str_list_elt_t *nf;
-     str_list_elt_t **niter;
+     hash_table_t new_files_table;
 
      if (old_pkg == NULL) {
          return 0;
@@ -1386,20 +1403,21 @@ static int remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
      old_files = pkg_get_installed_files(old_pkg);
      new_files = pkg_get_installed_files(pkg);
 
+     new_files_table.entries = NULL;
+     hash_table_init("new_files" , &new_files_table, 20);
+     for (nf = str_list_first(new_files); nf; nf = str_list_next(new_files, nf)) {
+         if (nf && nf->data)
+            hash_table_insert(&new_files_table, nf->data, nf->data);
+     }
+
      for (of = str_list_first(old_files); of; of = str_list_next(old_files, of)) {
          pkg_t *owner;
          char *old, *new;
          old = (char *)of->data;
-         for (nf = str_list_first(new_files); nf; nf = str_list_next(new_files, nf)) {
-              new = nf->data;
-              if (strcmp(old, new) == 0) {
-                    niter = &nf;
-                    nf=str_list_next(new_files, nf);
-                    str_list_remove(new_files, niter);
-                    free(new);
-                    goto NOT_OBSOLETE;
-              }
-         }
+          new = (char *) hash_table_get (&new_files_table, old);
+          if (new)
+               continue;
+
          if (file_is_dir(old)) {
               continue;
          }
@@ -1419,11 +1437,9 @@ static int remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
                                 strerror(errno));
               }
          }
-
-     NOT_OBSOLETE:
-         ;
      }
 
+     hash_table_deinit(&new_files_table);
      pkg_free_installed_files(old_pkg);
      pkg_free_installed_files(pkg);