Return negative error code from opkg_download(), not curl error codes.
[oweals/opkg-lede.git] / libopkg / opkg_download.c
index 70627665ae2de59cb638783a6265526ac5462667..cfbf35119311a800a4484b00860ec246527ac3ac 100644 (file)
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 */
+
 #include "config.h"
 
-#include "includes.h"
+#include <stdio.h>
+#include <unistd.h>
+
 #include "opkg_download.h"
 #include "opkg_message.h"
 
@@ -86,8 +89,6 @@ opkg_download(const char *src, const char *dest_file_name,
     char *src_base = basename(src_basec);
     char *tmp_file_location;
 
-    free(src_basec);
-
     opkg_msg(NOTICE,"Downloading %s.\n", src);
        
     if (str_starts_with(src, "file:")) {
@@ -95,13 +96,15 @@ opkg_download(const char *src, const char *dest_file_name,
        opkg_msg(INFO, "Copying %s to %s...", file_src, dest_file_name);
        err = file_copy(file_src, dest_file_name);
        opkg_msg(INFO, "Done.\n");
+        free(src_basec);
        return err;
     }
 
     sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
+    free(src_basec);
     err = unlink(tmp_file_location);
     if (err && errno != ENOENT) {
-       opkg_perror(ERROR, "Failed to unlink %s\n", tmp_file_location);
+       opkg_perror(ERROR, "Failed to unlink %s", tmp_file_location);
        free(tmp_file_location);
        return -1;
     }
@@ -141,7 +144,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;
        }
 
     }
@@ -171,7 +174,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