r4808 - trunk/src/target/opkg/libopkg
tick at docs.openmoko.org
tick at docs.openmoko.org
Thu Nov 20 11:04:46 CET 2008
Author: tick
Date: 2008-11-20 11:04:46 +0100 (Thu, 20 Nov 2008)
New Revision: 4808
Modified:
trunk/src/target/opkg/libopkg/args.c
trunk/src/target/opkg/libopkg/args.h
trunk/src/target/opkg/libopkg/opkg.c
trunk/src/target/opkg/libopkg/opkg_conf.c
trunk/src/target/opkg/libopkg/opkg_conf.h
trunk/src/target/opkg/libopkg/opkg_download.c
Log:
opkg: adding cache support
opkg-cl --cache <cache_directory>
Thank for Werner
Modified: trunk/src/target/opkg/libopkg/args.c
===================================================================
--- trunk/src/target/opkg/libopkg/args.c 2008-11-20 10:04:22 UTC (rev 4807)
+++ trunk/src/target/opkg/libopkg/args.c 2008-11-20 10:04:46 UTC (rev 4808)
@@ -42,7 +42,8 @@
ARGS_OPT_NODEPS,
ARGS_OPT_VERBOSITY,
ARGS_OPT_MULTIPLE_PROVIDERS,
- ARGS_OPT_AUTOREMOVE
+ ARGS_OPT_AUTOREMOVE,
+ ARGS_OPT_CACHE,
};
int args_init(args_t *args)
@@ -92,6 +93,7 @@
free (args->dest);
free (args->tmp_dir);
+ free (args->cache);
free(args->conf_file);
args->conf_file = NULL;
}
@@ -104,6 +106,7 @@
static struct option long_options[] = {
{"query-all", 0, 0, 'A'},
{"autoremove", 0, 0, ARGS_OPT_AUTOREMOVE},
+ {"cache", 1, 0, ARGS_OPT_CACHE},
{"conf-file", 1, 0, 'f'},
{"conf", 1, 0, 'f'},
{"dest", 1, 0, 'd'},
@@ -180,6 +183,10 @@
case ARGS_OPT_AUTOREMOVE:
args->autoremove = 1;
break;
+ case ARGS_OPT_CACHE:
+ free(args->cache);
+ args->cache = strdup(optarg);
+ break;
case ARGS_OPT_FORCE_DEFAULTS:
args->force_defaults = 1;
break;
@@ -277,6 +284,7 @@
printf("\t 2 informative messages\n");
printf("\t 3 debug output\n");
printf("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
+ printf("\t--cache <directory> Use a package cache\n");
printf("\t-conf <conf_file> Default configuration file location\n");
printf(" is %s/%s\n", ARGS_DEFAULT_CONF_FILE_DIR, ARGS_DEFAULT_CONF_FILE_NAME);
printf("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
Modified: trunk/src/target/opkg/libopkg/args.h
===================================================================
--- trunk/src/target/opkg/libopkg/args.h 2008-11-20 10:04:22 UTC (rev 4807)
+++ trunk/src/target/opkg/libopkg/args.h 2008-11-20 10:04:46 UTC (rev 4808)
@@ -42,6 +42,7 @@
char *offline_root;
char *offline_root_pre_script_cmd;
char *offline_root_post_script_cmd;
+ char *cache;
};
typedef struct args args_t;
Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c 2008-11-20 10:04:22 UTC (rev 4807)
+++ trunk/src/target/opkg/libopkg/opkg.c 2008-11-20 10:04:46 UTC (rev 4808)
@@ -273,6 +273,12 @@
a->offline_root_post_script_cmd = strdup (c->offline_root_post_script_cmd);
}
+ if (c->cache) {
+ if (a->cache)
+ free (a->cache);
+ a->cache = strdup(c->cache);
+ }
+
/* throw away old opkg_conf and start again */
opkg_conf_deinit (opkg->conf);
opkg_conf_init (opkg->conf, opkg->args);
Modified: trunk/src/target/opkg/libopkg/opkg_conf.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_conf.c 2008-11-20 10:04:22 UTC (rev 4807)
+++ trunk/src/target/opkg/libopkg/opkg_conf.c 2008-11-20 10:04:46 UTC (rev 4808)
@@ -49,6 +49,7 @@
int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options)
{
opkg_option_t tmp[] = {
+ { "cache", OPKG_OPT_TYPE_STRING, &conf->cache},
{ "force_defaults", OPKG_OPT_TYPE_BOOL, &conf->force_defaults },
{ "force_depends", OPKG_OPT_TYPE_BOOL, &conf->force_depends },
{ "force_overwrite", OPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
@@ -270,6 +271,8 @@
opkg_conf_override_string(&conf->offline_root_post_script_cmd,
args->offline_root_post_script_cmd);
+ opkg_conf_override_string(&conf->cache, args->cache);
+
/* Pigi: added a flag to disable the checking of structures if the command does not need to
read anything from there.
*/
@@ -338,6 +341,8 @@
opkg_conf_free_string(&conf->offline_root_pre_script_cmd);
opkg_conf_free_string(&conf->offline_root_post_script_cmd);
+ opkg_conf_free_string(&conf->cache);
+
if (conf->verbosity > 1) {
int i;
hash_table_t *hashes[] = {
Modified: trunk/src/target/opkg/libopkg/opkg_conf.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_conf.h 2008-11-20 10:04:22 UTC (rev 4807)
+++ trunk/src/target/opkg/libopkg/opkg_conf.h 2008-11-20 10:04:46 UTC (rev 4808)
@@ -70,6 +70,7 @@
int query_all;
int verbosity;
int noaction;
+ char *cache;
/* proxy options */
char *http_proxy;
Modified: trunk/src/target/opkg/libopkg/opkg_download.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_download.c 2008-11-20 10:04:22 UTC (rev 4807)
+++ trunk/src/target/opkg/libopkg/opkg_download.c 2008-11-20 10:04:46 UTC (rev 4808)
@@ -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 @@
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;
More information about the commitlog
mailing list