static int show_summary (slapt_src_slackbuild_list *sbs, slapt_list_t *names, int action, SLAPT_BOOL_T prompt) { int i, line_len = 0; printf (gettext ("The following packages will be %s:\n"), action == INSTALL_OPT ? gettext ("installed") : action == BUILD_OPT ? gettext ("built") : gettext ("fetched") ); for (i = 0; i < names->count; i++) { slapt_list_t *parts = slapt_parse_delimited_list (names->items[i], ':'); const char *name = parts->items[0]; int name_len = strlen (name); if (line_len == 0) { printf (" %s ", name); line_len += name_len + 1; } else if (line_len < 80 - name_len) { printf ("%s ", name); line_len += name_len + 1; } else { printf ("\n %s ", name); line_len = name_len + 2; } slapt_free_list (parts); } printf ("\n"); if (names->count < sbs->count) { line_len = 0; printf (gettext ("The following dependent slackbuilds will be built and installed:\n")); for (i = 0; i < sbs->count; i++) { const char *name = sbs->slackbuilds[i]->name; const char *version = sbs->slackbuilds[i]->version; char *namever = slapt_malloc (sizeof *namever * (strlen (name) + strlen (version) + 2)); sprintf (namever, "%s:%s", name, version); if (slapt_search_list (names, name) == NULL && slapt_search_list (names, namever) == NULL) { int name_len = strlen (name); if (line_len == 0) { printf (" %s ", name); line_len += name_len + 2; } else if (line_len < 80 - name_len) { printf ("%s ", name); line_len += name_len + 1; } else { printf ("\n %s ", name); line_len = name_len + 2; } } free (namever); } printf ("\n"); } if (prompt == SLAPT_TRUE) { if (slapt_ask_yes_no (gettext ("Do you want to continue? [y/N] ")) != 1) { printf (gettext ("Abort.\n")); return 0; } } return action; }
int slapt_handle_transaction (const slapt_rc_config *global_config, slapt_transaction_t *tran) { unsigned int i, pkg_dl_count = 0, dl_counter = 0; double download_size = 0; double already_download_size = 0; double uncompressed_size = 0; char dl_note[SLAPT_PKG_DL_NOTE_LEN]; /* show unmet dependencies */ if (tran->missing_err->err_count > 0) { fprintf(stderr,gettext("The following packages have unmet dependencies:\n")); for (i=0; i < tran->missing_err->err_count; ++i) { fprintf(stderr,gettext(" %s: Depends: %s\n"), tran->missing_err->errs[i]->pkg,tran->missing_err->errs[i]->error); } } /* show conflicts */ if (tran->conflict_err->err_count > 0) { for (i=0; i < tran->conflict_err->err_count; ++i) { fprintf(stderr,gettext("%s, which is required by %s, is excluded\n"), tran->conflict_err->errs[i]->error,tran->conflict_err->errs[i]->pkg); } } /* show pkgs to exclude */ if (tran->exclude_pkgs->pkg_count > 0) { unsigned int len = 0; printf(gettext("The following packages have been EXCLUDED:\n")); printf(" "); for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) { const slapt_pkg_info_t *e = tran->exclude_pkgs->pkgs[i]; if (len + strlen(e->name) + 1 < MAX_LINE_LEN) { printf("%s ",e->name); len += strlen(e->name) + 1; } else { printf("\n %s ",e->name); len = strlen(e->name) + 3; } } printf("\n"); } /* show suggested pkgs */ slapt_generate_suggestions(tran); if (tran->suggests->count > 0) { unsigned int len = 0; printf(gettext("Suggested packages:\n")); printf(" "); for (i = 0; i < tran->suggests->count; ++i) { char *s = tran->suggests->items[i]; /* don't show suggestion for something we already have in the transaction */ if (slapt_search_transaction(tran,s) == 1) continue; if (len + strlen(s) + 1 < MAX_LINE_LEN) { printf("%s ",s); len += strlen(s) + 1; } else { printf("\n %s ",s); len = strlen(s) + 3; } } printf("\n"); } /* show pkgs to install */ if (tran->install_pkgs->pkg_count > 0) { unsigned int len = 0; printf(gettext("The following NEW packages will be installed:\n")); printf(" "); for (i = 0; i < tran->install_pkgs->pkg_count; ++i) { slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i]; size_t existing_file_size = 0; if (len + strlen(p->name) + 1 < MAX_LINE_LEN) { printf("%s ",p->name); len += strlen(p->name) + 1; } else { printf("\n %s ",p->name); len = strlen(p->name) + 3; } existing_file_size = slapt_get_pkg_file_size(global_config,p) / 1024; download_size += p->size_c; if (existing_file_size <= p->size_c) already_download_size += existing_file_size; uncompressed_size += p->size_u; } printf("\n"); } /* show pkgs to remove */ if (tran->remove_pkgs->pkg_count > 0) { unsigned int len = 0; printf(gettext("The following packages will be REMOVED:\n")); printf(" "); for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) { const slapt_pkg_info_t *r = tran->remove_pkgs->pkgs[i]; if (len + strlen(r->name) + 1 < MAX_LINE_LEN) { printf("%s ",r->name); len += strlen(r->name) + 1; } else { printf("\n %s ",r->name); len = strlen(r->name) + 3; } uncompressed_size -= r->size_u; } printf("\n"); } /* show pkgs to upgrade */ if (tran->upgrade_pkgs->pkg_count > 0) { unsigned int len = 0; if ((tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count) > 0) { printf(gettext("The following packages will be upgraded:\n")); printf(" "); } for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) { slapt_pkg_info_t *u = tran->upgrade_pkgs->pkgs[i]->upgrade; slapt_pkg_info_t *p = tran->upgrade_pkgs->pkgs[i]->installed; size_t existing_file_size = 0; int line_len = len + strlen(u->name) + 1; existing_file_size = slapt_get_pkg_file_size( global_config,u) / 1024; download_size += u->size_c; if (existing_file_size <= u->size_c) already_download_size += existing_file_size; uncompressed_size += u->size_u; uncompressed_size -= p->size_u; if (tran->upgrade_pkgs->pkgs[i]->reinstall == SLAPT_TRUE) continue; if (line_len < MAX_LINE_LEN) { printf("%s ",u->name); len += strlen(u->name) + 1; } else { printf("\n %s ",u->name); len = strlen(u->name) + 3; } } if ((tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count) > 0) printf("\n"); if (tran->upgrade_pkgs->reinstall_count > 0) { unsigned int len = 0; printf(gettext("The following packages will be reinstalled:\n")); printf(" "); for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) { slapt_pkg_info_t *u = tran->upgrade_pkgs->pkgs[i]->upgrade; int line_len = len + strlen(u->name) + 1; if (tran->upgrade_pkgs->pkgs[i]->reinstall == SLAPT_FALSE) continue; if (line_len < MAX_LINE_LEN) { printf("%s ",u->name); len += strlen(u->name) + 1; } else { printf("\n %s ",u->name); len = strlen(u->name) + 3; } } printf("\n"); } } /* print the summary */ printf(ngettext("%d upgraded, ", "%d upgraded, ", tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count), tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count); printf(ngettext("%d reinstalled, ", "%d reinstalled, ", tran->upgrade_pkgs->reinstall_count), tran->upgrade_pkgs->reinstall_count); printf(ngettext("%d newly installed, ", "%d newly installed, ", tran->install_pkgs->pkg_count), tran->install_pkgs->pkg_count); printf(ngettext("%d to remove, ", "%d to remove, ", tran->remove_pkgs->pkg_count), tran->remove_pkgs->pkg_count); printf(ngettext("%d not upgraded.\n", "%d not upgraded.\n", tran->exclude_pkgs->pkg_count), tran->exclude_pkgs->pkg_count); /* only show this if we are going to do download something */ if (tran->upgrade_pkgs->pkg_count > 0 || tran->install_pkgs->pkg_count > 0) { /* how much we need to download */ double need_to_download_size = download_size - already_download_size; /* make sure it's not negative due to changing pkg sizes on upgrades */ if (need_to_download_size < 0) need_to_download_size = 0; if (already_download_size > 0) { printf(gettext("Need to get %.1f%s/%.1f%s of archives.\n"), (need_to_download_size > 1024) ? need_to_download_size / (double)1024 : need_to_download_size, (need_to_download_size > 1024) ? "MB" : "kB", (download_size > 1024) ? download_size / (double)1024 : download_size, (download_size > 1024) ? "MB" : "kB" ); } else { printf(gettext("Need to get %.1f%s of archives.\n"), (download_size > 1024) ? download_size / (double)1024 : download_size, (download_size > 1024) ? "MB" : "kB" ); } /* check we have enough space to download to our working dir */ if (slapt_disk_space_check (global_config->working_dir,need_to_download_size) == SLAPT_FALSE) { printf( gettext("You don't have enough free space in %s\n"), global_config->working_dir ); exit(EXIT_FAILURE); } /* check that we have enough space in the root filesystem */ if (global_config->download_only == SLAPT_FALSE) { if (slapt_disk_space_check ("/", uncompressed_size) == SLAPT_FALSE) { printf(gettext("You don't have enough free space in %s\n"),"/"); exit(EXIT_FAILURE); } } } if (tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 || tran->install_pkgs->pkg_count > 0) { if (global_config->download_only == SLAPT_FALSE) { if ((int)uncompressed_size < 0) { uncompressed_size *= -1; printf(gettext("After unpacking %.1f%s disk space will be freed.\n"), (uncompressed_size > 1024) ? uncompressed_size / (double)1024 : uncompressed_size, (uncompressed_size > 1024) ? "MB" : "kB" ); } else { printf( gettext("After unpacking %.1f%s of additional disk space will be used.\n"), (uncompressed_size > 1024) ? uncompressed_size / (double)1024 : uncompressed_size, (uncompressed_size > 1024) ? "MB" : "kB" ); } } } /* prompt */ if ((global_config->prompt == SLAPT_TRUE) || ((tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 || (tran->install_pkgs->pkg_count > 0 && global_config->dist_upgrade == SLAPT_TRUE)) && (global_config->no_prompt == SLAPT_FALSE && global_config->download_only == SLAPT_FALSE && global_config->simulate == SLAPT_FALSE && global_config->print_uris == SLAPT_FALSE)) ) { if (slapt_ask_yes_no(gettext("Do you want to continue? [y/N] ")) != 1) { printf(gettext("Abort.\n")); return 1; } } if (global_config->print_uris == SLAPT_TRUE) { for (i = 0; i < tran->install_pkgs->pkg_count; ++i) { const slapt_pkg_info_t *info = tran->install_pkgs->pkgs[i]; const char *location = info->location + strspn(info->location, "./"); printf("%s%s/%s-%s%s\n", info->mirror, location, info->name, info->version, info->file_ext); } for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) { const slapt_pkg_info_t *info = tran->upgrade_pkgs->pkgs[i]->upgrade; const char *location = info->location + strspn(info->location, "./"); printf("%s%s/%s-%s%s\n", info->mirror, location, info->name, info->version, info->file_ext); } return 0; } /* if simulate is requested, just show what could happen and return */ if (global_config->simulate == SLAPT_TRUE) { for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) { const slapt_pkg_info_t *r = tran->remove_pkgs->pkgs[i]; printf(gettext("%s-%s is to be removed\n"), r->name, r->version); } for (i = 0;i < tran->queue->count; ++i) { if (tran->queue->pkgs[i]->type == INSTALL) { printf(gettext("%s-%s is to be installed\n"), tran->queue->pkgs[i]->pkg.i->name, tran->queue->pkgs[i]->pkg.i->version ); } else if (tran->queue->pkgs[i]->type == UPGRADE) { printf(gettext("%s-%s is to be upgraded to version %s\n"), tran->queue->pkgs[i]->pkg.u->upgrade->name, tran->queue->pkgs[i]->pkg.u->installed->version, tran->queue->pkgs[i]->pkg.u->upgrade->version ); } } printf(gettext("Done\n")); return 0; } pkg_dl_count = tran->install_pkgs->pkg_count + tran->upgrade_pkgs->pkg_count; /* download pkgs */ for (i = 0; i < tran->install_pkgs->pkg_count; ++i) { unsigned int retry_count, failed = 1; ++dl_counter; snprintf(dl_note, SLAPT_PKG_DL_NOTE_LEN, "%d/%d", dl_counter, pkg_dl_count); for (retry_count = 0; retry_count < global_config->retry; ++retry_count) { const char *err = slapt_download_pkg(global_config,tran->install_pkgs->pkgs[i], dl_note); if (err) { fprintf(stderr,gettext("Failed to download: %s\n"),err); failed = 1; } else { failed = 0; break; } } if (failed == 1) exit(EXIT_FAILURE); } for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) { unsigned int retry_count, failed = 1; ++dl_counter; snprintf(dl_note, SLAPT_PKG_DL_NOTE_LEN, "%d/%d", dl_counter, pkg_dl_count); for (retry_count = 0; retry_count < global_config->retry; ++retry_count) { const char *err = slapt_download_pkg(global_config,tran->upgrade_pkgs->pkgs[i]->upgrade, dl_note); if (err) { fprintf(stderr,gettext("Failed to download: %s\n"),err); failed = 1; } else { failed = 0; break; } } if (failed == 1) exit(EXIT_FAILURE); } printf("\n"); /* run transaction, remove, install, and upgrade */ if (global_config->download_only == SLAPT_FALSE) { for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) { if (slapt_remove_pkg(global_config,tran->remove_pkgs->pkgs[i]) == -1) { exit(EXIT_FAILURE); } } for (i = 0;i < tran->queue->count; ++i) { if (tran->queue->pkgs[i]->type == INSTALL) { printf(gettext("Preparing to install %s-%s\n"), tran->queue->pkgs[i]->pkg.i->name, tran->queue->pkgs[i]->pkg.i->version); if (slapt_install_pkg(global_config, tran->queue->pkgs[i]->pkg.i) == -1) { exit(EXIT_FAILURE); } } else if (tran->queue->pkgs[i]->type == UPGRADE) { printf(gettext("Preparing to replace %s-%s with %s-%s\n"), tran->queue->pkgs[i]->pkg.u->upgrade->name, tran->queue->pkgs[i]->pkg.u->installed->version, tran->queue->pkgs[i]->pkg.u->upgrade->name, tran->queue->pkgs[i]->pkg.u->upgrade->version); if (slapt_upgrade_pkg(global_config, tran->queue->pkgs[i]->pkg.u->upgrade) == -1) { exit(EXIT_FAILURE); } } } } printf(gettext("Done\n")); return 0; }