libopkg: mark to-be-installed non-local, non-url packages for detail parsing
[oweals/opkg-lede.git] / libopkg / opkg_download.c
index 260790b95adb28d626d4329a3db545bc4d267047..73ff1ac711038fcc213e55064d89770f6e484ffe 100644 (file)
@@ -253,7 +253,9 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir)
 {
        int err;
        char *url;
+       char *local_filename;
        char *stripped_filename;
+       char *filename;
 
        if (pkg->src == NULL) {
                opkg_msg(ERROR,
@@ -261,27 +263,31 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir)
                         pkg->name);
                return -1;
        }
-       if (pkg->filename == NULL) {
+
+       filename = pkg_get_string(pkg, PKG_FILENAME);
+
+       if (filename == NULL) {
                opkg_msg(ERROR,
                         "Package %s does not have a valid filename field.\n",
                         pkg->name);
                return -1;
        }
 
-       sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
+       sprintf_alloc(&url, "%s/%s", pkg->src->value, filename);
 
-       /* The pkg->filename might be something like
+       /* The filename might be something like
           "../../foo.opk". While this is correct, and exactly what we
           want to use to construct url above, here we actually need to
           use just the filename part, without any directory. */
 
-       stripped_filename = strrchr(pkg->filename, '/');
+       stripped_filename = strrchr(filename, '/');
        if (!stripped_filename)
-               stripped_filename = pkg->filename;
+               stripped_filename = filename;
 
-       sprintf_alloc(&pkg->local_filename, "%s/%s", dir, stripped_filename);
+       sprintf_alloc(&local_filename, "%s/%s", dir, stripped_filename);
+       pkg_set_string(pkg, PKG_LOCAL_FILENAME, local_filename);
 
-       err = opkg_download_cache(url, pkg->local_filename, NULL, NULL);
+       err = opkg_download_cache(url, local_filename, NULL, NULL);
        free(url);
 
        return err;
@@ -294,6 +300,7 @@ int opkg_prepare_url_for_install(const char *url, char **namep)
 {
        int err = 0;
        pkg_t *pkg;
+       abstract_pkg_t *ab_pkg;
 
        pkg = pkg_new();
 
@@ -323,10 +330,17 @@ int opkg_prepare_url_for_install(const char *url, char **namep)
                if (err)
                        return err;
                opkg_msg(DEBUG2, "Package %s provided by hand (%s).\n",
-                        pkg->name, pkg->local_filename);
+                        pkg->name, pkg_get_string(pkg, PKG_LOCAL_FILENAME));
                pkg->provided_by_hand = 1;
 
        } else {
+               ab_pkg = ensure_abstract_pkg_by_name(url);
+
+               if (!(ab_pkg->state_flag & SF_NEED_DETAIL)) {
+                       opkg_msg(DEBUG, "applying abpkg flag to %s\n", ab_pkg->name);
+                       ab_pkg->state_flag |= SF_NEED_DETAIL;
+               }
+
                pkg_deinit(pkg);
                free(pkg);
                return 0;