X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fpkg.c;h=265f5541f37c8f98904e2b58f50a3cbea768330c;hp=467dcef908f53a030f8c46075ce2e64cac3f3442;hb=970666583189a1f2712c1baa0b8b6a40a9b71b75;hpb=e0108bbf815b1806c96e3cbdc2a2dc162f7c1fe1 diff --git a/libopkg/pkg.c b/libopkg/pkg.c index 467dcef..265f554 100644 --- a/libopkg/pkg.c +++ b/libopkg/pkg.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "pkg.h" @@ -95,7 +96,7 @@ pkg_init(pkg_t *pkg) pkg->recommends_str = NULL; pkg->suggests_count = 0; pkg->recommends_count = 0; - + active_list_init(&pkg->list); pkg->conflicts = NULL; @@ -103,7 +104,7 @@ pkg_init(pkg_t *pkg) pkg->replaces = NULL; pkg->replaces_count = 0; - + pkg->pre_depends_count = 0; pkg->pre_depends_str = NULL; pkg->provides_count = 0; @@ -188,7 +189,7 @@ pkg_deinit(pkg_t *pkg) if (pkg->description) free(pkg->description); pkg->description = NULL; - + pkg->state_want = SW_UNKNOWN; pkg->state_flag = SF_OK; pkg->state_status = SS_NOT_INSTALLED; @@ -221,11 +222,11 @@ pkg_deinit(pkg_t *pkg) pkg->pre_depends_count = 0; pkg->provides_count = 0; - + if (pkg->filename) free(pkg->filename); pkg->filename = NULL; - + if (pkg->local_filename) free(pkg->local_filename); pkg->local_filename = NULL; @@ -281,7 +282,7 @@ pkg_init_from_file(pkg_t *pkg, const char *filename) pkg->local_filename = xstrdup(filename); tmp = xstrdup(filename); - sprintf_alloc(&control_path, "%s/%s.control.XXXXXX", + sprintf_alloc(&control_path, "%s/%s.control.XXXXXX", conf->tmp_dir, basename(tmp)); free(tmp); @@ -461,7 +462,7 @@ set_flags_from_control(pkg_t *pkg){ fp = fopen(file_name, "r"); if (fp == NULL) { - opkg_perror(ERROR, "Failed to open %s"); + opkg_perror(ERROR, "Failed to open %s", file_name); free(file_name); return; } @@ -641,8 +642,8 @@ pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field) fprintf(fp, "Conffiles:\n"); for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) { if (((conffile_t *)iter->data)->name && ((conffile_t *)iter->data)->value) { - fprintf(fp, " %s %s\n", - ((conffile_t *)iter->data)->name, + fprintf(fp, " %s %s\n", + ((conffile_t *)iter->data)->name, ((conffile_t *)iter->data)->value); } } @@ -713,7 +714,7 @@ pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field) case 'M': if (strcasecmp(field, "Maintainer") == 0) { if (pkg->maintainer) { - fprintf(fp, "maintainer: %s\n", pkg->maintainer); + fprintf(fp, "Maintainer: %s\n", pkg->maintainer); } } else if (strcasecmp(field, "MD5sum") == 0) { if (pkg->md5sum) { @@ -1004,7 +1005,7 @@ pkg_name_version_and_architecture_compare(const void *p1, const void *p2) a->name, b->name); return 0; } - + namecmp = strcmp(a->name, b->name); if (namecmp) return namecmp; @@ -1072,6 +1073,7 @@ pkg_get_installed_files(pkg_t *pkg) char *line; char *installed_file_name; unsigned int rootdirlen = 0; + int list_from_package; pkg->installed_files_ref_cnt++; @@ -1081,17 +1083,23 @@ pkg_get_installed_files(pkg_t *pkg) pkg->installed_files = str_list_alloc(); - /* For uninstalled packages, get the file list directly from the package. - For installed packages, look at the package.list file in the database. - */ - if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) { + /* + * For installed packages, look at the package.list file in the database. + * For uninstalled packages, get the file list directly from the package. + */ + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) + list_from_package = 1; + else + list_from_package = 0; + + if (list_from_package) { if (pkg->local_filename == NULL) { return pkg->installed_files; } /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary file. In other words, change deb_extract so that it can simply return the file list as a char *[] rather than - insisting on writing in to a FILE * as it does now. */ + insisting on writing it to a FILE * as it does now. */ sprintf_alloc(&list_file_name, "%s/%s.list.XXXXXX", conf->tmp_dir, pkg->name); fd = mkstemp(list_file_name); @@ -1140,14 +1148,14 @@ pkg_get_installed_files(pkg_t *pkg) while (1) { char *file_name; - + line = file_read_line_alloc(list_file); if (line == NULL) { break; } file_name = line; - if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) { + if (list_from_package) { if (*file_name == '.') { file_name++; } @@ -1173,7 +1181,7 @@ pkg_get_installed_files(pkg_t *pkg) fclose(list_file); - if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) { + if (list_from_package) { unlink(list_file_name); free(list_file_name); } @@ -1248,7 +1256,7 @@ pkg_run_script(pkg_t *pkg, const char *script, const char *args) /* XXX: FEATURE: When conf->offline_root is set, we should run the maintainer script within a chroot environment. */ - if (conf->offline_root) { + if (conf->offline_root && !conf->force_postinstall) { opkg_msg(INFO, "Offline root mode: not running %s.%s.\n", pkg->name, script); return 0; @@ -1291,7 +1299,8 @@ pkg_run_script(pkg_t *pkg, const char *script, const char *args) free(cmd); if (err) { - opkg_msg(ERROR, "%s script returned status %d.\n", script, err); + opkg_msg(ERROR, "package \"%s\" %s script returned status %d.\n", + pkg->name, script, err); return err; } @@ -1338,8 +1347,8 @@ pkg_info_preinstall_check(void) "files for pkg %s.\n", pkg->name); break; } - for (iter = str_list_first(installed_files), niter = str_list_next(installed_files, iter); - iter; + for (iter = str_list_first(installed_files), niter = str_list_next(installed_files, iter); + iter; iter = niter, niter = str_list_next(installed_files, iter)) { char *installed_file = (char *) iter->data; file_hash_set_file_owner(installed_file, pkg);