summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-12-10 22:04:35 (EST)
committer graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-12-10 22:04:35 (EST)
commit993e14cd113fccd973c35fd1322625804d5e5142 (patch)
tree782f9a8ddb595a238ee1e1a907fc76fe1b860421
parent307864afe92e3b941d66bb334b32979eac2b41ab (diff)
Move loading of feeds and status files out of opkg_conf_init().
git-svn-id: http://opkg.googlecode.com/svn/trunk@483 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r--libopkg/args.h3
-rw-r--r--libopkg/libopkg.c26
-rw-r--r--libopkg/opkg.c48
-rw-r--r--libopkg/opkg_cmd.c9
-rw-r--r--libopkg/opkg_conf.c101
-rw-r--r--libopkg/pkg_hash.c61
-rw-r--r--libopkg/pkg_hash.h3
7 files changed, 133 insertions, 118 deletions
diff --git a/libopkg/args.h b/libopkg/args.h
index 176d354..82bae56 100644
--- a/libopkg/args.h
+++ b/libopkg/args.h
@@ -22,9 +22,6 @@ struct args
{
char *conf_file;
char *dest;
-
- int nocheckfordirorfile;
- int noreadfeedsfile;
};
typedef struct args args_t;
diff --git a/libopkg/libopkg.c b/libopkg/libopkg.c
index f6fc251..f6f6fe9 100644
--- a/libopkg/libopkg.c
+++ b/libopkg/libopkg.c
@@ -33,6 +33,8 @@ opkg_op (int argc, char *argv[])
args_t args;
char *cmd_name;
opkg_cmd_t *cmd;
+ int nocheckfordirorfile = 0;
+ int noreadfeedsfile = 0;
args_init (&args);
@@ -48,7 +50,7 @@ opkg_op (int argc, char *argv[])
!strcmp(cmd_name,"print_architecture") ||
!strcmp(cmd_name,"print-installation-architecture") ||
!strcmp(cmd_name,"print_installation_architecture") )
- args.nocheckfordirorfile = 1;
+ nocheckfordirorfile = 1;
if ( !strcmp(cmd_name,"flag") ||
!strcmp(cmd_name,"configure") ||
@@ -60,7 +62,7 @@ opkg_op (int argc, char *argv[])
!strcmp(cmd_name,"list_installed") ||
!strcmp(cmd_name,"list-installed") ||
!strcmp(cmd_name,"status") )
- args.noreadfeedsfile = 1;
+ noreadfeedsfile = 1;
cmd = opkg_cmd_find (cmd_name);
if (cmd == NULL)
@@ -75,10 +77,16 @@ opkg_op (int argc, char *argv[])
err = opkg_conf_init (&args);
args_deinit (&args);
if (err)
- {
- print_error_list();
- free_error_list();
- return err;
+ goto err0;
+
+ if (!nocheckfordirorfile) {
+ if (!noreadfeedsfile) {
+ if ((err = pkg_hash_load_feeds()))
+ goto err1;
+ }
+
+ if ((err = pkg_hash_load_status_files()))
+ goto err1;
}
if (cmd->requires_args && opts == argc)
@@ -91,10 +99,16 @@ opkg_op (int argc, char *argv[])
err = opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts));
+
#ifdef HAVE_CURL
opkg_curl_cleanup();
#endif
+err1:
opkg_conf_deinit ();
+err0:
+ print_error_list();
+ free_error_list();
+
return err;
}
diff --git a/libopkg/opkg.c b/libopkg/opkg.c
index 046b5a0..383dfb5 100644
--- a/libopkg/opkg.c
+++ b/libopkg/opkg.c
@@ -33,8 +33,6 @@
#include <libbb/libbb.h>
-args_t *args;
-
#define opkg_assert(expr) if (!(expr)) { \
printf ("opkg: file %s: line %d (%s): Assertation '%s' failed",\
__FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); }
@@ -117,18 +115,28 @@ curl_progress_cb(struct _curl_cb_data *cb_data, double t, /* dltotal */
int
opkg_new()
{
- int err;
+ args_t args;
- args = xcalloc(1, sizeof(args_t));
- args_init(args);
+ args_init(&args);
- err = opkg_conf_init(args);
- if (err) {
- free(args);
- return -1;
- }
+ if (opkg_conf_init(&args))
+ goto err0;
+
+ args_deinit(&args);
+
+ if (pkg_hash_load_feeds())
+ goto err1;
+
+ if (pkg_hash_load_status_files())
+ goto err1;
return 0;
+
+err1:
+ pkg_hash_deinit();
+err0:
+ opkg_conf_deinit();
+ return -1;
}
void
@@ -138,19 +146,25 @@ opkg_free(void)
opkg_curl_cleanup();
#endif
opkg_conf_deinit();
- args_deinit(args);
- free(args);
}
int
opkg_re_read_config_files(void)
{
- /* Unfortunately, the easiest way to re-read the config files right now is to
- * throw away conf and start again */
- opkg_free();
- memset(conf, '\0', sizeof(opkg_conf_t));
- return opkg_new();
+ pkg_hash_deinit();
+ pkg_hash_init();
+
+ if (pkg_hash_load_feeds())
+ goto err;
+
+ if (pkg_hash_load_status_files())
+ goto err;
+
return 0;
+
+err:
+ pkg_hash_deinit();
+ return -1;
}
void
diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c
index 30d3126..439a860 100644
--- a/libopkg/opkg_cmd.c
+++ b/libopkg/opkg_cmd.c
@@ -1213,12 +1213,5 @@ opkg_cmd_find(const char *name)
int
opkg_cmd_exec(opkg_cmd_t *cmd, int argc, const char **argv)
{
- int result;
-
- result = (cmd->fun)(argc, argv);
-
- print_error_list();
- free_error_list();
-
- return result;
+ return (cmd->fun)(argc, argv);
}
diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c
index 47b5438..1afa612 100644
--- a/libopkg/opkg_conf.c
+++ b/libopkg/opkg_conf.c
@@ -84,56 +84,7 @@ opkg_option_t options[] = {
};
static int
-opkg_conf_set_default_dest(const char *default_dest_name)
-{
- pkg_dest_list_elt_t *iter;
- pkg_dest_t *dest;
-
- for (iter = void_list_first(&conf->pkg_dest_list); iter; iter = void_list_next(&conf->pkg_dest_list, iter)) {
- dest = (pkg_dest_t *)iter->data;
- if (strcmp(dest->name, default_dest_name) == 0) {
- conf->default_dest = dest;
- conf->restrict_to_default_dest = 1;
- return 0;
- }
- }
-
- opkg_msg(ERROR, "Unknown dest name: `%s'.\n", default_dest_name);
-
- return 1;
-}
-
-static int
-set_and_load_pkg_src_list(pkg_src_list_t *pkg_src_list)
-{
- pkg_src_list_elt_t *iter;
- pkg_src_t *src;
- char *list_file;
-
- for (iter = void_list_first(pkg_src_list); iter; iter = void_list_next(pkg_src_list, iter)) {
- src = (pkg_src_t *)iter->data;
- if (src == NULL) {
- continue;
- }
-
- sprintf_alloc(&list_file, "%s/%s",
- conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
- src->name);
-
- if (file_exists(list_file)) {
- if (pkg_hash_add_from_file(list_file, src, NULL, 0)) {
- free(list_file);
- return -1;
- }
- }
- free(list_file);
- }
-
- return 0;
-}
-
-static int
-set_and_load_pkg_dest_list(nv_pair_list_t *nv_pair_list)
+resolve_pkg_dest_list(nv_pair_list_t *nv_pair_list, const char *default_dest_name)
{
nv_pair_list_elt_t *iter;
nv_pair_t *nv_pair;
@@ -148,19 +99,22 @@ set_and_load_pkg_dest_list(nv_pair_list_t *nv_pair_list)
} else {
root_dir = xstrdup(nv_pair->value);
}
+
dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, conf->lists_dir);
free(root_dir);
- if (dest == NULL) {
- continue;
- }
- if (conf->default_dest == NULL) {
+
+ if (conf->default_dest == NULL)
conf->default_dest = dest;
+
+ if (default_dest_name && !strcmp(dest->name, default_dest_name)) {
+ conf->default_dest = dest;
+ conf->restrict_to_default_dest = 1;
}
- if (file_exists(dest->status_file_name)) {
- if (pkg_hash_add_from_file(dest->status_file_name,
- NULL, dest, 1))
- return -1;
- }
+ }
+
+ if (default_dest_name && !conf->restrict_to_default_dest) {
+ opkg_msg(ERROR, "Unknown dest name: `%s'.\n", default_dest_name);
+ return -1;
}
return 0;
@@ -548,33 +502,12 @@ opkg_conf_init(const args_t *args)
OPKG_CONF_DEFAULT_DEST_ROOT_DIR);
}
- if (!(args->nocheckfordirorfile)) {
-
- if (!(args->noreadfeedsfile)) {
- if (set_and_load_pkg_src_list(&conf->pkg_src_list)) {
- nv_pair_list_deinit(&tmp_dest_nv_pair_list);
- return -1;
- }
- }
-
- /* Now that we have resolved conf->offline_root, we can commit to
- the directory names for the dests and load in all the package
- lists. */
- if (set_and_load_pkg_dest_list(&tmp_dest_nv_pair_list)) {
- nv_pair_list_deinit(&tmp_dest_nv_pair_list);
- return -1;
- }
-
- if (args->dest) {
- err = opkg_conf_set_default_dest(args->dest);
- if (err) {
- nv_pair_list_deinit(&tmp_dest_nv_pair_list);
- return -1;
- }
- }
- }
+ err = resolve_pkg_dest_list(&tmp_dest_nv_pair_list, args->dest);
nv_pair_list_deinit(&tmp_dest_nv_pair_list);
+ if (err)
+ return -1;
+
return 0;
}
diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c
index 5b4fe4b..f5d4782 100644
--- a/libopkg/pkg_hash.c
+++ b/libopkg/pkg_hash.c
@@ -28,6 +28,8 @@
#include "pkg_hash.h"
#include "pkg_parse.h"
#include "opkg_utils.h"
+#include "sprintf_alloc.h"
+#include "file_util.h"
#include "libbb/libbb.h"
void
@@ -126,6 +128,65 @@ pkg_hash_add_from_file(const char *file_name,
return ret;
}
+/*
+ * Load in feed files from the cached "src" and/or "src/gz" locations.
+ */
+int
+pkg_hash_load_feeds(void)
+{
+ pkg_src_list_elt_t *iter;
+ pkg_src_t *src;
+ char *list_file, *lists_dir;
+
+ opkg_msg(INFO, "\n");
+
+ lists_dir = conf->restrict_to_default_dest ?
+ conf->default_dest->lists_dir : conf->lists_dir;
+
+ for (iter = void_list_first(&conf->pkg_src_list); iter;
+ iter = void_list_next(&conf->pkg_src_list, iter)) {
+
+ src = (pkg_src_t *)iter->data;
+
+ sprintf_alloc(&list_file, "%s/%s", lists_dir, src->name);
+
+ if (file_exists(list_file)) {
+ if (pkg_hash_add_from_file(list_file, src, NULL, 0)) {
+ free(list_file);
+ return -1;
+ }
+ }
+ free(list_file);
+ }
+
+ return 0;
+}
+
+/*
+ * Load in status files from the configured "dest"s.
+ */
+int
+pkg_hash_load_status_files(void)
+{
+ pkg_dest_list_elt_t *iter;
+ pkg_dest_t *dest;
+
+ opkg_msg(INFO, "\n");
+
+ for (iter = void_list_first(&conf->pkg_dest_list); iter;
+ iter = void_list_next(&conf->pkg_dest_list, iter)) {
+
+ dest = (pkg_dest_t *)iter->data;
+
+ if (file_exists(dest->status_file_name)) {
+ if (pkg_hash_add_from_file(dest->status_file_name, NULL, dest, 1))
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
static abstract_pkg_t *
abstract_pkg_fetch_by_name(const char * pkg_name)
{
diff --git a/libopkg/pkg_hash.h b/libopkg/pkg_hash.h
index 67134d2..0ff18aa 100644
--- a/libopkg/pkg_hash.h
+++ b/libopkg/pkg_hash.h
@@ -32,6 +32,9 @@ void pkg_hash_fetch_available(pkg_vec_t *available);
int pkg_hash_add_from_file(const char *file_name, pkg_src_t *src,
pkg_dest_t *dest, int is_status_file);
+int pkg_hash_load_feeds(void);
+int pkg_hash_load_status_files(void);
+
void hash_insert_pkg(pkg_t *pkg, int set_status);
abstract_pkg_t * ensure_abstract_pkg_by_name(const char * pkg_name);