unarchive.c \
copy_file.c \
copy_file_chunk.c \
- error_msg.c error_msg_and_die.c \
- perror_msg.c perror_msg_and_die.c \
xreadlink.c \
concat_path_file.c \
- verror_msg.c vperror_msg.c \
- xfuncs.c messages.c \
+ xfuncs.c \
last_char_is.c \
make_directory.c \
safe_strncpy.c \
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void error_msg(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- verror_msg(s, p);
- va_end(p);
- putc('\n', stderr);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void error_msg_and_die(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- verror_msg(s, p);
- va_end(p);
- putc('\n', stderr);
- exit(EXIT_FAILURE);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
int unzip_pipe[2];
if (pipe(unzip_pipe)!=0) {
- perror_msg("%s: pipe", __FUNCTION__);
+ perror_msg("pipe");
return(NULL);
}
if ((*pid = fork()) == -1) {
- perror_msg("%s: fork", __FUNCTION__);
+ perror_msg("fork");
return(NULL);
}
if (*pid==0) {
int ret;
if (waitpid(gunzip_pid, &status, 0) == -1) {
- perror_msg("%s: waitpid", __FUNCTION__);
+ perror_msg("waitpid");
return -1;
}
if (WIFSIGNALED(status)) {
- error_msg("%s: unzip process killed by signal %d\n",
- __FUNCTION__, WTERMSIG(status));
+ error_msg("Unzip process killed by signal %d.\n",
+ WTERMSIG(status));
return -1;
}
if (!WIFEXITED(status)) {
/* shouldn't happen */
- error_msg("%s: Your system is broken: got status %d from waitpid\n",
- __FUNCTION__, status);
+ error_msg("Your system is broken: got status %d from waitpid.\n",
+ status);
return -1;
}
if ((ret = WEXITSTATUS(status))) {
- error_msg("%s: unzip process failed with return code %d.\n",
- __FUNCTION__, ret);
+ error_msg("Unzip process failed with return code %d.\n",
+ ret);
return -1;
}
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
-
+#include <stdlib.h>
#include <netdb.h>
-#include <features.h>
+#include "../libopkg/opkg_message.h"
#ifndef FALSE
#define FALSE ((int) 0)
#define TRUE ((int) 1)
#endif
-extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
-extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
-extern void perror_msg(const char *s, ...);
-extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
-extern void archive_xread_all(int fd, char *buf, size_t count);
+#define error_msg(fmt, args...) opkg_msg(ERROR, fmt"\n", ##args)
+#define perror_msg(fmt, args...) opkg_perror(ERROR, fmt, ##args)
+#define error_msg_and_die(fmt, args...) \
+ do { \
+ error_msg(fmt, ##args); \
+ exit(EXIT_FAILURE); \
+ } while (0)
+#define perror_msg_and_die(fmt, args...) \
+ do { \
+ perror_msg(fmt, ##args); \
+ exit(EXIT_FAILURE); \
+ } while (0)
-/* These two are used internally -- you shouldn't need to use them */
-extern void verror_msg(const char *s, va_list p);
-extern void vperror_msg(const char *s, va_list p);
+extern void archive_xread_all(int fd, char *buf, size_t count);
const char *mode_string(int mode);
const char *time_string(time_t timeVal);
FILEUTILS_FORCE = 8,
};
-extern const char *applet_name;
-extern const char * const memory_exhausted;
-
#endif /* __LIBBB_H__ */
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include "libbb.h"
-
-const char * const memory_exhausted = "memory exhausted";
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void perror_msg(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- vperror_msg(s, p);
- va_end(p);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void perror_msg_and_die(const char *s, ...)
-{
- va_list p;
-
- va_start(p, s);
- vperror_msg(s, p);
- va_end(p);
- exit(EXIT_FAILURE);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
goto cleanup;
}
archive_offset += file_entry->size;
- copy_file_chunk(src_stream, dst_stream, file_entry->size);
+ *err = copy_file_chunk(src_stream, dst_stream, file_entry->size);
fclose(dst_stream);
}
break;
if (mkdir(full_name, file_entry->mode) < 0) {
if ((function & extract_quiet) != extract_quiet) {
*err = -1;
- perror_msg("%s: %s", __FUNCTION__, full_name);
+ perror_msg("Cannot make dir %s", full_name);
}
}
}
else if (extract_function & extract_data_tar_gz) {
ared_file = "data.tar.gz";
} else {
- fprintf(stderr, "no file specified to extract -- extract_function=%x\n", extract_function);
+ opkg_msg(ERROR, "Internal error: extract_function=%x\n",
+ extract_function);
*err = -1;
goto cleanup;
}
/* open a stream of decompressed data */
uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
if (uncompressed_stream == NULL) {
- printf("%s: %d\n", __FUNCTION__, __LINE__);
*err = -1;
goto cleanup;
}
static unsigned long crc; /* shift register contents */
-/* Return codes from gzip */
-static const int ERROR = 1;
-
/*
* window size--must be a power of two, and
* at least 32K for zip's deflate method
static void abort_gzip()
{
error_msg("gzip aborted\n");
- _exit(ERROR);
+ _exit(-1);
}
static void make_crc_table()
}
if (method < 0) {
- printf("it failed\n");
- return(exit_code); /* error message already emitted */
+ return(exit_code);
}
make_crc_table();
int res = inflate();
if (res == 3) {
- error_msg(memory_exhausted);
+ perror_msg("inflate");
exit_code = 1;
} else if (res != 0) {
error_msg("invalid compressed data--format violated");
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void verror_msg(const char *s, va_list p)
-{
- fflush(stdout);
- fprintf(stderr, "%s: ", applet_name);
- vfprintf(stderr, s, p);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void vperror_msg(const char *s, va_list p)
-{
- int err=errno;
- if(s == 0) s = "";
- verror_msg(s, p);
- if (*s) s = ": ";
- fprintf(stderr, "%s%s\n", s, strerror(err));
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
{
void *ptr = malloc(size);
if (ptr == NULL && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("malloc");
return ptr;
}
{
ptr = realloc(ptr, size);
if (ptr == NULL && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("realloc");
return ptr;
}
{
void *ptr = calloc(nmemb, size);
if (ptr == NULL && nmemb != 0 && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("calloc");
return ptr;
}
t = strdup (s);
if (t == NULL)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("strdup");
return t;
}
buf = xrealloc(buf, bufsize += GROWBY);
readsize = readlink(path, buf, bufsize); /* 1st try */
if (readsize == -1) {
- perror_msg("%s:%s", applet_name, path);
+ perror_msg("%s", path);
return NULL;
}
}
opkg_libcore_sources = args.c args.h libopkg.c libopkg.h\
- user.c user.h \
- opkg.c opkg.h includes.h \
- opkg_error.h opkg_defines.h
+ includes.h \
+ opkg.c opkg.h \
+ opkg_defines.h
opkg_cmd_sources = opkg_cmd.c opkg_cmd.h \
opkg_configure.c opkg_configure.h \
opkg_download.c opkg_download.h \
struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) {
struct active_list *next=NULL;
if ( !head ) {
- fprintf(stderr, "active_list_next head = %p, ptr = %p invalid value!!\n", head, ptr);
+ opkg_msg(ERROR, "Internal error: head=%p, ptr=%p\n", head, ptr);
return NULL;
}
if ( !ptr )
struct active_list * active_list_prev(struct active_list *head, struct active_list *ptr) {
struct active_list *prev=NULL;
if ( !head ) {
- fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr);
+ opkg_msg(ERROR, "Internal error: head=%p, ptr=%p\n", head, ptr);
return NULL;
}
if ( !ptr )
node->depended = head;
}
-struct active_list * active_list_head_new() {
+struct active_list * active_list_head_new(void) {
struct active_list * head = xcalloc(1, sizeof(struct active_list));
active_list_init(head);
return head;
};
-struct active_list * active_list_head_new();
+struct active_list * active_list_head_new(void);
void active_list_head_delete(struct active_list *);
void active_list_init(struct active_list *ptr);
void active_list_clear(struct active_list *head);
#include "args.h"
#include "sprintf_alloc.h"
#include "libbb/libbb.h"
+#include "opkg_conf.h"
static void print_version(void);
enum long_args_opt
{
- ARGS_OPT_FORCE_DEFAULTS = 129,
- ARGS_OPT_FORCE_MAINTAINER,
+ ARGS_OPT_FORCE_MAINTAINER = 129,
ARGS_OPT_FORCE_DEPENDS,
ARGS_OPT_FORCE_OVERWRITE,
ARGS_OPT_FORCE_DOWNGRADE,
ARGS_OPT_FORCE_SPACE,
ARGS_OPT_NOACTION,
ARGS_OPT_NODEPS,
- ARGS_OPT_MULTIPLE_PROVIDERS,
ARGS_OPT_AUTOREMOVE,
ARGS_OPT_CACHE,
};
sprintf_alloc(&args->conf_file, "%s/%s", OPKGETCDIR,
ARGS_DEFAULT_CONF_FILE_NAME);
-
- args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
- args->force_maintainer = ARGS_DEFAULT_FORCE_MAINTAINER;
- args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
- args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
- args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
- args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
- args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
- args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
- args->autoremove = ARGS_DEFAULT_AUTOREMOVE;
- args->noaction = ARGS_DEFAULT_NOACTION;
- args->nodeps = ARGS_DEFAULT_NODEPS;
- args->verbosity = ARGS_DEFAULT_VERBOSITY;
- args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
- args->offline_root_path = ARGS_DEFAULT_OFFLINE_ROOT_PATH;
- args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
- args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
- args->multiple_providers = 0;
- args->nocheckfordirorfile = 0;
- args->noreadfeedsfile = 0;
+ conf->verbosity = ARGS_DEFAULT_VERBOSITY;
}
void args_deinit(args_t *args)
{
- free (args->offline_root);
- free (args->offline_root_path);
- free (args->offline_root_pre_script_cmd);
- free (args->offline_root_post_script_cmd);
-
free (args->dest);
- free (args->tmp_dir);
- free (args->cache);
free(args->conf_file);
args->conf_file = NULL;
}
{"conf-file", 1, 0, 'f'},
{"conf", 1, 0, 'f'},
{"dest", 1, 0, 'd'},
- {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
- {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
- {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
- {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
+ {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
+ {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
{"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
{"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
{"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
{"force_removal_of_essential_packages", 0, 0,
ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
- {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
- {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
{"noaction", 0, 0, ARGS_OPT_NOACTION},
{"nodeps", 0, 0, ARGS_OPT_NODEPS},
{"offline", 1, 0, 'o'},
{"offline-root", 1, 0, 'o'},
- {"offline-path", 1, 0, 'p'},
- {"offline-root-path", 1, 0, 'p'},
{"test", 0, 0, ARGS_OPT_NOACTION},
{"tmp-dir", 1, 0, 't'},
{"tmp_dir", 1, 0, 't'},
switch (c) {
case 'A':
- args->query_all = 1;
+ conf->query_all = 1;
break;
case 'd':
args->dest = xstrdup(optarg);
args->conf_file = xstrdup(optarg);
break;
case 'o':
- args->offline_root = xstrdup(optarg);
- break;
- case 'p':
- args->offline_root_path = xstrdup(optarg);
+ conf->offline_root = xstrdup(optarg);
break;
case 't':
- args->tmp_dir = xstrdup(optarg);
+ conf->tmp_dir = xstrdup(optarg);
break;
case 'v':
print_version();
exit(0);
case 'V':
- args->verbosity = atoi(optarg);
+ conf->verbosity = atoi(optarg);
break;
case ARGS_OPT_AUTOREMOVE:
- args->autoremove = 1;
+ conf->autoremove = 1;
break;
case ARGS_OPT_CACHE:
- free(args->cache);
- args->cache = xstrdup(optarg);
- break;
- case ARGS_OPT_FORCE_DEFAULTS:
- args->force_defaults = 1;
+ free(conf->cache);
+ conf->cache = xstrdup(optarg);
break;
case ARGS_OPT_FORCE_MAINTAINER:
- args->force_maintainer = 1;
+ conf->force_maintainer = 1;
break;
case ARGS_OPT_FORCE_DEPENDS:
- args->force_depends = 1;
+ conf->force_depends = 1;
break;
case ARGS_OPT_FORCE_OVERWRITE:
- args->force_overwrite = 1;
+ conf->force_overwrite = 1;
break;
case ARGS_OPT_FORCE_DOWNGRADE:
- args->force_downgrade = 1;
+ conf->force_downgrade = 1;
break;
case ARGS_OPT_FORCE_REINSTALL:
- args->force_reinstall = 1;
+ conf->force_reinstall = 1;
break;
case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
- args->force_removal_of_essential_packages = 1;
+ conf->force_removal_of_essential_packages = 1;
break;
case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
- args->force_removal_of_dependent_packages = 1;
+ conf->force_removal_of_dependent_packages = 1;
break;
case ARGS_OPT_FORCE_SPACE:
- args->force_space = 1;
- break;
- case ARGS_OPT_MULTIPLE_PROVIDERS:
- args->multiple_providers = 1;
+ conf->force_space = 1;
break;
case ARGS_OPT_NODEPS:
- args->nodeps = 1;
+ conf->nodeps = 1;
break;
case ARGS_OPT_NOACTION:
- args->noaction = 1;
+ conf->noaction = 1;
break;
case ':':
- parse_err++;
+ parse_err = -1;
break;
case '?':
- parse_err++;
+ parse_err = -1;
break;
default:
printf("Confusion: getopt_long returned %d\n", c);
}
if (parse_err) {
- return -parse_err;
+ return parse_err;
} else {
return optind;
}
}
-void args_usage(char *complaint)
+void args_usage(const char *complaint)
{
if (complaint) {
printf("opkg: %s\n", complaint);
printf(" directory name in a pinch).\n");
printf("\t-o <dir> Use <dir> as the root directory for\n");
printf("\t--offline-root <dir> offline installation of packages.\n");
- printf("\t--offline-path <path> $PATH for postinsts scripts in offline mode\n");
printf("\nForce Options:\n");
printf("\t--force-depends Install/remove despite failed dependences\n");
- printf("\t--force-defaults Use default options for questions asked by opkg\n");
+ printf("\t--force-maintainer Overwrite preexisting config files\n");
printf("\t--force-reinstall Reinstall package(s)\n");
printf("\t--force-overwrite Overwrite files from other package(s)\n");
printf("\t--force-downgrade Allow opkg to downgrade packages\n");
{
char *conf_file;
char *dest;
- char *tmp_dir;
- int force_defaults;
- int force_maintainer;
- int force_depends;
- int force_overwrite;
- int force_downgrade;
- int force_reinstall;
- int force_removal_of_essential_packages;
- int force_removal_of_dependent_packages;
- int force_space;
- int noaction;
- int nodeps;
- int multiple_providers;
- int query_all;
- int verbosity;
+
int nocheckfordirorfile;
int noreadfeedsfile;
- int autoremove;
- char *offline_root;
- char *offline_root_path;
- char *offline_root_pre_script_cmd;
- char *offline_root_post_script_cmd;
- char *cache;
};
typedef struct args args_t;
#define ARGS_DEFAULT_CONF_FILE_DIR OPKGETCDIR"/opkg"
#define ARGS_DEFAULT_CONF_FILE_NAME "opkg.conf"
#define ARGS_DEFAULT_DEST NULL
-#define ARGS_DEFAULT_FORCE_DEFAULTS 0
-#define ARGS_DEFAULT_FORCE_MAINTAINER 0
-#define ARGS_DEFAULT_FORCE_DEPENDS 0
-#define ARGS_DEFAULT_FORCE_OVERWRITE 0
-#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
-#define ARGS_DEFAULT_FORCE_REINSTALL 0
-#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
-#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
-#define ARGS_DEFAULT_FORCE_SPACE 0
-#define ARGS_DEFAULT_OFFLINE_ROOT NULL
-#define ARGS_DEFAULT_OFFLINE_ROOT_PATH NULL
-#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
-#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
-#define ARGS_DEFAULT_NOACTION 0
-#define ARGS_DEFAULT_NODEPS 0
-#define ARGS_DEFAULT_VERBOSE_WGET 0
#define ARGS_DEFAULT_VERBOSITY 1
-#define ARGS_DEFAULT_AUTOREMOVE 0
void args_init(args_t *args);
void args_deinit(args_t *args);
int args_parse(args_t *args, int argc, char *argv[]);
-void args_usage(char *complaint);
+void args_usage(const char *complaint);
#endif
nv_pair_deinit(conffile);
}
-int conffile_has_been_modified(opkg_conf_t *conf, conffile_t *conffile)
+int conffile_has_been_modified(conffile_t *conffile)
{
char *md5sum;
char *filename = conffile->name;
int ret = 1;
if (conffile->value == NULL) {
- opkg_message(conf, OPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
+ opkg_msg(NOTICE, "Conffile %s has no md5sum.\n", conffile->name);
return 1;
}
- root_filename = root_filename_alloc(conf, filename);
+ root_filename = root_filename_alloc(filename);
md5sum = file_md5sum_alloc(root_filename);
if (md5sum && (ret = strcmp(md5sum, conffile->value))) {
- opkg_message(conf, OPKG_INFO, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
- conffile->name, md5sum, conffile->value);
+ opkg_msg(INFO, "Conffile %s:\n\told md5=%s\n\tnew md5=%s\n",
+ conffile->name, md5sum, conffile->value);
}
free(root_filename);
int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
void conffile_deinit(conffile_t *conffile);
-int conffile_has_been_modified(struct opkg_conf *conf, conffile_t *conffile);
+int conffile_has_been_modified(conffile_t *conffile);
#endif
file_read_line_alloc(FILE *fp)
{
char buf[BUFSIZ];
- int buf_len;
+ unsigned int buf_len;
char *line = NULL;
- int line_size = 0;
+ unsigned int line_size = 0;
int got_nl = 0;
buf[0] = '\0';
if (err == 0)
unlink(src);
} else {
- fprintf(stderr, "%s: rename(%s, %s): %s\n",
- __FUNCTION__, src, dest, strerror(errno));
+ opkg_perror(ERROR, "Failed to rename %s to %s",
+ src, dest);
}
}
err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
if (err)
- fprintf(stderr, "%s: copy_file(%s, %s)\n",
- __FUNCTION__, src, dest);
+ opkg_msg(ERROR, "Failed to copy file %s to %s.\n",
+ src, dest);
return err;
}
file = fopen(file_name, "r");
if (file == NULL) {
- fprintf(stderr, "%s: Failed to open file %s: %s\n",
- __FUNCTION__, file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to open file %s", file_name);
free(md5sum_hex);
return NULL;
}
err = md5_stream(file, md5sum_bin);
if (err) {
- fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
- __FUNCTION__, file_name, strerror(err));
+ opkg_msg(ERROR, "Could't compute md5sum for %s.\n", file_name);
fclose(file);
free(md5sum_hex);
return NULL;
file = fopen(file_name, "r");
if (file == NULL) {
- fprintf(stderr, "%s: Failed to open file %s: %s\n",
- __FUNCTION__, file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to open file %s", file_name);
free(sha256sum_hex);
return NULL;
}
err = sha256_stream(file, sha256sum_bin);
if (err) {
- fprintf(stderr, "%s: ERROR computing sha256sum for %s: %s\n",
- __FUNCTION__, file_name, strerror(err));
+ opkg_msg(ERROR, "Could't compute sha256sum for %s.\n", file_name);
fclose(file);
free(sha256sum_hex);
return NULL;
dir = opendir(path);
if (dir == NULL) {
- perror_msg("%s: opendir(%s)", __FUNCTION__, path);
+ opkg_perror(ERROR, "Failed to open dir %s", path);
return -1;
}
if (fchdir(dirfd(dir)) == -1) {
- perror_msg("%s: fchdir(%s)", __FUNCTION__, path);
+ opkg_perror(ERROR, "Failed to change to dir %s", path);
closedir(dir);
return -1;
}
errno = 0;
if ((dent = readdir(dir)) == NULL) {
if (errno) {
- perror_msg("%s: readdir(%s)",
- __FUNCTION__, path);
+ opkg_perror(ERROR, "Failed to read dir %s",
+ path);
ret = -1;
}
break;
{
struct stat st;
if ((ret = lstat(dent->d_name, &st)) == -1) {
- perror_msg("%s: lstat(%s)",
- __FUNCTION__, dent->d_name);
+ opkg_perror(ERROR, "Failed to lstat %s",
+ dent->d_name);
break;
}
if (S_ISDIR(st.st_mode)) {
}
if ((ret = unlink(dent->d_name)) == -1) {
- perror_msg("%s: unlink(%s)",
- __FUNCTION__, dent->d_name);
+ opkg_perror(ERROR, "Failed to unlink %s", dent->d_name);
break;
}
}
if (chdir("..") == -1) {
ret = -1;
- perror_msg("%s: chdir(%s/..)", __FUNCTION__, path);
+ opkg_perror(ERROR, "Failed to change to dir %s/..", path);
}
if (rmdir(path) == -1 ) {
ret = -1;
- perror_msg("%s: rmdir(%s)", __FUNCTION__, path);
+ opkg_perror(ERROR, "Failed to remove dir %s", path);
}
if (closedir(dir) == -1) {
ret = -1;
- perror_msg("%s: closedir(%s)", __FUNCTION__, path);
+ opkg_perror(ERROR, "Failed to close dir %s", path);
}
return ret;
hash_table_init(const char *name, hash_table_t *hash, int len)
{
if (hash->entries != NULL) {
- fprintf(stderr, "ERROR: %s called on a non empty hash table\n",
- __FUNCTION__);
+ opkg_msg(ERROR, "Internal error: non empty hash table.\n");
return;
}
if (hash_entry->key)
{
if (strcmp(key, hash_entry->key) == 0) {
- // opkg_message(NULL, OPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
hash->n_hits++;
return hash_entry->data;
}
#include "file_util.h"
#include "opkg_message.h"
-#include "opkg_error.h"
/* This is used for backward compatibility */
int
opkg_op (int argc, char *argv[])
{
- int err, optind;
+ int err, opts;
args_t args;
char *cmd_name;
opkg_cmd_t *cmd;
- opkg_conf_t opkg_conf;
args_init (&args);
- optind = args_parse (&args, argc, argv);
- if (optind == argc || optind < 0)
+ opts = args_parse (&args, argc, argv);
+ if (opts == argc || opts < 0)
{
args_usage ("opkg must have one sub-command argument");
}
- cmd_name = argv[optind++];
-/* Pigi: added a flag to disable the checking of structures if the command does not need to
- read anything from there.
-*/
+ cmd_name = argv[opts++];
+
if ( !strcmp(cmd_name,"print-architecture") ||
!strcmp(cmd_name,"print_architecture") ||
!strcmp(cmd_name,"print-installation-architecture") ||
!strcmp(cmd_name,"print_installation_architecture") )
args.nocheckfordirorfile = 1;
-/* Pigi: added a flag to disable the reading of feed files if the command does not need to
- read anything from there.
-*/
if ( !strcmp(cmd_name,"flag") ||
!strcmp(cmd_name,"configure") ||
!strcmp(cmd_name,"remove") ||
!strcmp(cmd_name,"status") )
args.noreadfeedsfile = 1;
+ cmd = opkg_cmd_find (cmd_name);
+ if (cmd == NULL)
+ {
+ fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
+ cmd_name);
+ args_usage (NULL);
+ }
- err = opkg_conf_init (&opkg_conf, &args);
+ conf->pfm = cmd->pfm;
+
+ err = opkg_conf_init (&args);
args_deinit (&args);
if (err)
{
return err;
}
- cmd = opkg_cmd_find (cmd_name);
- if (cmd == NULL)
- {
- fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
- cmd_name);
- args_usage (NULL);
- }
-
- if (cmd->requires_args && optind == argc)
+ if (cmd->requires_args && opts == argc)
{
fprintf (stderr,
"%s: the ``%s'' command requires at least one argument\n",
- __FUNCTION__, cmd_name);
+ argv[0], cmd_name);
args_usage (NULL);
}
- err = opkg_cmd_exec (cmd, &opkg_conf, argc - optind, (const char **) (argv + optind), NULL);
+ err = opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts));
#ifdef HAVE_CURL
opkg_curl_cleanup();
#endif
- opkg_conf_deinit (&opkg_conf);
+ opkg_conf_deinit ();
return err;
}
#include "args.h"
#include "pkg.h"
-#include "user.h"
extern int opkg_op(int argc, char *argv[]); /* opkglib.c */
#include "opkg_download.h"
#include "opkg_remove.h"
#include "opkg_upgrade.h"
-#include "opkg_error.h"
#include "sprintf_alloc.h"
#include "file_util.h"
#include <libbb/libbb.h>
-struct _opkg_t
-{
- args_t *args;
- opkg_conf_t *conf;
- opkg_option_t *options;
-};
+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 (); }
-#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data);
-#define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0
+#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (&d, user_data);
/** Private Functions ***/
new->repository = xstrdup(old->src->name);
new->description = xstrdup(old->description);
new->tags = xstrdup(old->tags);
- new->url = xstrdup(old->url);
- new->size = (old->size) ? atoi (old->size) : 0;
+ new->size = old->size;
new->installed = (old->state_status == SS_INSTALLED);
return new;
}
static int
-opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
+opkg_configure_packages(char *pkg_name)
{
pkg_vec_t *all;
int i;
int r, err = 0;
all = pkg_vec_alloc ();
- pkg_hash_fetch_available (&conf->pkg_hash, all);
+ pkg_hash_fetch_available (all);
for (i = 0; i < all->len; i++)
{
if (pkg->state_status == SS_UNPACKED)
{
- r = opkg_configure (conf, pkg);
+ r = opkg_configure (pkg);
if (r == 0)
{
pkg->state_status = SS_INSTALLED;
{
opkg_progress_callback_t cb;
opkg_progress_data_t *progress_data;
- opkg_t *opkg;
void *user_data;
int start_range;
int finish_range;
progress = cb_data->start_range + (d / t * ((cb_data->finish_range - cb_data->start_range)));
cb_data->progress_data->percentage = progress;
- (cb_data->cb)(cb_data->opkg,
- cb_data->progress_data,
+ (cb_data->cb)(cb_data->progress_data,
cb_data->user_data);
return 0;
free (p->architecture);
free (p->description);
free (p->tags);
- free (p->url);
free (p->repository);
free (p);
}
-opkg_t *
+int
opkg_new ()
{
- opkg_t *opkg;
int err;
- opkg = xcalloc(1, sizeof (opkg_t));
-
- opkg->args = xcalloc(1, sizeof (args_t));
- args_init (opkg->args);
+ args = xcalloc(1, sizeof (args_t));
+ args_init (args);
- opkg->conf = xcalloc(1, sizeof (opkg_conf_t));
- err = opkg_conf_init (opkg->conf, opkg->args);
+ err = opkg_conf_init (args);
if (err)
{
- free (opkg->conf);
- free (opkg->args);
- free (opkg);
- return NULL;
+ args_deinit (args);
+ free (args);
+ return -1;
}
- opkg_init_options_array (opkg->conf, &opkg->options);
- return opkg;
+ return 0;
}
void
-opkg_free (opkg_t *opkg)
+opkg_free (void)
{
- opkg_assert (opkg != NULL);
-
#ifdef HAVE_CURL
opkg_curl_cleanup();
#endif
- opkg_conf_deinit (opkg->conf);
- args_deinit (opkg->args);
- free (opkg->options);
- free (opkg->args);
- free (opkg->conf);
- free (opkg);
+ opkg_conf_deinit ();
+ args_deinit (args);
+ free (args);
}
int
-opkg_re_read_config_files (opkg_t *opkg)
+opkg_re_read_config_files (void)
{
- args_t *a;
- opkg_conf_t *c;
-
- opkg_assert (opkg != NULL);
-
- a = opkg->args;
- c = opkg->conf;
-
- /* Unfortunatly, the easiest way to re-read the config files right now is to
- * throw away opkg->conf and start again */
-
- /* copy the settings we need to keep */
- a->autoremove = c->autoremove;
- a->force_depends = c->force_depends;
- a->force_defaults = c->force_defaults;
- a->force_maintainer = c->force_maintainer;
- a->force_overwrite = c->force_overwrite;
- a->force_downgrade = c->force_downgrade;
- a->force_reinstall = c->force_reinstall;
- a->force_removal_of_dependent_packages = c->force_removal_of_dependent_packages;
- a->force_removal_of_essential_packages = c->force_removal_of_essential_packages;
- a->nodeps = c->nodeps;
- a->noaction = c->noaction;
- a->query_all = c->query_all;
- a->verbosity = c->verbosity;
-
- if (c->offline_root)
- {
- if (a->offline_root) free (a->offline_root);
- a->offline_root = xstrdup(c->offline_root);
- }
-
- if (c->offline_root_pre_script_cmd)
- {
- if (a->offline_root_pre_script_cmd) free (a->offline_root_pre_script_cmd);
- a->offline_root_pre_script_cmd = xstrdup(c->offline_root_pre_script_cmd);
- }
-
- if (c->offline_root_post_script_cmd)
- {
- if (a->offline_root_post_script_cmd) free (a->offline_root_post_script_cmd);
- a->offline_root_post_script_cmd = xstrdup(c->offline_root_post_script_cmd);
- }
-
- if (c->cache) {
- if (a->cache)
- free (a->cache);
- a->cache = xstrdup(c->cache);
- }
-
- /* throw away old opkg_conf and start again */
- opkg_conf_deinit (opkg->conf);
- opkg_conf_init (opkg->conf, opkg->args);
-
- free (opkg->options);
- opkg_init_options_array (opkg->conf, &opkg->options);
-
- return 0;
+ /* 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();
}
void
-opkg_get_option (opkg_t *opkg, char *option, void **value)
+opkg_get_option (char *option, void **value)
{
int i = 0;
- opkg_option_t *options;
-
- opkg_assert (opkg != NULL);
- opkg_assert (option != NULL);
- opkg_assert (value != NULL);
-
- options = opkg->options;
+ extern opkg_option_t options[];
/* look up the option
* TODO: this would be much better as a hash table
}
void
-opkg_set_option (opkg_t *opkg, char *option, void *value)
+opkg_set_option (char *option, void *value)
{
int i = 0, found = 0;
- opkg_option_t *options;
+ extern opkg_option_t options[];
- opkg_assert (opkg != NULL);
opkg_assert (option != NULL);
opkg_assert (value != NULL);
- options = opkg->options;
-
/* look up the option
* TODO: this would be much better as a hash table
*/
/**
* @brief libopkg API: Install package
- * @param opkg Then opkg handler
* @param package_name The name of package in which is going to install
* @param progress_callback The callback function that report the status to caller.
*/
int
-opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_install_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
int err;
char *stripped_filename;
int i, ndepends;
char **unresolved = NULL;
- opkg_assert (opkg != NULL);
opkg_assert (package_name != NULL);
/* ... */
- pkg_info_preinstall_check (opkg->conf);
+ pkg_info_preinstall_check ();
/* check to ensure package is not already installed */
- old = pkg_hash_fetch_installed_by_name(&opkg->conf->pkg_hash, package_name);
+ old = pkg_hash_fetch_installed_by_name(package_name);
if (old)
{
/* XXX: Error: Package is already installed. */
return OPKG_PACKAGE_ALREADY_INSTALLED;
}
- new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, package_name);
+ new = pkg_hash_fetch_best_installation_candidate_by_name(package_name);
if (!new)
{
/* XXX: Error: Could not find package to install */
/* find dependancies and download them */
deps = pkg_vec_alloc ();
/* this function does not return the original package, so we insert it later */
- ndepends = pkg_hash_fetch_unsatisfied_dependencies (opkg->conf, new, deps, &unresolved);
+ ndepends = pkg_hash_fetch_unsatisfied_dependencies (new, deps, &unresolved);
if (unresolved)
{
/* XXX: Error: Could not satisfy dependencies */
if ( ! stripped_filename )
stripped_filename = pkg->filename;
- sprintf_alloc(&pkg->local_filename, "%s/%s", opkg->conf->tmp_dir, stripped_filename);
+ sprintf_alloc(&pkg->local_filename, "%s/%s", conf->tmp_dir, stripped_filename);
cb_data.cb = progress_callback;
cb_data.progress_data = &pdata;
- cb_data.opkg = opkg;
cb_data.user_data = user_data;
/* 75% of "install" progress is for downloading */
cb_data.start_range = 75 * i / deps->len;
cb_data.finish_range = 75 * (i + 1) / deps->len;
- err = opkg_download(opkg->conf, url, pkg->local_filename,
+ err = opkg_download(url, pkg->local_filename,
(curl_progress_func) curl_progress_cb, &cb_data);
free(url);
/* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
all = pkg_vec_alloc ();
- pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+ pkg_hash_fetch_available (all);
for (i = 0; i < all->len; i++)
{
all->pkgs[i]->parent->dependencies_checked = 0;
progress (pdata, 75);
/* unpack the package */
- err = opkg_install_pkg(opkg->conf, new, 0);
+ err = opkg_install_pkg(new, 0);
if (err)
{
progress (pdata, 75);
/* run configure scripts, etc. */
- err = opkg_configure_packages (opkg->conf, NULL);
+ err = opkg_configure_packages (NULL);
if (err)
{
opkg_package_free (pdata.package);
}
/* write out status files and file lists */
- opkg_conf_write_status_files (opkg->conf);
- pkg_write_changed_filelists (opkg->conf);
+ opkg_conf_write_status_files ();
+ pkg_write_changed_filelists ();
progress (pdata, 100);
opkg_package_free (pdata.package);
}
int
-opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_remove_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
int err;
pkg_t *pkg = NULL;
pkg_t *pkg_to_remove;
opkg_progress_data_t pdata;
- opkg_assert (opkg != NULL);
opkg_assert (package_name != NULL);
- pkg_info_preinstall_check (opkg->conf);
+ pkg_info_preinstall_check ();
- pkg = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, package_name);
+ pkg = pkg_hash_fetch_installed_by_name (package_name);
if (pkg == NULL)
{
}
progress (pdata, 25);
- if (opkg->conf->restrict_to_default_dest)
+ if (conf->restrict_to_default_dest)
{
- pkg_to_remove = pkg_hash_fetch_installed_by_name_dest (&opkg->conf->pkg_hash,
- pkg->name,
- opkg->conf->default_dest);
+ pkg_to_remove = pkg_hash_fetch_installed_by_name_dest (pkg->name,
+ conf->default_dest);
}
else
{
- pkg_to_remove = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, pkg->name );
+ pkg_to_remove = pkg_hash_fetch_installed_by_name (pkg->name);
}
progress (pdata, 75);
- err = opkg_remove_pkg (opkg->conf, pkg_to_remove, 0);
+ err = opkg_remove_pkg (pkg_to_remove, 0);
/* write out status files and file lists */
- opkg_conf_write_status_files (opkg->conf);
- pkg_write_changed_filelists (opkg->conf);
+ opkg_conf_write_status_files ();
+ pkg_write_changed_filelists ();
progress (pdata, 100);
}
int
-opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_upgrade_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
int err;
pkg_t *pkg;
opkg_progress_data_t pdata;
-
-
- opkg_assert (opkg != NULL);
opkg_assert (package_name != NULL);
- pkg_info_preinstall_check (opkg->conf);
+ pkg_info_preinstall_check ();
- if (opkg->conf->restrict_to_default_dest)
+ if (conf->restrict_to_default_dest)
{
- pkg = pkg_hash_fetch_installed_by_name_dest (&opkg->conf->pkg_hash,
- package_name,
- opkg->conf->default_dest);
+ pkg = pkg_hash_fetch_installed_by_name_dest (package_name,
+ conf->default_dest);
if (pkg == NULL)
{
/* XXX: Error: Package not installed in default_dest */
}
else
{
- pkg = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash,
- package_name);
+ pkg = pkg_hash_fetch_installed_by_name (package_name);
}
if (!pkg)
pdata.package = pkg_t_to_opkg_package_t (pkg);
progress (pdata, 0);
- err = opkg_upgrade_pkg (opkg->conf, pkg);
+ err = opkg_upgrade_pkg (pkg);
/* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
if (err)
{
}
progress (pdata, 75);
- err = opkg_configure_packages (opkg->conf, NULL);
+ err = opkg_configure_packages (NULL);
if (err) {
opkg_package_free (pdata.package);
return OPKG_UNKNOWN_ERROR;
}
/* write out status files and file lists */
- opkg_conf_write_status_files (opkg->conf);
- pkg_write_changed_filelists (opkg->conf);
+ opkg_conf_write_status_files ();
+ pkg_write_changed_filelists ();
progress (pdata, 100);
opkg_package_free (pdata.package);
}
int
-opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_upgrade_all (opkg_progress_callback_t progress_callback, void *user_data)
{
pkg_vec_t *installed;
int err = 0;
pdata.action = OPKG_INSTALL;
pdata.package = NULL;
- opkg_assert (opkg != NULL);
progress (pdata, 0);
installed = pkg_vec_alloc ();
- pkg_info_preinstall_check (opkg->conf);
+ pkg_info_preinstall_check ();
- pkg_hash_fetch_all_installed (&opkg->conf->pkg_hash, installed);
+ pkg_hash_fetch_all_installed (installed);
for (i = 0; i < installed->len; i++)
{
pkg = installed->pkgs[i];
progress (pdata, 99 * i / installed->len);
opkg_package_free (pdata.package);
- err += opkg_upgrade_pkg (opkg->conf, pkg);
+ err += opkg_upgrade_pkg (pkg);
}
pkg_vec_free (installed);
if (err)
return 1;
- err = opkg_configure_packages (opkg->conf, NULL);
+ err = opkg_configure_packages (NULL);
if (err)
return 1;
}
int
-opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_update_package_lists (opkg_progress_callback_t progress_callback, void *user_data)
{
char *tmp;
int err, result = 0;
int sources_list_count, sources_done;
opkg_progress_data_t pdata;
- opkg_assert (opkg != NULL);
-
pdata.action = OPKG_DOWNLOAD;
pdata.package = NULL;
progress (pdata, 0);
sprintf_alloc (&lists_dir, "%s",
- (opkg->conf->restrict_to_default_dest)
- ? opkg->conf->default_dest->lists_dir
- : opkg->conf->lists_dir);
+ (conf->restrict_to_default_dest)
+ ? conf->default_dest->lists_dir
+ : conf->lists_dir);
if (!file_is_dir (lists_dir))
{
}
}
- sprintf_alloc(&tmp, "%s/update-XXXXXX", opkg->conf->tmp_dir);
+ sprintf_alloc(&tmp, "%s/update-XXXXXX", conf->tmp_dir);
if (mkdtemp (tmp) == NULL) {
/* XXX: Error: could not create temporary file name */
free (lists_dir);
/* count the number of sources so we can give some progress updates */
sources_list_count = 0;
sources_done = 0;
- list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
+ list_for_each_entry(iter, &conf->pkg_src_list.head, node)
{
sources_list_count++;
}
- list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
+ list_for_each_entry(iter, &conf->pkg_src_list.head, node)
{
char *url, *list_file_name = NULL;
cb_data.cb = progress_callback;
cb_data.progress_data = &pdata;
- cb_data.opkg = opkg;
cb_data.user_data = user_data;
cb_data.start_range = 100 * sources_done / sources_list_count;
cb_data.finish_range = 100 * (sources_done + 1) / sources_list_count;
- err = opkg_download (opkg->conf, url, tmp_file_name, (curl_progress_func) curl_progress_cb, &cb_data);
+ err = opkg_download (url, tmp_file_name, (curl_progress_func) curl_progress_cb, &cb_data);
if (err == 0)
{
free (tmp_file_name);
}
else
- err = opkg_download (opkg->conf, url, list_file_name, NULL, NULL);
+ err = opkg_download (url, list_file_name, NULL, NULL);
if (err)
{
free (url);
#if defined(HAVE_GPGME) || defined(HAVE_OPENSSL)
- if ( opkg->conf->check_signature ) {
+ if ( conf->check_signature ) {
char *sig_file_name;
/* download detached signitures to verify the package lists */
/* get the url for the sig file */
/* make sure there is no existing signature file */
unlink (sig_file_name);
- err = opkg_download (opkg->conf, url, sig_file_name, NULL, NULL);
+ err = opkg_download (url, sig_file_name, NULL, NULL);
if (err)
{
/* XXX: Warning: Download failed */
else
{
int err;
- err = opkg_verify_file (opkg->conf, list_file_name, sig_file_name);
+ err = opkg_verify_file (list_file_name, sig_file_name);
if (err == 0)
{
/* XXX: Notice: Signature check passed */
free (lists_dir);
/* Now re-read the package lists to update package hash tables. */
- opkg_re_read_config_files (opkg);
+ opkg_re_read_config_files ();
return result;
}
int
-opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
+opkg_list_packages (opkg_package_callback_t callback, void *user_data)
{
pkg_vec_t *all;
int i;
- opkg_assert (opkg);
opkg_assert (callback);
all = pkg_vec_alloc ();
- pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+ pkg_hash_fetch_available (all);
for (i = 0; i < all->len; i++)
{
pkg_t *pkg;
pkg = all->pkgs[i];
package = pkg_t_to_opkg_package_t (pkg);
- callback (opkg, package, user_data);
+ callback (package, user_data);
opkg_package_free (package);
}
}
int
-opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
+opkg_list_upgradable_packages (opkg_package_callback_t callback, void *user_data)
{
struct active_list *head;
struct active_list *node;
pkg_t *old=NULL, *new = NULL;
static opkg_package_t* package=NULL;
-
- opkg_assert (opkg);
opkg_assert (callback);
/* ensure all data is valid */
- pkg_info_preinstall_check (opkg->conf);
+ pkg_info_preinstall_check ();
- head = prepare_upgrade_list(opkg->conf);
+ head = prepare_upgrade_list();
for (node=active_list_next(head, head); node; active_list_next(head,node)) {
old = list_entry(node, pkg_t, list);
- new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name);
+ new = pkg_hash_fetch_best_installation_candidate_by_name(old->name);
if (new == NULL)
continue;
package = pkg_t_to_opkg_package_t (new);
- callback (opkg, package, user_data);
+ callback (package, user_data);
opkg_package_free (package);
}
active_list_head_delete(head);
}
opkg_package_t*
-opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char *arch, const char *repo)
+opkg_find_package (const char *name, const char *ver, const char *arch, const char *repo)
{
pkg_vec_t *all;
opkg_package_t *package = NULL;
int i;
#define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
- opkg_assert (opkg);
-
all = pkg_vec_alloc ();
- pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+ pkg_hash_fetch_available (all);
for (i = 0; i < all->len; i++)
{
pkg_t *pkg;
#endif
/**
* @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status.
- * @param opkg The opkg_t
* @return return how many repositories cannot access. 0 means all okay.
*/
-int opkg_repository_accessibility_check(opkg_t *opkg)
+int opkg_repository_accessibility_check(void)
{
pkg_src_list_elt_t *iter;
str_list_elt_t *iter1;
int err;
char *repo_ptr;
char *stmp;
- opkg_assert(opkg != NULL);
src = str_list_alloc();
- list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
+ list_for_each_entry(iter, &conf->pkg_src_list.head, node)
{
if (strstr(((pkg_src_t *)iter->data)->value, "://") &&
index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/'))
iter1 = str_list_pop(src);
repositories--;
- err = opkg_download(opkg->conf, iter1->data, "/dev/null", NULL, NULL);
+ err = opkg_download(iter1->data, "/dev/null", NULL, NULL);
#ifdef HAVE_CURL
if (!(err == CURLE_OK ||
err == CURLE_HTTP_RETURNED_ERROR ||
#ifndef OPKG_H
#define OPKG_H
-typedef struct _opkg_t opkg_t;
typedef struct _opkg_package_t opkg_package_t;
typedef struct _opkg_progress_data_t opkg_progress_data_t;
-typedef void (*opkg_progress_callback_t) (opkg_t *opkg, const opkg_progress_data_t *progress, void *user_data);
-typedef void (*opkg_package_callback_t) (opkg_t *opkg, opkg_package_t *package, void *user_data);
+typedef void (*opkg_progress_callback_t) (const opkg_progress_data_t *progress, void *user_data);
+typedef void (*opkg_package_callback_t) (opkg_package_t *package, void *user_data);
enum _opkg_action_t
{
char *repository;
char *description;
char *tags;
- char *url;
int size;
int installed;
};
opkg_package_t* opkg_package_new ();
void opkg_package_free (opkg_package_t *package);
-opkg_t* opkg_new ();
-void opkg_free (opkg_t *opkg);
-void opkg_get_option (opkg_t *opkg, char *option, void **value);
-void opkg_set_option (opkg_t *opkg, char *option, void *value);
-int opkg_re_read_config_files (opkg_t *opkg);
+int opkg_new (void);
+void opkg_free (void);
+int opkg_re_read_config_files (void);
+void opkg_get_option (char *option, void **value);
+void opkg_set_option (char *option, void *value);
-int opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
-int opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
-int opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
-int opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);
-int opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);
+int opkg_install_package (const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_remove_package (const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_package (const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_all (opkg_progress_callback_t callback, void *user_data);
+int opkg_update_package_lists (opkg_progress_callback_t callback, void *user_data);
-int opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data);
-int opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data);
-opkg_package_t* opkg_find_package (opkg_t *opkg, const char *name, const char *version, const char *architecture, const char *repository);
+int opkg_list_packages (opkg_package_callback_t callback, void *user_data);
+int opkg_list_upgradable_packages (opkg_package_callback_t callback, void *user_data);
+opkg_package_t* opkg_find_package (const char *name, const char *version, const char *architecture, const char *repository);
-int opkg_repository_accessibility_check(opkg_t *opkg);
+int opkg_repository_accessibility_check(void);
#endif /* OPKG_H */
#include "opkg_upgrade.h"
#include "opkg_remove.h"
#include "opkg_configure.h"
-#include "opkg_message.h"
#include "libopkg.h"
#include "xsystem.h"
-static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_info_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatdepends_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatdepends_recursively_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatsuggests_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatrecommends_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatprovides_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatconflicts_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatreplaces_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_configure_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int pkg_mark_provides(pkg_t *pkg);
-
-/* XXX: CLEANUP: The usage strings should be incorporated into this
- array for easier maintenance */
-static opkg_cmd_t cmds[] = {
- {"update", 0, (opkg_cmd_fun_t)opkg_update_cmd},
- {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd},
- {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd},
- {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd},
- {"list-installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd},
- {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd},
- {"list-upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd},
- {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd},
- {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd},
- {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd},
- {"install", 1, (opkg_cmd_fun_t)opkg_install_cmd},
- {"remove", 1, (opkg_cmd_fun_t)opkg_remove_cmd},
- {"configure", 0, (opkg_cmd_fun_t)opkg_configure_cmd},
- {"files", 1, (opkg_cmd_fun_t)opkg_files_cmd},
- {"search", 1, (opkg_cmd_fun_t)opkg_search_cmd},
- {"download", 1, (opkg_cmd_fun_t)opkg_download_cmd},
- {"compare_versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd},
- {"compare-versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd},
- {"print-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
- {"print_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
- {"print-installation-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
- {"print_installation_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
- {"depends", 1, (opkg_cmd_fun_t)opkg_depends_cmd},
- {"whatdepends", 1, (opkg_cmd_fun_t)opkg_whatdepends_cmd},
- {"whatdependsrec", 1, (opkg_cmd_fun_t)opkg_whatdepends_recursively_cmd},
- {"whatrecommends", 1, (opkg_cmd_fun_t)opkg_whatrecommends_cmd},
- {"whatsuggests", 1, (opkg_cmd_fun_t)opkg_whatsuggests_cmd},
- {"whatprovides", 1, (opkg_cmd_fun_t)opkg_whatprovides_cmd},
- {"whatreplaces", 1, (opkg_cmd_fun_t)opkg_whatreplaces_cmd},
- {"whatconflicts", 1, (opkg_cmd_fun_t)opkg_whatconflicts_cmd},
-};
-
-static void print_pkg(pkg_t *pkg)
+static void
+print_pkg(pkg_t *pkg)
{
char *version = pkg_version_str_alloc(pkg);
if (pkg->description)
}
int opkg_state_changed;
-static void write_status_files_if_changed(opkg_conf_t *conf)
+
+static void
+write_status_files_if_changed(void)
{
if (opkg_state_changed && !conf->noaction) {
- opkg_message(conf, OPKG_INFO,
- " writing status file\n");
- opkg_conf_write_status_files(conf);
- pkg_write_changed_filelists(conf);
+ opkg_msg(INFO, "Writing status file.\n");
+ opkg_conf_write_status_files();
+ pkg_write_changed_filelists();
} else {
- opkg_message(conf, OPKG_DEBUG, "Nothing to be done\n");
- }
-}
-
-
-static int num_cmds = sizeof(cmds) / sizeof(opkg_cmd_t);
-
-opkg_cmd_t *opkg_cmd_find(const char *name)
-{
- int i;
- opkg_cmd_t *cmd;
-
- for (i=0; i < num_cmds; i++) {
- cmd = &cmds[i];
- if (strcmp(name, cmd->name) == 0) {
- return cmd;
- }
+ opkg_msg(DEBUG, "Nothing to be done.\n");
}
-
- return NULL;
}
-int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **argv, void *userdata)
+static void
+sigint_handler(int sig)
{
- int result;
-
- result = (cmd->fun)(conf, argc, argv);
-
- print_error_list();
- free_error_list();
-
- return result;
+ signal(sig, SIG_DFL);
+ opkg_msg(NOTICE, "Interrupted. Writing out status database.\n");
+ write_status_files_if_changed();
+ exit(128 + sig);
}
-static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_update_cmd(int argc, char **argv)
{
char *tmp;
int err;
if (! file_is_dir(lists_dir)) {
if (file_exists(lists_dir)) {
- opkg_message(conf, OPKG_ERROR,
- "%s: ERROR: %s exists, but is not a directory\n",
- __FUNCTION__, lists_dir);
+ opkg_msg(ERROR, "%s exists, but is not a directory.\n",
+ lists_dir);
free(lists_dir);
return -1;
}
err = file_mkdir_hier(lists_dir, 0755);
if (err) {
- opkg_message(conf, OPKG_ERROR,
- "%s: ERROR: failed to make directory %s: %s\n",
- __FUNCTION__, lists_dir, strerror(errno));
free(lists_dir);
return -1;
}
sprintf_alloc(&tmp, "%s/update-XXXXXX", conf->tmp_dir);
if (mkdtemp (tmp) == NULL) {
- perror ("mkdtemp");
+ opkg_perror(ERROR, "Failed to make temp dir %s", conf->tmp_dir);
return -1;
}
FILE *in, *out;
sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
- err = opkg_download(conf, url, tmp_file_name, NULL, NULL);
+ err = opkg_download(url, tmp_file_name, NULL, NULL);
if (err == 0) {
- opkg_message (conf, OPKG_NOTICE, "Inflating %s\n", url);
+ opkg_msg(NOTICE, "Inflating %s.\n", url);
in = fopen (tmp_file_name, "r");
out = fopen (list_file_name, "w");
if (in && out)
}
free(tmp_file_name);
} else
- err = opkg_download(conf, url, list_file_name, NULL, NULL);
+ err = opkg_download(url, list_file_name, NULL, NULL);
if (err) {
failures++;
} else {
- opkg_message(conf, OPKG_NOTICE,
- "Updated list of available packages in %s\n",
+ opkg_msg(NOTICE, "Updated list of available packages in %s.\n",
list_file_name);
}
free(url);
/* Put the signature in the right place */
sprintf_alloc (&tmp_file_name, "%s/%s.sig", lists_dir, src->name);
- err = opkg_download(conf, url, tmp_file_name, NULL, NULL);
+ err = opkg_download(url, tmp_file_name, NULL, NULL);
if (err) {
failures++;
- opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
+ opkg_msg(NOTICE, "Signature check failed.\n");
} else {
- int err;
- err = opkg_verify_file (conf, list_file_name, tmp_file_name);
+ err = opkg_verify_file (list_file_name, tmp_file_name);
if (err == 0)
- opkg_message (conf, OPKG_NOTICE, "Signature check passed\n");
+ opkg_msg(NOTICE, "Signature check passed.\n");
else
- opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
+ opkg_msg(NOTICE, "Signature check failed.\n");
}
/* We shouldn't unlink the signature ! */
// unlink (tmp_file_name);
typedef struct opkg_intercept *opkg_intercept_t;
-static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
+static opkg_intercept_t
+opkg_prep_intercepts(void)
{
opkg_intercept_t ctx;
char *newpath;
sprintf_alloc(&ctx->statedir, "%s/opkg-intercept-XXXXXX", conf->tmp_dir);
if (mkdtemp(ctx->statedir) == NULL) {
- fprintf(stderr, "%s: mkdtemp: %s\n", __FUNCTION__, strerror(errno));
+ opkg_perror(ERROR,"Failed to make temp dir %s", ctx->statedir);
free(ctx->oldpath);
free(ctx->statedir);
free(newpath);
return ctx;
}
-static int opkg_finalize_intercepts(opkg_intercept_t ctx)
+static int
+opkg_finalize_intercepts(opkg_intercept_t ctx)
{
DIR *dir;
int err = 0;
}
closedir(dir);
} else
- perror (ctx->statedir);
+ opkg_perror(ERROR, "Failed to open dir %s", ctx->statedir);
rm_r(ctx->statedir);
free (ctx->statedir);
used to end recursion and avoid an infinite loop on graph cycles.
pkg_vec ordered will finally contain the ordered set of packages.
*/
-static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *all,
+static int
+opkg_recurse_pkgs_in_order(pkg_t *pkg, pkg_vec_t *all,
pkg_vec_t *visited, pkg_vec_t *ordered)
{
int j,k,l,m;
/* If the package has already been visited (by this function), skip it */
for(j = 0; j < visited->len; j++)
if ( ! strcmp(visited->pkgs[j]->name, pkg->name)) {
- opkg_message(conf, OPKG_INFO,
- " pkg: %s already visited\n", pkg->name);
+ opkg_msg(INFO, "pkg %s already visited, skipping.\n", pkg->name);
return 0;
}
count = pkg->pre_depends_count + pkg->depends_count + \
pkg->recommends_count + pkg->suggests_count;
- opkg_message(conf, OPKG_INFO,
- " pkg: %s\n", pkg->name);
+ opkg_msg(INFO, "pkg %s.\n", pkg->name);
/* Iterate over all the dependencies of pkg. For each one, find a package
that is either installed or unpacked and satisfies this dependency.
l = 0;
if (dependents != NULL)
while (l < abpkg->provided_by->len && dependents[l] != NULL) {
- opkg_message(conf, OPKG_INFO,
- " Descending on pkg: %s\n",
+ opkg_msg(INFO, "Descending on pkg %s.\n",
dependents [l]->name);
/* find whether dependent l is installed or unpacked,
dep = all->pkgs[m];
if ( dep->state_status != SS_NOT_INSTALLED)
if ( ! strcmp(dep->name, dependents[l]->name)) {
- opkg_recurse_pkgs_in_order(conf, dep, all,
+ opkg_recurse_pkgs_in_order(dep, all,
visited, ordered);
/* Stop the outer loop */
l = abpkg->provided_by->len;
}
-static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
+static int
+opkg_configure_packages(char *pkg_name)
{
pkg_vec_t *all, *ordered, *visited;
int i;
opkg_intercept_t ic;
int r, err = 0;
- opkg_message(conf, OPKG_INFO,
- "Configuring unpacked packages\n");
- fflush( stdout );
+ opkg_msg(INFO, "Configuring unpacked packages.\n");
all = pkg_vec_alloc();
- pkg_hash_fetch_available(&conf->pkg_hash, all);
+ pkg_hash_fetch_available(all);
/* Reorder pkgs in order to be configured according to the Depends: tag
order */
- opkg_message(conf, OPKG_INFO,
- "Reordering packages before configuring them...\n");
+ opkg_msg(INFO, "Reordering packages before configuring them...\n");
ordered = pkg_vec_alloc();
visited = pkg_vec_alloc();
for(i = 0; i < all->len; i++) {
pkg = all->pkgs[i];
- opkg_recurse_pkgs_in_order(conf, pkg, all, visited, ordered);
+ opkg_recurse_pkgs_in_order(pkg, all, visited, ordered);
}
- ic = opkg_prep_intercepts (conf);
+ ic = opkg_prep_intercepts();
if (ic == NULL) {
err = -1;
goto error;
continue;
if (pkg->state_status == SS_UNPACKED) {
- opkg_message(conf, OPKG_NOTICE,
- "Configuring %s\n", pkg->name);
- fflush( stdout );
- r = opkg_configure(conf, pkg);
+ opkg_msg(NOTICE, "Configuring %s.\n", pkg->name);
+ r = opkg_configure(pkg);
if (r == 0) {
pkg->state_status = SS_INSTALLED;
pkg->parent->state_status = SS_INSTALLED;
return err;
}
-static opkg_conf_t *global_conf;
-
-static void sigint_handler(int sig)
-{
- signal(sig, SIG_DFL);
- opkg_message(NULL, OPKG_NOTICE,
- "opkg: interrupted. writing out status database\n");
- write_status_files_if_changed(global_conf);
- exit(128 + sig);
-}
-
-static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_install_cmd(int argc, char **argv)
{
int i;
char *arg;
int err=0;
- global_conf = conf;
signal(SIGINT, sigint_handler);
/*
for (i=0; i < argc; i++) {
arg = argv[i];
- opkg_message(conf, OPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
- err = opkg_prepare_url_for_install(conf, arg, &argv[i]);
+ opkg_msg(DEBUG2, "%s\n", arg);
+ err = opkg_prepare_url_for_install(arg, &argv[i]);
if (err)
return err;
}
- pkg_info_preinstall_check(conf);
+ pkg_info_preinstall_check();
for (i=0; i < argc; i++) {
arg = argv[i];
- err = opkg_install_by_name(conf, arg);
+ err = opkg_install_by_name(arg);
if (err) {
- opkg_message(conf, OPKG_ERROR, "Cannot find package %s.\n", arg);
+ opkg_msg(ERROR, "Cannot install package %s.\n", arg);
}
}
- opkg_configure_packages(conf, NULL);
+ opkg_configure_packages(NULL);
- write_status_files_if_changed(conf);
+ write_status_files_if_changed();
return err;
}
-static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_upgrade_cmd(int argc, char **argv)
{
int i;
pkg_t *pkg;
int err;
- global_conf = conf;
signal(SIGINT, sigint_handler);
if (argc) {
for (i=0; i < argc; i++) {
char *arg = argv[i];
- err = opkg_prepare_url_for_install(conf, arg, &arg);
+ err = opkg_prepare_url_for_install(arg, &arg);
if (err)
return err;
}
- pkg_info_preinstall_check(conf);
+ pkg_info_preinstall_check();
for (i=0; i < argc; i++) {
char *arg = argv[i];
if (conf->restrict_to_default_dest) {
- pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
- argv[i],
- conf->default_dest);
+ pkg = pkg_hash_fetch_installed_by_name_dest(argv[i],
+ conf->default_dest);
if (pkg == NULL) {
- opkg_message(conf, OPKG_NOTICE,
- "Package %s not installed in %s\n",
+ opkg_msg(NOTICE, "Package %s not installed in %s.\n",
argv[i], conf->default_dest->name);
continue;
}
} else {
- pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
- argv[i]);
+ pkg = pkg_hash_fetch_installed_by_name(argv[i]);
}
if (pkg)
- opkg_upgrade_pkg(conf, pkg);
+ opkg_upgrade_pkg(pkg);
else {
- opkg_install_by_name(conf, arg);
+ opkg_install_by_name(arg);
}
}
} else {
pkg_vec_t *installed = pkg_vec_alloc();
- pkg_info_preinstall_check(conf);
+ pkg_info_preinstall_check();
- pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
+ pkg_hash_fetch_all_installed(installed);
for (i = 0; i < installed->len; i++) {
pkg = installed->pkgs[i];
- opkg_upgrade_pkg(conf, pkg);
+ opkg_upgrade_pkg(pkg);
}
pkg_vec_free(installed);
}
- opkg_configure_packages(conf, NULL);
+ opkg_configure_packages(NULL);
- write_status_files_if_changed(conf);
+ write_status_files_if_changed();
return 0;
}
-static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_download_cmd(int argc, char **argv)
{
int i, err;
char *arg;
pkg_t *pkg;
- pkg_info_preinstall_check(conf);
+ pkg_info_preinstall_check();
for (i = 0; i < argc; i++) {
arg = argv[i];
- pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
+ pkg = pkg_hash_fetch_best_installation_candidate_by_name(arg);
if (pkg == NULL) {
- opkg_message(conf, OPKG_ERROR,
- "Cannot find package %s.\n"
- "Check the spelling or perhaps run 'opkg update'\n",
- arg);
+ opkg_msg(ERROR, "Cannot find package %s.\n", arg);
continue;
}
- err = opkg_download_pkg(conf, pkg, ".");
+ err = opkg_download_pkg(pkg, ".");
if (err) {
- opkg_message(conf, OPKG_ERROR,
- "Failed to download %s\n", pkg->name);
+ opkg_msg(ERROR, "Failed to download %s.\n", pkg->name);
} else {
- opkg_message(conf, OPKG_NOTICE,
- "Downloaded %s as %s\n",
+ opkg_msg(NOTICE, "Downloaded %s as %s.\n",
pkg->name, pkg->local_filename);
}
}
}
-static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_list_cmd(int argc, char **argv)
{
int i;
pkg_vec_t *available;
pkg_name = argv[0];
}
available = pkg_vec_alloc();
- pkg_hash_fetch_available(&conf->pkg_hash, available);
+ pkg_hash_fetch_available(available);
pkg_vec_sort(available, pkg_compare_names);
for (i=0; i < available->len; i++) {
pkg = available->pkgs[i];
}
-static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_list_installed_cmd(int argc, char **argv)
{
int i ;
pkg_vec_t *available;
pkg_name = argv[0];
}
available = pkg_vec_alloc();
- pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
+ pkg_hash_fetch_all_installed(available);
pkg_vec_sort(available, pkg_compare_names);
for (i=0; i < available->len; i++) {
pkg = available->pkgs[i];
return 0;
}
-static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_list_upgradable_cmd(int argc, char **argv)
{
- struct active_list *head = prepare_upgrade_list(conf);
+ struct active_list *head = prepare_upgrade_list();
struct active_list *node=NULL;
pkg_t *_old_pkg, *_new_pkg;
char *old_v, *new_v;
for (node = active_list_next(head, head); node;node = active_list_next(head,node)) {
_old_pkg = list_entry(node, pkg_t, list);
- _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name);
+ _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(_old_pkg->name);
if (_new_pkg == NULL)
continue;
old_v = pkg_version_str_alloc(_old_pkg);
return 0;
}
-static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int installed_only)
+static int
+opkg_info_status_cmd(int argc, char **argv, int installed_only)
{
int i;
pkg_vec_t *available;
available = pkg_vec_alloc();
if (installed_only)
- pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
+ pkg_hash_fetch_all_installed(available);
else
- pkg_hash_fetch_available(&conf->pkg_hash, available);
+ pkg_hash_fetch_available(available);
for (i=0; i < available->len; i++) {
pkg = available->pkgs[i];
pkg_formatted_info(stdout, pkg);
- if (conf->verbosity >= OPKG_NOTICE) {
+ if (conf->verbosity >= NOTICE) {
conffile_list_elt_t *iter;
for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
conffile_t *cf = (conffile_t *)iter->data;
- int modified = conffile_has_been_modified(conf, cf);
+ int modified = conffile_has_been_modified(cf);
if (cf->value)
- opkg_message(conf, OPKG_INFO,
- "conffile=%s md5sum=%s modified=%d\n",
+ opkg_msg(INFO, "conffile=%s md5sum=%s modified=%d.\n",
cf->name, cf->value, modified);
}
}
return 0;
}
-static int opkg_info_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_info_cmd(int argc, char **argv)
{
- return opkg_info_status_cmd(conf, argc, argv, 0);
+ return opkg_info_status_cmd(argc, argv, 0);
}
-static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_status_cmd(int argc, char **argv)
{
- return opkg_info_status_cmd(conf, argc, argv, 1);
+ return opkg_info_status_cmd(argc, argv, 1);
}
-static int opkg_configure_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_configure_cmd(int argc, char **argv)
{
-
- int err;
- if (argc > 0) {
- char *pkg_name = NULL;
+ int err;
+ char *pkg_name = NULL;
- pkg_name = argv[0];
+ if (argc > 0)
+ pkg_name = argv[0];
- err = opkg_configure_packages (conf, pkg_name);
-
- } else {
- err = opkg_configure_packages (conf, NULL);
- }
+ err = opkg_configure_packages(pkg_name);
- write_status_files_if_changed(conf);
+ write_status_files_if_changed();
- return err;
+ return err;
}
-static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_remove_cmd(int argc, char **argv)
{
int i, a, done;
pkg_t *pkg;
pkg_t *pkg_to_remove;
pkg_vec_t *available;
- global_conf = conf;
done = 0;
signal(SIGINT, sigint_handler);
- pkg_info_preinstall_check(conf);
+ pkg_info_preinstall_check();
available = pkg_vec_alloc();
- pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
+ pkg_hash_fetch_all_installed(available);
for (i=0; i<argc; i++) {
for (a=0; a<available->len; a++) {
continue;
}
if (conf->restrict_to_default_dest) {
- pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
+ pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(
pkg->name,
conf->default_dest);
} else {
- pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
+ pkg_to_remove = pkg_hash_fetch_installed_by_name(pkg->name);
}
if (pkg_to_remove == NULL) {
- opkg_message(conf, OPKG_ERROR, "Package %s is not installed.\n", pkg->name);
+ opkg_msg(ERROR, "Package %s is not installed.\n", pkg->name);
continue;
}
if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
- opkg_message(conf, OPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
+ opkg_msg(ERROR, "Package %s not installed.\n", pkg->name);
continue;
}
- opkg_remove_pkg(conf, pkg_to_remove, 0);
+ opkg_remove_pkg(pkg_to_remove, 0);
done = 1;
}
}
pkg_vec_free(available);
if (done == 0)
- opkg_message(conf, OPKG_NOTICE, "No packages removed.\n");
+ opkg_msg(NOTICE, "No packages removed.\n");
- write_status_files_if_changed(conf);
+ write_status_files_if_changed();
return 0;
}
-static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_flag_cmd(int argc, char **argv)
{
int i;
pkg_t *pkg;
const char *flags = argv[0];
- global_conf = conf;
signal(SIGINT, sigint_handler);
for (i=1; i < argc; i++) {
if (conf->restrict_to_default_dest) {
- pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
- argv[i],
+ pkg = pkg_hash_fetch_installed_by_name_dest(argv[i],
conf->default_dest);
} else {
- pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
+ pkg = pkg_hash_fetch_installed_by_name(argv[i]);
}
if (pkg == NULL) {
- opkg_message(conf, OPKG_ERROR,
- "Package %s is not installed.\n", argv[i]);
+ opkg_msg(ERROR, "Package %s is not installed.\n", argv[i]);
continue;
}
if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
}
opkg_state_changed++;
- opkg_message(conf, OPKG_NOTICE,
- "Setting flags for package %s to %s\n",
+ opkg_msg(NOTICE, "Setting flags for package %s to %s.\n",
pkg->name, flags);
}
- write_status_files_if_changed(conf);
+ write_status_files_if_changed();
return 0;
}
-static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_files_cmd(int argc, char **argv)
{
pkg_t *pkg;
str_list_t *files;
char *pkg_version;
if (argc < 1) {
- return EINVAL;
+ return -1;
}
- pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
- argv[0]);
+ pkg = pkg_hash_fetch_installed_by_name(argv[0]);
if (pkg == NULL) {
- opkg_message(conf, OPKG_ERROR,
- "Package %s not installed.\n", argv[0]);
+ opkg_msg(ERROR, "Package %s not installed.\n", argv[0]);
return 0;
}
- files = pkg_get_installed_files(conf, pkg);
+ files = pkg_get_installed_files(pkg);
pkg_version = pkg_version_str_alloc(pkg);
printf("Package %s (%s) is installed on %s and has the following files:\n",
return 0;
}
-static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_depends_cmd(int argc, char **argv)
{
int i, j, k;
int depends_count;
pkg_t *pkg;
char *str;
- pkg_info_preinstall_check(conf);
+ pkg_info_preinstall_check();
available_pkgs = pkg_vec_alloc();
if (conf->query_all)
- pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
+ pkg_hash_fetch_available(available_pkgs);
else
- pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
+ pkg_hash_fetch_all_installed(available_pkgs);
for (i=0; i<argc; i++) {
for (j=0; j<available_pkgs->len; j++) {
pkg->recommends_count +
pkg->suggests_count;
- opkg_message(conf, OPKG_NOTICE, "%s depends on:\n",
- pkg->name);
+ opkg_msg(NOTICE, "%s depends on:\n", pkg->name);
for (k=0; k<depends_count; k++) {
cdep = &pkg->depends[k];
continue;
str = pkg_depend_str(pkg, k);
- opkg_message(conf, OPKG_NOTICE, "\t%s\n", str);
+ opkg_msg(NOTICE, "\t%s\n", str);
free(str);
}
return 0;
}
+static int
+pkg_mark_provides(pkg_t *pkg)
+{
+ int provides_count = pkg->provides_count;
+ abstract_pkg_t **provides = pkg->provides;
+ int i;
+ pkg->parent->state_flag |= SF_MARKED;
+ for (i = 0; i < provides_count; i++) {
+ provides[i]->state_flag |= SF_MARKED;
+ }
+ return 0;
+}
+
enum what_field_type {
WHATDEPENDS,
WHATCONFLICTS,
WHATSUGGESTS
};
-static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type what_field_type, int recursive, int argc, char **argv)
+static int
+opkg_what_depends_conflicts_cmd(enum depend_type what_field_type, int recursive, int argc, char **argv)
{
depend_t *possibility;
compound_depend_t *cdep;
available_pkgs = pkg_vec_alloc();
if (conf->query_all)
- pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
+ pkg_hash_fetch_available(available_pkgs);
else
- pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
+ pkg_hash_fetch_all_installed(available_pkgs);
/* mark the root set */
pkg_vec_clear_marks(available_pkgs);
- opkg_message(conf, OPKG_NOTICE, "Root set:\n");
+ opkg_msg(NOTICE, "Root set:\n");
for (i = 0; i < argc; i++)
pkg_vec_mark_if_matches(available_pkgs, argv[i]);
if (pkg->state_flag & SF_MARKED) {
/* mark the parent (abstract) package */
pkg_mark_provides(pkg);
- opkg_message(conf, OPKG_NOTICE, " %s\n", pkg->name);
+ opkg_msg(NOTICE, " %s\n", pkg->name);
}
}
- opkg_message(conf, OPKG_NOTICE, "What %s root set\n", rel_str);
+ opkg_msg(NOTICE, "What %s root set\n", rel_str);
do {
changed = 0;
changed++;
ver = pkg_version_str_alloc(pkg);
- opkg_message(conf, OPKG_NOTICE,
- "\t%s %s\t%s %s",
+ opkg_msg(NOTICE, "\t%s %s\t%s %s",
pkg->name,
ver,
rel_str,
possibility->pkg->name);
free(ver);
if (possibility->version) {
- opkg_message(conf, OPKG_NOTICE,
- " (%s%s)",
+ opkg_msg(NOTICE, " (%s%s)",
constraint_to_str(possibility->constraint),
possibility->version);
}
- if (!pkg_dependence_satisfiable(conf, possibility))
- opkg_message(conf, OPKG_NOTICE,
+ if (!pkg_dependence_satisfiable(possibility))
+ opkg_msg(NOTICE,
" unsatisfiable");
- opkg_message(conf, OPKG_NOTICE, "\n");
+ opkg_msg(NOTICE, "\n");
goto next_package;
}
}
return 0;
}
-static int pkg_mark_provides(pkg_t *pkg)
+static int
+opkg_whatdepends_recursively_cmd(int argc, char **argv)
{
- int provides_count = pkg->provides_count;
- abstract_pkg_t **provides = pkg->provides;
- int i;
- pkg->parent->state_flag |= SF_MARKED;
- for (i = 0; i < provides_count; i++) {
- provides[i]->state_flag |= SF_MARKED;
- }
- return 0;
+ return opkg_what_depends_conflicts_cmd(DEPEND, 1, argc, argv);
}
-static int opkg_whatdepends_recursively_cmd(opkg_conf_t *conf, int argc, char **argv)
-{
- return opkg_what_depends_conflicts_cmd(conf, DEPEND, 1, argc, argv);
-}
-static int opkg_whatdepends_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatdepends_cmd(int argc, char **argv)
{
- return opkg_what_depends_conflicts_cmd(conf, DEPEND, 0, argc, argv);
+ return opkg_what_depends_conflicts_cmd(DEPEND, 0, argc, argv);
}
-static int opkg_whatsuggests_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatsuggests_cmd(int argc, char **argv)
{
- return opkg_what_depends_conflicts_cmd(conf, SUGGEST, 0, argc, argv);
+ return opkg_what_depends_conflicts_cmd(SUGGEST, 0, argc, argv);
}
-static int opkg_whatrecommends_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatrecommends_cmd(int argc, char **argv)
{
- return opkg_what_depends_conflicts_cmd(conf, RECOMMEND, 0, argc, argv);
+ return opkg_what_depends_conflicts_cmd(RECOMMEND, 0, argc, argv);
}
-static int opkg_whatconflicts_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatconflicts_cmd(int argc, char **argv)
{
- return opkg_what_depends_conflicts_cmd(conf, CONFLICTS, 0, argc, argv);
+ return opkg_what_depends_conflicts_cmd(CONFLICTS, 0, argc, argv);
}
-static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
+static int
+opkg_what_provides_replaces_cmd(enum what_field_type what_field_type, int argc, char **argv)
{
if (argc > 0) {
const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
int i;
- pkg_info_preinstall_check(conf);
+ pkg_info_preinstall_check();
if (conf->query_all)
- pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
+ pkg_hash_fetch_available(available_pkgs);
else
- pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
+ pkg_hash_fetch_all_installed(available_pkgs);
for (i = 0; i < argc; i++) {
const char *target = argv[i];
int j;
- opkg_message(conf, OPKG_ERROR, "What %s %s\n",
+ opkg_msg(NOTICE, "What %s %s\n",
rel_str, target);
for (j = 0; j < available_pkgs->len; j++) {
pkg_t *pkg = available_pkgs->pkgs[j];
? pkg->provides[k]
: pkg->replaces[k]);
if (fnmatch(target, apkg->name, 0) == 0) {
- opkg_message(conf, OPKG_ERROR, " %s", pkg->name);
+ opkg_msg(NOTICE, " %s", pkg->name);
if (strcmp(target, apkg->name) != 0)
- opkg_message(conf, OPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
- opkg_message(conf, OPKG_ERROR, "\n");
+ opkg_msg(NOTICE, "\t%s %s\n",
+ rel_str, apkg->name);
+ opkg_msg(NOTICE, "\n");
}
}
}
return 0;
}
-static int opkg_whatprovides_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatprovides_cmd(int argc, char **argv)
{
- return opkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
+ return opkg_what_provides_replaces_cmd(WHATPROVIDES, argc, argv);
}
-static int opkg_whatreplaces_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatreplaces_cmd(int argc, char **argv)
{
- return opkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
+ return opkg_what_provides_replaces_cmd(WHATREPLACES, argc, argv);
}
-static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_search_cmd(int argc, char **argv)
{
int i;
char *installed_file;
if (argc < 1) {
- return EINVAL;
+ return -1;
}
installed = pkg_vec_alloc();
- pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
+ pkg_hash_fetch_all_installed(installed);
pkg_vec_sort(installed, pkg_compare_names);
for (i=0; i < installed->len; i++) {
pkg = installed->pkgs[i];
- installed_files = pkg_get_installed_files(conf, pkg);
+ installed_files = pkg_get_installed_files(pkg);
for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
installed_file = (char *)iter->data;
return 0;
}
-static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_compare_versions_cmd(int argc, char **argv)
{
if (argc == 3) {
/* this is a bit gross */
parse_version(&p2, argv[2]);
return pkg_version_satisfied(&p1, &p2, argv[1]);
} else {
- opkg_message(conf, OPKG_ERROR,
+ opkg_msg(ERROR,
"opkg compare_versions <v1> <op> <v2>\n"
"<op> is one of <= >= << >> =\n");
return -1;
}
}
-static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_print_architecture_cmd(int argc, char **argv)
{
nv_pair_list_elt_t *l;
}
return 0;
}
+
+
+/* XXX: CLEANUP: The usage strings should be incorporated into this
+ array for easier maintenance */
+static opkg_cmd_t cmds[] = {
+ {"update", 0, (opkg_cmd_fun_t)opkg_update_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd, PFM_SOURCE},
+ {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd, PFM_SOURCE},
+ {"list-installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd, PFM_SOURCE},
+ {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd, PFM_SOURCE},
+ {"list-upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd, PFM_SOURCE},
+ {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd, 0},
+ {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"install", 1, (opkg_cmd_fun_t)opkg_install_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"remove", 1, (opkg_cmd_fun_t)opkg_remove_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"configure", 0, (opkg_cmd_fun_t)opkg_configure_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"files", 1, (opkg_cmd_fun_t)opkg_files_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"search", 1, (opkg_cmd_fun_t)opkg_search_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"download", 1, (opkg_cmd_fun_t)opkg_download_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"compare_versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"compare-versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"print-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"print_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"print-installation-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"print_installation_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"depends", 1, (opkg_cmd_fun_t)opkg_depends_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"whatdepends", 1, (opkg_cmd_fun_t)opkg_whatdepends_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"whatdependsrec", 1, (opkg_cmd_fun_t)opkg_whatdepends_recursively_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"whatrecommends", 1, (opkg_cmd_fun_t)opkg_whatrecommends_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"whatsuggests", 1, (opkg_cmd_fun_t)opkg_whatsuggests_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"whatprovides", 1, (opkg_cmd_fun_t)opkg_whatprovides_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"whatreplaces", 1, (opkg_cmd_fun_t)opkg_whatreplaces_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+ {"whatconflicts", 1, (opkg_cmd_fun_t)opkg_whatconflicts_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+};
+
+opkg_cmd_t *
+opkg_cmd_find(const char *name)
+{
+ int i;
+ opkg_cmd_t *cmd;
+ int num_cmds = sizeof(cmds) / sizeof(opkg_cmd_t);
+
+ for (i=0; i < num_cmds; i++) {
+ cmd = &cmds[i];
+ if (strcmp(name, cmd->name) == 0)
+ return cmd;
+ }
+
+ return NULL;
+}
+
+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;
+}
#ifndef OPKG_CMD_H
#define OPKG_CMD_H
-typedef int (*opkg_cmd_fun_t)(opkg_conf_t *conf, int argc, const char **argv);
+typedef int (*opkg_cmd_fun_t)(int argc, const char **argv);
struct opkg_cmd
{
- char *name;
+ const char *name;
int requires_args;
opkg_cmd_fun_t fun;
+ uint pfm; /* package field mask */
};
typedef struct opkg_cmd opkg_cmd_t;
opkg_cmd_t *opkg_cmd_find(const char *name);
-int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc,
- const char **argv, void *userdata);
+int opkg_cmd_exec(opkg_cmd_t *cmd, int argc, const char **argv);
extern int opkg_state_changed;
#endif
#include "includes.h"
#include "opkg_conf.h"
-#include "opkg_error.h"
#include "xregex.h"
#include "sprintf_alloc.h"
#include <errno.h>
#include <glob.h>
-static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
- pkg_src_list_t *pkg_src_list,
- nv_pair_list_t *tmp_dest_nv_pair_list);
-static int opkg_conf_set_option(const opkg_option_t *options,
- const char *name, const char *value);
-static int opkg_conf_set_default_dest(opkg_conf_t *conf,
- const char *default_dest_name);
-static int set_and_load_pkg_src_list(opkg_conf_t *conf,
- pkg_src_list_t *nv_pair_list);
-static int set_and_load_pkg_dest_list(opkg_conf_t *conf,
- nv_pair_list_t *nv_pair_list);
-
-void 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 },
- { "test", OPKG_OPT_TYPE_INT, &conf->noaction },
- { "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 },
- { "proxy_user", OPKG_OPT_TYPE_STRING, &conf->proxy_user },
- { "query-all", OPKG_OPT_TYPE_BOOL, &conf->query_all },
- { "tmp_dir", OPKG_OPT_TYPE_STRING, &conf->tmp_dir },
- { "verbosity", OPKG_OPT_TYPE_BOOL, &conf->verbosity },
+static int lock_fd;
+
+static opkg_conf_t _conf;
+opkg_conf_t *conf = &_conf;
+
+/*
+ * Config file options
+ */
+opkg_option_t options[] = {
+ { "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_BOOL, &_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 },
+ { "test", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
+ { "noaction", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
+ { "nodeps", OPKG_OPT_TYPE_BOOL, &_conf.nodeps },
+ { "offline_root", OPKG_OPT_TYPE_STRING, &_conf.offline_root },
+ { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd },
+ { "proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user },
+ { "query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all },
+ { "tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir },
+ { "verbosity", OPKG_OPT_TYPE_INT, &_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 },
+ { "signature_ca_file", OPKG_OPT_TYPE_STRING, &_conf.signature_ca_file },
+ { "signature_ca_path", OPKG_OPT_TYPE_STRING, &_conf.signature_ca_path },
#endif
#if defined(HAVE_PATHFINDER)
- { "check_x509_path", OPKG_OPT_TYPE_INT, &conf->check_x509_path },
+ { "check_x509_path", OPKG_OPT_TYPE_BOOL, &_conf.check_x509_path },
#endif
#if defined(HAVE_SSLCURL) && defined(HAVE_CURL)
- { "ssl_engine", OPKG_OPT_TYPE_STRING, &conf->ssl_engine },
- { "ssl_cert", OPKG_OPT_TYPE_STRING, &conf->ssl_cert },
- { "ssl_cert_type", OPKG_OPT_TYPE_STRING, &conf->ssl_cert_type },
- { "ssl_key", OPKG_OPT_TYPE_STRING, &conf->ssl_key },
- { "ssl_key_type", OPKG_OPT_TYPE_STRING, &conf->ssl_key_type },
- { "ssl_key_passwd", OPKG_OPT_TYPE_STRING, &conf->ssl_key_passwd },
- { "ssl_ca_file", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_file },
- { "ssl_ca_path", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_path },
- { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL, &conf->ssl_dont_verify_peer },
+ { "ssl_engine", OPKG_OPT_TYPE_STRING, &_conf.ssl_engine },
+ { "ssl_cert", OPKG_OPT_TYPE_STRING, &_conf.ssl_cert },
+ { "ssl_cert_type", OPKG_OPT_TYPE_STRING, &_conf.ssl_cert_type },
+ { "ssl_key", OPKG_OPT_TYPE_STRING, &_conf.ssl_key },
+ { "ssl_key_type", OPKG_OPT_TYPE_STRING, &_conf.ssl_key_type },
+ { "ssl_key_passwd", OPKG_OPT_TYPE_STRING, &_conf.ssl_key_passwd },
+ { "ssl_ca_file", OPKG_OPT_TYPE_STRING, &_conf.ssl_ca_file },
+ { "ssl_ca_path", OPKG_OPT_TYPE_STRING, &_conf.ssl_ca_path },
+ { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL, &_conf.ssl_dont_verify_peer },
#endif
- { NULL }
- };
-
- *options = xcalloc(1, sizeof(tmp));
- memcpy(*options, tmp, sizeof(tmp));
+ { NULL, 0, NULL }
};
-static void opkg_conf_override_string(char **conf_str, char *arg_str)
-{
- if (arg_str) {
- if (*conf_str) {
- free(*conf_str);
- }
- *conf_str = xstrdup(arg_str);
- }
-}
-
-static void opkg_conf_free_string(char **conf_str)
-{
- if (*conf_str) {
- free(*conf_str);
- *conf_str = NULL;
- }
-}
-
-int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
-{
- int err;
- int errno_copy;
- char *tmp_dir_base, *tmp2;
- nv_pair_list_t tmp_dest_nv_pair_list;
- char *lock_file = NULL;
- glob_t globbuf;
- char *etc_opkg_conf_pattern;
- char *offline_root = NULL;
-
- memset(conf, 0, sizeof(opkg_conf_t));
-
-#if defined(HAVE_PATHFINDER)
- conf->check_x509_path = 1;
-#endif
-
- pkg_src_list_init(&conf->pkg_src_list);
-
- nv_pair_list_init(&tmp_dest_nv_pair_list);
- pkg_dest_list_init(&conf->pkg_dest_list);
-
- nv_pair_list_init(&conf->arch_list);
-
- conf->restrict_to_default_dest = 0;
- conf->default_dest = NULL;
-
- if (args->conf_file) {
- struct stat stat_buf;
- err = stat(args->conf_file, &stat_buf);
- if (err == 0)
- if (opkg_conf_parse_file(conf, args->conf_file,
- &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
- /* Memory leakage from opkg_conf_parse-file */
- return -1;
- }
- }
-
- opkg_conf_override_string(&conf->offline_root, args->offline_root);
- offline_root = conf->offline_root;
-
- if (conf->offline_root)
- sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", conf->offline_root);
- else {
- char *conf_file_dir = getenv("OPKG_CONF_DIR");
- if (conf_file_dir == NULL)
- conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
- 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);
- free (etc_opkg_conf_pattern);
- if (!err) {
- int i;
- for (i = 0; i < globbuf.gl_pathc; i++) {
- if (globbuf.gl_pathv[i])
- if (args->conf_file &&
- !strcmp(args->conf_file, globbuf.gl_pathv[i]))
- continue;
- if ( opkg_conf_parse_file(conf, globbuf.gl_pathv[i],
- &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
- /* Memory leakage from opkg_conf_parse-file */
- return -1;
- }
- if (offline_root != conf->offline_root) {
- opkg_message(conf, OPKG_ERROR,
- "Config file %s, within an offline "
- "root contains option offline_root.\n",
- globbuf.gl_pathv[i]);
- return -1;
- }
- }
- }
- globfree(&globbuf);
-
- 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,
- args->offline_root_post_script_cmd);
-
- opkg_conf_override_string(&conf->cache, args->cache);
- opkg_conf_override_string(&conf->tmp_dir, args->tmp_dir);
-
- /* check for lock file */
- if (conf->offline_root)
- sprintf_alloc (&lock_file, "%s/%s/lock", conf->offline_root, OPKG_STATE_DIR_PREFIX);
- else
- sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX);
-
- err = conf->lock_fd = creat (lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
- if (err != -1)
- err = lockf (conf->lock_fd, F_TLOCK, 0);
- errno_copy = errno;
-
- if (err) {
- opkg_message (conf, OPKG_ERROR, "Could not lock %s: %s\n",
- lock_file, strerror(errno_copy));
- free(lock_file);
- return -1;
- }
- free(lock_file);
-
- if (conf->tmp_dir)
- tmp_dir_base = conf->tmp_dir;
- else
- tmp_dir_base = getenv("TMPDIR");
- sprintf_alloc(&tmp2, "%s/%s",
- tmp_dir_base ? tmp_dir_base : OPKG_CONF_DEFAULT_TMP_DIR_BASE,
- OPKG_CONF_TMP_DIR_SUFFIX);
- if (conf->tmp_dir)
- free(conf->tmp_dir);
- conf->tmp_dir = mkdtemp(tmp2);
- if (conf->tmp_dir == NULL) {
- opkg_message(conf, OPKG_ERROR,
- "%s: Creating temp dir %s failed: %s\n",
- __FUNCTION__, tmp2, strerror(errno));
- return -1;
- }
-
- pkg_hash_init("pkg-hash", &conf->pkg_hash, OPKG_CONF_DEFAULT_HASH_LEN);
- hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
- hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN/16);
-
- if (conf->lists_dir == NULL)
- conf->lists_dir = xstrdup(OPKG_CONF_LISTS_DIR);
-
- if (conf->offline_root) {
- char *tmp;
- sprintf_alloc(&tmp, "%s/%s", conf->offline_root, conf->lists_dir);
- free(conf->lists_dir);
- conf->lists_dir = tmp;
- }
-
- /* if no architectures were defined, then default all, noarch, and host architecture */
- if (nv_pair_list_empty(&conf->arch_list)) {
- nv_pair_list_append(&conf->arch_list, "all", "1");
- nv_pair_list_append(&conf->arch_list, "noarch", "1");
- nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
- }
-
- /* Even if there is no conf file, we'll need at least one dest. */
- 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);
- }
-
- /* After parsing the file, set options from command-line, (so that
- command-line arguments take precedence) */
- /* XXX: CLEANUP: The interaction between args.c and opkg_conf.c
- really needs to be cleaned up. There is so much duplication
- right now it is ridiculous. Maybe opkg_conf_t should just save
- a pointer to args_t (which could then not be freed), rather
- than duplicating every field here? */
- if (args->autoremove) {
- conf->autoremove = 1;
- }
- if (args->force_depends) {
- conf->force_depends = 1;
- }
- if (args->force_defaults) {
- conf->force_defaults = 1;
- }
- if (args->force_maintainer) {
- conf->force_maintainer = 1;
- }
- if (args->force_overwrite) {
- conf->force_overwrite = 1;
- }
- if (args->force_downgrade) {
- conf->force_downgrade = 1;
- }
- if (args->force_space) {
- conf->force_space = 1;
- }
- if (args->force_reinstall) {
- conf->force_reinstall = 1;
- }
- if (args->force_removal_of_dependent_packages) {
- conf->force_removal_of_dependent_packages = 1;
- }
- if (args->force_removal_of_essential_packages) {
- conf->force_removal_of_essential_packages = 1;
- }
- if (args->nodeps) {
- conf->nodeps = 1;
- }
- if (args->noaction) {
- conf->noaction = 1;
- }
- if (args->query_all) {
- conf->query_all = 1;
- }
- if (args->verbosity != conf->verbosity) {
- conf->verbosity = args->verbosity;
- }
-
-/* Pigi: added a flag to disable the checking of structures if the command does not need to
- read anything from there.
-*/
- if (!(args->nocheckfordirorfile)) {
-
- if (!(args->noreadfeedsfile)) {
- if (set_and_load_pkg_src_list(conf, &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(conf, &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(conf, args->dest);
- if (err) {
- nv_pair_list_deinit(&tmp_dest_nv_pair_list);
- return -1;
- }
- }
- }
- nv_pair_list_deinit(&tmp_dest_nv_pair_list);
-
- return 0;
-}
-
-void opkg_conf_deinit(opkg_conf_t *conf)
-{
- rm_r(conf->tmp_dir);
-
- free(conf->tmp_dir);
- free(conf->lists_dir);
-
- pkg_src_list_deinit(&conf->pkg_src_list);
- pkg_dest_list_deinit(&conf->pkg_dest_list);
- nv_pair_list_deinit(&conf->arch_list);
-
- opkg_conf_free_string(&conf->cache);
-
- opkg_conf_free_string(&conf->ftp_proxy);
- opkg_conf_free_string(&conf->http_proxy);
- opkg_conf_free_string(&conf->no_proxy);
-
- 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);
-
- opkg_conf_free_string(&conf->proxy_passwd);
- opkg_conf_free_string(&conf->proxy_user);
-
-#if defined(HAVE_OPENSSL)
- opkg_conf_free_string(&conf->signature_ca_file);
- opkg_conf_free_string(&conf->signature_ca_path);
-#endif
-
-#if defined(HAVE_SSLCURL)
- opkg_conf_free_string(&conf->ssl_engine);
- opkg_conf_free_string(&conf->ssl_cert);
- opkg_conf_free_string(&conf->ssl_cert_type);
- opkg_conf_free_string(&conf->ssl_key);
- opkg_conf_free_string(&conf->ssl_key_type);
- opkg_conf_free_string(&conf->ssl_key_passwd);
- opkg_conf_free_string(&conf->ssl_ca_file);
- opkg_conf_free_string(&conf->ssl_ca_path);
-#endif
-
- if (conf->verbosity >= OPKG_DEBUG) {
- hash_print_stats(&conf->pkg_hash);
- hash_print_stats(&conf->file_hash);
- hash_print_stats(&conf->obs_file_hash);
- }
-
- if (&conf->pkg_hash)
- pkg_hash_deinit(&conf->pkg_hash);
- if (&conf->file_hash)
- hash_table_deinit(&conf->file_hash);
- if (&conf->obs_file_hash)
- hash_table_deinit(&conf->obs_file_hash);
-
- /* lockf maybe defined with warn_unused_result */
- if(lockf(conf->lock_fd, F_ULOCK, 0) != 0){
- opkg_message(conf, OPKG_DEBUG, "%s: unlock failed: %s\n",
- __FUNCTION__,
- strerror(errno));
- }
- close(conf->lock_fd);
-}
-
-static int opkg_conf_set_default_dest(opkg_conf_t *conf,
- const char *default_dest_name)
+static int
+opkg_conf_set_default_dest(const char *default_dest_name)
{
pkg_dest_list_elt_t *iter;
pkg_dest_t *dest;
}
}
- fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
+ opkg_msg(ERROR, "Unknown dest name: `%s'.\n", default_dest_name);
return 1;
}
static int
-set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
+set_and_load_pkg_src_list(pkg_src_list_t *pkg_src_list)
{
pkg_src_list_elt_t *iter;
pkg_src_t *src;
src->name);
if (file_exists(list_file)) {
- if (pkg_hash_add_from_file(conf, list_file, src, NULL, 0)) {
+ if (pkg_hash_add_from_file(list_file, src, NULL, 0)) {
free(list_file);
return -1;
}
}
static int
-set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list)
+set_and_load_pkg_dest_list(nv_pair_list_t *nv_pair_list)
{
nv_pair_list_elt_t *iter;
nv_pair_t *nv_pair;
conf->default_dest = dest;
}
if (file_exists(dest->status_file_name)) {
- if (pkg_hash_add_from_file(conf, dest->status_file_name,
+ if (pkg_hash_add_from_file(dest->status_file_name,
NULL, dest, 1))
return -1;
}
return 0;
}
-static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
+static int
+opkg_conf_set_option(const char *name, const char *value)
+{
+ int i = 0;
+ while (options[i].name) {
+ if (strcmp(options[i].name, name) == 0) {
+ switch (options[i].type) {
+ case OPKG_OPT_TYPE_BOOL:
+ if (*(int *)options[i].value) {
+ opkg_msg(ERROR, "Duplicate boolean option %s, "
+ "leaving this option on.\n", name);
+ return 0;
+ }
+ *((int * const)options[i].value) = 1;
+ return 0;
+ case OPKG_OPT_TYPE_INT:
+ if (value) {
+ if (*(int *)options[i].value) {
+ opkg_msg(ERROR, "Duplicate option %s, "
+ "using first seen value \"%d\".\n",
+ name, *((int *)options[i].value));
+ return 0;
+ }
+ *((int * const)options[i].value) = atoi(value);
+ return 0;
+ } else {
+ opkg_msg(ERROR, "Option %s needs an argument\n",
+ name);
+ return -1;
+ }
+ case OPKG_OPT_TYPE_STRING:
+ if (value) {
+ if (*(char **)options[i].value) {
+ opkg_msg(ERROR, "Duplicate option %s, "
+ "using first seen value \"%s\".\n",
+ name, *((char **)options[i].value));
+ return 0;
+ }
+ *((char ** const)options[i].value) = xstrdup(value);
+ return 0;
+ } else {
+ opkg_msg(ERROR, "Option %s needs an argument\n",
+ name);
+ return -1;
+ }
+ }
+ }
+ i++;
+ }
+
+ opkg_msg(ERROR, "Unrecognized option: %s=%s\n", name, value);
+ return -1;
+}
+
+static int
+opkg_conf_parse_file(const char *filename,
pkg_src_list_t *pkg_src_list,
nv_pair_list_t *tmp_dest_nv_pair_list)
{
int err;
- opkg_option_t * options;
FILE *file;
regex_t valid_line_re, comment_re;
#define regmatch_size 12
regmatch_t regmatch[regmatch_size];
- opkg_init_options_array(conf, &options);
-
file = fopen(filename, "r");
if (file == NULL) {
- fprintf(stderr, "%s: failed to open %s: %s\n",
- __FUNCTION__, filename, strerror(errno));
- free(options);
+ opkg_perror(ERROR, "Failed to open %s", filename);
return -1;
}
- opkg_message(conf, OPKG_NOTICE, "loading conf file %s\n", filename);
+
+ opkg_msg(INFO, "Loading conf file %s.\n", filename);
err = xregcomp(&comment_re,
"^[[:space:]]*(#.*|[[:space:]]*)$",
REG_EXTENDED);
if (err) {
- free(options);
return -1;
}
err = xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
if (err) {
- free(options);
return -1;
}
}
if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
- fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
+ opkg_msg(ERROR, "%s:%d: Ignoring invalid line: `%s'\n",
filename, line_num, line);
goto NEXT_LINE;
}
pkg_dest_list_init. (We do a similar thing with
tmp_src_nv_pair_list for sake of symmetry.) */
if (strcmp(type, "option") == 0) {
- opkg_conf_set_option(options, name, value);
+ opkg_conf_set_option(name, value);
} else if (strcmp(type, "src") == 0) {
if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
pkg_src_list_append (pkg_src_list, name, value, extra, 0);
} else {
- opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
- name, value);
+ opkg_msg(ERROR, "Duplicate src declaration (%s %s). "
+ "Skipping.\n", name, value);
}
} else if (strcmp(type, "src/gz") == 0) {
if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
pkg_src_list_append (pkg_src_list, name, value, extra, 1);
} else {
- opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
- name, value);
+ opkg_msg(ERROR, "Duplicate src declaration (%s %s). "
+ "Skipping.\n", name, value);
}
} else if (strcmp(type, "dest") == 0) {
nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
} else if (strcmp(type, "lists_dir") == 0) {
conf->lists_dir = xstrdup(value);
} else if (strcmp(type, "arch") == 0) {
- opkg_message(conf, OPKG_INFO, "supported arch %s priority (%s)\n", name, value);
+ opkg_msg(INFO, "Supported arch %s priority (%s)\n", name, value);
if (!value) {
- opkg_message(conf, OPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
+ opkg_msg(NOTICE, "No priority given for architecture %s,"
+ "defaulting to 10\n", name);
value = xstrdup("10");
}
nv_pair_list_append(&conf->arch_list, name, value);
} else {
- fprintf(stderr, "WARNING: Ignoring unknown configuration "
+ opkg_msg(ERROR, "Ignoring unknown configuration "
"parameter: %s %s %s\n", type, name, value);
- free(options);
return -1;
}
free(line);
}
- free(options);
regfree(&comment_re);
regfree(&valid_line_re);
fclose(file);
return 0;
}
-static int opkg_conf_set_option(const opkg_option_t *options,
- const char *name, const char *value)
-{
- int i = 0;
- while (options[i].name) {
- if (strcmp(options[i].name, name) == 0) {
- switch (options[i].type) {
- case OPKG_OPT_TYPE_BOOL:
- *((int *)options[i].value) = 1;
- return 0;
- case OPKG_OPT_TYPE_INT:
- if (value) {
- *((int *)options[i].value) = atoi(value);
- return 0;
- } else {
- printf("%s: Option %s need an argument\n",
- __FUNCTION__, name);
- return EINVAL;
- }
- case OPKG_OPT_TYPE_STRING:
- if (value) {
- *((char **)options[i].value) = xstrdup(value);
- return 0;
- } else {
- printf("%s: Option %s need an argument\n",
- __FUNCTION__, name);
- return EINVAL;
- }
- }
- }
- i++;
- }
-
- fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
- __FUNCTION__, name, value);
- return EINVAL;
-}
-
-int opkg_conf_write_status_files(opkg_conf_t *conf)
+int
+opkg_conf_write_status_files(void)
{
pkg_dest_list_elt_t *iter;
pkg_dest_t *dest;
dest->status_fp = fopen(dest->status_file_name, "w");
if (dest->status_fp == NULL) {
- fprintf(stderr, "%s: Can't open status file: %s: %s\n",
- __FUNCTION__, dest->status_file_name, strerror(errno));
+ opkg_perror(ERROR, "Can't open status file %s",
+ dest->status_file_name);
ret = -1;
}
}
all = pkg_vec_alloc();
- pkg_hash_fetch_available(&conf->pkg_hash, all);
+ pkg_hash_fetch_available(all);
for(i = 0; i < all->len; i++) {
pkg = all->pkgs[i];
continue;
}
if (pkg->dest == NULL) {
- fprintf(stderr, "%s: ERROR: Can't write status for "
- "package %s since it has a NULL dest\n",
- __FUNCTION__, pkg->name);
+ opkg_msg(ERROR, "Internal error: package %s has a NULL dest\n",
+ pkg->name);
continue;
}
if (pkg->dest->status_fp)
}
-char *root_filename_alloc(opkg_conf_t *conf, char *filename)
+char *
+root_filename_alloc(char *filename)
+{
+ char *root_filename;
+ sprintf_alloc(&root_filename, "%s%s",
+ (conf->offline_root ? conf->offline_root : ""), filename);
+ return root_filename;
+}
+
+int
+opkg_conf_init(const args_t *args)
{
- char *root_filename;
- sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
- return root_filename;
+ int err;
+ char *tmp_dir_base, *tmp2;
+ nv_pair_list_t tmp_dest_nv_pair_list;
+ char *lock_file = NULL;
+ glob_t globbuf;
+ char *etc_opkg_conf_pattern;
+
+ conf->restrict_to_default_dest = 0;
+ conf->default_dest = NULL;
+#if defined(HAVE_PATHFINDER)
+ conf->check_x509_path = 1;
+#endif
+
+ pkg_src_list_init(&conf->pkg_src_list);
+
+ nv_pair_list_init(&tmp_dest_nv_pair_list);
+ pkg_dest_list_init(&conf->pkg_dest_list);
+
+ nv_pair_list_init(&conf->arch_list);
+
+ if (args->conf_file) {
+ struct stat stat_buf;
+ err = stat(args->conf_file, &stat_buf);
+ if (err == 0)
+ if (opkg_conf_parse_file(args->conf_file,
+ &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
+ /* Memory leakage from opkg_conf_parse-file */
+ return -1;
+ }
+ }
+
+ if (conf->offline_root)
+ sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", conf->offline_root);
+ else {
+ const char *conf_file_dir = getenv("OPKG_CONF_DIR");
+ if (conf_file_dir == NULL)
+ conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
+ 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);
+ free (etc_opkg_conf_pattern);
+ if (!err) {
+ int i;
+ for (i = 0; i < globbuf.gl_pathc; i++) {
+ if (globbuf.gl_pathv[i])
+ if (args->conf_file &&
+ !strcmp(args->conf_file, globbuf.gl_pathv[i]))
+ continue;
+ if ( opkg_conf_parse_file(globbuf.gl_pathv[i],
+ &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
+ /* Memory leakage from opkg_conf_parse-file */
+ return -1;
+ }
+ }
+ }
+ globfree(&globbuf);
+
+ /* check for lock file */
+ if (conf->offline_root)
+ sprintf_alloc (&lock_file, "%s/%s/lock", conf->offline_root, OPKG_STATE_DIR_PREFIX);
+ else
+ sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX);
+
+ if (creat(lock_file, S_IRUSR | S_IWUSR | S_IRGRP) == -1) {
+ opkg_perror(ERROR, "Could not create lock file %s", lock_file);
+ free(lock_file);
+ return -1;
+ }
+
+ if (lockf(lock_fd, F_TLOCK, (off_t)0) == -1) {
+ opkg_perror(ERROR, "Could not lock %s", lock_file);
+ free(lock_file);
+ return -1;
+ }
+
+ free(lock_file);
+
+ if (conf->tmp_dir)
+ tmp_dir_base = conf->tmp_dir;
+ else
+ tmp_dir_base = getenv("TMPDIR");
+ sprintf_alloc(&tmp2, "%s/%s",
+ tmp_dir_base ? tmp_dir_base : OPKG_CONF_DEFAULT_TMP_DIR_BASE,
+ OPKG_CONF_TMP_DIR_SUFFIX);
+ if (conf->tmp_dir)
+ free(conf->tmp_dir);
+ conf->tmp_dir = mkdtemp(tmp2);
+ if (conf->tmp_dir == NULL) {
+ opkg_perror(ERROR, "Creating temp dir %s failed", tmp2);
+ return -1;
+ }
+
+ pkg_hash_init();
+ hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
+ hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN/16);
+
+ if (conf->lists_dir == NULL)
+ conf->lists_dir = xstrdup(OPKG_CONF_LISTS_DIR);
+
+ if (conf->offline_root) {
+ char *tmp;
+ sprintf_alloc(&tmp, "%s/%s", conf->offline_root, conf->lists_dir);
+ free(conf->lists_dir);
+ conf->lists_dir = tmp;
+ }
+
+ /* if no architectures were defined, then default all, noarch, and host architecture */
+ if (nv_pair_list_empty(&conf->arch_list)) {
+ nv_pair_list_append(&conf->arch_list, "all", "1");
+ nv_pair_list_append(&conf->arch_list, "noarch", "1");
+ nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
+ }
+
+ /* Even if there is no conf file, we'll need at least one dest. */
+ 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);
+ }
+
+ 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;
+ }
+ }
+ }
+ nv_pair_list_deinit(&tmp_dest_nv_pair_list);
+
+ return 0;
+}
+
+void
+opkg_conf_deinit(void)
+{
+ int i;
+ char **tmp;
+
+ rm_r(conf->tmp_dir);
+
+ free(conf->lists_dir);
+
+ pkg_src_list_deinit(&conf->pkg_src_list);
+ pkg_dest_list_deinit(&conf->pkg_dest_list);
+ nv_pair_list_deinit(&conf->arch_list);
+
+ for (i=0; options[i].name; i++) {
+ if (options[i].type == OPKG_OPT_TYPE_STRING) {
+ tmp = (char **)options[i].value;
+ if (*tmp) {
+ free(*tmp);
+ *tmp = NULL;
+ }
+ }
+ }
+
+ if (conf->verbosity >= DEBUG) {
+ hash_print_stats(&conf->pkg_hash);
+ hash_print_stats(&conf->file_hash);
+ hash_print_stats(&conf->obs_file_hash);
+ }
+
+ if (&conf->pkg_hash)
+ pkg_hash_deinit();
+ if (&conf->file_hash)
+ hash_table_deinit(&conf->file_hash);
+ if (&conf->obs_file_hash)
+ hash_table_deinit(&conf->obs_file_hash);
+
+ /* lockf may be defined with warn_unused_result */
+ if (lockf(lock_fd, F_ULOCK, (off_t)0) != 0) {
+ opkg_perror(ERROR, "unlock failed");
+ }
+
+ close(lock_fd);
}
#define OPKG_CONF_H
typedef struct opkg_conf opkg_conf_t;
+extern opkg_conf_t *conf;
#include "hash_table.h"
#include "args.h"
struct opkg_conf
{
- int lock_fd; /* file descriptor for the lock file */
pkg_src_list_t pkg_src_list;
pkg_dest_list_t pkg_dest_list;
nv_pair_list_t arch_list;
char *tmp_dir;
char *lists_dir;
+ uint pfm; /* package field mask */
+
/* options */
int autoremove;
int force_depends;
int check_signature;
int nodeps; /* do not follow dependences */
char *offline_root;
- char *offline_root_path;
- char *offline_root_pre_script_cmd;
- char *offline_root_post_script_cmd;
int query_all;
int verbosity;
int noaction;
struct opkg_option {
const char *name;
const opkg_option_type_t type;
- const void *value;
+ void * const value;
};
-int opkg_conf_init(opkg_conf_t *conf, const args_t *args);
-void opkg_conf_deinit(opkg_conf_t *conf);
-
-int opkg_conf_write_status_files(opkg_conf_t *conf);
-char *root_filename_alloc(opkg_conf_t *conf, char *filename);
-
+int opkg_conf_init(const args_t *args);
+void opkg_conf_deinit(void);
-void opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options);
+int opkg_conf_write_status_files(void);
+char *root_filename_alloc(char *filename);
#endif
#include "opkg_message.h"
#include "opkg_cmd.h"
-int opkg_configure(opkg_conf_t *conf, pkg_t *pkg)
+int
+opkg_configure(pkg_t *pkg)
{
int err;
/* DPKG_INCOMPATIBILITY:
dpkg actually includes a version number to this script call */
- err = pkg_run_script(conf, pkg, "postinst", "configure");
+ err = pkg_run_script(pkg, "postinst", "configure");
if (err) {
- opkg_message(conf, OPKG_ERROR, "ERROR: %s.postinst returned %d\n", pkg->name, err);
+ opkg_msg(ERROR, "%s.postinst returned %d.\n", pkg->name, err);
return err;
}
#include "opkg_conf.h"
-int opkg_configure(opkg_conf_t *opkg_conf, pkg_t *pkg);
+int opkg_configure(pkg_t *pkg);
#endif
#endif
#ifdef HAVE_OPENSSL
-static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath);
+static X509_STORE *setup_verify(char *CAfile, char *CApath);
#endif
#ifdef HAVE_CURL
* each time
*/
static CURL *curl = NULL;
-static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data);
+static CURL *opkg_curl_init(curl_progress_func cb, void *data);
#endif
static int
return (strncmp(str, prefix, strlen(prefix)) == 0);
}
-int opkg_download(opkg_conf_t *conf, const char *src,
- const char *dest_file_name, curl_progress_func cb, void *data)
+int
+opkg_download(const char *src, const char *dest_file_name,
+ curl_progress_func cb, void *data)
{
int err = 0;
char *src_base = basename(src_basec);
char *tmp_file_location;
- opkg_message(conf,OPKG_NOTICE,"Downloading %s\n", src);
+ free(src_basec);
+
+ opkg_msg(NOTICE,"Downloading %s.\n", src);
if (str_starts_with(src, "file:")) {
const char *file_src = src + 5;
- opkg_message(conf,OPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
+ opkg_msg(INFO, "Copying %s to %s...", file_src, dest_file_name);
err = file_copy(file_src, dest_file_name);
- opkg_message(conf,OPKG_INFO,"Done\n");
- free(src_basec);
+ opkg_msg(INFO, "Done.\n");
return err;
}
sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
err = unlink(tmp_file_location);
if (err && errno != ENOENT) {
- opkg_message(conf,OPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
- __FUNCTION__, tmp_file_location, strerror(errno));
+ opkg_perror(ERROR, "Failed to unlink %s\n", tmp_file_location);
free(tmp_file_location);
- free(src_basec);
return -1;
}
if (conf->http_proxy) {
- opkg_message(conf,OPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
+ opkg_msg(DEBUG, "Setting environment variable: http_proxy = %s.\n",
+ conf->http_proxy);
setenv("http_proxy", conf->http_proxy, 1);
}
if (conf->ftp_proxy) {
- opkg_message(conf,OPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
+ opkg_msg(DEBUG, "Setting environment variable: ftp_proxy = %s.\n",
+ conf->ftp_proxy);
setenv("ftp_proxy", conf->ftp_proxy, 1);
}
if (conf->no_proxy) {
- opkg_message(conf,OPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
+ opkg_msg(DEBUG,"Setting environment variable: no_proxy = %s.\n",
+ conf->no_proxy);
setenv("no_proxy", conf->no_proxy, 1);
}
CURLcode res;
FILE * file = fopen (tmp_file_location, "w");
- curl = opkg_curl_init (conf, cb, data);
+ curl = opkg_curl_init (cb, data);
if (curl)
{
curl_easy_setopt (curl, CURLOPT_URL, src);
{
long error_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code);
- opkg_message(conf, OPKG_ERROR, "Failed to download %s. \nerror detail: %s\n", src, curl_easy_strerror(res));
+ opkg_msg(ERROR, "Failed to download %s: %s.\n",
+ src, curl_easy_strerror(res));
free(tmp_file_location);
- free(src_basec);
return res;
}
else
{
free(tmp_file_location);
- free(src_basec);
return -1;
}
#else
res = xsystem(argv);
if (res) {
- opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, res);
+ opkg_msg(ERROR, "Failed to download %s, wget returned %d.\n", src, res);
free(tmp_file_location);
- free(src_basec);
return res;
}
}
err = file_move(tmp_file_location, dest_file_name);
free(tmp_file_location);
- free(src_basec);
return err;
}
-static int opkg_download_cache(opkg_conf_t *conf, const char *src,
- const char *dest_file_name, curl_progress_func cb, void *data)
+static int
+opkg_download_cache(const char *src, const char *dest_file_name,
+ curl_progress_func cb, void *data)
{
char *cache_name = xstrdup(src);
char *cache_location, *p;
int err = 0;
if (!conf->cache || str_starts_with(src, "file:")) {
- err = opkg_download(conf, src, dest_file_name, cb, data);
+ err = opkg_download(src, dest_file_name, cb, data);
goto out1;
}
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);
+ opkg_msg(NOTICE, "Copying %s.\n", cache_location);
else {
- err = opkg_download(conf, src, cache_location, cb, data);
+ err = opkg_download(src, cache_location, cb, data);
if (err) {
(void) unlink(cache_location);
goto out2;
return err;
}
-int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
+int
+opkg_download_pkg(pkg_t *pkg, const char *dir)
{
int err;
char *url;
char *stripped_filename;
if (pkg->src == NULL) {
- opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
- pkg->name, pkg->parent->name);
+ opkg_msg(ERROR, "Package %s is not available from any configured src.\n",
+ pkg->name);
return -1;
}
if (pkg->filename == NULL) {
- opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) does not have a valid filename field.\n",pkg->name, pkg->parent->name);
+ opkg_msg(ERROR, "Package %s does not have a valid filename field.\n",
+ pkg->name);
return -1;
}
sprintf_alloc(&pkg->local_filename, "%s/%s", dir, stripped_filename);
- err = opkg_download_cache(conf, url, pkg->local_filename, NULL, NULL);
+ err = opkg_download_cache(url, pkg->local_filename, NULL, NULL);
free(url);
return err;
/*
* Downloads file from url, installs in package database, return package name.
*/
-int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep)
+int
+opkg_prepare_url_for_install(const char *url, char **namep)
{
int err = 0;
pkg_t *pkg;
char *file_base = basename(file_basec);
sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
- err = opkg_download(conf, url, tmp_file, NULL, NULL);
+ err = opkg_download(url, tmp_file, NULL, NULL);
if (err)
return err;
- err = pkg_init_from_file(conf, pkg, tmp_file);
+ err = pkg_init_from_file(pkg, tmp_file);
if (err)
return err;
|| strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
|| strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
- err = pkg_init_from_file(conf, pkg, url);
+ err = pkg_init_from_file(pkg, url);
if (err)
return err;
- opkg_message(conf, OPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
+ opkg_msg(DEBUG2, "Package %s provided by hand (%s).\n",
+ pkg->name, pkg->local_filename);
pkg->provided_by_hand = 1;
} else {
return 0;
}
- if (!pkg->architecture) {
- opkg_message(conf, OPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
- return -1;
- }
-
pkg->dest = conf->default_dest;
pkg->state_want = SW_INSTALL;
pkg->state_flag |= SF_PREFER;
- pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
+ hash_insert_pkg(pkg, 1);
if (namep) {
*namep = pkg->name;
}
int
-opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
+opkg_verify_file (char *text_file, char *sig_file)
{
#if defined HAVE_GPGME
if (conf->check_signature == 0 )
int status = -1;
gpgme_ctx_t ctx;
gpgme_data_t sig, text, key;
- gpgme_error_t err = -1;
+ gpgme_error_t err;
gpgme_verify_result_t result;
gpgme_signature_t s;
char *trusted_path = NULL;
openssl_init();
// Set-up the key store
- if(!(store = setup_verify(conf, conf->signature_ca_file, conf->signature_ca_path))){
- opkg_message(conf, OPKG_ERROR,
- "Can't open CA certificates\n");
+ if(!(store = setup_verify(conf->signature_ca_file, conf->signature_ca_path))){
+ opkg_msg(ERROR, "Can't open CA certificates.\n");
goto verify_file_end;
}
// Open a BIO to read the sig file
if (!(in = BIO_new_file(sig_file, "rb"))){
- opkg_message(conf, OPKG_ERROR,
- "Can't open signature file %s\n", sig_file);
+ opkg_msg(ERROR, "Can't open signature file %s.\n", sig_file);
goto verify_file_end;
}
// Read the PKCS7 block contained in the sig file
p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
if(!p7){
- opkg_message(conf, OPKG_ERROR,
- "Can't read signature file (Corrupted ?)\n");
+ opkg_msg(ERROR, "Can't read signature file %s (Corrupted ?).\n",
+ sig_file);
goto verify_file_end;
}
#if defined(HAVE_PATHFINDER)
if(conf->check_x509_path){
if(!pkcs7_pathfinder_verify_signers(p7)){
- opkg_message(conf, OPKG_ERROR, "pkcs7_pathfinder_verify_signers: "
- "Path verification failed\n");
+ opkg_msg(ERROR, "pkcs7_pathfinder_verify_signers: "
+ "Path verification failed.\n");
goto verify_file_end;
}
}
// Open the Package file to authenticate
if (!(indata = BIO_new_file(text_file, "rb"))){
- opkg_message(conf, OPKG_ERROR,
- "Can't open file %s\n", text_file);
+ opkg_msg(ERROR, "Can't open file %s.\n", text_file);
goto verify_file_end;
}
// Let's verify the autenticity !
if (PKCS7_verify(p7, NULL, store, indata, NULL, PKCS7_BINARY) != 1){
// Get Off My Lawn!
- opkg_message(conf, OPKG_ERROR,
- "Verification failure\n");
+ opkg_msg(ERROR, "Verification failure.\n");
}else{
// Victory !
status = 0;
#if defined HAVE_OPENSSL
-static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){
+static X509_STORE *
+setup_verify(char *CAfile, char *CApath)
+{
X509_STORE *store = NULL;
X509_LOOKUP *lookup = NULL;
if (CAfile) {
if(!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) {
// Invalid CA => Bye bye
- opkg_message(conf, OPKG_ERROR,
- "Error loading file %s\n", CAfile);
+ opkg_msg(ERROR, "Error loading file %s.\n", CAfile);
goto end;
}
} else {
if (CApath) {
if(!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) {
- opkg_message(conf, OPKG_ERROR,
- "Error loading directory %s\n", CApath);
+ opkg_msg(ERROR, "Error loading directory %s.\n", CApath);
goto end;
}
} else {
}
}
-static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data){
+static CURL *
+opkg_curl_init(curl_progress_func cb, void *data)
+{
if(curl == NULL){
curl = curl_easy_init();
/* use crypto engine */
if (curl_easy_setopt(curl, CURLOPT_SSLENGINE, conf->ssl_engine) != CURLE_OK){
- opkg_message(conf, OPKG_ERROR, "can't set crypto engine: '%s'\n",
+ opkg_msg(ERROR, "Can't set crypto engine '%s'.\n",
conf->ssl_engine);
opkg_curl_cleanup();
}
/* set the crypto engine as default */
if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK){
- opkg_message(conf, OPKG_ERROR, "can't set crypto engine as default\n");
+ opkg_msg(ERROR, "Can't set crypto engine '%s' as default.\n",
+ conf->ssl_engine);
opkg_curl_cleanup();
return NULL;
if(conf->ssl_key_passwd){
if (curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, conf->ssl_key_passwd) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set key password\n");
+ opkg_msg(DEBUG, "Failed to set key password.\n");
}
}
if(conf->ssl_cert_type){
if (curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, conf->ssl_cert_type) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set certificate format\n");
+ opkg_msg(DEBUG, "Failed to set certificate format.\n");
}
}
/* SSL cert name isn't mandatory */
if(conf->ssl_key_type){
if (curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, conf->ssl_key_type) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set key format\n");
+ opkg_msg(DEBUG, "Failed to set key format.\n");
}
}
if(conf->ssl_key){
if (curl_easy_setopt(curl, CURLOPT_SSLKEY, conf->ssl_key) != CURLE_OK)
{
- opkg_message(conf, OPKG_DEBUG, "Failed to set key\n");
+ opkg_msg(DEBUG, "Failed to set key.\n");
}
}
#ifdef HAVE_PATHFINDER
if(conf->check_x509_path){
if (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, curl_ssl_ctx_function) != CURLE_OK){
- opkg_message(conf, OPKG_DEBUG, "Failed to set ssl path verification callback\n");
+ opkg_msg(DEBUG, "Failed to set ssl path verification callback.\n");
}else{
curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, NULL);
}
typedef int (*curl_progress_func)(void *data, double t, double d, double ultotal, double ulnow);
-int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name, curl_progress_func cb, void *data);
-int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir);
+int opkg_download(const char *src, const char *dest_file_name, curl_progress_func cb, void *data);
+int opkg_download_pkg(pkg_t *pkg, const char *dir);
/*
* Downloads file from url, installs in package database, return package name.
*/
-int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep);
+int opkg_prepare_url_for_install(const char *url, char **namep);
-int opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file);
+int opkg_verify_file (char *text_file, char *sig_file);
#ifdef HAVE_CURL
void opkg_curl_cleanup(void);
#endif
+++ /dev/null
-/* opkg_error.h - the opkg package management system
-
- Copyright (C) 2008 OpenMoko Inc
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-*/
-
-#ifndef OPKG_ERROR_H
-#define OPKG_ERROR_H
-
-struct errlist {
- char * errmsg;
- struct errlist * next;
-} ;
-
-#endif /* OPKG_ERROR_H */
#include "sprintf_alloc.h"
#include "file_util.h"
#include "xsystem.h"
-#include "user.h"
#include "libbb/libbb.h"
static int
-satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg)
+satisfy_dependencies_for(pkg_t *pkg)
{
int i, err;
pkg_vec_t *depends = pkg_vec_alloc();
char **tmp, **unresolved = NULL;
int ndepends;
- ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
- pkg, depends,
+ ndepends = pkg_hash_fetch_unsatisfied_dependencies(pkg, depends,
&unresolved);
if (unresolved) {
- opkg_message(conf, OPKG_ERROR,
- "%s: Cannot satisfy the following dependencies for %s:\n\t",
- conf->force_depends ? "Warning" : "ERROR", pkg->name);
+ opkg_msg(ERROR, "Cannot satisfy the following dependencies for %s:\n",
+ pkg->name);
tmp = unresolved;
while (*unresolved) {
- opkg_message(conf, OPKG_ERROR, " %s", *unresolved);
+ opkg_msg(ERROR, "\t%s", *unresolved);
free(*unresolved);
unresolved++;
}
free(tmp);
- opkg_message(conf, OPKG_ERROR, "\n");
+ opkg_msg(ERROR, "\n");
if (! conf->force_depends) {
- opkg_message(conf, OPKG_INFO,
+ opkg_msg(INFO,
"This could mean that your package list is out of date or that the packages\n"
"mentioned above do not yet exist (try 'opkg update'). To proceed in spite\n"
"of this problem try again with the '-force-depends' option.\n");
it in, so check first. */
if ((dep->state_status != SS_INSTALLED)
&& (dep->state_status != SS_UNPACKED)) {
- opkg_message(conf, OPKG_DEBUG2,"Function: %s calling opkg_install_pkg \n",__FUNCTION__);
- err = opkg_install_pkg(conf, dep,0);
+ opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n");
+ err = opkg_install_pkg(dep, 0);
/* mark this package as having been automatically installed to
* satisfy a dependancy */
dep->auto_installed = 1;
}
static int
-check_conflicts_for(opkg_conf_t *conf, pkg_t *pkg)
+check_conflicts_for(pkg_t *pkg)
{
int i;
pkg_vec_t *conflicts = NULL;
- int level;
- const char *prefix;
+ message_level_t level;
+
if (conf->force_depends) {
- level = OPKG_NOTICE;
- prefix = "Warning";
+ level = NOTICE;
} else {
- level = OPKG_ERROR;
- prefix = "ERROR";
+ level = ERROR;
}
if (!conf->force_depends)
- conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
+ conflicts = pkg_hash_fetch_conflicts(pkg);
if (conflicts) {
- opkg_message(conf, level,
- "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
+ opkg_msg(level, "The following packages conflict with %s:\n",
+ pkg->name);
i = 0;
while (i < conflicts->len)
- opkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
- opkg_message(conf, level, "\n");
+ opkg_msg(level, "\t%s", conflicts->pkgs[i++]->name);
+ opkg_msg(level, "\n");
pkg_vec_free(conflicts);
return -1;
}
}
static int
-update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
+update_file_ownership(pkg_t *new_pkg, pkg_t *old_pkg)
{
str_list_t *new_list, *old_list;
str_list_elt_t *iter, *niter;
- new_list = pkg_get_installed_files(conf, new_pkg);
+ new_list = pkg_get_installed_files(new_pkg);
if (new_list == NULL)
return -1;
iter;
iter = niter, niter = str_list_next(new_list, niter)) {
char *new_file = (char *)iter->data;
- pkg_t *owner = file_hash_get_file_owner(conf, new_file);
+ pkg_t *owner = file_hash_get_file_owner(new_file);
if (!new_file)
- opkg_message(conf, OPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
+ opkg_msg(ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
if (!owner || (owner == old_pkg))
- file_hash_set_file_owner(conf, new_file, new_pkg);
+ file_hash_set_file_owner(new_file, new_pkg);
}
if (old_pkg) {
- old_list = pkg_get_installed_files(conf, old_pkg);
+ old_list = pkg_get_installed_files(old_pkg);
if (old_list == NULL) {
pkg_free_installed_files(new_pkg);
return -1;
iter;
iter = niter, niter = str_list_next(old_list, niter)) {
char *old_file = (char *)iter->data;
- pkg_t *owner = file_hash_get_file_owner(conf, old_file);
+ pkg_t *owner = file_hash_get_file_owner(old_file);
if (owner == old_pkg) {
/* obsolete */
hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
}
static int
-verify_pkg_installable(opkg_conf_t *conf, pkg_t *pkg)
+verify_pkg_installable(pkg_t *pkg)
{
- /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
-
- /* sma 6.20.02: yup; here's the first bit */
- /*
- * XXX: BUG easy for cworth
- * 1) please point the call below to the correct current root destination
- * 2) we need to resolve how to check the required space for a pending pkg,
- * my diddling with the .opk file size below isn't going to cut it.
- * 3) return a proper error code instead of 1
- */
- int comp_size, blocks_available;
- char *root_dir;
-
- if (!conf->force_space && pkg->installed_size != NULL) {
- root_dir = pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir;
- blocks_available = get_available_blocks(root_dir);
-
- comp_size = strtoul(pkg->installed_size, NULL, 0);
- /* round up a blocks count without doing fancy-but-slow casting jazz */
- comp_size = (int)((comp_size + 1023) / 1024);
-
- if (comp_size >= blocks_available) {
- opkg_message(conf, OPKG_ERROR,
- "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
- blocks_available, root_dir, pkg->name, comp_size);
- return ENOSPC;
- }
- }
+ unsigned long kbs_available, pkg_size_kbs;
+ char *root_dir;
+
+ if (conf->force_space || pkg->installed_size == 0)
+ return 0;
+
+ root_dir = pkg->dest ? pkg->dest->root_dir :
+ conf->default_dest->root_dir;
+ kbs_available = get_available_kbytes(root_dir);
+
+ pkg_size_kbs = (pkg->installed_size + 1023)/1024;
+
+ if (pkg_size_kbs >= kbs_available) {
+ opkg_msg(ERROR, "Only have %dkb available on filesystem %s, "
+ "pkg %s needs %d\n",
+ kbs_available, root_dir, pkg->name, pkg_size_kbs);
+ return -1;
+ }
+
return 0;
}
static int
-unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg)
+unpack_pkg_control_files(pkg_t *pkg)
{
int err;
char *conffiles_file_name;
pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
if (pkg->tmp_unpack_dir == NULL) {
- opkg_message(conf, OPKG_ERROR,
- "%s: Failed to create temporary directory '%s': %s\n",
- __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
+ opkg_perror(ERROR, "Failed to create temporary directory '%s'",
+ pkg->tmp_unpack_dir);
return -1;
}
conffiles_file = fopen(conffiles_file_name, "r");
if (conffiles_file == NULL) {
- fprintf(stderr, "%s: failed to open %s: %s\n",
- __FUNCTION__, conffiles_file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to open %s", conffiles_file_name);
free(conffiles_file_name);
return -1;
}
* which are no longer a dependency in the new (upgraded) pkg.
*/
static int
-pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+pkg_remove_orphan_dependent(pkg_t *pkg, pkg_t *old_pkg)
{
int i, j, k, l, found;
int n_deps;
/*
* old_pkg has a dependency that pkg does not.
*/
- p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash,
+ p = pkg_hash_fetch_installed_by_name(
cd0->possibilities[j]->pkg->name);
if (!p)
if (!p->auto_installed)
continue;
- n_deps = pkg_has_installed_dependents(conf, NULL, p,
- &dependents);
+ n_deps = pkg_has_installed_dependents(p, &dependents);
n_deps--; /* don't count old_pkg */
if (n_deps == 0) {
- opkg_message (conf, OPKG_NOTICE,
- "%s was autoinstalled and is "
+ opkg_msg(NOTICE, "%s was autoinstalled and is "
"now orphaned, removing.\n",
p->name);
* which we need to ignore during removal. */
p->state_flag |= SF_REPLACE;
- opkg_remove_pkg(conf, p, 0);
+ opkg_remove_pkg(p, 0);
} else
- opkg_message(conf, OPKG_INFO,
- "%s was autoinstalled and is "
+ opkg_msg(INFO, "%s was autoinstalled and is "
"still required by %d "
"installed packages.\n",
p->name, n_deps);
/* returns number of installed replacees */
static int
-pkg_get_installed_replacees(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
+pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
{
abstract_pkg_t **replaces = pkg->replaces;
int replaces_count = pkg->replaces_count;
}
static int
-pkg_remove_installed_replacees(opkg_conf_t *conf, pkg_vec_t *replacees)
+pkg_remove_installed_replacees(pkg_vec_t *replacees)
{
int i;
int replaces_count = replacees->len;
pkg_t *replacee = replacees->pkgs[i];
int err;
replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
- err = opkg_remove_pkg(conf, replacee,0);
+ err = opkg_remove_pkg(replacee, 0);
if (err)
return err;
}
/* to unwind the removal: make sure they are installed */
static int
-pkg_remove_installed_replacees_unwind(opkg_conf_t *conf, pkg_vec_t *replacees)
+pkg_remove_installed_replacees_unwind(pkg_vec_t *replacees)
{
int i, err;
int replaces_count = replacees->len;
for (i = 0; i < replaces_count; i++) {
pkg_t *replacee = replacees->pkgs[i];
if (replacee->state_status != SS_INSTALLED) {
- opkg_message(conf, OPKG_DEBUG2,"Function: %s calling opkg_install_pkg \n",__FUNCTION__);
- err = opkg_install_pkg(conf, replacee,0);
+ opkg_msg(DEBUG2, "Calling opkg_install_pkg.\n");
+ err = opkg_install_pkg(replacee, 0);
if (err)
return err;
}
/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
static int
-opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
+opkg_install_check_downgrade(pkg_t *pkg, pkg_t *old_pkg, int message)
{
if (old_pkg) {
char message_out[15];
}
if (cmp > 0) {
- opkg_message(conf, OPKG_NOTICE,
+ opkg_msg(NOTICE,
"Not downgrading package %s on %s from %s to %s.\n",
old_pkg->name, old_pkg->dest->name, old_version, new_version);
rc = 1;
} else if (cmp < 0) {
- opkg_message(conf, OPKG_NOTICE,
- "%s%s on %s from %s to %s...\n",
+ opkg_msg(NOTICE, "%s%s on %s from %s to %s...\n",
message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
pkg->dest = old_pkg->dest;
rc = 0;
} else /* cmp == 0 */ {
if (conf->force_reinstall) {
- opkg_message(conf, OPKG_NOTICE,
- "Reinstalling %s (%s) on %s...\n",
+ opkg_msg(NOTICE, "Reinstalling %s (%s) on %s...\n",
pkg->name, new_version, old_pkg->dest->name);
pkg->dest = old_pkg->dest;
rc = 0;
} else {
- opkg_message(conf, OPKG_NOTICE,
- "Not installing %s (%s) on %s -- already installed.\n",
+ opkg_msg(NOTICE, "%s (%s) already install on %s."
+ " Not reinstalling.\n",
pkg->name, new_version, old_pkg->dest->name);
rc = 1;
}
strncpy( message_out,"Installing ",strlen("Installing ") );
char *version = pkg_version_str_alloc(pkg);
- opkg_message(conf, OPKG_NOTICE,
- "%s%s (%s) to %s...\n", message_out,
+ opkg_msg(NOTICE, "%s%s (%s) to %s...\n", message_out,
pkg->name, version, pkg->dest->name);
free(version);
return 0;
static int
-prerm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+prerm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg)
{
/* DPKG_INCOMPATIBILITY:
dpkg does some things here that we don't do yet. Do we care?
}
static int
-prerm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+prerm_upgrade_old_pkg_unwind(pkg_t *pkg, pkg_t *old_pkg)
{
/* DPKG_INCOMPATIBILITY:
dpkg does some things here that we don't do yet. Do we care?
}
static int
-prerm_deconfigure_conflictors(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
+prerm_deconfigure_conflictors(pkg_t *pkg, pkg_vec_t *conflictors)
{
/* DPKG_INCOMPATIBILITY:
dpkg does some things here that we don't do yet. Do we care?
}
static int
-prerm_deconfigure_conflictors_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
+prerm_deconfigure_conflictors_unwind(pkg_t *pkg, pkg_vec_t *conflictors)
{
/* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
do yet. Do we care? (See prerm_deconfigure_conflictors for
}
static int
-preinst_configure(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+preinst_configure(pkg_t *pkg, pkg_t *old_pkg)
{
int err;
char *preinst_args;
preinst_args = xstrdup("install");
}
- err = pkg_run_script(conf, pkg, "preinst", preinst_args);
+ err = pkg_run_script(pkg, "preinst", preinst_args);
if (err) {
- opkg_message(conf, OPKG_ERROR,
- "Aborting installation of %s\n", pkg->name);
- return 1;
+ opkg_msg(ERROR, "Aborting installation of %s.\n", pkg->name);
+ return -1;
}
free(preinst_args);
}
static int
-preinst_configure_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+preinst_configure_unwind(pkg_t *pkg, pkg_t *old_pkg)
{
/* DPKG_INCOMPATIBILITY:
dpkg does the following error unwind, should we?
static int
-backup_make_backup(opkg_conf_t *conf, const char *file_name)
+backup_make_backup(const char *file_name)
{
int err;
char *backup;
backup = backup_filename_alloc(file_name);
err = file_copy(file_name, backup);
if (err) {
- opkg_message(conf, OPKG_ERROR,
- "%s: Failed to copy %s to %s\n",
- __FUNCTION__, file_name, backup);
+ opkg_msg(ERROR, "Failed to copy %s to %s\n",
+ file_name, backup);
}
free(backup);
}
static int
-backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+backup_modified_conffiles(pkg_t *pkg, pkg_t *old_pkg)
{
int err;
conffile_list_elt_t *iter;
char *cf_name;
cf = iter->data;
- cf_name = root_filename_alloc(conf, cf->name);
+ cf_name = root_filename_alloc(cf->name);
/* Don't worry if the conffile is just plain gone */
- if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
- err = backup_make_backup(conf, cf_name);
+ if (file_exists(cf_name) && conffile_has_been_modified(cf)) {
+ err = backup_make_backup(cf_name);
if (err) {
return err;
}
for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
char *cf_name;
cf = (conffile_t *)iter->data;
- cf_name = root_filename_alloc(conf, cf->name);
+ cf_name = root_filename_alloc(cf->name);
/* Ignore if this was a conffile in old_pkg as well */
if (pkg_get_conffile(old_pkg, cf->name)) {
continue;
}
if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
- err = backup_make_backup(conf, cf_name);
+ err = backup_make_backup(cf_name);
if (err) {
return err;
}
}
static int
-backup_modified_conffiles_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
{
conffile_list_elt_t *iter;
static int
-check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+check_data_file_clashes(pkg_t *pkg, pkg_t *old_pkg)
{
/* DPKG_INCOMPATIBILITY:
opkg takes a slightly different approach than dpkg at this
int clashes = 0;
- files_list = pkg_get_installed_files(conf, pkg);
+ files_list = pkg_get_installed_files(pkg);
if (files_list == NULL)
return -1;
iter = niter, niter = str_list_next(files_list, iter)) {
char *root_filename;
char *filename = (char *) iter->data;
- root_filename = root_filename_alloc(conf, filename);
+ root_filename = root_filename_alloc(filename);
if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
pkg_t *owner;
pkg_t *obs;
- /* Pre-existing conffiles are OK */
- /* @@@@ should have way to check that it is a conffile -Jamey */
+
if (backup_exists_for(root_filename)) {
continue;
}
/* Pre-existing files are OK if force-overwrite was asserted. */
if (conf->force_overwrite) {
/* but we need to change who owns this file */
- file_hash_set_file_owner(conf, filename, pkg);
+ file_hash_set_file_owner(filename, pkg);
continue;
}
- owner = file_hash_get_file_owner(conf, filename);
+ owner = file_hash_get_file_owner(filename);
/* Pre-existing files are OK if owned by the pkg being upgraded. */
if (owner && old_pkg) {
/* Pre-existing files are OK if owned by a package replaced by new pkg. */
if (owner) {
- opkg_message(conf, OPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
+ opkg_msg(DEBUG2, "Checking replaces for %s in package %s\n",
+ filename, owner->name);
if (pkg_replaces(pkg, owner)) {
continue;
}
/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
then it's ok to overwrite. */
if (strcmp(owner->name,pkg->name)==0){
- opkg_message(conf, OPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
+ opkg_msg(INFO, "Replacing pre-existing file %s"
+ " owned by package %s\n",
+ filename, owner->name);
continue;
}
}
/* Pre-existing files are OK if they are obsolete */
obs = hash_table_get(&conf->obs_file_hash, filename);
if (obs) {
- opkg_message(conf, OPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
+ opkg_msg(INFO, "Pre-exiting file %s is obsolete."
+ " obs_pkg=%s\n",
+ filename, obs->name);
continue;
}
/* We have found a clash. */
- opkg_message(conf, OPKG_ERROR,
- "Package %s wants to install file %s\n"
+ opkg_msg(ERROR, "Package %s wants to install file %s\n"
"\tBut that file is already provided by package ",
pkg->name, filename);
if (owner) {
- opkg_message(conf, OPKG_ERROR,
- "%s\n", owner->name);
+ opkg_msg(ERROR, "%s\n", owner->name);
} else {
- opkg_message(conf, OPKG_ERROR,
- "<no package>\nPlease move this file out of the way and try again.\n");
+ opkg_msg(ERROR, "<no package>\n"
+ "Please move this file out of the way and try again.\n");
}
clashes++;
}
* XXX: This function sucks, as does the below comment.
*/
static int
-check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+check_data_file_clashes_change(pkg_t *pkg, pkg_t *old_pkg)
{
/* Basically that's the worst hack I could do to be able to change ownership of
file list, but, being that we have no way to unwind the mods, due to structure
char *root_filename = NULL;
- files_list = pkg_get_installed_files(conf, pkg);
+ files_list = pkg_get_installed_files(pkg);
if (files_list == NULL)
return -1;
free(root_filename);
root_filename = NULL;
}
- root_filename = root_filename_alloc(conf, filename);
+ root_filename = root_filename_alloc(filename);
if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
pkg_t *owner;
- owner = file_hash_get_file_owner(conf, filename);
+ owner = file_hash_get_file_owner(filename);
if (conf->force_overwrite) {
/* but we need to change who owns this file */
- file_hash_set_file_owner(conf, filename, pkg);
+ file_hash_set_file_owner(filename, pkg);
continue;
}
if (pkg_replaces(pkg, owner)) {
/* It's now time to change the owner of that file.
It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
- opkg_message(conf, OPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
- file_hash_set_file_owner(conf, filename, pkg);
+ opkg_msg(INFO, "Replacing pre-existing file %s "
+ "owned by package %s\n",
+ filename, owner->name);
+ file_hash_set_file_owner(filename, pkg);
continue;
}
}
}
static int
-check_data_file_clashes_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+check_data_file_clashes_unwind(pkg_t *pkg, pkg_t *old_pkg)
{
/* Nothing to do since check_data_file_clashes doesn't change state */
return 0;
}
static int
-postrm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+postrm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg)
{
/* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
1. If the package is being upgraded, call
}
static int
-postrm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+postrm_upgrade_old_pkg_unwind(pkg_t *pkg, pkg_t *old_pkg)
{
/* DPKG_INCOMPATIBILITY:
dpkg does some things here that we don't do yet. Do we care?
}
static int
-remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+remove_obsolesced_files(pkg_t *pkg, pkg_t *old_pkg)
{
int err;
str_list_t *old_files;
str_list_elt_t *nf;
hash_table_t new_files_table;
- old_files = pkg_get_installed_files(conf, old_pkg);
+ old_files = pkg_get_installed_files(old_pkg);
if (old_files == NULL)
return -1;
- new_files = pkg_get_installed_files(conf, pkg);
+ new_files = pkg_get_installed_files(pkg);
if (new_files == NULL) {
pkg_free_installed_files(old_pkg);
return -1;
if (file_is_dir(old)) {
continue;
}
- owner = file_hash_get_file_owner(conf, old);
+ owner = file_hash_get_file_owner(old);
if (owner != old_pkg) {
/* in case obsolete file no longer belongs to old_pkg */
continue;
}
/* old file is obsolete */
- opkg_message(conf, OPKG_INFO,
- " removing obsolete file %s\n", old);
+ opkg_msg(INFO, "Removing obsolete file %s.\n", old);
if (!conf->noaction) {
err = unlink(old);
if (err) {
- opkg_message(conf, OPKG_ERROR, " Warning: remove %s failed: %s\n", old,
- strerror(errno));
+ opkg_perror(ERROR, "unlinking %s failed", old);
}
}
}
}
static int
-install_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+install_maintainer_scripts(pkg_t *pkg, pkg_t *old_pkg)
{
int ret;
char *prefix;
}
static int
-remove_disappeared(opkg_conf_t *conf, pkg_t *pkg)
+remove_disappeared(pkg_t *pkg)
{
/* DPKG_INCOMPATIBILITY:
This is a fairly sophisticated dpkg operation. Shall we
}
static int
-install_data_files(opkg_conf_t *conf, pkg_t *pkg)
+install_data_files(pkg_t *pkg)
{
int err;
actually do the data file installation now. See comments in
check_data_file_clashes() for more details. */
- opkg_message(conf, OPKG_INFO,
- " extracting data files to %s\n", pkg->dest->root_dir);
+ opkg_msg(INFO, "Extracting data files to %s.\n", pkg->dest->root_dir);
err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
if (err) {
return err;
}
- /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
- so we can't save ourself from removing important packages
- At this point we (should) have extracted the .control file, so it
- would be a good idea to reload the data in it, and set the Essential
- state in *pkg. From now on the Essential is back in status file and
- we can protect again.
- We should operate this way:
- fopen the file ( pkg->dest->root_dir/pkg->name.control )
- check for "Essential" in it
- set the value in pkg->essential.
- This new routine could be useful also for every other flag
- Pigi: 16/03/2004 */
- set_flags_from_control(conf, pkg) ;
+ /* The "Essential" control field may only be present in the control
+ * file and not in the Packages list. Ensure we capture it regardless.
+ *
+ * XXX: This should be fixed outside of opkg, in the Package list.
+ */
+ set_flags_from_control(pkg) ;
- opkg_message(conf, OPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
- err = pkg_write_filelist(conf, pkg);
+ opkg_msg(DEBUG, "Calling pkg_write_filelist.\n");
+ err = pkg_write_filelist(pkg);
if (err)
return err;
}
static int
-user_prefers_old_conffile(const char *file_name, const char *backup)
-{
- char *response;
- const char *short_file_name;
-
- short_file_name = strrchr(file_name, '/');
- if (short_file_name) {
- short_file_name++;
- } else {
- short_file_name = file_name;
- }
-
- while (1) {
- response = get_user_response(" Configuration file '%s'\n"
- " ==> File on system created by you or by a script.\n"
- " ==> File also in package provided by package maintainer.\n"
- " What would you like to do about it ? Your options are:\n"
- " Y or I : install the package maintainer's version\n"
- " N or O : keep your currently-installed version\n"
- " D : show the differences between the versions (if diff is installed)\n"
- " The default action is to keep your current version.\n"
- " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
-
- if (response == NULL)
- return 1;
-
- if (strcmp(response, "y") == 0
- || strcmp(response, "i") == 0
- || strcmp(response, "yes") == 0) {
- free(response);
- return 0;
- }
-
- if (strcmp(response, "d") == 0) {
- const char *argv[] = {"diff", "-u", backup, file_name, NULL};
- xsystem(argv);
- printf(" [Press ENTER to continue]\n");
- response = file_read_line_alloc(stdin);
- free(response);
- continue;
- }
-
- free(response);
- return 1;
- }
-}
-
-static int
-resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg)
+resolve_conffiles(pkg_t *pkg)
{
conffile_list_elt_t *iter;
conffile_t *cf;
for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
char *root_filename;
cf = (conffile_t *)iter->data;
- root_filename = root_filename_alloc(conf, cf->name);
+ root_filename = root_filename_alloc(cf->name);
/* Might need to initialize the md5sum for each conffile */
if (cf->value == NULL) {
cf_backup = backup_filename_alloc(root_filename);
-
if (file_exists(cf_backup)) {
/* Let's compute md5 to test if files are changed */
md5sum = file_md5sum_alloc(cf_backup);
if (md5sum && cf->value && strcmp(cf->value,md5sum) != 0 ) {
if (conf->force_maintainer) {
- opkg_message(conf, OPKG_NOTICE, "Conffile %s using maintainer's setting.\n", cf_backup);
- } else if (conf->force_defaults
- || user_prefers_old_conffile(root_filename, cf_backup) ) {
+ opkg_msg(NOTICE, "Conffile %s using maintainer's setting.\n",
+ cf_backup);
+ } else {
+ char *new_conffile;
+ sprintf_alloc(&new_conffile, "%s-opkg", root_filename);
+ opkg_msg(NOTICE, "Existing conffile %s "
+ "is different from the conffile in the new package."
+ " The new conffile will be placed at %s.\n",
+ root_filename, new_conffile);
+ rename(root_filename, new_conffile);
rename(cf_backup, root_filename);
- }
+ free(new_conffile);
+ }
}
unlink(cf_backup);
if (md5sum)
int
-opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name)
+opkg_install_by_name(const char *pkg_name)
{
int cmp;
pkg_t *old, *new;
char *old_version, *new_version;
- old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
+ old = pkg_hash_fetch_installed_by_name(pkg_name);
if (old)
- opkg_message(conf, OPKG_DEBUG2, "Old versions from pkg_hash_fetch %s \n", old->version);
+ opkg_msg(DEBUG2, "Old versions from pkg_hash_fetch %s.\n",
+ old->version);
- new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
+ new = pkg_hash_fetch_best_installation_candidate_by_name(pkg_name);
if (new == NULL)
return -1;
- opkg_message(conf, OPKG_DEBUG2, "Versions from pkg_hash_fetch in %s ", __FUNCTION__);
+ opkg_msg(DEBUG2, "Versions from pkg_hash_fetch:");
if ( old )
- opkg_message(conf, OPKG_DEBUG2, " old %s ", old->version);
- opkg_message(conf, OPKG_DEBUG2, " new %s\n", new->version);
+ opkg_msg(DEBUG2, " old %s ", old->version);
+ opkg_msg(DEBUG2, " new %s\n", new->version);
new->state_flag |= SF_USER;
if (old) {
cmp = pkg_compare_versions(old, new);
if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
- opkg_message(conf, OPKG_DEBUG, " Forcing downgrade \n");
+ opkg_msg(DEBUG, "Forcing downgrade\n");
cmp = -1 ; /* then we force opkg to downgrade */
/* We need to use a value < 0 because in the 0 case we are asking to */
/* reinstall, and some check could fail asking the "force-reinstall" option */
}
- opkg_message(conf, OPKG_DEBUG,
- "Comparing visible versions of pkg %s:"
+ opkg_msg(DEBUG, "Comparing visible versions of pkg %s:"
"\n\t%s is installed "
"\n\t%s is available "
"\n\t%d was comparison result\n",
pkg_name, old_version, new_version, cmp);
if (cmp == 0 && !conf->force_reinstall) {
- opkg_message(conf, OPKG_NOTICE,
+ opkg_msg(NOTICE,
"Package %s (%s) installed in %s is up to date.\n",
old->name, old_version, old->dest->name);
free(old_version);
free(new_version);
return 0;
} else if (cmp > 0) {
- opkg_message(conf, OPKG_NOTICE,
+ opkg_msg(NOTICE,
"Not downgrading package %s on %s from %s to %s.\n",
old->name, old->dest->name, old_version, new_version);
free(old_version);
free(new_version);
}
- opkg_message(conf, OPKG_DEBUG2,"%s: calling opkg_install_pkg \n",__FUNCTION__);
- return opkg_install_pkg(conf, new,0);
+ opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n");
+ return opkg_install_pkg(new, 0);
}
/**
* @brief Really install a pkg_t
*/
int
-opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
+opkg_install_pkg(pkg_t *pkg, int from_upgrade)
{
int err = 0;
int message = 0;
if ( from_upgrade )
message = 1; /* Coming from an upgrade, and should change the output message */
- if (!pkg) {
- opkg_message(conf, OPKG_ERROR,
- "INTERNAL ERROR: null pkg passed to opkg_install_pkg\n");
- return -1;
- }
-
- opkg_message(conf, OPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
+ opkg_msg(DEBUG2, "Calling pkg_arch_supported.\n");
- if (!pkg_arch_supported(conf, pkg)) {
- opkg_message(conf, OPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
+ if (!pkg_arch_supported(pkg)) {
+ opkg_msg(ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
pkg->architecture, pkg->name);
return -1;
}
if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
- err = satisfy_dependencies_for(conf, pkg);
+ err = satisfy_dependencies_for(pkg);
if (err)
return -1;
- opkg_message(conf, OPKG_NOTICE,
- "Package %s is already installed in %s.\n",
+ opkg_msg(NOTICE, "Package %s is already installed on %s.\n",
pkg->name, pkg->dest->name);
return 0;
}
pkg->dest = conf->default_dest;
}
- old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
+ old_pkg = pkg_hash_fetch_installed_by_name(pkg->name);
- err = opkg_install_check_downgrade(conf, pkg, old_pkg, message);
+ err = opkg_install_check_downgrade(pkg, old_pkg, message);
if (err)
return -1;
old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
}
- err = check_conflicts_for(conf, pkg);
+ err = check_conflicts_for(pkg);
if (err)
return -1;
if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0)
return 0;
- err = verify_pkg_installable(conf, pkg);
+ err = verify_pkg_installable(pkg);
if (err)
return -1;
if (pkg->local_filename == NULL) {
- err = opkg_download_pkg(conf, pkg, conf->tmp_dir);
+ err = opkg_download_pkg(pkg, conf->tmp_dir);
if (err) {
- opkg_message(conf, OPKG_ERROR,
- "Failed to download %s. Perhaps you need to run 'opkg update'?\n",
+ opkg_msg(ERROR, "Failed to download %s. "
+ "Perhaps you need to run 'opkg update'?\n",
pkg->name);
return -1;
}
if (file_exists (sig_file_name))
{
- if (opkg_verify_file (conf, list_file_name, sig_file_name)){
- opkg_message(conf, OPKG_ERROR, "Failed to verify the signature of: %s\n",
+ if (opkg_verify_file (list_file_name, sig_file_name)){
+ opkg_msg(ERROR, "Failed to verify the signature of %s.\n",
list_file_name);
return -1;
}
}else{
- opkg_message(conf, OPKG_ERROR, "Signature file is missing. "
- "Perhaps you need to run 'opkg update'?\n");
+ opkg_msg(ERROR, "Signature file is missing for %s. "
+ "Perhaps you need to run 'opkg update'?\n",
+ pkg->name);
return -1;
}
file_md5 = file_md5sum_alloc(pkg->local_filename);
if (file_md5 && strcmp(file_md5, pkg->md5sum))
{
- opkg_message(conf, OPKG_ERROR,
- "Package %s md5sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n",
- pkg->name);
+ opkg_msg(ERROR, "Package %s md5sum mismatch. "
+ "Either the opkg or the package index are corrupt. "
+ "Try 'opkg update'.\n",
+ pkg->name);
free(file_md5);
return -1;
}
file_sha256 = file_sha256sum_alloc(pkg->local_filename);
if (file_sha256 && strcmp(file_sha256, pkg->sha256sum))
{
- opkg_message(conf, OPKG_ERROR,
- "Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n",
- pkg->name);
+ opkg_msg(ERROR, "Package %s sha256sum mismatch. "
+ "Either the opkg or the package index are corrupt. "
+ "Try 'opkg update'.\n",
+ pkg->name);
free(file_sha256);
return -1;
}
#endif
if (pkg->tmp_unpack_dir == NULL) {
- if (unpack_pkg_control_files(conf, pkg) == -1) {
- opkg_message(conf, OPKG_ERROR, "Failed to unpack control"
- " files from %s.\n", pkg->local_filename);
+ if (unpack_pkg_control_files(pkg) == -1) {
+ opkg_msg(ERROR, "Failed to unpack control files from %s.\n",
+ pkg->local_filename);
return -1;
}
}
- /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
-/* Pigi: check if it will pass from here when replacing. It seems to fail */
-/* That's rather strange that files don't change owner. Investigate !!!!!!*/
- err = update_file_ownership(conf, pkg, old_pkg);
+ err = update_file_ownership(pkg, old_pkg);
if (err)
return -1;
if (conf->nodeps == 0) {
- err = satisfy_dependencies_for(conf, pkg);
+ err = satisfy_dependencies_for(pkg);
if (err)
return -1;
if (pkg->state_status == SS_UNPACKED)
}
replacees = pkg_vec_alloc();
- pkg_get_installed_replacees(conf, pkg, replacees);
+ pkg_get_installed_replacees(pkg, replacees);
/* this next section we do with SIGINT blocked to prevent inconsistency between opkg database and filesystem */
pkg->state_flag |= SF_FILELIST_CHANGED;
if (old_pkg)
- pkg_remove_orphan_dependent(conf, pkg, old_pkg);
+ pkg_remove_orphan_dependent(pkg, old_pkg);
/* XXX: BUG: we really should treat replacement more like an upgrade
* Instead, we're going to remove the replacees
*/
- err = pkg_remove_installed_replacees(conf, replacees);
+ err = pkg_remove_installed_replacees(replacees);
if (err)
goto UNWIND_REMOVE_INSTALLED_REPLACEES;
- err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
+ err = prerm_upgrade_old_pkg(pkg, old_pkg);
if (err)
goto UNWIND_PRERM_UPGRADE_OLD_PKG;
- err = prerm_deconfigure_conflictors(conf, pkg, replacees);
+ err = prerm_deconfigure_conflictors(pkg, replacees);
if (err)
goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
- err = preinst_configure(conf, pkg, old_pkg);
+ err = preinst_configure(pkg, old_pkg);
if (err)
goto UNWIND_PREINST_CONFIGURE;
- err = backup_modified_conffiles(conf, pkg, old_pkg);
+ err = backup_modified_conffiles(pkg, old_pkg);
if (err)
goto UNWIND_BACKUP_MODIFIED_CONFFILES;
- err = check_data_file_clashes(conf, pkg, old_pkg);
+ err = check_data_file_clashes(pkg, old_pkg);
if (err)
goto UNWIND_CHECK_DATA_FILE_CLASHES;
- err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
+ err = postrm_upgrade_old_pkg(pkg, old_pkg);
if (err)
goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
old_pkg->state_want = SW_DEINSTALL;
if (old_pkg->state_flag & SF_NOPRUNE) {
- opkg_message(conf, OPKG_INFO,
- " not removing obsolesced files because package marked noprune\n");
+ opkg_msg(INFO, "Not removing obsolesced files because "
+ "package %s marked noprune.\n",
+ old_pkg->name);
} else {
- opkg_message(conf, OPKG_INFO,
- " removing obsolesced files\n");
- if (remove_obsolesced_files(conf, pkg, old_pkg)) {
- opkg_message(conf, OPKG_ERROR, "Failed to determine "
+ opkg_msg(INFO, "Removing obsolesced files for %s\n",
+ old_pkg->name);
+ if (remove_obsolesced_files(pkg, old_pkg)) {
+ opkg_msg(ERROR, "Failed to determine "
"obsolete files from previously "
"installed %s\n", old_pkg->name);
}
}
/* removing files from old package, to avoid ghost files */
- remove_data_files_and_list(conf, old_pkg);
- remove_maintainer_scripts(conf, old_pkg);
+ remove_data_files_and_list(old_pkg);
+ remove_maintainer_scripts(old_pkg);
}
- opkg_message(conf, OPKG_INFO,
- " installing maintainer scripts\n");
- if (install_maintainer_scripts(conf, pkg, old_pkg)) {
- opkg_message(conf, OPKG_ERROR, "Failed to extract maintainer"
- " scripts for %s. Package debris may remain!\n",
+ opkg_msg(INFO, "Installing maintainer scripts.\n");
+ if (install_maintainer_scripts(pkg, old_pkg)) {
+ opkg_msg(ERROR, "Failed to extract maintainer scripts for %s."
+ " Package debris may remain!\n",
pkg->name);
goto pkg_is_hosed;
}
/* the following just returns 0 */
- remove_disappeared(conf, pkg);
+ remove_disappeared(pkg);
- opkg_message(conf, OPKG_INFO,
- " installing data files\n");
+ opkg_msg(INFO, "Installing data files for %s.\n", pkg->name);
- if (install_data_files(conf, pkg)) {
- opkg_message(conf, OPKG_ERROR, "Failed to extract data files "
- "for %s. Package debris may remain!\n",
+ if (install_data_files(pkg)) {
+ opkg_msg(ERROR, "Failed to extract data files for %s. "
+ "Package debris may remain!\n",
pkg->name);
goto pkg_is_hosed;
}
- err = check_data_file_clashes_change(conf, pkg, old_pkg);
+ err = check_data_file_clashes_change(pkg, old_pkg);
if (err) {
- opkg_message(conf, OPKG_ERROR,
- "check_data_file_clashes_change() failed for "
+ opkg_msg(ERROR, "check_data_file_clashes_change() failed for "
"for files belonging to %s.\n",
pkg->name);
}
- opkg_message(conf, OPKG_INFO,
- " resolving conf files\n");
- resolve_conffiles(conf, pkg);
+ opkg_msg(INFO, "Resolving conf files for %s\n", pkg->name);
+ resolve_conffiles(pkg);
pkg->state_status = SS_UNPACKED;
old_state_flag = pkg->state_flag;
pkg->state_flag &= ~SF_PREFER;
- opkg_message(conf, OPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
+ opkg_msg(DEBUG, "pkg=%s old_state_flag=%x state_flag=%x\n",
+ pkg->name, old_state_flag, pkg->state_flag);
if (old_pkg && !conf->force_reinstall) {
old_pkg->state_status = SS_NOT_INSTALLED;
if (ab_pkg)
ab_pkg->state_status = pkg->state_status;
- opkg_message(conf, OPKG_INFO, "Done.\n");
-
sigprocmask(SIG_UNBLOCK, &newset, &oldset);
pkg_vec_free (replacees);
return 0;
UNWIND_POSTRM_UPGRADE_OLD_PKG:
- postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
+ postrm_upgrade_old_pkg_unwind(pkg, old_pkg);
UNWIND_CHECK_DATA_FILE_CLASHES:
- check_data_file_clashes_unwind(conf, pkg, old_pkg);
+ check_data_file_clashes_unwind(pkg, old_pkg);
UNWIND_BACKUP_MODIFIED_CONFFILES:
- backup_modified_conffiles_unwind(conf, pkg, old_pkg);
+ backup_modified_conffiles_unwind(pkg, old_pkg);
UNWIND_PREINST_CONFIGURE:
- preinst_configure_unwind(conf, pkg, old_pkg);
+ preinst_configure_unwind(pkg, old_pkg);
UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
- prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
+ prerm_deconfigure_conflictors_unwind(pkg, replacees);
UNWIND_PRERM_UPGRADE_OLD_PKG:
- prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
+ prerm_upgrade_old_pkg_unwind(pkg, old_pkg);
UNWIND_REMOVE_INSTALLED_REPLACEES:
- pkg_remove_installed_replacees_unwind(conf, replacees);
+ pkg_remove_installed_replacees_unwind(replacees);
pkg_is_hosed:
- opkg_message(conf, OPKG_INFO,
- "Failed.\n");
-
sigprocmask(SIG_UNBLOCK, &newset, &oldset);
pkg_vec_free (replacees);
#include "pkg.h"
#include "opkg_conf.h"
-#include "opkg_error.h"
-int opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name);
-int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrading);
+int opkg_install_by_name(const char *pkg_name);
+int opkg_install_pkg(pkg_t *pkg, int from_upgrading);
#endif
/* opkg_message.c - the opkg package management system
+ Copyright (C) 2009 Ubiq Technologies <graham.gower@gmail.com>
Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
This program is free software; you can redistribute it and/or
#include "includes.h"
#include "opkg_conf.h"
#include "opkg_message.h"
-#include "opkg_error.h"
-#include "opkg_utils.h"
+#include "libbb/libbb.h"
+
+struct errlist {
+ char *errmsg;
+ struct errlist *next;
+};
+
+static struct errlist *error_list_head, *error_list_tail;
+
+static void
+push_error_list(char *msg)
+{
+ struct errlist *e;
+
+ e = xcalloc(1, sizeof(struct errlist));
+ e->errmsg = xstrdup(msg);
+ e->next = NULL;
+
+ if (error_list_head) {
+ error_list_tail->next = e;
+ error_list_tail = e;
+ } else {
+ error_list_head = error_list_tail = e;
+ }
+}
+
+void
+free_error_list(void)
+{
+ struct errlist *err, *err_tmp;
+
+ err = error_list_head;
+ while (err != NULL) {
+ free(err->errmsg);
+ err_tmp = err;
+ err = err->next;
+ free(err_tmp);
+ }
+}
+
+void
+print_error_list(void)
+{
+ struct errlist *err = error_list_head;
+
+ if (err) {
+ printf("Collected errors:\n");
+ /* Here we print the errors collected and free the list */
+ while (err != NULL) {
+ printf(" * %s", err->errmsg);
+ err = err->next;
+ }
+ }
+}
void
-opkg_message (opkg_conf_t * conf, message_level_t level, char *fmt, ...)
+opkg_message (message_level_t level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
- if (level == OPKG_ERROR) {
+ if (level == ERROR) {
char msg[256];
vsnprintf(msg, 256, fmt, ap);
push_error_list(msg);
/* opkg_message.h - the opkg package management system
+ Copyright (C) 2009 Ubiq Technologies <graham.gower@gmail.com>
Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
This program is free software; you can redistribute it and/or
#ifndef _OPKG_MESSAGE_H_
#define _OPKG_MESSAGE_H_
-#include "opkg_conf.h"
+#include <string.h>
+#include <errno.h>
typedef enum {
- OPKG_ERROR, /* error conditions */
- OPKG_NOTICE, /* normal but significant condition */
- OPKG_INFO, /* informational message */
- OPKG_DEBUG, /* debug level message */
- OPKG_DEBUG2, /* more debug level message */
+ ERROR, /* error conditions */
+ NOTICE, /* normal but significant condition */
+ INFO, /* informational message */
+ DEBUG, /* debug level message */
+ DEBUG2, /* more debug level message */
} message_level_t;
-extern void opkg_message(opkg_conf_t *conf, message_level_t level, char *fmt, ...);
+void free_error_list(void);
+void print_error_list(void);
+void opkg_message(message_level_t level, const char *fmt, ...);
+
+#define opkg_msg(l, fmt, args...) \
+ do { \
+ if (l == NOTICE) \
+ opkg_message(l, fmt, ##args); \
+ else \
+ opkg_message(l, "%s: "fmt, __FUNCTION__, ##args); \
+ } while (0)
+
+#define opkg_perror(l, fmt, args...) \
+ opkg_msg(l, fmt": %s.\n", ##args, strerror(errno))
#endif /* _OPKG_MESSAGE_H_ */
int validated = pathfinder_dbus_verify(certdata_str, policy, 0, 0, &errmsg);
if (!validated)
- fprintf(stderr, "curlcb_pathfinder: Path verification failed: %s\n", errmsg);
+ opkg_msg(ERROR, "Path verification failed: %s.\n", errmsg);
free(certdata_str);
free(errmsg);
#include <glob.h>
#include "opkg_remove.h"
-#include "opkg_error.h"
#include "opkg_cmd.h"
#include "file_util.h"
* Every package implicitly provides itself.
*/
int
-pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
+pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
{
int nprovides = pkg->provides_count;
abstract_pkg_t **provides = pkg->provides;
- int n_installed_dependents = 0;
+ unsigned int n_installed_dependents = 0;
int i;
for (i = 0; i < nprovides; i++) {
abstract_pkg_t *providee = provides[i];
}
static int
-opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
+opkg_remove_dependent_pkgs(pkg_t *pkg, abstract_pkg_t **dependents)
{
int i;
int a;
abstract_pkg_t * ab_pkg;
if((ab_pkg = pkg->parent) == NULL){
- fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
- __FUNCTION__, pkg->name);
+ opkg_msg(ERROR, "Internal error: pkg %s isn't in hash table\n",
+ pkg->name);
return 0;
}
int err=0;
for (i = 0; i < dependent_pkgs->len; i++) {
- err = opkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
+ err = opkg_remove_pkg(dependent_pkgs->pkgs[i],0);
if (err) {
pkg_vec_free(dependent_pkgs);
break;
}
static void
-print_dependents_warning(opkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
+print_dependents_warning(pkg_t *pkg, abstract_pkg_t **dependents)
{
abstract_pkg_t *dep_ab_pkg;
- opkg_message(conf, OPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
+ opkg_msg(ERROR, "Package %s is depended upon by packages:\n", pkg->name);
while ((dep_ab_pkg = *dependents++) != NULL) {
if (dep_ab_pkg->state_status == SS_INSTALLED)
- opkg_message(conf, OPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
+ opkg_msg(ERROR, "\t%s\n", dep_ab_pkg->name);
}
- opkg_message(conf, OPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
- opkg_message(conf, OPKG_ERROR, "");
- opkg_message(conf, OPKG_ERROR, "You can force removal of this package with --force-depends.\n");
- opkg_message(conf, OPKG_ERROR, "You can force removal of this package and its dependents\n");
- opkg_message(conf, OPKG_ERROR, "with --force-removal-of-dependent-packages\n");
+ opkg_msg(ERROR, "These might cease to work if package %s is removed.\n\n",
+ pkg->name);
+ opkg_msg(ERROR, "Force removal of this package with --force-depends.\n");
+ opkg_msg(ERROR, "Force removal of this package and its dependents\n");
+ opkg_msg(ERROR, "with --force-removal-of-dependent-packages.\n");
}
/*
* by the removal of pkg.
*/
static int
-remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg)
+remove_autoinstalled(pkg_t *pkg)
{
int i, j;
int n_deps;
if (cdep->type != DEPEND)
continue;
for (j=0; j<cdep->possibility_count; j++) {
- p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash,
+ p = pkg_hash_fetch_installed_by_name(
cdep->possibilities[j]->pkg->name);
/* If the package is not installed, this could have
if (!p->auto_installed)
continue;
- n_deps = pkg_has_installed_dependents(conf, NULL, p,
- &dependents);
+ n_deps = pkg_has_installed_dependents(p, &dependents);
if (n_deps == 0) {
- opkg_message(conf, OPKG_NOTICE,
- "%s was autoinstalled and is "
- "now orphaned, removing\n",
+ opkg_msg(NOTICE, "%s was autoinstalled and is "
+ "now orphaned, removing.\n",
p->name);
- opkg_remove_pkg(conf, p, 0);
+ opkg_remove_pkg(p, 0);
} else
- opkg_message(conf, OPKG_INFO,
- "%s was autoinstalled and is "
+ opkg_msg(INFO, "%s was autoinstalled and is "
"still required by %d "
"installed packages.\n",
p->name, n_deps);
}
int
-opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
+opkg_remove_pkg(pkg_t *pkg, int from_upgrade)
{
int err;
abstract_pkg_t *parent_pkg = NULL;
*/
if (pkg->essential && !from_upgrade) {
if (conf->force_removal_of_essential_packages) {
- fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
+ opkg_msg(NOTICE,
+ "Removing essential package %s under your coercion.\n"
"\tIf your system breaks, you get to keep both pieces\n",
pkg->name);
} else {
- fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
+ opkg_msg(NOTICE, "Refusing to remove essential package %s.\n"
"\tRemoving an essential package may lead to an unusable system, but if\n"
"\tyou enjoy that kind of pain, you can force opkg to proceed against\n"
"\tits will with the option: --force-removal-of-essential-packages\n",
&& !(pkg->state_flag & SF_REPLACE)) {
abstract_pkg_t **dependents;
int has_installed_dependents =
- pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
+ pkg_has_installed_dependents(pkg, &dependents);
if (has_installed_dependents) {
/*
*/
if (!conf->force_removal_of_dependent_packages) {
- print_dependents_warning(conf, parent_pkg, pkg, dependents);
+ print_dependents_warning(pkg, dependents);
free(dependents);
return -1;
}
/* remove packages depending on this package - Karthik */
- err = opkg_remove_dependent_pkgs (conf, pkg, dependents);
+ err = opkg_remove_dependent_pkgs(pkg, dependents);
if (err) {
free(dependents);
return err;
}
if (from_upgrade == 0) {
- opkg_message (conf, OPKG_NOTICE,
- "Removing package %s from %s...\n", pkg->name, pkg->dest->name);
+ opkg_msg(NOTICE, "Removing package %s from %s...\n",
+ pkg->name, pkg->dest->name);
}
pkg->state_flag |= SF_FILELIST_CHANGED;
pkg->state_want = SW_DEINSTALL;
opkg_state_changed++;
- pkg_run_script(conf, pkg, "prerm", "remove");
+ pkg_run_script(pkg, "prerm", "remove");
/* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
maintains an empty filelist rather than deleting it. That seems
like a big pain, and I don't see that that should make a big
difference, but for anyone who wants tighter compatibility,
feel free to fix this. */
- remove_data_files_and_list(conf, pkg);
+ remove_data_files_and_list(pkg);
- pkg_run_script(conf, pkg, "postrm", "remove");
+ pkg_run_script(pkg, "postrm", "remove");
- remove_maintainer_scripts(conf, pkg);
+ remove_maintainer_scripts(pkg);
pkg->state_status = SS_NOT_INSTALLED;
if (parent_pkg)
/* remove autoinstalled packages that are orphaned by the removal of this one */
if (conf->autoremove)
- remove_autoinstalled (conf, pkg);
+ remove_autoinstalled(pkg);
return 0;
}
void
-remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
+remove_data_files_and_list(pkg_t *pkg)
{
str_list_t installed_dirs;
str_list_t *installed_files;
pkg_t *owner;
int rootdirlen = 0;
- installed_files = pkg_get_installed_files(conf, pkg);
+ installed_files = pkg_get_installed_files(pkg);
if (installed_files == NULL) {
- opkg_message(conf, OPKG_ERROR, "Failed to determine installed "
+ opkg_msg(ERROR, "Failed to determine installed "
"files for %s. None removed.\n", pkg->name);
return;
}
conffile = pkg_get_conffile(pkg, file_name+rootdirlen);
if (conffile) {
- if (conffile_has_been_modified(conf, conffile)) {
- opkg_message (conf, OPKG_NOTICE,
- " not deleting modified conffile %s\n", file_name);
+ if (conffile_has_been_modified(conffile)) {
+ opkg_msg(NOTICE, "Not deleting modified conffile %s.\n",
+ file_name);
continue;
}
}
- opkg_message(conf, OPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
- if (!conf->noaction)
+ if (!conf->noaction) {
+ opkg_msg(INFO, "Deleting %s.\n", file_name, conf->noaction);
unlink(file_name);
+ } else
+ opkg_msg(INFO, "Not deleting %s. (noaction)\n",
+ file_name);
+
}
/* Remove empty directories */
file_name = (char *)iter->data;
if (rmdir(file_name) == 0) {
- opkg_message(conf, OPKG_INFO, " deleting %s\n", file_name);
+ opkg_msg(INFO, "Deleting %s.\n", file_name);
removed_a_dir = 1;
str_list_remove(&installed_dirs, &iter);
}
}
pkg_free_installed_files(pkg);
- pkg_remove_installed_files_list(conf, pkg);
+ pkg_remove_installed_files_list(pkg);
/* Don't print warning for dirs that are provided by other packages */
for (iter = str_list_first(&installed_dirs); iter; iter = str_list_next(&installed_dirs, iter)) {
file_name = (char *)iter->data;
- owner = file_hash_get_file_owner(conf, file_name);
+ owner = file_hash_get_file_owner(file_name);
if (owner) {
free(iter->data);
iter->data = NULL;
}
void
-remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg)
+remove_maintainer_scripts(pkg_t *pkg)
{
int i, err;
char *globpattern;
return;
for (i = 0; i < globbuf.gl_pathc; i++) {
- opkg_message(conf, OPKG_INFO, "deleting %s\n",
- globbuf.gl_pathv[i]);
+ opkg_msg(INFO, "Deleting %s.\n", globbuf.gl_pathv[i]);
unlink(globbuf.gl_pathv[i]);
}
globfree(&globbuf);
#include "pkg.h"
#include "opkg_conf.h"
-int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message);
-int pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
-void remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg);
-void remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg);
+int opkg_remove_pkg(pkg_t *pkg,int message);
+int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
+void remove_data_files_and_list(pkg_t *pkg);
+void remove_maintainer_scripts(pkg_t *pkg);
#endif
#include "includes.h"
#include "opkg_install.h"
+#include "opkg_upgrade.h"
#include "opkg_message.h"
int
-opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
+opkg_upgrade_pkg(pkg_t *old)
{
pkg_t *new;
int cmp;
char *old_version, *new_version;
if (old->state_flag & SF_HOLD) {
- opkg_message(conf, OPKG_NOTICE,
- "Not upgrading package %s which is marked "
- "hold (flags=%#x)\n", old->name, old->state_flag);
+ opkg_msg(NOTICE, "Not upgrading package %s which is marked "
+ "hold (flags=%#x).\n", old->name, old->state_flag);
return 0;
}
- new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
+ new = pkg_hash_fetch_best_installation_candidate_by_name(old->name);
if (new == NULL) {
old_version = pkg_version_str_alloc(old);
- opkg_message(conf, OPKG_NOTICE,
- "Assuming locally installed package %s (%s) "
+ opkg_msg(NOTICE, "Assuming locally installed package %s (%s) "
"is up to date.\n", old->name, old_version);
free(old_version);
return 0;
new_version = pkg_version_str_alloc(new);
cmp = pkg_compare_versions(old, new);
- opkg_message(conf, OPKG_DEBUG,
- "comparing visible versions of pkg %s:"
+ opkg_msg(DEBUG, "Comparing visible versions of pkg %s:"
"\n\t%s is installed "
"\n\t%s is available "
"\n\t%d was comparison result\n",
old->name, old_version, new_version, cmp);
if (cmp == 0) {
- opkg_message(conf, OPKG_INFO,
- "Package %s (%s) installed in %s is up to date.\n",
+ opkg_msg(INFO, "Package %s (%s) installed in %s is up to date.\n",
old->name, old_version, old->dest->name);
free(old_version);
free(new_version);
return 0;
} else if (cmp > 0) {
- opkg_message(conf, OPKG_NOTICE,
- "Not downgrading package %s on %s from %s to %s.\n",
+ opkg_msg(NOTICE, "Not downgrading package %s on %s from %s to %s.\n",
old->name, old->dest->name, old_version, new_version);
free(old_version);
free(new_version);
free(old_version);
free(new_version);
new->state_flag |= SF_USER;
- return opkg_install_pkg(conf, new,1);
+ return opkg_install_pkg(new,1);
}
}
struct active_list *
-prepare_upgrade_list(opkg_conf_t *conf)
+prepare_upgrade_list(void)
{
struct active_list *head = active_list_head_new();
struct active_list *all = active_list_head_new();
struct active_list *node=NULL;
/* ensure all data is valid */
- pkg_info_preinstall_check (conf);
+ pkg_info_preinstall_check();
hash_table_foreach(&conf->pkg_hash, pkg_hash_check_installed_pkg_helper, all);
for (node=active_list_next(all,all); node; node = active_list_next(all, node)) {
int cmp;
old = list_entry(node, pkg_t, list);
- new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
+ new = pkg_hash_fetch_best_installation_candidate_by_name(old->name);
if (new == NULL)
continue;
#define OPKG_UPGRADE_H
#include "active_list.h"
-int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old);
-struct active_list * prepare_upgrade_list (opkg_conf_t *conf);
+int opkg_upgrade_pkg(pkg_t *old);
+struct active_list * prepare_upgrade_list (void);
#endif
#include "includes.h"
#include <errno.h>
#include <ctype.h>
-#include <sys/vfs.h>
+#include <sys/statvfs.h>
#include "opkg_utils.h"
#include "pkg.h"
void print_pkg_status(pkg_t * pkg, FILE * file);
-long unsigned int get_available_blocks(char * filesystem)
+unsigned long
+get_available_kbytes(char * filesystem)
{
- struct statfs sfs;
+ struct statvfs f;
- if(statfs(filesystem, &sfs)){
- fprintf(stderr, "bad statfs\n");
+ if (statvfs(filesystem, &f) == -1) {
+ opkg_perror(ERROR, "Failed to statvfs for %s", filesystem);
return 0;
}
- /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
- // Actually ((sfs.f_bavail * sfs.f_bsize) / 1024)
+ // Actually ((sfs.f_bavail * sfs.f_frsize) / 1024)
// and here we try to avoid overflow.
- if (sfs.f_bsize >= 1024)
- return (sfs.f_bavail * (sfs.f_bsize / 1024));
- else if (sfs.f_bsize > 0)
- return sfs.f_bavail / (1024 / sfs.f_bsize);
- fprintf(stderr, "bad statfs f_bsize == 0\n");
+ if (f.f_frsize >= 1024)
+ return (f.f_bavail * (f.f_frsize / 1024));
+ else if (f.f_frsize > 0)
+ return f.f_bavail / (1024 / f.f_frsize);
+
+ opkg_msg(ERROR, "Unknown block size for target filesystem.\n");
+
return 0;
}
}
return 1;
}
-
-static struct errlist *error_list_head, *error_list_tail;
-
-/*
- * XXX: this function should not allocate memory as it may be called to
- * print an error because we are out of memory.
- */
-void push_error_list(char * msg)
-{
- struct errlist *e;
-
- e = xcalloc(1, sizeof(struct errlist));
- e->errmsg = xstrdup(msg);
- e->next = NULL;
-
- if (error_list_head) {
- error_list_tail->next = e;
- error_list_tail = e;
- } else {
- error_list_head = error_list_tail = e;
- }
-}
-
-void free_error_list(void)
-{
- struct errlist *err, *err_tmp;
-
- err = error_list_head;
- while (err != NULL) {
- free(err->errmsg);
- err_tmp = err;
- err = err->next;
- free(err_tmp);
- }
-}
-
-void print_error_list (void)
-{
- struct errlist *err = error_list_head;
-
- if (err) {
- printf ("Collected errors:\n");
- /* Here we print the errors collected and free the list */
- while (err != NULL) {
- printf (" * %s", err->errmsg);
- err = err->next;
- }
- }
-}
#ifndef OPKG_UTILS_H
#define OPKG_UTILS_H
-#include "pkg.h"
-#include "opkg_error.h"
-
-void push_error_list(char * msg);
-void free_error_list(void);
-void print_error_list(void);
-
-long unsigned int get_available_blocks(char * filesystem);
+unsigned long get_available_kbytes(char * filesystem);
char *trim_xstrdup(const char *line);
int line_is_blank(const char *line);
typedef struct enum_map enum_map_t;
struct enum_map
{
- int value;
- char *str;
+ unsigned int value;
+ const char *str;
};
static const enum_map_t pkg_state_want_map[] = {
active_list_init(&pkg->list);
- /* Abhaya: added init for conflicts fields */
pkg->conflicts = NULL;
pkg->conflicts_count = 0;
- /* added for replaces. Jamey 7/23/2002 */
pkg->replaces = NULL;
pkg->replaces_count = 0;
#if defined HAVE_SHA256
pkg->sha256sum = NULL;
#endif
- pkg->size = NULL;
- pkg->installed_size = NULL;
+ pkg->size = 0;
+ pkg->installed_size = 0;
pkg->priority = NULL;
pkg->source = NULL;
conffile_list_init(&pkg->conffiles);
pkg->sha256sum = NULL;
#endif
- if (pkg->size)
- free(pkg->size);
- pkg->size = NULL;
-
- if (pkg->installed_size)
- free(pkg->installed_size);
- pkg->installed_size = NULL;
-
if (pkg->priority)
free(pkg->priority);
pkg->priority = NULL;
}
int
-pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename)
+pkg_init_from_file(pkg_t *pkg, const char *filename)
{
int fd, err = 0;
FILE *control_file;
basename(filename));
fd = mkstemp(control_path);
if (fd == -1) {
- perror_msg("%s: mkstemp(%s)", __FUNCTION__, control_path);
+ opkg_perror(ERROR, "Failed to make temp file %s", control_path);
err = -1;
goto err0;
}
control_file = fdopen(fd, "r+");
if (control_file == NULL) {
- perror_msg("%s: fdopen", __FUNCTION__, control_path);
+ opkg_perror(ERROR, "Failed to fdopen %s", control_path);
close(fd);
err = -1;
goto err1;
err = pkg_extract_control_file_to_stream(pkg, control_file);
if (err) {
- opkg_message(conf, OPKG_ERROR, "Failed to extract control file"
- " from %s\n", filename);
+ opkg_msg(ERROR, "Failed to extract control file from %s.\n",
+ filename);
goto err2;
}
rewind(control_file);
- if (pkg_parse_from_stream(pkg, control_file, PFM_ALL))
+ if (pkg_parse_from_stream(pkg, control_file, 0))
err = -1;
err2:
}
/* Merge any new information in newpkg into oldpkg */
-/* XXX: CLEANUP: This function shouldn't actually modify anything in
- newpkg, but should leave it usable. This rework is so that
- pkg_hash_insert doesn't clobber the pkg that you pass into it. */
-/*
- * uh, i thought that i had originally written this so that it took
- * two pkgs and returned a new one? we can do that again... -sma
- */
int
-pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
+pkg_merge(pkg_t *oldpkg, pkg_t *newpkg)
{
if (oldpkg == newpkg) {
return 0;
oldpkg->maintainer = xstrdup(newpkg->maintainer);
if(!oldpkg->description)
oldpkg->description = xstrdup(newpkg->description);
- if (set_status) {
- /* merge the state_flags from the new package */
- oldpkg->state_want = newpkg->state_want;
- oldpkg->state_status = newpkg->state_status;
- oldpkg->state_flag = newpkg->state_flag;
- } else {
- if (oldpkg->state_want == SW_UNKNOWN)
- oldpkg->state_want = newpkg->state_want;
- if (oldpkg->state_status == SS_NOT_INSTALLED)
- oldpkg->state_status = newpkg->state_status;
- oldpkg->state_flag |= newpkg->state_flag;
- }
if (!oldpkg->depends_count && !oldpkg->pre_depends_count && !oldpkg->recommends_count && !oldpkg->suggests_count) {
oldpkg->depends_count = newpkg->depends_count;
oldpkg->sha256sum = xstrdup(newpkg->sha256sum);
#endif
if (!oldpkg->size)
- oldpkg->size = xstrdup(newpkg->size);
+ oldpkg->size = newpkg->size;
if (!oldpkg->installed_size)
- oldpkg->installed_size = xstrdup(newpkg->installed_size);
+ oldpkg->installed_size = newpkg->installed_size;
if (!oldpkg->priority)
oldpkg->priority = xstrdup(newpkg->priority);
if (!oldpkg->source)
oldpkg->source = xstrdup(newpkg->source);
+
if (nv_pair_list_empty(&oldpkg->conffiles)){
list_splice_init(&newpkg->conffiles.head, &oldpkg->conffiles.head);
- conffile_list_init(&newpkg->conffiles);
}
+
if (!oldpkg->installed_files){
oldpkg->installed_files = newpkg->installed_files;
oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
newpkg->installed_files = NULL;
}
+
if (!oldpkg->essential)
oldpkg->essential = newpkg->essential;
}
void
-set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){
+set_flags_from_control(pkg_t *pkg){
char *file_name;
FILE *fp;
fp = fopen(file_name, "r");
if (fp == NULL) {
- opkg_message(conf, OPKG_ERROR, "%s: fopen(%s): %s\n",
- __FUNCTION__, file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to open %s");
free(file_name);
return;
}
free(file_name);
- if (pkg_parse_from_stream(pkg, fp, PFM_ESSENTIAL)) {
- opkg_message(conf, OPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
+ if (pkg_parse_from_stream(pkg, fp, PFM_ALL ^ PFM_ESSENTIAL)) {
+ opkg_msg(DEBUG, "Unable to read control file for %s. May be empty.\n",
+ pkg->name);
}
fclose(fp);
return;
}
-static char *
+static const char *
pkg_state_want_to_str(pkg_state_want_t sw)
{
int i;
}
}
- fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
- __FUNCTION__, sw);
+ opkg_msg(ERROR, "Internal error: state_want=%d\n", sw);
return "<STATE_WANT_UNKNOWN>";
}
}
}
- fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
- __FUNCTION__, str);
+ opkg_msg(ERROR, "Internal error: state_want=%s\n", str);
return SW_UNKNOWN;
}
pkg_state_flag_to_str(pkg_state_flag_t sf)
{
int i;
- int len;
+ unsigned int len;
char *str;
/* clear the temporary flags before converting to string */
{
int i;
int sf = SF_OK;
+ const char *sfname;
+ unsigned int sfname_len;
if (strcmp(str, "ok") == 0) {
return SF_OK;
}
for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
- const char *sfname = pkg_state_flag_map[i].str;
- int sfname_len = strlen(sfname);
+ sfname = pkg_state_flag_map[i].str;
+ sfname_len = strlen(sfname);
if (strncmp(str, sfname, sfname_len) == 0) {
sf |= pkg_state_flag_map[i].value;
str += sfname_len;
return sf;
}
-static char *
+static const char *
pkg_state_status_to_str(pkg_state_status_t ss)
{
int i;
}
}
- fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
- __FUNCTION__, ss);
+ opkg_msg(ERROR, "Internal error: state_status=%d\n", ss);
return "<STATE_STATUS_UNKNOWN>";
}
}
}
- fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
- __FUNCTION__, str);
+ opkg_msg(ERROR, "Internal error: state_status=%s\n", str);
return SS_NOT_INSTALLED;
}
case 'i':
case 'I':
if (strcasecmp(field, "Installed-Size") == 0) {
- fprintf(fp, "Installed-Size: %s\n", pkg->installed_size);
+ fprintf(fp, "Installed-Size: %ld\n", pkg->installed_size);
} else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
fprintf(fp, "Installed-Time: %lu\n", pkg->installed_time);
}
#endif
} else if (strcasecmp(field, "Size") == 0) {
if (pkg->size) {
- fprintf(fp, "Size: %s\n", pkg->size);
+ fprintf(fp, "Size: %ld\n", pkg->size);
}
} else if (strcasecmp(field, "Source") == 0) {
if (pkg->source) {
return;
UNKNOWN_FMT_FIELD:
- fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
+ opkg_msg(ERROR, "Internal error: field=%s\n", field);
}
void
return;
}
- /* XXX: QUESTION: Do we actually want more fields here? The
- original idea was to save space by installing only what was
- needed for actual computation, (package, version, status,
- essential, conffiles). The assumption is that all other fields
- can be found in th available file.
-
- But, someone proposed the idea to make it possible to
- reconstruct a .opk from an installed package, (ie. for beaming
- from one handheld to another). So, maybe we actually want a few
- more fields here, (depends, suggests, etc.), so that that would
- be guaranteed to work even in the absence of more information
- from the available file.
-
- 28-MAR-03: kergoth and I discussed this yesterday. We think
- the essential info needs to be here for all installed packages
- because they may not appear in the Packages files on various
- feeds. Furthermore, one should be able to install from URL or
- local storage without requiring a Packages file from any feed.
- -Jamey
- */
pkg_formatted_field(file, pkg, "Package");
pkg_formatted_field(file, pkg, "Version");
pkg_formatted_field(file, pkg, "Depends");
return r == 0;
}
- fprintf(stderr, "unknown operator: %s", op);
+ opkg_msg(ERROR, "Unknown operator: %s.\n", op);
return 0;
}
int namecmp;
int vercmp;
if (!a->name || !b->name) {
- fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
- a, a->name, b, b->name);
+ opkg_msg(ERROR, "Internal error: a->name=%p, b->name=%p.\n",
+ a->name, b->name);
return 0;
}
if (vercmp)
return vercmp;
if (!a->arch_priority || !b->arch_priority) {
- fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
- a, a->arch_priority, b, b->arch_priority);
+ opkg_msg(ERROR, "Internal error: a->arch_priority=%i b->arch_priority=%i.\n",
+ a->arch_priority, b->arch_priority);
return 0;
}
if (a->arch_priority > b->arch_priority)
const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
if (!a->name || !b->name) {
- fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
- a, a->name, b, b->name);
+ opkg_msg(ERROR, "Internal error: a->name=%p b->name=%p.\n",
+ a->name, b->name);
return 0;
}
return strcmp(a->name, b->name);
* XXX: this should be broken into two functions
*/
str_list_t *
-pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg)
+pkg_get_installed_files(pkg_t *pkg)
{
int err, fd;
char *list_file_name = NULL;
FILE *list_file = NULL;
char *line;
char *installed_file_name;
- int rootdirlen = 0;
+ unsigned int rootdirlen = 0;
pkg->installed_files_ref_cnt++;
conf->tmp_dir, pkg->name);
fd = mkstemp(list_file_name);
if (fd == -1) {
- opkg_message(conf, OPKG_ERROR, "%s: mkstemp(%s): %s",
- __FUNCTION__, list_file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to make temp file %s.",
+ list_file_name);
free(list_file_name);
return pkg->installed_files;
}
list_file = fdopen(fd, "r+");
if (list_file == NULL) {
- opkg_message(conf, OPKG_ERROR, "%s: fdopen: %s",
- __FUNCTION__, strerror(errno));
+ opkg_perror(ERROR, "Failed to fdopen temp file %s.",
+ list_file_name);
close(fd);
unlink(list_file_name);
free(list_file_name);
}
err = pkg_extract_data_file_names_to_stream(pkg, list_file);
if (err) {
- opkg_message(conf, OPKG_ERROR, "%s: Error extracting file list "
- "from %s\n", __FUNCTION__,
+ opkg_msg(ERROR, "Error extracting file list from %s.\n",
pkg->local_filename);
fclose(list_file);
unlink(list_file_name);
pkg->dest->info_dir, pkg->name);
list_file = fopen(list_file_name, "r");
if (list_file == NULL) {
- opkg_message(conf, OPKG_ERROR, "%s: fopen(%s): %s\n",
- __FUNCTION__, list_file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to open %s.\n",
+ list_file_name);
free(list_file_name);
return pkg->installed_files;
}
}
void
-pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg)
+pkg_remove_installed_files_list(pkg_t *pkg)
{
char *list_file_name;
}
int
-pkg_run_script(opkg_conf_t *conf, pkg_t *pkg,
- const char *script, const char *args)
+pkg_run_script(pkg_t *pkg, const char *script, const char *args)
{
int err;
char *path;
if (conf->noaction)
return 0;
- /* XXX: CLEANUP: There must be a better way to handle maintainer
- scripts when running with offline_root mode and/or a dest other
- than '/'. I've been playing around with some clever chroot
- tricks and I might come up with something workable. */
- /*
- * Attempt to provide a restricted environment for offline operation
- * Need the following set as a minimum:
- * OPKG_OFFLINE_ROOT = absolute path to root dir
- * D = absolute path to root dir (for OE generated postinst)
- * PATH = something safe (a restricted set of utilities)
- */
-
- if (conf->offline_root) {
- if (conf->offline_root_path) {
- setenv("PATH", conf->offline_root_path, 1);
- } else {
- opkg_message(conf, OPKG_NOTICE,
- "(offline root mode: not running %s.%s)\n", pkg->name, script);
- return 0;
- }
- setenv("OPKG_OFFLINE_ROOT", conf->offline_root, 1);
- setenv("D", conf->offline_root, 1);
- }
-
/* XXX: FEATURE: When conf->offline_root is set, we should run the
maintainer script within a chroot environment. */
+ if (conf->offline_root) {
+ opkg_msg(INFO, "Offline root mode: not running %s.%s.\n",
+ pkg->name, script);
+ return 0;
+ }
/* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
have scripts in pkg->tmp_unpack_dir. */
if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
if (pkg->dest == NULL) {
- fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
- __FUNCTION__, pkg->name);
- return EINVAL;
+ opkg_msg(ERROR, "Internal error: %s has a NULL dest.\n",
+ pkg->name);
+ return -1;
}
sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
} else {
if (pkg->tmp_unpack_dir == NULL) {
- fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
- __FUNCTION__, pkg->name);
- return EINVAL;
+ opkg_msg(ERROR, "Internal error: %s has a NULL tmp_unpack_dir.\n",
+ pkg->name);
+ return -1;
}
sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
}
- opkg_message(conf, OPKG_INFO, "Running script %s\n", path);
+ opkg_msg(INFO, "Running script %s.\n", path);
setenv("PKG_ROOT",
pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
free(cmd);
if (err) {
- fprintf(stderr, "%s script returned status %d\n", script, err);
+ opkg_msg(ERROR, "%s script returned status %d.\n", script, err);
return err;
}
}
int
-pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg)
+pkg_arch_supported(pkg_t *pkg)
{
nv_pair_list_elt_t *l;
list_for_each_entry(l , &conf->arch_list.head, node) {
nv_pair_t *nv = (nv_pair_t *)l->data;
if (strcmp(nv->name, pkg->architecture) == 0) {
- opkg_message(conf, OPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
+ opkg_msg(DEBUG, "Arch %s (priority %s) supported for pkg %s.\n",
+ nv->name, nv->value, pkg->name);
return 1;
}
}
- opkg_message(conf, OPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
+ opkg_msg(DEBUG, "Arch %s unsupported for pkg %s.\n",
+ pkg->architecture, pkg->name);
return 0;
}
-int
-pkg_get_arch_priority(opkg_conf_t *conf, const char *archname)
+static int
+pkg_get_arch_priority(const char *archname)
{
nv_pair_list_elt_t *l;
}
void
-pkg_info_preinstall_check(opkg_conf_t *conf)
+pkg_info_preinstall_check(void)
{
int i;
- hash_table_t *pkg_hash = &conf->pkg_hash;
pkg_vec_t *available_pkgs = pkg_vec_alloc();
pkg_vec_t *installed_pkgs = pkg_vec_alloc();
- opkg_message(conf, OPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
- pkg_hash_fetch_available(pkg_hash, available_pkgs);
+ opkg_msg(INFO, "Updating arch priority for each package.\n");
+ pkg_hash_fetch_available(available_pkgs);
/* update arch_priority for each package */
for (i = 0; i < available_pkgs->len; i++) {
pkg_t *pkg = available_pkgs->pkgs[i];
int arch_priority = 1;
if (!pkg)
continue;
- // opkg_message(conf, OPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
- if (pkg->architecture)
- arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
- else
- opkg_message(conf, OPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
- // opkg_message(conf, OPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
+ arch_priority = pkg_get_arch_priority(pkg->architecture);
pkg->arch_priority = arch_priority;
}
pkg_t *pkg = available_pkgs->pkgs[i];
if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
/* clear flags and want for any uninstallable package */
- opkg_message(conf, OPKG_DEBUG, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
- pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
+ opkg_msg(DEBUG, "Clearing state_want and state_flag for pkg=%s "
+ "(arch_priority=%d flag=%d want=%d)\n",
+ pkg->name, pkg->arch_priority,
+ pkg->state_flag, pkg->state_want);
pkg->state_want = SW_UNKNOWN;
pkg->state_flag = 0;
}
pkg_vec_free(available_pkgs);
/* update the file owner data structure */
- opkg_message(conf, OPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
- pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
+ opkg_msg(INFO, "Updating file owner list.\n");
+ pkg_hash_fetch_all_installed(installed_pkgs);
for (i = 0; i < installed_pkgs->len; i++) {
pkg_t *pkg = installed_pkgs->pkgs[i];
- str_list_t *installed_files = pkg_get_installed_files(conf, pkg); /* this causes installed_files to be cached */
+ str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
str_list_elt_t *iter, *niter;
if (installed_files == NULL) {
- opkg_message(conf, OPKG_ERROR, "Failed to determine installed "
+ opkg_msg(ERROR, "Failed to determine installed "
"files for pkg %s.\n", pkg->name);
break;
}
iter;
iter = niter, niter = str_list_next(installed_files, iter)) {
char *installed_file = (char *) iter->data;
- // opkg_message(conf, OPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
- file_hash_set_file_owner(conf, installed_file, pkg);
+ file_hash_set_file_owner(installed_file, pkg);
}
pkg_free_installed_files(pkg);
}
}
struct pkg_write_filelist_data {
- opkg_conf_t *conf;
pkg_t *pkg;
FILE *stream;
};
-void
+static void
pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
{
struct pkg_write_filelist_data *data = data_;
}
int
-pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg)
+pkg_write_filelist(pkg_t *pkg)
{
struct pkg_write_filelist_data data;
char *list_file_name;
sprintf_alloc(&list_file_name, "%s/%s.list",
pkg->dest->info_dir, pkg->name);
- opkg_message(conf, OPKG_INFO, "%s: creating %s file for pkg %s\n",
- __FUNCTION__, list_file_name, pkg->name);
+ opkg_msg(INFO, "Creating %s file for pkg %s.\n",
+ list_file_name, pkg->name);
data.stream = fopen(list_file_name, "w");
if (!data.stream) {
- opkg_message(conf, OPKG_ERROR, "%s: fopen(%s, \"w\"): %s\n",
- __FUNCTION__, list_file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to open %s",
+ list_file_name);
free(list_file_name);
return -1;
}
data.pkg = pkg;
- data.conf = conf;
hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
fclose(data.stream);
free(list_file_name);
}
int
-pkg_write_changed_filelists(opkg_conf_t *conf)
+pkg_write_changed_filelists(void)
{
pkg_vec_t *installed_pkgs = pkg_vec_alloc();
- hash_table_t *pkg_hash = &conf->pkg_hash;
int i, err, ret = 0;
if (conf->noaction)
return 0;
- opkg_message(conf, OPKG_INFO, "%s: saving changed filelists\n",
- __FUNCTION__);
+ opkg_msg(INFO, "Saving changed filelists.\n");
- pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
+ pkg_hash_fetch_all_installed(installed_pkgs);
for (i = 0; i < installed_pkgs->len; i++) {
pkg_t *pkg = installed_pkgs->pkgs[i];
if (pkg->state_flag & SF_FILELIST_CHANGED) {
- err = pkg_write_filelist(conf, pkg);
+ err = pkg_write_filelist(pkg);
if (err)
ret = -1;
}
pkg_vec_t * pkgs;
pkg_state_status_t state_status;
pkg_state_flag_t state_flag;
- struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
+
+ /* XXX: This should be abstract_pkg_vec_t for consistency. */
+ struct abstract_pkg ** depended_upon_by;
+
abstract_pkg_vec_t * provided_by;
abstract_pkg_vec_t * replaced_by;
};
pkg_state_flag_t state_flag;
pkg_state_status_t state_status;
char **depends_str;
- int depends_count;
+ unsigned int depends_count;
char **pre_depends_str;
- int pre_depends_count;
+ unsigned int pre_depends_count;
char **recommends_str;
- int recommends_count;
+ unsigned int recommends_count;
char **suggests_str;
- int suggests_count;
+ unsigned int suggests_count;
struct active_list list; /* Used for installing|upgrading */
compound_depend_t * depends;
- /* Abhaya: new conflicts */
char **conflicts_str;
compound_depend_t * conflicts;
- int conflicts_count;
+ unsigned int conflicts_count;
char **replaces_str;
- int replaces_count;
+ unsigned int replaces_count;
abstract_pkg_t ** replaces;
char **provides_str;
- int provides_count;
+ unsigned int provides_count;
abstract_pkg_t ** provides;
abstract_pkg_t *parent;
- pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
-
char *filename;
char *local_filename;
- char *url;
char *tmp_unpack_dir;
char *md5sum;
#if defined HAVE_SHA256
char *sha256sum;
#endif
- char *size;
- char *installed_size;
+ unsigned long size; /* in bytes */
+ unsigned long installed_size; /* in bytes */
char *priority;
char *source;
conffile_list_t conffiles;
pkg_t *pkg_new(void);
void pkg_deinit(pkg_t *pkg);
-int pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename);
+int pkg_init_from_file(pkg_t *pkg, const char *filename);
abstract_pkg_t *abstract_pkg_new(void);
/*
* merges fields from newpkg into oldpkg.
- * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
+ * Forcibly sets oldpkg state_status, state_want and state_flags
*/
-int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
+int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg);
char *pkg_version_str_alloc(pkg_t *pkg);
void pkg_formatted_info(FILE *fp, pkg_t *pkg);
void pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field);
-void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg);
+void set_flags_from_control(pkg_t *pkg);
void pkg_print_status(pkg_t * pkg, FILE * file);
-str_list_t *pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg);
+str_list_t *pkg_get_installed_files(pkg_t *pkg);
void pkg_free_installed_files(pkg_t *pkg);
-void pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg);
+void pkg_remove_installed_files_list(pkg_t *pkg);
conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
-int pkg_run_script(struct opkg_conf *conf, pkg_t *pkg,
- const char *script, const char *args);
+int pkg_run_script(pkg_t *pkg, const char *script, const char *args);
/* enum mappings */
pkg_state_want_t pkg_state_want_from_str(char *str);
int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
-int pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg);
-void pkg_info_preinstall_check(opkg_conf_t *conf);
+int pkg_arch_supported(pkg_t *pkg);
+void pkg_info_preinstall_check(void);
-int pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg);
-int pkg_write_changed_filelists(opkg_conf_t *conf);
+int pkg_write_filelist(pkg_t *pkg);
+int pkg_write_changed_filelists(void);
#endif
#include "hash_table.h"
#include "libbb/libbb.h"
-static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
+static int parseDepends(compound_depend_t *compound_depend, char * depend_str);
static depend_t * depend_init(void);
static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
}
/* returns ndependences or negative error value */
-int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg,
- pkg_vec_t *unsatisfied, char *** unresolved)
+int
+pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t *unsatisfied,
+ char *** unresolved)
{
pkg_t * satisfier_entry_pkg;
int i, j, k;
* which are marked at the abstract_pkg level
*/
if (!(ab_pkg = pkg->parent)) {
- fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
+ opkg_msg(ERROR, "Internal error, with pkg %s.\n", pkg->name);
*unresolved = NULL;
return 0;
}
int rc;
pkg_vec_t *tmp_vec = pkg_vec_alloc ();
/* check for not-already-installed dependencies */
- rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
- pkg_scout,
+ rc = pkg_hash_fetch_unsatisfied_dependencies(pkg_scout,
tmp_vec,
&newstuff);
if (newstuff == NULL) {
pkg_t *p = tmp_vec->pkgs[m];
if (p->state_want == SW_INSTALL)
continue;
- opkg_message(conf, OPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
+ opkg_msg(DEBUG,
+ "Not installing %s due"
+ " to requirement for %s.\n",
+ pkg_scout->name,
+ p->name);
ok = 0;
break;
}
pkg_vec_free (tmp_vec);
if (ok) {
/* mark this one for installation */
- opkg_message(conf, OPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
+ opkg_msg(NOTICE,
+ "Adding satisfier for greedy"
+ " dependence %s.\n",
+ pkg_scout->name);
pkg_vec_insert(unsatisfied, pkg_scout);
}
} else {
- opkg_message(conf, OPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
+ opkg_msg(DEBUG,
+ "Not installing %s due to "
+ "broken depends.\n",
+ pkg_scout->name);
free (newstuff);
}
}
depend_t *dependence_to_satisfy = possible_satisfiers[j];
abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
pkg_t *satisfying_pkg =
- pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
+ pkg_hash_fetch_best_installation_candidate(satisfying_apkg,
pkg_installed_and_constraint_satisfied,
dependence_to_satisfy, 1);
/* Being that I can't test constraing in pkg_hash, I will test it here */
satisfying_pkg = NULL;
}
}
- opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
+ opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg);
if (satisfying_pkg != NULL) {
found = 1;
break;
depend_t *dependence_to_satisfy = possible_satisfiers[j];
abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
pkg_t *satisfying_pkg =
- pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
+ pkg_hash_fetch_best_installation_candidate(satisfying_apkg,
pkg_constraint_satisfied,
dependence_to_satisfy, 1);
/* Being that I can't test constraing in pkg_hash, I will test it here too */
if (satisfying_pkg != NULL
&& (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
&& (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
- opkg_message (conf, OPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
- pkg->name, satisfying_pkg->name);
+ opkg_msg(NOTICE, "%s: ignoring recommendation for "
+ "%s at user request\n",
+ pkg->name, satisfying_pkg->name);
continue;
}
- opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
+ opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg);
if (satisfying_pkg != NULL) {
satisfier_entry_pkg = satisfying_pkg;
break;
if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
the_lost = add_unresolved_dep(pkg, the_lost, i);
else
- opkg_message (conf, OPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
- pkg->name, compound_depend->possibilities[0]->pkg->name);
+ opkg_msg(NOTICE,
+ "%s: unsatisfied recommendation for %s\n",
+ pkg->name,
+ compound_depend->possibilities[0]->pkg->name);
}
else {
if (compound_depend->type == SUGGEST) {
/* just mention it politely */
- opkg_message (conf, OPKG_NOTICE, "package %s suggests installing %s\n",
- pkg->name, satisfier_entry_pkg->name);
+ opkg_msg(NOTICE, "package %s suggests installing %s\n",
+ pkg->name, satisfier_entry_pkg->name);
} else {
char ** newstuff = NULL;
if (satisfier_entry_pkg != pkg &&
!is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
- pkg_hash_fetch_unsatisfied_dependencies(conf,
- satisfier_entry_pkg,
+ pkg_hash_fetch_unsatisfied_dependencies(satisfier_entry_pkg,
unsatisfied,
&newstuff);
the_lost = merge_unresolved(the_lost, newstuff);
really conflicts
returns 0 if conflicts <> replaces or 1 if conflicts == replaces
*/
-int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
+static int
+is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
{
int i ;
int replaces_count = pkg->replaces_count;
for (i = 0; i < replaces_count; i++) {
if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
- opkg_message(NULL, OPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
+ opkg_msg(DEBUG2, "Seems I've found a replace %s %s\n",
+ pkg_scout->name, pkg->replaces[i]->name);
return 1;
}
}
}
-/* Abhaya: added support for conflicts */
-pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
+pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
{
pkg_vec_t * installed_conflicts, * test_vec;
compound_depend_t * conflicts;
* which are marked at the abstract_pkg level
*/
if(!(ab_pkg = pkg->parent)){
- fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
+ opkg_msg(ERROR, "Internal error: %s not in hash table\n", pkg->name);
return (pkg_vec_t *)NULL;
}
for(j = 0; j < conflicts->possibility_count; j++){
possible_satisfier = possible_satisfiers[j];
if (!possible_satisfier)
- fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
+ opkg_msg(ERROR, "Internal error: possible_satisfier=NULL\n");
if (!possible_satisfier->pkg)
- fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
+ opkg_msg(ERROR, "Internal error: possible_satisfier->pkg=NULL\n");
test_vec = possible_satisfier->pkg->pkgs;
if (test_vec) {
/* pkg_vec found, it is an actual package conflict
for(k = 0; k < test_vec->len; k++){
pkg_scout = pkg_scouts[k];
if (!pkg_scout) {
- fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
+ opkg_msg(ERROR, "Internal error: pkg_scout=NULL\n");
continue;
}
if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
return 0;
}
-int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend)
+int pkg_dependence_satisfiable(depend_t *depend)
{
abstract_pkg_t *apkg = depend->pkg;
abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
return 0;
}
-int pkg_dependence_satisfied(opkg_conf_t *conf, depend_t *depend)
+int pkg_dependence_satisfied(depend_t *depend)
{
abstract_pkg_t *apkg = depend->pkg;
abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
return resized;
}
-void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
+void buildProvides(abstract_pkg_t * ab_pkg, pkg_t * pkg)
{
int i;
pkg->provides[0] = ab_pkg;
for (i=1; i<pkg->provides_count; i++) {
- abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash,
+ abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(
pkg->provides_str[i-1]);
free(pkg->provides_str[i-1]);
free(pkg->provides_str);
}
-/* Abhaya: added conflicts support */
-void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
+void buildConflicts(pkg_t * pkg)
{
int i;
compound_depend_t * conflicts;
conflicts = pkg->conflicts = xcalloc(pkg->conflicts_count, sizeof(compound_depend_t));
for (i = 0; i < pkg->conflicts_count; i++) {
conflicts->type = CONFLICTS;
- parseDepends(conflicts, hash,
- pkg->conflicts_str[i]);
+ parseDepends(conflicts, pkg->conflicts_str[i]);
free(pkg->conflicts_str[i]);
conflicts++;
}
free(pkg->conflicts_str);
}
-void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
+void buildReplaces(abstract_pkg_t * ab_pkg, pkg_t * pkg)
{
int i;
pkg->replaces = xcalloc(pkg->replaces_count, sizeof(abstract_pkg_t *));
for(i = 0; i < pkg->replaces_count; i++){
- abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
+ abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(pkg->replaces_str[i]);
pkg->replaces[i] = old_abpkg;
free(pkg->replaces_str[i]);
free(pkg->replaces_str);
}
-void buildDepends(hash_table_t * hash, pkg_t * pkg)
+void buildDepends(pkg_t * pkg)
{
- int count;
+ unsigned int count;
int i;
compound_depend_t * depends;
depends = pkg->depends = xcalloc(count, sizeof(compound_depend_t));
for(i = 0; i < pkg->pre_depends_count; i++){
- parseDepends(depends, hash, pkg->pre_depends_str[i]);
+ parseDepends(depends, pkg->pre_depends_str[i]);
free(pkg->pre_depends_str[i]);
depends->type = PREDEPEND;
depends++;
free(pkg->pre_depends_str);
for(i = 0; i < pkg->depends_count; i++){
- parseDepends(depends, hash, pkg->depends_str[i]);
+ parseDepends(depends, pkg->depends_str[i]);
free(pkg->depends_str[i]);
depends++;
}
free(pkg->depends_str);
for(i = 0; i < pkg->recommends_count; i++){
- parseDepends(depends, hash, pkg->recommends_str[i]);
+ parseDepends(depends, pkg->recommends_str[i]);
free(pkg->recommends_str[i]);
depends->type = RECOMMEND;
depends++;
free(pkg->recommends_str);
for(i = 0; i < pkg->suggests_count; i++){
- parseDepends(depends, hash, pkg->suggests_str[i]);
+ parseDepends(depends, pkg->suggests_str[i]);
free(pkg->suggests_str[i]);
depends->type = SUGGEST;
depends++;
}
/*
- * Returns a printable string for pkg's dependency at the specified index. The
+ * Returns a printable string for pkg's dependency at the specified idx. The
* resultant string must be passed to free() by the caller.
*/
char *
-pkg_depend_str(pkg_t *pkg, int index)
+pkg_depend_str(pkg_t *pkg, int idx)
{
- int i, len;
+ int i;
+ unsigned int len;
char *str;
compound_depend_t *cdep;
depend_t *dep;
len = 0;
- cdep = &pkg->depends[index];
+ cdep = &pkg->depends[idx];
/* calculate string length */
for (i=0; i<cdep->possibility_count; i++) {
}
static int parseDepends(compound_depend_t *compound_depend,
- hash_table_t * hash, char * depend_str)
+ char * depend_str)
{
char * pkg_name, buffer[2048];
- int num_of_ors = 0;
+ unsigned int num_of_ors = 0;
int i;
char * src, * dest;
depend_t ** possibilities;
*dest++ = *src++;
*dest = '\0';
pkg_name = trim_xstrdup(buffer);
- if (pkg_name == NULL )
- return -ENOMEM;
/* now look at possible version info */
while(*src && *src != ')')
*dest++ = *src++;
*dest = '\0';
-
- possibilities[i]->version = trim_xstrdup(buffer);
- /* fprintf(stderr, "let's print the depends version string:");
- fprintf(stderr, "version %s\n", possibilities[i]->version);*/
- if (possibilities[i]->version == NULL )
- return -ENOMEM;
-
+ possibilities[i]->version = trim_xstrdup(buffer);
}
/* hook up the dependency to its abstract pkg */
- possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
+ possibilities[i]->pkg = ensure_abstract_pkg_by_name(pkg_name);
free(pkg_name);
};
typedef struct compound_depend compound_depend_t;
-#include "hash_table.h"
-
-void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
-void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
-void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
-void buildDepends(hash_table_t * hash, pkg_t * pkg);
+void buildProvides(abstract_pkg_t * ab_pkg, pkg_t * pkg);
+void buildConflicts(pkg_t * pkg);
+void buildReplaces(abstract_pkg_t * ab_pkg, pkg_t * pkg);
+void buildDepends(pkg_t * pkg);
/**
* pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
char *pkg_depend_str(pkg_t *pkg, int index);
void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
-int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
-pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg);
-int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend);
-int pkg_dependence_satisfied(opkg_conf_t *conf, depend_t *depend);
+int pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
+pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
+int pkg_dependence_satisfiable(depend_t *depend);
+int pkg_dependence_satisfied(depend_t *depend);
const char* constraint_to_str(enum version_constraint c);
#endif
#include "file_util.h"
#include "sprintf_alloc.h"
-/* assuage libb functions */
-const char *applet_name = "opkg";
-
int
pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
{
#include "libbb/libbb.h"
void
-pkg_hash_init(const char *name, hash_table_t *hash, int len)
+pkg_hash_init(void)
{
- hash_table_init(name, hash, len);
+ hash_table_init("pkg-hash", &conf->pkg_hash,
+ OPKG_CONF_DEFAULT_HASH_LEN);
}
static void
}
void
-pkg_hash_deinit(hash_table_t *hash)
+pkg_hash_deinit(void)
{
- hash_table_foreach(hash, free_pkgs, NULL);
- hash_table_deinit(hash);
-}
-
-
-/* Find the default arch for a given package status file if none is given. */
-static char *
-pkg_get_default_arch(opkg_conf_t *conf)
-{
- nv_pair_list_elt_t *l;
- char *def_arch = HOST_CPU_STR; /* Default arch */
- int def_prio = 0; /* Other archs override this */
-
- list_for_each_entry(l , &conf->arch_list.head, node) {
- nv_pair_t *nv = (nv_pair_t *)l->data;
- int priority = strtol(nv->value, NULL, 0);
-
- /* Check if this arch has higher priority, and is valid */
- if ((priority > def_prio) &&
- (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
- /* Our new default */
- def_prio = priority;
- def_arch = nv->name;
- }
- }
-
- return xstrdup(def_arch);
+ hash_table_foreach(&conf->pkg_hash, free_pkgs, NULL);
+ hash_table_deinit(&conf->pkg_hash);
}
int
-pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name,
+pkg_hash_add_from_file(const char *file_name,
pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
{
- hash_table_t *hash = &conf->pkg_hash;
pkg_t *pkg;
FILE *fp;
char *buf;
fp = fopen(file_name, "r");
if (fp == NULL) {
- fprintf(stderr, "%s: fopen(%s): %s\n",
- __FUNCTION__, file_name, strerror(errno));
+ opkg_perror(ERROR, "Failed to open %s", file_name);
return -1;
}
pkg->src = src;
pkg->dest = dest;
- ret = pkg_parse_from_stream_nomalloc(pkg, fp, PFM_ALL,
+ ret = pkg_parse_from_stream_nomalloc(pkg, fp, 0,
&buf, len);
if (ret) {
pkg_deinit (pkg);
free(pkg);
if (ret == -1)
break;
- if (ret == EINVAL)
+ if (ret == 1)
/* Probably a blank line, continue parsing. */
ret = 0;
continue;
if (!pkg->architecture) {
char *version_str = pkg_version_str_alloc(pkg);
- pkg->architecture = pkg_get_default_arch(conf);
- opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
- pkg->name, version_str, pkg->architecture);
+ opkg_msg(ERROR, "Package %s version %s has no "
+ "architecture specified, ignoring.\n",
+ pkg->name, version_str);
free(version_str);
+ continue;
}
- hash_insert_pkg(hash, pkg, is_status_file, conf);
+ hash_insert_pkg(pkg, is_status_file);
} while (!feof(fp));
}
static abstract_pkg_t *
-abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
+abstract_pkg_fetch_by_name(const char * pkg_name)
{
- return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
+ return (abstract_pkg_t *)hash_table_get(&conf->pkg_hash, pkg_name);
}
pkg_t *
-pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf,
- abstract_pkg_t *apkg,
+pkg_hash_fetch_best_installation_candidate(abstract_pkg_t *apkg,
int (*constraint_fcn)(pkg_t *pkg, void *cdata),
void *cdata, int quiet)
{
matching_apkgs = abstract_pkg_vec_alloc();
providers = abstract_pkg_vec_alloc();
- opkg_message(conf, OPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
+ opkg_msg(DEBUG, "Best installation candidate for %s:\n", apkg->name);
provided_apkg_vec = apkg->provided_by;
nprovides = provided_apkg_vec->len;
provided_apkgs = provided_apkg_vec->pkgs;
if (nprovides > 1)
- opkg_message(conf, OPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
+ opkg_msg(DEBUG, "apkg=%s nprovides=%d.\n", apkg->name, nprovides);
/* accumulate all the providers */
for (i = 0; i < nprovides; i++) {
abstract_pkg_t *provider_apkg = provided_apkgs[i];
- opkg_message(conf, OPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
+ opkg_msg(DEBUG, "Adding %s to providers.\n", provider_apkg->name);
abstract_pkg_vec_insert(providers, provider_apkg);
}
nprovides = providers->len;
if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
replacement_apkg = provider_apkg->replaced_by->pkgs[0];
if (provider_apkg->replaced_by->len > 1) {
- opkg_message(conf, OPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
- provider_apkg->name, replacement_apkg->name);
+ opkg_msg(NOTICE, "Multiple replacers for %s, "
+ "using first one (%s).\n",
+ provider_apkg->name, replacement_apkg->name);
}
}
if (replacement_apkg)
- opkg_message(conf, OPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
+ opkg_msg(DEBUG, "replacement_apkg=%s for provider_apkg=%s.\n",
replacement_apkg->name, provider_apkg->name);
if (replacement_apkg && (replacement_apkg != provider_apkg)) {
}
if (!(vec = provider_apkg->pkgs)) {
- opkg_message(conf, OPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
+ opkg_msg(DEBUG, "No pkgs for provider_apkg %s.\n",
+ provider_apkg->name);
continue;
}
/* now check for supported architecture */
{
int max_count = 0;
- int i;
/* count packages matching max arch priority and keep track of last one */
for (i = 0; i < vec->len; i++) {
pkg_t *maybe = vec->pkgs[i];
- opkg_message(conf, OPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
- maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
+ opkg_msg(DEBUG, "%s arch=%s arch_priority=%d version=%s.\n",
+ maybe->name, maybe->architecture,
+ maybe->arch_priority, maybe->version);
/* We make sure not to add the same package twice. Need to search for the reason why
they show up twice sometimes. */
if ((maybe->arch_priority > 0) && (! pkg_vec_contains(matching_pkgs, maybe))) {
if (matching_pkgs->len < 1) {
if (wrong_arch_found)
- opkg_message (conf, OPKG_ERROR, "Packages for %s found, but"
+ opkg_msg(ERROR, "Packages for %s found, but"
" incompatible with the architectures configured\n",
apkg->name);
pkg_vec_free(matching_pkgs);
if (matching_apkgs->len > 1)
abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
-/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
- needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
-/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
- Until now I always got the latest, but that breaks the downgrade option.
- If I stop at the first one, I would probably miss the new ones
- Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
- or from a Packages feed.
- It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
-/*Pigi*/
-
for (i = 0; i < matching_pkgs->len; i++) {
pkg_t *matching = matching_pkgs->pkgs[i];
- if (constraint_fcn(matching, cdata)) { /* We found it */
- opkg_message(conf, OPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
+ if (constraint_fcn(matching, cdata)) {
+ opkg_msg(DEBUG, "Candidate: %s %s.\n",
+ matching->name, matching->version) ;
good_pkg_by_name = matching;
- if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
+ /* It has been provided by hand, so it is what user want */
+ if (matching->provided_by_hand == 1)
break;
}
}
latest_installed_parent = matching;
if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
if (held_pkg)
- opkg_message(conf, OPKG_NOTICE, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
- held_pkg->name, matching->name);
+ opkg_msg(NOTICE, "Multiple packages (%s and %s) providing"
+ " same name marked HOLD or PREFER. "
+ "Using latest.\n",
+ held_pkg->name, matching->name);
held_pkg = matching;
}
}
if (matching->arch_priority > prio) {
priorized_matching = matching;
prio = matching->arch_priority;
- opkg_message(conf, OPKG_DEBUG, "Match with priority %i %s\n", prio, matching->name);
+ opkg_msg(DEBUG, "Match %s with priority %i.\n",
+ matching->name, prio);
}
}
}
- if (conf->verbosity >= OPKG_INFO && matching_apkgs->len > 1) {
- opkg_message(conf, OPKG_INFO, "%s: for apkg=%s, %d matching pkgs\n",
- __FUNCTION__, apkg->name, matching_pkgs->len);
+ if (conf->verbosity >= INFO && matching_apkgs->len > 1) {
+ opkg_msg(INFO, "%d matching pkgs for apkg=%s:\n",
+ matching_pkgs->len, apkg->name);
for (i = 0; i < matching_pkgs->len; i++) {
pkg_t *matching = matching_pkgs->pkgs[i];
- opkg_message(conf, OPKG_INFO, " %s %s %s\n",
- matching->name, matching->version, matching->architecture);
+ opkg_msg(INFO, "%s %s %s\n",
+ matching->name, matching->version,
+ matching->architecture);
}
}
return good_pkg_by_name;
}
if (held_pkg) {
- opkg_message(conf, OPKG_INFO, " using held package %s\n", held_pkg->name);
+ opkg_msg(INFO, "Using held package %s.\n", held_pkg->name);
return held_pkg;
}
if (latest_installed_parent) {
- opkg_message(conf, OPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
+ opkg_msg(INFO, "Using latest version of installed package %s.\n",
+ latest_installed_parent->name);
return latest_installed_parent;
}
if (priorized_matching) {
- opkg_message(conf, OPKG_INFO, " using priorized matching %s %s %s\n",
- priorized_matching->name, priorized_matching->version, priorized_matching->architecture);
+ opkg_msg(INFO, "Using priorized matching %s %s %s.\n",
+ priorized_matching->name, priorized_matching->version,
+ priorized_matching->architecture);
return priorized_matching;
}
if (nmatching > 1) {
- opkg_message(conf, OPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
+ opkg_msg(INFO, "No matching pkg out of %d matching_apkgs.\n",
+ nmatching);
return NULL;
}
if (latest_matching) {
- opkg_message(conf, OPKG_INFO, " using latest matching %s %s %s\n",
- latest_matching->name, latest_matching->version, latest_matching->architecture);
+ opkg_msg(INFO, "Using latest matching %s %s %s.\n",
+ latest_matching->name, latest_matching->version,
+ latest_matching->architecture);
return latest_matching;
}
return NULL;
}
static pkg_vec_t *
-pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
+pkg_vec_fetch_by_name(const char *pkg_name)
{
abstract_pkg_t * ab_pkg;
- if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
+ if(!(ab_pkg = abstract_pkg_fetch_by_name(pkg_name)))
return NULL;
if (ab_pkg->pkgs)
pkg_t *
-pkg_hash_fetch_best_installation_candidate_by_name(opkg_conf_t *conf,
- const char *name)
+pkg_hash_fetch_best_installation_candidate_by_name(const char *name)
{
- hash_table_t *hash = &conf->pkg_hash;
abstract_pkg_t *apkg = NULL;
- if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
+ if (!(apkg = abstract_pkg_fetch_by_name(name)))
return NULL;
- return pkg_hash_fetch_best_installation_candidate(conf, apkg,
+ return pkg_hash_fetch_best_installation_candidate(apkg,
pkg_name_constraint_fcn, apkg->name, 0);
}
pkg_t *
-pkg_hash_fetch_by_name_version(hash_table_t *hash,
- const char *pkg_name, const char * version)
+pkg_hash_fetch_by_name_version(const char *pkg_name, const char * version)
{
pkg_vec_t * vec;
int i;
char *version_str = NULL;
- if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
+ if(!(vec = pkg_vec_fetch_by_name(pkg_name)))
return NULL;
for(i = 0; i < vec->len; i++) {
}
pkg_t *
-pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
- const char *pkg_name, pkg_dest_t *dest)
+pkg_hash_fetch_installed_by_name_dest(const char *pkg_name, pkg_dest_t *dest)
{
pkg_vec_t * vec;
int i;
- if (!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
+ if (!(vec = pkg_vec_fetch_by_name(pkg_name))) {
return NULL;
}
}
pkg_t *
-pkg_hash_fetch_installed_by_name(hash_table_t *hash,
- const char *pkg_name)
+pkg_hash_fetch_installed_by_name(const char *pkg_name)
{
pkg_vec_t * vec;
int i;
- if (!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
+ if (!(vec = pkg_vec_fetch_by_name(pkg_name))) {
return NULL;
}
}
void
-pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
+pkg_hash_fetch_available(pkg_vec_t *all)
{
- hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
+ hash_table_foreach(&conf->pkg_hash, pkg_hash_fetch_available_helper,
+ all);
}
static void
}
void
-pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
+pkg_hash_fetch_all_installed(pkg_vec_t *all)
{
- hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
+ hash_table_foreach(&conf->pkg_hash, pkg_hash_fetch_all_installed_helper,
+ all);
}
/*
* This assumes that the abstract pkg doesn't exist.
*/
static abstract_pkg_t *
-add_new_abstract_pkg_by_name(hash_table_t *hash, const char *pkg_name)
+add_new_abstract_pkg_by_name(const char *pkg_name)
{
abstract_pkg_t *ab_pkg;
ab_pkg = abstract_pkg_new();
ab_pkg->name = xstrdup(pkg_name);
- hash_table_insert(hash, pkg_name, ab_pkg);
+ hash_table_insert(&conf->pkg_hash, pkg_name, ab_pkg);
return ab_pkg;
}
abstract_pkg_t *
-ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
+ensure_abstract_pkg_by_name(const char *pkg_name)
{
abstract_pkg_t * ab_pkg;
- if (!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
- ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
+ if (!(ab_pkg = abstract_pkg_fetch_by_name(pkg_name)))
+ ab_pkg = add_new_abstract_pkg_by_name(pkg_name);
return ab_pkg;
}
-pkg_t *
-hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,
- opkg_conf_t *conf)
+void
+hash_insert_pkg(pkg_t *pkg, int set_status)
{
abstract_pkg_t * ab_pkg;
- if(!pkg)
- return pkg;
-
- buildDepends(hash, pkg);
-
- ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
+ ab_pkg = ensure_abstract_pkg_by_name(pkg->name);
+ if (!ab_pkg->pkgs)
+ ab_pkg->pkgs = pkg_vec_alloc();
- if (set_status) {
- if (pkg->state_status == SS_INSTALLED) {
- ab_pkg->state_status = SS_INSTALLED;
- } else if (pkg->state_status == SS_UNPACKED) {
- ab_pkg->state_status = SS_UNPACKED;
- }
+ if (pkg->state_status == SS_INSTALLED) {
+ ab_pkg->state_status = SS_INSTALLED;
+ } else if (pkg->state_status == SS_UNPACKED) {
+ ab_pkg->state_status = SS_UNPACKED;
}
- if(!ab_pkg->pkgs)
- ab_pkg->pkgs = pkg_vec_alloc();
+ buildDepends(pkg);
- buildProvides(hash, ab_pkg, pkg);
+ buildProvides(ab_pkg, pkg);
/* Need to build the conflicts graph before replaces for correct
* calculation of replaced_by relation.
*/
- buildConflicts(hash, ab_pkg, pkg);
+ buildConflicts(pkg);
- buildReplaces(hash, ab_pkg, pkg);
+ buildReplaces(ab_pkg, pkg);
buildDependedUponBy(pkg, ab_pkg);
- /* pkg_vec_insert_merge might munge package, but it returns an
- * unmunged pkg.
- */
- pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
+ pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status);
pkg->parent = ab_pkg;
-
- return pkg;
}
pkg_t *
-file_hash_get_file_owner(opkg_conf_t *conf, const char *file_name)
+file_hash_get_file_owner(const char *file_name)
{
return hash_table_get(&conf->file_hash, file_name);
}
void
-file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name,
- pkg_t *owning_pkg)
+file_hash_set_file_owner(const char *file_name, pkg_t *owning_pkg)
{
pkg_t *old_owning_pkg = hash_table_get(&conf->file_hash, file_name);
int file_name_len = strlen(file_name);
return;
if (conf->offline_root) {
- int len = strlen(conf->offline_root);
+ unsigned int len = strlen(conf->offline_root);
if (strncmp(file_name, conf->offline_root, len) == 0) {
file_name += len;
}
hash_table_insert(&conf->file_hash, file_name, owning_pkg);
if (old_owning_pkg) {
- pkg_get_installed_files(conf, old_owning_pkg);
+ pkg_get_installed_files(old_owning_pkg);
str_list_remove_elt(old_owning_pkg->installed_files, file_name);
pkg_free_installed_files(old_owning_pkg);
#include "hash_table.h"
-void pkg_hash_init(const char *name, hash_table_t *hash, int len);
-void pkg_hash_deinit(hash_table_t *hash);
-void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
+void pkg_hash_init(void);
+void pkg_hash_deinit(void);
-void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
+void pkg_hash_fetch_available(pkg_vec_t *available);
-int pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name,
- pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
-pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,opkg_conf_t *conf);
+int pkg_hash_add_from_file(const char *file_name, pkg_src_t *src,
+ pkg_dest_t *dest, int is_status_file);
+void hash_insert_pkg(pkg_t *pkg, int set_status);
-abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
-void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
-pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
- const char *pkg_name,
+abstract_pkg_t * ensure_abstract_pkg_by_name(const char * pkg_name);
+void pkg_hash_fetch_all_installed(pkg_vec_t *installed);
+pkg_t * pkg_hash_fetch_by_name_version(const char *pkg_name,
const char * version);
-pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pkg_t *apkg,
+pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t *apkg,
int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
-pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(opkg_conf_t *conf, const char *name);
-pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
- const char *pkg_name);
-pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
- const char *pkg_name,
+pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(const char *name);
+pkg_t *pkg_hash_fetch_installed_by_name(const char *pkg_name);
+pkg_t *pkg_hash_fetch_installed_by_name_dest(const char *pkg_name,
pkg_dest_t *dest);
-pkg_t *file_hash_get_file_owner(opkg_conf_t *conf, const char *file_name);
-void file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, pkg_t *pkg);
+pkg_t *file_hash_get_file_owner(const char *file_name);
+void file_hash_set_file_owner(const char *file_name, pkg_t *pkg);
#endif
#include "libbb/libbb.h"
static int
-is_field(char *type, const char *line)
+is_field(const char *type, const char *line)
{
if (!strncmp(line, type, strlen(type)))
return 1;
}
static char *
-parse_simple(char *type, const char *line)
+parse_simple(const char *type, const char *line)
{
return trim_xstrdup(line + strlen(type) + 1);
}
* Parse a comma separated string into an array.
*/
static char **
-parse_comma_separated(const char *raw, int *count)
+parse_comma_separated(const char *raw, unsigned int *count)
{
char **depends = NULL;
const char *start, *end;
if (sscanf(sstr, "Status: %63s %63s %63s",
sw_str, sf_str, ss_str) != 3) {
- fprintf(stderr, "%s: failed to parse Status line for %s\n",
- __FUNCTION__, pkg->name);
+ opkg_msg(ERROR, "Failed to parse Status line for %s\n",
+ pkg->name);
return;
}
char file_name[1024], md5sum[35];
if (sscanf(cstr, "%1023s %34s", file_name, md5sum) != 2) {
- fprintf(stderr, "%s: failed to parse Conffiles line for %s\n",
- __FUNCTION__, pkg->name);
+ opkg_msg(ERROR, "Failed to parse Conffiles line for %s\n",
+ pkg->name);
return;
}
errno = 0;
pkg->epoch = strtoul(vstr, NULL, 10);
if (errno) {
- fprintf(stderr, "%s: %s: invalid epoch: %s\n",
- __FUNCTION__, pkg->name, strerror(errno));
+ opkg_perror(ERROR, "%s: invalid epoch", pkg->name);
}
vstr = ++colon;
} else {
static int reading_conffiles = 0, reading_description = 0;
int ret = 0;
+ /* Exclude globally masked fields. */
+ mask |= conf->pfm;
+
+ /* Flip the semantics of the mask. */
+ mask ^= PFM_ALL;
+
switch (*line) {
case 'A':
if ((mask & PFM_ARCHITECTURE ) && is_field("Architecture", line))
break;
case 'I':
- if ((mask && PFM_INSTALLED_SIZE) && is_field("Installed-Size", line))
- pkg->installed_size = parse_simple("Installed-Size", line);
- else if ((mask && PFM_INSTALLED_TIME) && is_field("Installed-Time", line)) {
+ if ((mask && PFM_INSTALLED_SIZE) && is_field("Installed-Size", line)) {
+ char *tmp = parse_simple("Installed-Size", line);
+ pkg->installed_size = strtoul(tmp, NULL, 0);
+ free (tmp);
+ } else if ((mask && PFM_INSTALLED_TIME) && is_field("Installed-Time", line)) {
char *tmp = parse_simple("Installed-Time", line);
pkg->installed_time = strtoul(tmp, NULL, 0);
free (tmp);
else if ((mask & PFM_SHA256SUM) && is_field("SHA256sum", line))
pkg->sha256sum = parse_simple("SHA256sum", line);
#endif
- else if ((mask & PFM_SIZE) && is_field("Size", line))
- pkg->size = parse_simple("Size", line);
- else if ((mask & PFM_SOURCE) && is_field("Source", line))
+ else if ((mask & PFM_SIZE) && is_field("Size", line)) {
+ char *tmp = parse_simple("Size", line);
+ pkg->size = strtoul(tmp, NULL, 0);
+ free (tmp);
+ } else if ((mask & PFM_SOURCE) && is_field("Source", line))
pkg->source = parse_simple("Source", line);
else if ((mask & PFM_STATUS) && is_field("Status", line))
parse_status(pkg, line);
buf[0] = '\0';
while (1) {
- if (fgets(buf, buflen, fp) == NULL) {
+ if (fgets(buf, (int)buflen, fp) == NULL) {
if (ferror(fp)) {
- fprintf(stderr, "%s: fgets: %s\n",
- __FUNCTION__, strerror(errno));
+ opkg_perror(ERROR, "fgets");
ret = -1;
} else if (strlen(*buf0) == buf0len-1) {
- fprintf(stderr, "%s: missing new line character"
- " at end of file!\n",
- __FUNCTION__);
+ opkg_msg(ERROR, "Missing new line character"
+ " at end of file!\n");
pkg_parse_line(pkg, *buf0, mask);
}
break;
* missing a newline, but we won't know until
* fgets fails to read more data.
*/
- fprintf(stderr, "%s: missing new line character"
- " at end of file!\n",
- __FUNCTION__);
+ opkg_msg(ERROR, "Missing new line character"
+ " at end of file!\n");
pkg_parse_line(pkg, *buf0, mask);
break;
}
if (buf0len >= EXCESSIVE_LINE_LEN) {
- fprintf(stderr, "%s: excessively long line at "
+ opkg_msg(ERROR, "Excessively long line at "
"%d. Corrupt file?\n",
- __FUNCTION__, lineno);
+ lineno);
ret = -1;
break;
}
if (pkg->name == NULL) {
/* probably just a blank line */
- ret = EINVAL;
+ ret = 1;
}
return ret;
* so identical versions have identical version strings,
* implying identical packages; let's marry these
*/
-pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,opkg_conf_t *conf)
+void pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status)
{
int i;
int found = 0;
/* look for a duplicate pkg by name, version, and architecture */
for (i = 0; i < vec->len; i++){
- opkg_message(conf, OPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
- __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
- vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
+ opkg_msg(DEBUG2, "%s %s arch=%s vs. %s %s arch=%s.\n",
+ pkg->name, pkg->version, pkg->architecture,
+ vec->pkgs[i]->name, vec->pkgs[i]->version,
+ vec->pkgs[i]->architecture);
if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
&& (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
&& (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
found = 1;
- opkg_message(conf, OPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
- __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
+ opkg_msg(DEBUG2, "Duplicate for pkg=%s version=%s arch=%s.\n",
+ pkg->name, pkg->version, pkg->architecture);
break;
}
}
/* we didn't find one, add it */
if (!found){
- opkg_message(conf, OPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
- __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
+ opkg_msg(DEBUG2, "Adding new pkg=%s version=%s arch=%s.\n",
+ pkg->name, pkg->version, pkg->architecture);
pkg_vec_insert(vec, pkg);
- return pkg;
+ return;
}
+
/* update the one that we have */
- else {
- opkg_message(conf, OPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
- __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
- if (set_status) {
- /* this is from the status file, so need to merge with existing database */
- opkg_message(conf, OPKG_DEBUG2, " with set_status\n");
- pkg_merge(vec->pkgs[i], pkg, set_status);
- /* XXX: CLEANUP: It's not so polite to free something here
- that was passed in from above. */
- pkg_deinit(pkg);
- free(pkg);
- } else {
- opkg_message(conf, OPKG_DEBUG2, " WITHOUT set_status\n");
- /* just overwrite the old one */
- pkg_deinit(vec->pkgs[i]);
- free(vec->pkgs[i]);
- vec->pkgs[i] = pkg;
- }
- return vec->pkgs[i];
+ opkg_msg(DEBUG2, "Merging %s %s arch=%s, set_status=%d.\n",
+ pkg->name, pkg->version, pkg->architecture, set_status);
+ if (set_status) {
+ /* This is from the status file,
+ * so need to merge with existing database */
+ pkg_merge(pkg, vec->pkgs[i]);
}
+
+ /* overwrite the old one */
+ pkg_deinit(vec->pkgs[i]);
+ free(vec->pkgs[i]);
+ vec->pkgs[i] = pkg;
}
void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
struct pkg_vec
{
pkg_t **pkgs;
- int len;
+ unsigned int len;
};
struct abstract_pkg_vec
{
abstract_pkg_t **pkgs;
- int len;
+ unsigned int len;
};
pkg_vec_t * pkg_vec_alloc(void);
void pkg_vec_free(pkg_vec_t *vec);
-void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
-/* pkg_vec_insert_merge: might munge pkg.
-* returns the pkg that is in the pkg graph */
-pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, opkg_conf_t *conf);
-/* this one never munges pkg */
+void pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status);
void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
int sprintf_alloc(char **str, const char *fmt, ...)
{
va_list ap;
- int n, size = 100;
+ int n;
+ unsigned size = 100;
if (!str) {
- fprintf(stderr, "Null string pointer passed to sprintf_alloc\n");
+ opkg_msg(ERROR, "Internal error: str=NULL.\n");
return -1;
}
if (!fmt) {
- fprintf(stderr, "Null fmt string passed to sprintf_alloc\n");
+ opkg_msg(ERROR, "Internal error: fmt=NULL.\n");
return -1;
}
+++ /dev/null
-/* user.c - the opkg package management system
-
- Jamey Hicks
-
- Copyright (C) 2002 Hewlett Packard Company
- Copyright (C) 2001 University of Southern California
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-*/
-#include <stdio.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include "file_util.h"
-
-char *get_user_response(const char *format, ...)
-{
- int i;
- va_list ap;
- char *response;
-
- va_start(ap, format);
- vprintf(format, ap);
- va_end(ap);
-
- if (!isatty(fileno(stdin)))
- return NULL;
-
- response = (char *)file_read_line_alloc(stdin);
- if (response == NULL)
- return NULL;
-
- for (i=0; response[i]; i++)
- response[i] = tolower(response[i]);
-
- return response;
-}
+++ /dev/null
-/* user.c - the opkg package management system
-
- Jamey Hicks
-
- Copyright (C) 2002 Hewlett Packard Company
- Copyright (C) 2001 University of Southern California
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-*/
-
-#include <stdio.h>
-#include <stdarg.h>
-
-char *get_user_response(const char *format, ...);
-
elt->data = data;
}
-void_list_elt_t * void_list_elt_new (void *data) {
+static void_list_elt_t * void_list_elt_new (void *data) {
void_list_elt_t *elt;
/* freed in void_list_elt_deinit */
elt = xcalloc(1, sizeof(void_list_elt_t));
break;
}
if ( pos != old_elt) {
- fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
+ opkg_msg(ERROR, "Internal error: element not found in list.\n");
return NULL;
}
static void print_regcomp_err(const regex_t *preg, int err)
{
- int size;
+ unsigned int size;
char *error;
- fprintf(stderr, "%s: Error compiling regex:", __FUNCTION__);
size = regerror(err, preg, 0, 0);
error = xcalloc(1, size);
regerror(err, preg, error, size);
- fprintf(stderr, "%s\n", error);
+
+ opkg_msg(ERROR, "Internal error compiling regex: %s.", error);
+
free(error);
}
switch (pid) {
case -1:
- perror_msg("%s: %s: vfork", __FUNCTION__, argv[0]);
+ opkg_perror(ERROR, "%s: vfork", argv[0]);
return -1;
case 0:
/* child */
}
if (waitpid(pid, &status, 0) == -1) {
- perror_msg("%s: %s: waitpid", __FUNCTION__, argv[0]);
+ opkg_perror(ERROR, "%s: waitpid", argv[0]);
return -1;
}
if (WIFSIGNALED(status)) {
- error_msg("%s: %s: Child killed by signal %d\n",
- __FUNCTION__, argv[0], WTERMSIG(status));
+ opkg_msg(ERROR, "%s: Child killed by signal %d.\n",
+ argv[0], WTERMSIG(status));
return -1;
}
if (!WIFEXITED(status)) {
/* shouldn't happen */
- error_msg("%s: %s: Your system is broken: got status %d "
- "from waitpid\n", __FUNCTION__, argv[0], status);
+ opkg_msg(ERROR, "%s: Your system is broken: got status %d "
+ "from waitpid.\n", argv[0], status);
return -1;
}
#define TEST_PACKAGE "aspell"
void
-progress_callback (opkg_t *opkg, const opkg_progress_data_t *progress, void *data)
+progress_callback (const opkg_progress_data_t *progress, void *data)
{
printf ("\r%s %3d%%", (char*) data, progress->percentage);
fflush (stdout);
}
void
-package_list_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
+package_list_callback (opkg_package_t *pkg, void *data)
{
static install_count = 0;
static total_count = 0;
}
void
-package_list_upgradable_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
+package_list_upgradable_callback (opkg_package_t *pkg, void *data)
{
printf ("%s - %s\n", pkg->name, pkg->version);
opkg_package_free (pkg);
"Architecture: %s\n"
"Description: %s\n"
"Tags: %s\n"
- "URL: %s\n"
"Size: %d\n"
"Installed: %s\n",
pkg->name,
pkg->architecture,
pkg->description,
pkg->tags,
- pkg->url,
pkg->size,
(pkg->installed ? "True" : "False")
);
void
-opkg_test (opkg_t *opkg)
+opkg_test (void)
{
int err;
opkg_package_t *pkg;
- err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
+ err = opkg_update_package_lists (progress_callback, "Updating...");
printf ("\nopkg_update_package_lists returned %d (%s)\n", err, errors[err]);
- opkg_list_packages (opkg, package_list_callback, NULL);
+ opkg_list_packages (package_list_callback, NULL);
printf ("\n");
if (find_pkg)
{
printf ("Finding package \"%s\"\n", find_pkg->name);
- pkg = opkg_find_package (opkg, find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->repository);
+ pkg = opkg_find_package (find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->repository);
if (pkg)
{
print_package (pkg);
else
printf ("No package available to test find_package.\n");
- err = opkg_install_package (opkg, TEST_PACKAGE, progress_callback, "Installing...");
+ err = opkg_install_package (TEST_PACKAGE, progress_callback, "Installing...");
printf ("\nopkg_install_package returned %d (%s)\n", err, errors[err]);
- err = opkg_upgrade_package (opkg, TEST_PACKAGE, progress_callback, "Upgrading...");
+ err = opkg_upgrade_package (TEST_PACKAGE, progress_callback, "Upgrading...");
printf ("\nopkg_upgrade_package returned %d (%s)\n", err, errors[err]);
- err = opkg_remove_package (opkg, TEST_PACKAGE, progress_callback, "Removing...");
+ err = opkg_remove_package (TEST_PACKAGE, progress_callback, "Removing...");
printf ("\nopkg_remove_package returned %d (%s)\n", err, errors[err]);
printf ("Listing upgradable packages...\n");
- opkg_list_upgradable_packages (opkg, package_list_upgradable_callback, NULL);
+ opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);
- err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
+ err = opkg_upgrade_all (progress_callback, "Upgrading all...");
printf ("\nopkg_upgrade_all returned %d (%s)\n", err, errors[err]);
}
int
main (int argc, char **argv)
{
- opkg_t *opkg;
opkg_package_t *pkg;
int err;
exit (0);
}
- opkg = opkg_new ();
+ opkg_new ();
- opkg_set_option (opkg, "offline_root", "/tmp/");
+ opkg_set_option ("offline_root", "/tmp/");
- opkg_re_read_config_files (opkg);
+ opkg_re_read_config_files ();
switch (argv[1][0])
{
case 'f':
- pkg = opkg_find_package (opkg, argv[2], NULL, NULL, NULL);
+ pkg = opkg_find_package (argv[2], NULL, NULL, NULL);
if (pkg)
{
print_package (pkg);
opkg_package_free (pkg);
break;
case 'i':
- err = opkg_install_package (opkg, argv[1], progress_callback, "Installing...");
+ err = opkg_install_package (argv[1], progress_callback, "Installing...");
printf ("\nopkg_install_package returned %d (%s)\n", err, errors[err]);
break;
printf ("");
if (argv[1][3] == 'd')
{
- err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
+ err = opkg_update_package_lists (progress_callback, "Updating...");
printf ("\nopkg_update_package_lists returned %d (%s)\n", err, errors[err]);
break;
}
{
if (argc < 3)
{
- err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
+ err = opkg_upgrade_all (progress_callback, "Upgrading all...");
printf ("\nopkg_upgrade_all returned %d (%s)\n", err, errors[err]);
}
else
{
- err = opkg_upgrade_package (opkg, argv[2], progress_callback, "Upgrading...");
+ err = opkg_upgrade_package (argv[2], progress_callback, "Upgrading...");
printf ("\nopkg_upgrade_package returned %d (%s)\n", err, errors[err]);
}
}
{
case 'u':
printf ("Listing upgradable packages...\n");
- opkg_list_upgradable_packages (opkg, package_list_upgradable_callback, NULL);
+ opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);
break;
case 'a':
printf ("Listing all packages...\n");
- opkg_list_packages (opkg, package_list_callback, NULL);
+ opkg_list_packages (package_list_callback, NULL);
printf ("\n");
break;
case 'i':
case 'r':
if (argv[1][1] == 'e')
{
- err = opkg_remove_package (opkg, argv[2], progress_callback, "Removing...");
+ err = opkg_remove_package (argv[2], progress_callback, "Removing...");
printf ("\nopkg_remove_package returned %d (%s)\n", err, errors[err]);
break;
}else if (argv[1][1] == 'p')
{
- err = opkg_repository_accessibility_check(opkg);
+ err = opkg_repository_accessibility_check();
printf("\nopkg_repository_accessibility_check returned (%d)\n", err);
break;
}
}
- opkg_free (opkg);
+ opkg_free ();
return 0;
}