Use vfork()/execvp() instead of system().
[project/opkg-lede.git] / libopkg / opkg_install.c
index 52af71e9aca7812b87650efe2a40d535fe1b3fe3..5e8596bfea1c83c22ab5fbb2dd3e0ee26a6b1028 100644 (file)
@@ -69,8 +69,6 @@ static int remove_disappeared(opkg_conf_t *conf, pkg_t *pkg);
 static int install_data_files(opkg_conf_t *conf, pkg_t *pkg);
 static int resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg);
 
-static int cleanup_temporary_files(opkg_conf_t *conf, pkg_t *pkg);
-
 static int user_prefers_old_conffile(const char *file, const char *backup);
 
 static char *backup_filename_alloc(const char *file_name);
@@ -429,7 +427,7 @@ 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_t *new_list = pkg_get_installed_files(conf, new_pkg);
      str_list_elt_t *iter, *niter;
 
      for (iter = str_list_first(new_list), niter = str_list_next(new_list, iter); 
@@ -443,7 +441,7 @@ static int update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_p
               file_hash_set_file_owner(conf, new_file, new_pkg);
      }
      if (old_pkg) {
-         str_list_t *old_list = pkg_get_installed_files(old_pkg);
+         str_list_t *old_list = pkg_get_installed_files(conf, old_pkg);
          for (iter = str_list_first(old_list), niter = str_list_next(old_list, iter); 
                   iter; 
                   iter = niter, niter = str_list_next(old_list, niter)) {
@@ -1004,10 +1002,6 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
 
          time(&pkg->installed_time);
 
-         opkg_message(conf, OPKG_INFO,
-                      "  cleanup temp files\n");
-         cleanup_temporary_files(conf, pkg);
-
          ab_pkg = pkg->parent;
          if (ab_pkg)
               ab_pkg->state_status = pkg->state_status;
@@ -1034,10 +1028,6 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      UNWIND_REMOVE_INSTALLED_REPLACEES:
          pkg_remove_installed_replacees_unwind(conf, replacees);
 
-         opkg_message(conf, OPKG_INFO,
-                      "  cleanup temp files\n");
-         cleanup_temporary_files(conf, pkg);
-
          opkg_message(conf, OPKG_INFO,
                       "Failed.\n");
 
@@ -1233,7 +1223,7 @@ static int check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
 
      int clashes = 0;
 
-     files_list = pkg_get_installed_files(pkg);
+     files_list = pkg_get_installed_files(conf, 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)) {
@@ -1324,7 +1314,7 @@ static int check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *
 
      int clashes = 0;
 
-     files_list = pkg_get_installed_files(pkg);
+     files_list = pkg_get_installed_files(conf, pkg);
      for (iter = str_list_first(files_list), niter = str_list_next(files_list, iter); 
              iter; 
              iter = niter, niter = str_list_next(files_list, niter)) {
@@ -1408,8 +1398,8 @@ static int remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
          return 0;
      }
 
-     old_files = pkg_get_installed_files(old_pkg);
-     new_files = pkg_get_installed_files(pkg);
+     old_files = pkg_get_installed_files(conf, old_pkg);
+     new_files = pkg_get_installed_files(conf, pkg);
 
      new_files_table.entries = NULL;
      hash_table_init("new_files" , &new_files_table, 20);
@@ -1570,7 +1560,7 @@ static int resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg)
                   if (conf->force_maintainer) {
                       opkg_message(conf, OPKG_NOTICE, "Conffile %s using maintainer's setting.\n", cf_backup);
                   } else if (conf->force_defaults
-                          || user_prefers_old_conffile(cf->name, cf_backup) ) {
+                          || user_prefers_old_conffile(root_filename, cf_backup) ) {
                       rename(cf_backup, root_filename);
                   }
               }
@@ -1620,13 +1610,8 @@ static int user_prefers_old_conffile(const char *file_name, const char *backup)
          }
 
          if (strcmp(response, "d") == 0) {
-              char *cmd;
-
-              free(response);
-              /* XXX: BUG rewrite to use exec or busybox's internal diff */
-              sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
-              xsystem(cmd);
-              free(cmd);
+              const char *argv[] = {"diff", "-u", backup, file_name, NULL};
+              xsystem(argv);
               printf("    [Press ENTER to continue]\n");
               response = file_read_line_alloc(stdin);
               free(response);
@@ -1638,57 +1623,6 @@ static int user_prefers_old_conffile(const char *file_name, const char *backup)
      }
 }
 
-/* XXX: CLEANUP: I'd like to move all of the code for
-   creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
-   it would make sense to cleanup pkg->tmp_unpack_dir directly from
-   pkg_deinit for example). */
-static int cleanup_temporary_files(opkg_conf_t *conf, pkg_t *pkg)
-{
-     DIR *tmp_dir;
-     struct dirent *dirent;
-     char *tmp_file;
-
-#ifdef OPKG_DEBUG_NO_TMP_CLEANUP
-#error
-     opkg_message(conf, OPKG_DEBUG,
-                 "%s: Not cleaning up %s since opkg compiled with OPKG_DEBUG_NO_TMP_CLEANUP\n",
-                 __FUNCTION__, pkg->tmp_unpack_dir);
-     return 0;
-#endif
-
-     if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
-         tmp_dir = opendir(pkg->tmp_unpack_dir);
-         if (tmp_dir) {
-              while (1) {
-                   dirent = readdir(tmp_dir);
-                   if (dirent == NULL) {
-                        break;
-                   }
-                   sprintf_alloc(&tmp_file, "%s/%s",
-                                 pkg->tmp_unpack_dir, dirent->d_name);
-                   if (! file_is_dir(tmp_file)) {
-                        unlink(tmp_file);
-                   }
-                   free(tmp_file);
-              }
-              closedir(tmp_dir);
-              rmdir(pkg->tmp_unpack_dir);
-              free(pkg->tmp_unpack_dir);
-              pkg->tmp_unpack_dir = NULL;
-         }
-     }
-
-     opkg_message(conf, OPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
-                 pkg->name, pkg->local_filename, conf->tmp_dir);
-     if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
-         unlink(pkg->local_filename);
-         free(pkg->local_filename);
-         pkg->local_filename = NULL;
-     }
-
-     return 0;
-}
-
 static char *backup_filename_alloc(const char *file_name)
 {
      char *backup;