+ progress (pdata, 0);
+
+ /* find dependancies and download them */
+ deps = pkg_vec_alloc ();
+ /* this function does not return the original package, so we insert it later */
+ ndepends = pkg_hash_fetch_unsatisfied_dependencies (opkg->conf, new, deps, &unresolved);
+ if (unresolved)
+ {
+ /* XXX: Error: Could not satisfy dependencies */
+ pkg_vec_free (deps);
+ return OPKG_DEPENDENCIES_FAILED;
+ }
+
+ /* insert the package we are installing so that we download it */
+ pkg_vec_insert (deps, new);
+
+ /* download package and dependancies */
+ for (i = 0; i < deps->len; i++)
+ {
+ pkg_t *pkg;
+ struct _curl_cb_data cb_data;
+ char *url;
+
+ pkg = deps->pkgs[i];
+ if (pkg->local_filename)
+ continue;
+
+ opkg_package_free (pdata.package);
+ pdata.package = old_pkg_to_new (pkg);
+ pdata.action = OPKG_DOWNLOAD;
+
+ if (pkg->src == NULL)
+ {
+ /* XXX: Error: Package not available from any configured src */
+ return OPKG_PACKAGE_NOT_AVAILABLE;
+ }
+
+ sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
+
+ /* Get the filename part, without any directory */
+ stripped_filename = strrchr(pkg->filename, '/');
+ if ( ! stripped_filename )
+ stripped_filename = pkg->filename;
+
+ sprintf_alloc(&pkg->local_filename, "%s/%s", opkg->conf->tmp_dir, stripped_filename);
+
+ cb_data.cb = progress_callback;
+ cb_data.progress_data = &pdata;
+ cb_data.opkg = opkg;
+ cb_data.user_data = user_data;
+ /* 75% of "install" progress is for downloading */
+ cb_data.start_range = 75 * i / deps->len;
+ cb_data.finish_range = 75 * (i + 1) / deps->len;
+
+ err = opkg_download(opkg->conf, url, pkg->local_filename,
+ (curl_progress_func) curl_progress_cb, &cb_data);
+ free(url);
+
+ if (err)
+ {
+ pkg_vec_free (deps);
+ opkg_package_free (pdata.package);
+ return OPKG_DOWNLOAD_FAILED;
+ }
+
+ }
+ pkg_vec_free (deps);
+
+ /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
+ all = pkg_vec_alloc ();
+ pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+ for (i = 0; i < all->len; i++)
+ {
+ all->pkgs[i]->parent->dependencies_checked = 0;
+ }
+ pkg_vec_free (all);
+
+
+ /* 75% of "install" progress is for downloading */
+ opkg_package_free (pdata.package);
+ pdata.package = old_pkg_to_new (new);
+ pdata.action = OPKG_INSTALL;
+ progress (pdata, 75);
+
+ /* unpack the package */
+ err = opkg_install_pkg(opkg->conf, new, 0);
+
+ if (err)
+ {
+ opkg_package_free (pdata.package);
+ switch (err)
+ {
+ case OPKG_INSTALL_ERR_NOT_TRUSTED: return OPKG_GPG_ERROR;
+ case OPKG_INSTALL_ERR_DOWNLOAD: return OPKG_DOWNLOAD_FAILED;
+ case OPKG_INSTALL_ERR_DEPENDENCIES:
+ case OPKG_INSTALL_ERR_CONFLICTS: return OPKG_DEPENDENCIES_FAILED;
+ case OPKG_INSTALL_ERR_ALREADY_INSTALLED: return OPKG_PACKAGE_ALREADY_INSTALLED;
+ case OPKG_INSTALL_ERR_SIGNATURE: return OPKG_GPG_ERROR;
+ case OPKG_INSTALL_ERR_MD5: return OPKG_MD5_ERROR;
+ default: return OPKG_UNKNOWN_ERROR;
+ }
+ }
+
+ progress (pdata, 75);
+
+ /* run configure scripts, etc. */
+ err = opkg_configure_packages (opkg->conf, NULL);
+ if (err)
+ {
+ opkg_package_free (pdata.package);
+ return OPKG_UNKNOWN_ERROR;
+ }
+
+ /* write out status files and file lists */