Permalink
Browse files

download: skip usage of intermediary file for downloading

  • Loading branch information...
falconindy committed Nov 12, 2010
1 parent 8cb1324 commit dcdd6e8f37eabe4ffeeb0304f9fedc2cb5cab9bb
Showing with 17 additions and 16 deletions.
  1. +1 −6 curl.c
  2. +6 −0 curl.h
  3. +10 −10 download.c
View
7 curl.c
@@ -33,12 +33,7 @@
#include "curl.h"
#include "util.h"
-struct response {
- size_t size;
- char *data;
-};
-
-static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *data) {
+size_t write_callback(void *ptr, size_t size, size_t nmemb, void *data) {
size_t realsize = size * nmemb;
struct response *mem = (struct response*)data;
View
6 curl.h
@@ -31,6 +31,12 @@
#define COWER_USERAGENT "cower/2.x"
+struct response {
+ size_t size;
+ char *data;
+};
+
+size_t write_callback(void*, size_t, size_t, void*);
char *curl_textfile_get(const char*);
CURL *curl_local_init(void);
View
@@ -42,7 +42,7 @@
#include "util.h"
#include "yajl.h"
-static int archive_extract_file(const char *file) {
+static int archive_extract_data(const struct response *file) {
struct archive *archive;
struct archive_entry *entry;
const int archive_flags = ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_TIME;
@@ -52,7 +52,7 @@ static int archive_extract_file(const char *file) {
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
- ret = archive_read_open_filename(archive, file, ARCHIVE_DEFAULT_BYTES_PER_BLOCK);
+ ret = archive_read_open_memory(archive, file->data, file->size);
if (ret != ARCHIVE_OK) {
goto finish;
}
@@ -88,7 +88,10 @@ int download_taurball(struct aur_pkg_t *aurpkg) {
CURLcode curlstat;
long httpcode;
int result = 0;
- FILE *fp;
+ struct response response = {
+ .size = 0,
+ .data = NULL
+ };
/* establish download dir */
dir = getcwd(NULL, PATH_MAX);
@@ -118,33 +121,29 @@ int download_taurball(struct aur_pkg_t *aurpkg) {
return(1);
}
- fp = fopen(tarball, "wb");
-
curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curlstat = curl_easy_perform(curl);
if (curlstat != CURLE_OK) {
cwr_fprintf(stderr, LOG_ERROR, "curl: %s\n", curl_easy_strerror(curlstat));
result = 1;
}
- fclose(fp);
-
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpcode);
if (httpcode != 200) {
cwr_fprintf(stderr, LOG_ERROR, "curl: server responded with code %ld\n",
httpcode);
result = 1;
}
- result = archive_extract_file(tarball);
+ result = archive_extract_data(&response);
if (result != ARCHIVE_EOF) { /* still no error, we have success */
cwr_printf(LOG_INFO, "%s%s%s downloaded to %s%s%s\n",
config->strings->pkg, pkgname, config->strings->c_off,
config->strings->uptodate, dir, config->strings->c_off);
- unlink(tarball);
} else {
cwr_fprintf(stderr, LOG_ERROR, "error downloading stuff\n");
}
@@ -154,6 +153,7 @@ int download_taurball(struct aur_pkg_t *aurpkg) {
FREE(url);
FREE(dir);
FREE(tarball);
+ FREE(response.data);
return(result);
}

0 comments on commit dcdd6e8

Please sign in to comment.