{
char *conf_file;
char *dest;
-
- int nocheckfordirorfile;
- int noreadfeedsfile;
};
typedef struct args args_t;
args_t args;
char *cmd_name;
opkg_cmd_t *cmd;
+ int nocheckfordirorfile = 0;
+ int noreadfeedsfile = 0;
args_init (&args);
!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") ||
!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)
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)
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;
}
#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 (); }
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
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
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);
}
};
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;
} 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;
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;
}
#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
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)
{
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);