This is not a bug any longer.
[oweals/opkg-lede.git] / libopkg / opkg_download.c
index 080326cae4a153a0da6efef11c10f4399b0ace2f..b1f009fa937ee9ce8e439d1dae273528ff5dcd67 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#include <libgen.h>
 
 #include "opkg_download.h"
 #include "opkg_message.h"
@@ -90,7 +91,7 @@ opkg_download(const char *src, const char *dest_file_name,
     char *tmp_file_location;
 
     opkg_msg(NOTICE,"Downloading %s.\n", src);
-       
+
     if (str_starts_with(src, "file:")) {
        const char *file_src = src + 5;
        opkg_msg(INFO, "Copying %s to %s...", file_src, dest_file_name);
@@ -144,7 +145,7 @@ opkg_download(const char *src, const char *dest_file_name,
            opkg_msg(ERROR, "Failed to download %s: %s.\n",
                    src, curl_easy_strerror(res));
            free(tmp_file_location);
-           return res;
+           return -1;
        }
 
     }
@@ -174,7 +175,7 @@ opkg_download(const char *src, const char *dest_file_name,
       if (res) {
        opkg_msg(ERROR, "Failed to download %s, wget returned %d.\n", src, res);
        free(tmp_file_location);
-       return res;
+       return -1;
       }
     }
 #endif
@@ -199,6 +200,13 @@ opkg_download_cache(const char *src, const char *dest_file_name,
        goto out1;
     }
 
+    if(!file_is_dir(conf->cache)){
+           opkg_msg(ERROR, "%s is not a directory.\n",
+                           conf->cache);
+           err = 1;
+           goto out1;
+    }
+
     for (p = cache_name; *p; p++)
        if (*p == '/')
            *p = ',';   /* looks nicer than | or # */
@@ -244,7 +252,7 @@ opkg_download_pkg(pkg_t *pkg, const char *dir)
 
     sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
 
-    /* XXX: BUG: The pkg->filename might be something like
+    /* The pkg->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. */
@@ -262,7 +270,7 @@ opkg_download_pkg(pkg_t *pkg, const char *dir)
 }
 
 /*
- * Downloads file from url, installs in package database, return package name. 
+ * Downloads file from url, installs in package database, return package name.
  */
 int
 opkg_prepare_url_for_install(const char *url, char **namep)
@@ -310,7 +318,7 @@ opkg_prepare_url_for_install(const char *url, char **namep)
      pkg->dest = conf->default_dest;
      pkg->state_want = SW_INSTALL;
      pkg->state_flag |= SF_PREFER;
-     hash_insert_pkg(pkg, 1);  
+     hash_insert_pkg(pkg, 1);
 
      if (namep) {
          *namep = pkg->name;
@@ -331,14 +339,14 @@ opkg_verify_file (char *text_file, char *sig_file)
     gpgme_verify_result_t result;
     gpgme_signature_t s;
     char *trusted_path = NULL;
-    
+
     err = gpgme_new (&ctx);
 
     if (err)
        return -1;
 
     sprintf_alloc(&trusted_path, "%s/%s", conf->offline_root, "/etc/opkg/trusted.gpg");
-    err = gpgme_data_new_from_file (&key, trusted_path, 1); 
+    err = gpgme_data_new_from_file (&key, trusted_path, 1);
     free (trusted_path);
     if (err)
     {
@@ -352,14 +360,14 @@ opkg_verify_file (char *text_file, char *sig_file)
     }
     gpgme_data_release (key);
 
-    err = gpgme_data_new_from_file (&sig, sig_file, 1); 
+    err = gpgme_data_new_from_file (&sig, sig_file, 1);
     if (err)
     {
        gpgme_release (ctx);
        return -1;
     }
 
-    err = gpgme_data_new_from_file (&text, text_file, 1); 
+    err = gpgme_data_new_from_file (&text, text_file, 1);
     if (err)
     {
         gpgme_data_release (sig);