+ 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;