opkg: fix problems in opkg_install_package and implement opkg_remove_package
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:11:50 +0000 (05:11 +0000)
committerticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:11:50 +0000 (05:11 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@83 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

Makefile.am
libopkg/opkg.c
tests/libopkg_test.c

index e48647768e55b7001f5e9f08c47afe3520f2b657..1ca13829933108987c17a66cea84f6ee1409bb38 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = libbb libopkg src
+SUBDIRS = libbb libopkg src tests
 
 HOST_CPU=@host_cpu@
 BUILD_CPU=@build_cpu@
 
 HOST_CPU=@host_cpu@
 BUILD_CPU=@build_cpu@
index 7340a06b1c4fa3fa99999b3f264910180734145a..3a662d2b24dff2806b53b2b6e43f7756fdc0095e 100644 (file)
@@ -25,6 +25,7 @@
 #include "opkg_install.h"
 #include "opkg_configure.h"
 #include "opkg_download.h"
 #include "opkg_install.h"
 #include "opkg_configure.h"
 #include "opkg_download.h"
+#include "opkg_remove.h"
 
 #include "sprintf_alloc.h"
 #include "file_util.h"
 
 #include "sprintf_alloc.h"
 #include "file_util.h"
@@ -246,7 +247,7 @@ int
 opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   int err;
 opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   int err;
-  char *package_id;
+  char *package_id = NULL;
 
   progress_callback (opkg, 0, user_data);
 
 
   progress_callback (opkg, 0, user_data);
 
@@ -257,6 +258,9 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   /* ... */
   pkg_info_preinstall_check (opkg->conf);
 
   /* ... */
   pkg_info_preinstall_check (opkg->conf);
 
+  if (!package_id)
+    package_id = strdup (package_name);
+
   /* unpack the package */
   if (opkg->conf->multiple_providers)
   {
   /* unpack the package */
   if (opkg->conf->multiple_providers)
   {
@@ -267,23 +271,85 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
     err = opkg_install_by_name (opkg->conf, package_id);
   }
 
     err = opkg_install_by_name (opkg->conf, package_id);
   }
 
+  if (err)
+    return err;
+
   progress_callback (opkg, 75, user_data);
 
   /* run configure scripts, etc. */
   err = opkg_configure_packages (opkg->conf, NULL);
   progress_callback (opkg, 75, user_data);
 
   /* run configure scripts, etc. */
   err = opkg_configure_packages (opkg->conf, NULL);
+  if (err)
+    return err;
 
   /* write out status files and file lists */
   opkg_conf_write_status_files (opkg->conf);
   pkg_write_changed_filelists (opkg->conf);
 
   progress_callback (opkg, 100, user_data);
 
   /* write out status files and file lists */
   opkg_conf_write_status_files (opkg->conf);
   pkg_write_changed_filelists (opkg->conf);
 
   progress_callback (opkg, 100, user_data);
-  return err;
+  return 0;
 }
 
 int
 opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
 }
 
 int
 opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
-  return 1;
+  pkg_t *pkg = NULL;
+  pkg_t *pkg_to_remove;
+
+  if (!opkg)
+    return 1;
+
+  if (!package_name)
+    return 1;
+
+  progress_callback (opkg, 0, user_data);
+
+  pkg_info_preinstall_check (opkg->conf);
+
+  pkg_vec_t *installed_pkgs = pkg_vec_alloc ();
+
+  pkg_hash_fetch_all_installed (&opkg->conf->pkg_hash, installed_pkgs);
+
+  progress_callback (opkg, 25, user_data);
+
+  pkg = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, package_name);
+
+  if (pkg == NULL)
+  {
+    /* XXX: Error: Package not installed. */
+    return 1;
+  }
+
+  if (pkg->state_status == SS_NOT_INSTALLED)
+  {
+    /* XXX:  Error: Package seems to be not installed (STATUS = NOT_INSTALLED). */
+    return 1;
+  }
+
+  progress_callback (opkg, 75, user_data);
+
+  if (opkg->conf->restrict_to_default_dest)
+  {
+    pkg_to_remove = pkg_hash_fetch_installed_by_name_dest (&opkg->conf->pkg_hash,
+                                                           pkg->name,
+                                                           opkg->conf->default_dest);
+  }
+  else
+  {
+    pkg_to_remove = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, pkg->name );
+  }
+
+
+  progress_callback (opkg, 75, user_data);
+
+  opkg_remove_pkg (opkg->conf, pkg_to_remove, 0);
+
+  /* write out status files and file lists */
+  opkg_conf_write_status_files (opkg->conf);
+  pkg_write_changed_filelists (opkg->conf);
+
+
+  progress_callback (opkg, 100, user_data);
+  return 0;
 }
 
 int
 }
 
 int
index 49aef22c9a379dd218f690128cc58d9fcaf4588e..205db5c2c8509122388df109dde66487af00ff03 100644 (file)
@@ -29,5 +29,9 @@ main (int argc, char **argv)
 
   printf ("opkg_install_package returned %d\n", err);
 
 
   printf ("opkg_install_package returned %d\n", err);
 
+  err = opkg_remove_package (opkg, "aspell", progress_callback, "Removing...");
+
+  printf ("opkg_remove_package returned %d\n", err);
+
   opkg_free (opkg);
 }
   opkg_free (opkg);
 }