Correctly update the obs_file_hash in offline root mode.
[oweals/opkg-lede.git] / libopkg / opkg_install.c
index e014d720c377fa3e4b113f07095097552a36bfba..4889ad89d353a0dae60c085d5ede2031bdebe96f 100644 (file)
@@ -58,7 +58,7 @@ satisfy_dependencies_for(pkg_t *pkg)
                       pkg->name);
          tmp = unresolved;
          while (*unresolved) {
-              opkg_msg(ERROR, "\t%s", *unresolved);
+              opkg_message(ERROR, "\t%s", *unresolved);
               free(*unresolved);
               unresolved++;
          }
@@ -174,7 +174,7 @@ update_file_ownership(pkg_t *new_pkg, pkg_t *old_pkg)
                   iter = niter, niter = str_list_next(old_list, niter)) {
               char *old_file = (char *)iter->data;
               pkg_t *owner = file_hash_get_file_owner(old_file);
-              if (owner == old_pkg) {
+              if (!owner || (owner == old_pkg)) {
                    /* obsolete */
                    hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
               }
@@ -297,7 +297,7 @@ unpack_pkg_control_files(pkg_t *pkg)
 static int
 pkg_remove_orphan_dependent(pkg_t *pkg, pkg_t *old_pkg) 
 {
-       int i, j, k, l, found;
+       int i, j, k, l, found,r, err = 0;
        int n_deps;
        pkg_t *p;
        struct compound_depend *cd0, *cd1;
@@ -362,7 +362,9 @@ pkg_remove_orphan_dependent(pkg_t *pkg, pkg_t *old_pkg)
                                 * which we need to ignore during removal. */
                                p->state_flag |= SF_REPLACE;
 
-                               opkg_remove_pkg(p, 0);
+                               r = opkg_remove_pkg(p, 0);
+                               if (!err)
+                                       err = r;
                        } else 
                                opkg_msg(INFO, "%s was autoinstalled and is "
                                                "still required by %d "
@@ -372,7 +374,7 @@ pkg_remove_orphan_dependent(pkg_t *pkg, pkg_t *old_pkg)
                }
        }
 
-       return 0;
+       return err;
 }
 
 /* returns number of installed replacees */
@@ -483,20 +485,20 @@ opkg_install_check_downgrade(pkg_t *pkg, pkg_t *old_pkg, int message)
          free(new_version);
          return rc;
      } else {
-      char message_out[15] ;
-      memset(message_out,'\x0',15);
-      if ( message ) 
-          strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
-      else
-          strncpy( message_out,"Installing ",strlen("Installing ") );
-         char *version = pkg_version_str_alloc(pkg);
-      
-      if(!conf->download_only)
-          opkg_msg(NOTICE, "%s%s (%s) to %s...\n", message_out,
+          char message_out[15] ;
+          memset(message_out,'\x0',15);
+          if ( message ) 
+               strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
+          else
+               strncpy( message_out,"Installing ",strlen("Installing ") );
+          char *version = pkg_version_str_alloc(pkg);
+
+          if(!conf->download_only)
+               opkg_msg(NOTICE, "%s%s (%s) to %s...\n", message_out,
                   pkg->name, version, pkg->dest->name);
-         free(version);
-         return 0;
+          free(version);
      }
+     return 0;
 }
 
 
@@ -746,7 +748,7 @@ check_data_file_clashes(pkg_t *pkg, pkg_t *old_pkg)
      */
      str_list_t *files_list;
      str_list_elt_t *iter, *niter;
-
+     char *filename;
      int clashes = 0;
 
      files_list = pkg_get_installed_files(pkg);
@@ -756,14 +758,12 @@ check_data_file_clashes(pkg_t *pkg, pkg_t *old_pkg)
      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(filename);
-         if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
+         filename = (char *) iter->data;
+         if (file_exists(filename) && (! file_is_dir(filename))) {
               pkg_t *owner;
               pkg_t *obs;
 
-              if (backup_exists_for(root_filename)) {
+              if (backup_exists_for(filename)) {
                    continue;
               }
 
@@ -814,14 +814,13 @@ check_data_file_clashes(pkg_t *pkg, pkg_t *old_pkg)
                            "\tBut that file is already provided by package ",
                            pkg->name, filename);
               if (owner) {
-                   opkg_msg(ERROR, "%s\n", owner->name);
+                   opkg_message(ERROR, "%s\n", owner->name);
               } else {
-                   opkg_msg(ERROR, "<no package>\n"
+                   opkg_message(ERROR, "<no package>\n"
                        "Please move this file out of the way and try again.\n");
               }
               clashes++;
          }
-         free(root_filename);
      }
      pkg_free_installed_files(pkg);
 
@@ -929,7 +928,7 @@ postrm_upgrade_old_pkg_unwind(pkg_t *pkg, pkg_t *old_pkg)
 static int
 remove_obsolesced_files(pkg_t *pkg, pkg_t *old_pkg)
 {
-     int err;
+     int err = 0;
      str_list_t *old_files;
      str_list_elt_t *of;
      str_list_t *new_files;
@@ -984,7 +983,7 @@ remove_obsolesced_files(pkg_t *pkg, pkg_t *old_pkg)
      pkg_free_installed_files(old_pkg);
      pkg_free_installed_files(pkg);
 
-     return 0;
+     return err;
 }
 
 static int
@@ -1101,7 +1100,7 @@ resolve_conffiles(pkg_t *pkg)
                   } else {
                       char *new_conffile;
                       sprintf_alloc(&new_conffile, "%s-opkg", root_filename);
-                      opkg_msg(NOTICE, "Existing conffile %s "
+                      opkg_msg(ERROR, "Existing conffile %s "
                            "is different from the conffile in the new package."
                            " The new conffile will be placed at %s.\n",
                            root_filename, new_conffile);
@@ -1136,8 +1135,10 @@ opkg_install_by_name(const char *pkg_name)
                        old->version);
     
      new = pkg_hash_fetch_best_installation_candidate_by_name(pkg_name);
-     if (new == NULL)
+     if (new == NULL) {
+       opkg_msg(NOTICE, "Unknown package '%s'.\n", pkg_name);
        return -1;
+     }
 
      opkg_msg(DEBUG2, "Versions from pkg_hash_fetch:");
      if ( old ) 
@@ -1237,7 +1238,7 @@ opkg_install_pkg(pkg_t *pkg, int from_upgrade)
 
      pkg->state_want = SW_INSTALL;
      if (old_pkg){                          
-         old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
+         old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependencies */
      }
 
      err = check_conflicts_for(pkg);