adding new flag flag_maintainer
[project/opkg-lede.git] / libopkg / opkg_conf.c
index b61fa3eb7af33bd1ceaac0b1ba057e82a1403247..0479b8a364b9b9d26747ee7370085396777fe2c1 100644 (file)
@@ -51,11 +51,13 @@ 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_maintainer", OPKG_OPT_TYPE_BOOL, &conf->force_maintainer }, 
          { "force_depends", OPKG_OPT_TYPE_BOOL, &conf->force_depends },
          { "force_overwrite", OPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
          { "force_downgrade", OPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
          { "force_reinstall", OPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
          { "force_space", OPKG_OPT_TYPE_BOOL, &conf->force_space },
+          { "check_signature", OPKG_OPT_TYPE_INT, &conf->check_signature }, 
          { "ftp_proxy", OPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
          { "http_proxy", OPKG_OPT_TYPE_STRING, &conf->http_proxy },
          { "no_proxy", OPKG_OPT_TYPE_STRING, &conf->no_proxy },
@@ -63,6 +65,7 @@ int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options)
          { "noaction", OPKG_OPT_TYPE_INT, &conf->noaction },
          { "nodeps", OPKG_OPT_TYPE_BOOL, &conf->nodeps },
          { "offline_root", OPKG_OPT_TYPE_STRING, &conf->offline_root },
+         { "offline_root_path", OPKG_OPT_TYPE_STRING, &conf->offline_root_path },
          { "offline_root_post_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
          { "offline_root_pre_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
          { "proxy_passwd", OPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
@@ -72,7 +75,7 @@ int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options)
          { NULL }
      };
 
-     *options = (opkg_option_t *)malloc(sizeof(tmp));
+     *options = (opkg_option_t *)calloc(1, sizeof(tmp));
      if ( options == NULL ){
         fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
         return -1;
@@ -181,7 +184,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
             lists_dir = tmp;
      }
 
-     pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
+     pending_dir = calloc(1, strlen(lists_dir)+strlen("/pending")+5);
      snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
 
      conf->lists_dir = strdup(lists_dir);
@@ -214,7 +217,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
      }
 
      /* Even if there is no conf file, we'll need at least one dest. */
-     if (tmp_dest_nv_pair_list.head == NULL) {
+     if (nv_pair_list_empty(&tmp_dest_nv_pair_list)) {
          nv_pair_list_append(&tmp_dest_nv_pair_list,
                              OPKG_CONF_DEFAULT_DEST_NAME,
                              OPKG_CONF_DEFAULT_DEST_ROOT_DIR);
@@ -236,6 +239,9 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
      if (args->force_defaults) {
          conf->force_defaults = 1;
      }
+     if (args->force_maintainer) {
+          conf->force_maintainer = 1;
+     }
      if (args->force_overwrite) {
          conf->force_overwrite = 1;
      }
@@ -266,6 +272,8 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
 
      opkg_conf_override_string(&conf->offline_root, 
                               args->offline_root);
+     opkg_conf_override_string(&conf->offline_root_path, 
+                              args->offline_root_path);
      opkg_conf_override_string(&conf->offline_root_pre_script_cmd, 
                               args->offline_root_pre_script_cmd);
      opkg_conf_override_string(&conf->offline_root_post_script_cmd, 
@@ -338,6 +346,7 @@ void opkg_conf_deinit(opkg_conf_t *conf)
                    hash_table_deinit(&conf->obs_file_hash);
 
      opkg_conf_free_string(&conf->offline_root);
+     opkg_conf_free_string(&conf->offline_root_path);
      opkg_conf_free_string(&conf->offline_root_pre_script_cmd);
      opkg_conf_free_string(&conf->offline_root_post_script_cmd);
 
@@ -379,8 +388,8 @@ static int opkg_conf_set_default_dest(opkg_conf_t *conf,
      pkg_dest_list_elt_t *iter;
      pkg_dest_t *dest;
 
-     for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
-         dest = iter->data;
+     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;
@@ -399,8 +408,8 @@ static int set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_
      pkg_src_t *src;
      char *list_file;
 
-     for (iter = pkg_src_list->head; iter; iter = iter->next) {
-          src = iter->data;
+     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;
          }
@@ -425,8 +434,8 @@ static int set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair
      pkg_dest_t *dest;
      char *root_dir;
 
-     for (iter = nv_pair_list->head; iter; iter = iter->next) {
-         nv_pair = iter->data;
+     for (iter = nv_pair_list_first(nv_pair_list); iter; iter = nv_pair_list_next(nv_pair_list, iter)) {
+         nv_pair = (nv_pair_t *)iter->data;
 
          if (conf->offline_root) {
               sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
@@ -642,22 +651,21 @@ static int opkg_conf_set_option(const opkg_option_t *options,
 
 int opkg_conf_write_status_files(opkg_conf_t *conf)
 {
-     pkg_dest_list_elt_t *iter;
      pkg_dest_t *dest;
      pkg_vec_t *all;
      pkg_t *pkg;
      register int i;
      int err;
+     FILE * status_file=NULL;
 
      if (conf->noaction)
          return 0;
-     for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
-         dest = iter->data;
-         dest->status_file = fopen(dest->status_file_tmp_name, "w");
-         if (dest->status_file == NULL) {
-              fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
-                      __FUNCTION__, dest->status_file_name, strerror(errno));
-         }
+
+     dest = (pkg_dest_t *)void_list_first(&conf->pkg_dest_list)->data;
+     status_file = fopen(dest->status_file_tmp_name, "w");
+     if (status_file == NULL) {
+         fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
+                 __FUNCTION__, dest->status_file_tmp_name, strerror(errno));
      }
 
      all = pkg_vec_alloc();
@@ -681,29 +689,25 @@ int opkg_conf_write_status_files(opkg_conf_t *conf)
                       __FUNCTION__, pkg->name);
               continue;
          }
-         if (pkg->dest->status_file) {
-              pkg_print_status(pkg, pkg->dest->status_file);
+         if (status_file) {
+              pkg_print_status(pkg, status_file);
          }
      }
 
      pkg_vec_free(all);
 
-     for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
-         dest = iter->data;
-         if (dest->status_file) {
-              err = ferror(dest->status_file);
-              fclose(dest->status_file);
-              dest->status_file = NULL;
-              if (!err) {
-                   file_move(dest->status_file_tmp_name, dest->status_file_name);
-              } else {
-                   fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
-                           "retaining old %s\n", __FUNCTION__, 
-                           dest->status_file_tmp_name, dest->status_file_name);
-              }
-         }
+     if (status_file) {
+         err = ferror(status_file);
+         fclose(status_file);
+         if (!err) {
+             file_move(dest->status_file_tmp_name, dest->status_file_name);
+         } else {
+             fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
+                     "retaining old %s\n", __FUNCTION__,
+                     dest->status_file_tmp_name, dest->status_file_name);
+         }
+         status_file = NULL;
      }
-
      return 0;
 }