opkg: fix the -force_space option
[oweals/opkg-lede.git] / libopkg / opkg_conf.c
index 0479b8a364b9b9d26747ee7370085396777fe2c1..8e9060223b1500a8fa4ddda149671f9ef52276db 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "xregex.h"
 #include "sprintf_alloc.h"
-#include "opkg_conf.h"
+#include "args.h"
 #include "opkg_message.h"
 #include "file_util.h"
 #include "str_util.h"
@@ -32,6 +32,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <errno.h>
+
+extern char *conf_file_dir;
 
 static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
                                pkg_src_list_t *pkg_src_list,
@@ -72,6 +75,10 @@ int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options)
          { "proxy_user", OPKG_OPT_TYPE_STRING, &conf->proxy_user },
          { "query-all", OPKG_OPT_TYPE_BOOL, &conf->query_all },
          { "verbosity", OPKG_OPT_TYPE_BOOL, &conf->verbosity },
+#if defined(HAVE_OPENSSL)
+         { "signature_ca_file", OPKG_OPT_TYPE_STRING, &conf->signature_ca_file },
+         { "signature_ca_path", OPKG_OPT_TYPE_STRING, &conf->signature_ca_path },
+#endif
          { NULL }
      };
 
@@ -106,11 +113,12 @@ static void opkg_conf_free_string(char **conf_str)
 int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
 {
      int err;
+     int errno_copy;
      char *tmp_dir_base;
      nv_pair_list_t tmp_dest_nv_pair_list;
      char *lists_dir = NULL, *lock_file = NULL;
      glob_t globbuf;
-     char *etc_opkg_conf_pattern = "/etc/opkg/*.conf";
+     char *etc_opkg_conf_pattern;
      char *pending_dir = NULL;
 
      memset(conf, 0, sizeof(opkg_conf_t));
@@ -133,12 +141,19 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
 
      conf->lock_fd = creat (lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
      err = lockf (conf->lock_fd, F_TLOCK, 0);
+     errno_copy = errno;
 
      free (lock_file);
 
      if (err)
      {
-       opkg_message (conf, OPKG_ERROR, "Could not obtain administrative lock\n");
+       if(args->offline_root) {
+         opkg_message (conf, OPKG_ERROR, "Could not obtain administrative lock for offline root (ERR: %s)  at %s/%s/lock\n",
+                 strerror(errno_copy), args->offline_root, OPKG_STATE_DIR_PREFIX);
+       } else {
+         opkg_message (conf, OPKG_ERROR, "Could not obtain administrative lock (ERR: %s) at %s/lock\n",
+                 strerror(errno_copy), OPKG_STATE_DIR_PREFIX);
+       }
        return OPKG_CONF_ERR_LOCK;
      }
 
@@ -192,10 +207,11 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
 
      if (args->offline_root) 
          sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", args->offline_root);
+     else
+         sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf", conf_file_dir);
      memset(&globbuf, 0, sizeof(globbuf));
      err = glob(etc_opkg_conf_pattern, 0, NULL, &globbuf);
-     if (args->offline_root)
-          free (etc_opkg_conf_pattern);
+     free (etc_opkg_conf_pattern);
      if (!err) {
          int i;
          for (i = 0; i < globbuf.gl_pathc; i++) {
@@ -248,6 +264,9 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
      if (args->force_downgrade) {
          conf->force_downgrade = 1;
      }
+     if (args->force_space) {
+         conf->force_space = 1;
+     }
      if (args->force_reinstall) {
          conf->force_reinstall = 1;
      }
@@ -352,6 +371,11 @@ void opkg_conf_deinit(opkg_conf_t *conf)
 
      opkg_conf_free_string(&conf->cache);
 
+#if defined(HAVE_OPENSSL)
+     opkg_conf_free_string(&conf->signature_ca_file);
+     opkg_conf_free_string(&conf->signature_ca_path);
+#endif
+
      if (conf->verbosity > 1) { 
          int i;
          hash_table_t *hashes[] = {
@@ -654,7 +678,7 @@ int opkg_conf_write_status_files(opkg_conf_t *conf)
      pkg_dest_t *dest;
      pkg_vec_t *all;
      pkg_t *pkg;
-     register int i;
+     int i;
      int err;
      FILE * status_file=NULL;