Changeset 4394
- Timestamp:
- 04/23/08 17:40:38 (5 years ago)
- Location:
- trunk/src/target/opkg/libopkg
- Files:
-
- 4 edited
-
opkg.c (modified) (4 diffs)
-
opkg_cmd.c (modified) (3 diffs)
-
opkg_download.c (modified) (4 diffs)
-
opkg_download.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/opkg/libopkg/opkg.c
r4391 r4394 88 88 } 89 89 90 struct _curl_cb_data 91 { 92 opkg_progress_callback_t cb; 93 opkg_t *opkg; 94 void *user_data; 95 int start_range; 96 int finish_range; 97 }; 98 99 int 100 curl_progress_cb (struct _curl_cb_data *cb_data, 101 double t, /* dltotal */ 102 double d, /* dlnow */ 103 double ultotal, 104 double ulnow) 105 { 106 int p = (t) ? d*100/t : 0; 107 static int prev = -1; 108 109 /* prevent the same value being sent twice (can occur due to rounding) */ 110 if (p == prev) 111 return 0; 112 prev = p; 113 114 if (t < 1) 115 return 0; 116 117 (cb_data->cb) (cb_data->opkg, 118 cb_data->start_range + (d/t * ((cb_data->finish_range - cb_data->start_range))), 119 cb_data->user_data); 120 121 return 0; 122 } 90 123 91 124 … … 457 490 char *tmp_file_name; 458 491 FILE *in, *out; 492 struct _curl_cb_data cb_data; 459 493 460 494 sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name); 461 495 462 496 /* XXX: Note: downloading url */ 463 err = opkg_download (opkg->conf, url, tmp_file_name); 497 498 cb_data.cb = progress_callback; 499 cb_data.opkg = opkg; 500 cb_data.user_data = user_data; 501 cb_data.start_range = 100 * sources_done / sources_list_count; 502 cb_data.finish_range = 100 * (sources_done + 1) / sources_list_count; 503 504 err = opkg_download (opkg->conf, url, tmp_file_name, (curl_progress_func) curl_progress_cb, &cb_data); 464 505 465 506 if (err == 0) … … 480 521 } 481 522 else 482 err = opkg_download (opkg->conf, url, list_file_name );523 err = opkg_download (opkg->conf, url, list_file_name, NULL, NULL); 483 524 484 525 if (err) … … 502 543 sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig"); 503 544 504 err = opkg_download (opkg->conf, url, tmp_file_name );545 err = opkg_download (opkg->conf, url, tmp_file_name, NULL, NULL); 505 546 if (err) 506 547 { -
trunk/src/target/opkg/libopkg/opkg_cmd.c
r4357 r4394 227 227 228 228 sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name); 229 err = opkg_download(conf, url, tmp_file_name );229 err = opkg_download(conf, url, tmp_file_name, NULL, NULL); 230 230 if (err == 0) { 231 231 opkg_message (conf, OPKG_NOTICE, "Inflating %s\n", url); … … 243 243 } 244 244 } else 245 err = opkg_download(conf, url, list_file_name );245 err = opkg_download(conf, url, list_file_name, NULL, NULL); 246 246 if (err) { 247 247 failures++; … … 267 267 sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig"); 268 268 269 err = opkg_download(conf, url, tmp_file_name );269 err = opkg_download(conf, url, tmp_file_name, NULL, NULL); 270 270 if (err) { 271 271 failures++; -
trunk/src/target/opkg/libopkg/opkg_download.c
r4389 r4394 34 34 #include "opkg_defines.h" 35 35 36 opkg_download_progress_callback opkg_cb_download_progress = NULL; 37 38 int 39 curl_progress_func (char* url, 40 double t, /* dltotal */ 41 double d, /* dlnow */ 42 double ultotal, 43 double ulnow) 44 { 45 int p = (t) ? d*100/t : 0; 46 47 if (opkg_cb_download_progress) 48 { 49 static int prev = -1; 50 51 /* don't report the same percentage multiple times 52 * (this can occur due to rounding) */ 53 if (prev == p) 54 return 0; 55 prev = p; 56 57 opkg_cb_download_progress (p, url); 58 return 0; 59 } 60 return 0; 61 } 62 63 int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name) 36 int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name, curl_progress_func cb, void *data) 64 37 { 65 38 int err = 0; … … 111 84 curl_easy_setopt (curl, CURLOPT_URL, src); 112 85 curl_easy_setopt (curl, CURLOPT_WRITEDATA, file); 113 curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); 114 curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, src); 115 curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func); 86 curl_easy_setopt (curl, CURLOPT_NOPROGRESS, (cb == NULL)); 87 if (cb) 88 { 89 curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, data); 90 curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, cb); 91 } 116 92 curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); 117 93 if (conf->http_proxy || conf->ftp_proxy) … … 180 156 sprintf_alloc(&pkg->local_filename, "%s/%s", dir, stripped_filename); 181 157 182 err = opkg_download(conf, url, pkg->local_filename );158 err = opkg_download(conf, url, pkg->local_filename, NULL, NULL); 183 159 free(url); 184 160 … … 205 181 206 182 sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base); 207 err = opkg_download(conf, url, tmp_file );183 err = opkg_download(conf, url, tmp_file, NULL, NULL); 208 184 if (err) 209 185 return err; -
trunk/src/target/opkg/libopkg/opkg_download.h
r4357 r4394 22 22 23 23 typedef void (*opkg_download_progress_callback)(int percent, char *url); 24 typedef int (*curl_progress_func)(void *data, double t, double d, double ultotal, double ulnow); 24 25 25 int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name); 26 27 int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name, curl_progress_func cb, void *data); 26 28 int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir); 27 29 /*
Note: See TracChangeset
for help on using the changeset viewer.
