/** * backend_download_packages: */ static void backend_download_packages (PkBackend *backend, gchar **package_ids, const gchar *directory) { guint i; guint len; const gchar *package_id; const gchar *files; const char *error; slapt_pkg_list_t *installed; slapt_pkg_list_t *available; slapt_pkg_info_t *pkg; const char *summary; const char *note = NULL; char *filename; pk_backend_set_status (backend, PK_STATUS_ENUM_LOADING_CACHE); installed = slapt_get_installed_pkgs(); available = slapt_get_available_pkgs(); pk_backend_set_status (backend, PK_STATUS_ENUM_DOWNLOAD); pk_backend_set_percentage (backend, 0); len = g_strv_length (package_ids); for (i=0; i<len; i++) { package_id = package_ids[i]; pkg = _get_pkg_from_string(package_id, available, installed); if (pkg == NULL) { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found"); continue; } summary = _get_pkg_summary(pkg); pk_backend_package (backend, PK_INFO_ENUM_DOWNLOADING, package_id, summary); g_free((gpointer) summary); error = slapt_download_pkg(_config, pkg, note); if (error == NULL) { filename = slapt_gen_pkg_file_name(_config, pkg); files = g_strdup(filename); pk_backend_files (backend, package_id, files); g_free((gpointer) files); free(filename); } else { pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED, error); } } slapt_free_pkg_list(available); slapt_free_pkg_list(installed); pk_backend_set_percentage (backend, 100); pk_backend_finished (backend); }
END_TEST START_TEST (test_pkg_info) { size_t i = -1; char *string = NULL; slapt_rc_config *rc = slapt_read_rc_config("./data/rc1"); string = slapt_gen_short_pkg_description(&pkg); fail_if (string == NULL); fail_unless (strcmp(string,"gslapt (GTK slapt-get, an APT like system for Slackware)") == 0); free(string); string = NULL; string = slapt_gen_filename_from_url("http://software.jaos.org/slackpacks/11.0/","PACKAGES.TXT"); fail_if (string == NULL); fail_unless (strcmp(string,".http:##software.jaos.org#slackpacks#11.0#PACKAGES.TXT") == 0); free(string); string = NULL; string = slapt_gen_head_cache_filename(".http:##software.jaos.org#slackpacks#11.0#PACKAGES.TXT"); fail_if (string == NULL); fail_unless (strcmp(string,".http:##software.jaos.org#slackpacks#11.0#PACKAGES.TXT.head") == 0); free(string); string = NULL; string = slapt_gen_pkg_url(&pkg); fail_if (string == NULL); fail_unless (strcmp(string,"http://software.jaos.org/slackpacks/11.0/./gslapt-0.3.15-i386-1.tgz") == 0); free(string); string = NULL; slapt_add_list_item(rc->exclude_list,"^gslapt$"); fail_if (slapt_is_excluded(rc,&pkg) == 0); slapt_remove_list_item(rc->exclude_list,"^gslapt$"); fail_unless (slapt_download_pkg(rc, &pkg, NULL) == 0); fail_unless (slapt_verify_downloaded_pkg(rc,&pkg) == 0); i = slapt_get_pkg_file_size(rc, &pkg); fail_if (i < 1); string = strdup(pkg.description); slapt_clean_description(string, pkg.name); fail_unless (strcmp(string," gslapt (GTK slapt-get, an APT like system for Slackware)\n") == 0); free(string); string = NULL; /* retrieve the packages changelog entry, if any. Returns NULL otherwise */ /* char *slapt_get_pkg_changelog(const slapt_pkg_info_t *pkg); */ /* get the package filelist, returns (char *) on success or NULL on error */ /* char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg); */ fail_unless (pkg.priority == SLAPT_PRIORITY_DEFAULT); fail_unless (strcmp(slapt_priority_to_str(pkg.priority),gettext("Default")) == 0); slapt_free_rc_config(rc); }
END_TEST START_TEST (test_slapt_download_pkg) { const char *err = NULL; slapt_rc_config *rc = slapt_read_rc_config("./data/rc1"); rc->progress_cb = _progress_cb; /* silence */ slapt_working_dir_init(rc); err = slapt_download_pkg(rc, &pkg, NULL); fail_if (err); slapt_free_rc_config(rc); }
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; }