diff options
author | ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2008-12-15 00:28:44 (EST) |
---|---|---|
committer | ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2008-12-15 00:28:44 (EST) |
commit | 2858b18db8d4cbbf5b76fee3abd734c2fc773e12 (patch) | |
tree | cee8c0c3a43b722f62680ed61a943b3273a68f66 /libopkg/opkg_download.c | |
parent | bb746681b0455150179978ddd5e6fadb4d18b0f3 (diff) |
opkg: adding cache support
opkg-cl --cache <cache_directory>
Thank for Werner
git-svn-id: http://opkg.googlecode.com/svn/trunk@154 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg/opkg_download.c')
-rw-r--r-- | libopkg/opkg_download.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index 1875195..5dabeed 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -33,7 +33,8 @@ #include "str_util.h" #include "opkg_defines.h" -int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name, curl_progress_func cb, void *data) +static int do_download(opkg_conf_t *conf, const char *src, + const char *dest_file_name, curl_progress_func cb, void *data) { int err = 0; @@ -135,6 +136,43 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name return 0; } +int opkg_download(opkg_conf_t *conf, const char *src, + const char *dest_file_name, curl_progress_func cb, void *data) +{ + char *cache_name = strdup(src); + char *cache_location, *p; + int err = 0; + + if (!conf->cache || str_starts_with(src, "file:")) { + err = do_download(conf, src, dest_file_name, cb, data); + goto out1; + } + + for (p = cache_name; *p; p++) + if (*p == '/') + *p = ','; /* looks nicer than | or # */ + + sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name); + if (file_exists(cache_location)) + opkg_message(conf, OPKG_NOTICE, "Copying %s\n", cache_location); + else { + err = do_download(conf, src, cache_location, cb, data); + if (err) { + (void) unlink(cache_location); + goto out2; + } + } + + err = file_copy(cache_location, dest_file_name); + + +out2: + free(cache_location); +out1: + free(cache_name); + return err; +} + int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir) { int err; |