summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2018-06-21 21:35:50 -0400
committerJason Woodward2018-06-21 21:48:14 -0400
commit9bb9cbc678a215be7345a1ccaed204f0f4c65493 (patch)
treee38cb40de4365fb21a5ec6e63f859db76af0b5d0
parent9004601351c8c4a9684ee341d4391e3a94b77eaf (diff)
downloadslapt-get-9bb9cbc678a215be7345a1ccaed204f0f4c65493.tar.gz
clang-format fixups
clang-format config: Language: Cpp BasedOnStyle: llvm IndentWidth: 4 AllowShortFunctionsOnASingleLine: None KeepEmptyLinesAtTheStartOfBlocks: false ColumnLimit: 0 UseTab: Never TabWidth: 4 BreakBeforeBraces: Linux PointerBindsToType: false SortIncludes: false
-rw-r--r--src/action.c1336
-rw-r--r--src/action.h3
-rw-r--r--src/common.c657
-rw-r--r--src/common.h75
-rw-r--r--src/configuration.c652
-rw-r--r--src/configuration.h54
-rw-r--r--src/curl.c707
-rw-r--r--src/curl.h14
-rw-r--r--src/gpgme.c509
-rw-r--r--src/gpgme.h9
-rw-r--r--src/main.c806
-rw-r--r--src/main.h34
-rw-r--r--src/package.c5227
-rw-r--r--src/package.h129
-rw-r--r--src/transaction.c1458
-rw-r--r--src/transaction.h35
-rw-r--r--t/common.h2
-rw-r--r--t/test.c85
-rw-r--r--t/test_common.c100
-rw-r--r--t/test_configuration.c143
-rw-r--r--t/test_curl.c155
-rw-r--r--t/test_packages.c640
-rw-r--r--t/test_transaction.c85
23 files changed, 6267 insertions, 6648 deletions
diff --git a/src/action.c b/src/action.c
index 27025f3..b094e4e 100644
--- a/src/action.c
+++ b/src/action.c
@@ -18,865 +18,809 @@
#include "main.h"
-static int cmp_pkg_arch(const char *a,const char *b);
+static int cmp_pkg_arch(const char *a, const char *b);
/* install pkg */
void slapt_pkg_action_install(const slapt_rc_config *global_config,
const slapt_list_t *action_args)
{
- unsigned int i;
- slapt_transaction_t *tran = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *avail_pkgs = NULL;
- slapt_regex_t *pkg_regex = NULL;
+ unsigned int i;
+ slapt_transaction_t *tran = NULL;
+ slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_pkg_list_t *avail_pkgs = NULL;
+ slapt_regex_t *pkg_regex = NULL;
- printf( gettext("Reading Package Lists...") );
- installed_pkgs = slapt_get_installed_pkgs();
- avail_pkgs = slapt_get_available_pkgs();
+ printf(gettext("Reading Package Lists..."));
+ installed_pkgs = slapt_get_installed_pkgs();
+ avail_pkgs = slapt_get_available_pkgs();
- if ( avail_pkgs == NULL || avail_pkgs->pkg_count == 0 )
- exit(EXIT_FAILURE);
-
- printf( gettext("Done\n") );
-
- tran = slapt_init_transaction();
-
- if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
-
- for (i = 0; i < action_args->count; ++i) {
- char *arg = action_args->items[i];
- slapt_pkg_info_t *pkg = NULL;
- slapt_pkg_info_t *installed_pkg = NULL;
+ if (avail_pkgs == NULL || avail_pkgs->pkg_count == 0)
+ exit(EXIT_FAILURE);
- /* Use regex to see if they specified a particular version */
- slapt_execute_regex(pkg_regex,arg);
+ printf(gettext("Done\n"));
- /* If so, parse it out and try to get that version only */
- if ( pkg_regex->reg_return == 0 ) {
- char *pkg_name,*pkg_version;
+ tran = slapt_init_transaction();
- pkg_name = slapt_regex_extract_match(pkg_regex, arg, 1);
- pkg_version = slapt_regex_extract_match(pkg_regex, arg, 2);
- pkg = slapt_get_exact_pkg(avail_pkgs, pkg_name, pkg_version);
+ if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- free(pkg_name);
- free(pkg_version);
+ for (i = 0; i < action_args->count; ++i) {
+ char *arg = action_args->items[i];
+ slapt_pkg_info_t *pkg = NULL;
+ slapt_pkg_info_t *installed_pkg = NULL;
- }
+ /* Use regex to see if they specified a particular version */
+ slapt_execute_regex(pkg_regex, arg);
- /* If regex doesnt match */
- if ( pkg_regex->reg_return != 0 || pkg == NULL ) {
- /* make sure there is a package called arg */
- pkg = slapt_get_newest_pkg(avail_pkgs,arg);
+ /* If so, parse it out and try to get that version only */
+ if (pkg_regex->reg_return == 0) {
+ char *pkg_name, *pkg_version;
- if ( pkg == NULL ) {
- fprintf(stderr,gettext("No such package: %s\n"),arg);
- exit(EXIT_FAILURE);
- }
+ pkg_name = slapt_regex_extract_match(pkg_regex, arg, 1);
+ pkg_version = slapt_regex_extract_match(pkg_regex, arg, 2);
+ pkg = slapt_get_exact_pkg(avail_pkgs, pkg_name, pkg_version);
- }
+ free(pkg_name);
+ free(pkg_version);
+ }
- installed_pkg = slapt_get_newest_pkg(installed_pkgs,pkg->name);
+ /* If regex doesnt match */
+ if (pkg_regex->reg_return != 0 || pkg == NULL) {
+ /* make sure there is a package called arg */
+ pkg = slapt_get_newest_pkg(avail_pkgs, arg);
- /* if it is not already installed, install it */
- if ( installed_pkg == NULL || global_config->no_upgrade == true) {
+ if (pkg == NULL) {
+ fprintf(stderr, gettext("No such package: %s\n"), arg);
+ exit(EXIT_FAILURE);
+ }
+ }
- if ( slapt_add_deps_to_trans(global_config,tran,avail_pkgs,
- installed_pkgs,pkg) == 0 ) {
+ installed_pkg = slapt_get_newest_pkg(installed_pkgs, pkg->name);
- slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran,avail_pkgs, installed_pkgs, pkg);
+ /* if it is not already installed, install it */
+ if (installed_pkg == NULL || global_config->no_upgrade == true) {
+ if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
+ installed_pkgs, pkg) == 0) {
+ slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, pkg);
- /* this comes first so we can pick up that we are installed the package when
+ /* this comes first so we can pick up that we are installed the package when
* checking conflicts */
- slapt_add_install_to_transaction(tran,pkg);
-
- /* if there are conflicts, we schedule the conflicts for removal */
- if (conflicts->pkg_count > 0 && global_config->ignore_dep != true) {
- unsigned int cindex = 0;
- for (cindex = 0; cindex < conflicts->pkg_count;cindex++) {
- /* make sure to remove the conflict's dependencies as well */
- unsigned int cdindex = 0;
- slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
- avail_pkgs, installed_pkgs,
- tran->install_pkgs, tran->remove_pkgs,
- conflicts->pkgs[cindex]);
- for (cdindex = 0; cdindex < conflict_deps->pkg_count; ++cdindex) {
- slapt_pkg_info_t *dep = conflict_deps->pkgs[cdindex];
- if ( slapt_get_exact_pkg(installed_pkgs,dep->name, dep->version) != NULL) {
- slapt_add_remove_to_transaction(tran,dep);
- }
- }
- slapt_free_pkg_list(conflict_deps);
-
- slapt_add_remove_to_transaction(tran,conflicts->pkgs[cindex]);
- }
- }
- slapt_free_pkg_list(conflicts);
-
- } else {
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- pkg->name);
- slapt_add_exclude_to_transaction(tran,pkg);
- }
-
- } else { /* else we upgrade or reinstall */
-
- /* it is already installed, attempt an upgrade */
- if (
- ((slapt_cmp_pkgs(installed_pkg,pkg)) < 0) ||
- (global_config->re_install == true)
- ) {
-
- if ( slapt_add_deps_to_trans(global_config,tran,avail_pkgs,
- installed_pkgs,pkg) == 0 ) {
-
- slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran,avail_pkgs,
- installed_pkgs, pkg);
- if (conflicts->pkg_count > 0 && global_config->ignore_dep != true) {
- unsigned int cindex = 0;
- for (cindex = 0;cindex < conflicts->pkg_count;cindex++) {
- /* make sure to remove the conflict's dependencies as well */
- unsigned int cdindex = 0;
- slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
- avail_pkgs, installed_pkgs,
- tran->install_pkgs, tran->remove_pkgs,
- conflicts->pkgs[cindex]);
- for (cdindex = 0; cdindex < conflict_deps->pkg_count; ++cdindex) {
- slapt_pkg_info_t *dep = conflict_deps->pkgs[cdindex];
- if ( slapt_get_exact_pkg(installed_pkgs,dep->name, dep->version) != NULL) {
- slapt_add_remove_to_transaction(tran,dep);
+ slapt_add_install_to_transaction(tran, pkg);
+
+ /* if there are conflicts, we schedule the conflicts for removal */
+ if (conflicts->pkg_count > 0 && global_config->ignore_dep != true) {
+ unsigned int cindex = 0;
+ for (cindex = 0; cindex < conflicts->pkg_count; cindex++) {
+ /* make sure to remove the conflict's dependencies as well */
+ unsigned int cdindex = 0;
+ slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
+ avail_pkgs, installed_pkgs,
+ tran->install_pkgs, tran->remove_pkgs,
+ conflicts->pkgs[cindex]);
+ for (cdindex = 0; cdindex < conflict_deps->pkg_count; ++cdindex) {
+ slapt_pkg_info_t *dep = conflict_deps->pkgs[cdindex];
+ if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
+ slapt_add_remove_to_transaction(tran, dep);
+ }
+ }
+ slapt_free_pkg_list(conflict_deps);
+
+ slapt_add_remove_to_transaction(tran, conflicts->pkgs[cindex]);
+ }
}
- }
- slapt_free_pkg_list(conflict_deps);
+ slapt_free_pkg_list(conflicts);
- slapt_add_remove_to_transaction(tran,conflicts->pkgs[cindex]);
+ } else {
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"),
+ pkg->name);
+ slapt_add_exclude_to_transaction(tran, pkg);
}
- }
-
- if (slapt_cmp_pkgs(installed_pkg,pkg) == 0)
- slapt_add_reinstall_to_transaction(tran,installed_pkg,pkg);
- else
- slapt_add_upgrade_to_transaction(tran,installed_pkg,pkg);
- slapt_free_pkg_list(conflicts);
+ } else { /* else we upgrade or reinstall */
+
+ /* it is already installed, attempt an upgrade */
+ if (
+ ((slapt_cmp_pkgs(installed_pkg, pkg)) < 0) ||
+ (global_config->re_install == true)) {
+ if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
+ installed_pkgs, pkg) == 0) {
+ slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs,
+ installed_pkgs, pkg);
+ if (conflicts->pkg_count > 0 && global_config->ignore_dep != true) {
+ unsigned int cindex = 0;
+ for (cindex = 0; cindex < conflicts->pkg_count; cindex++) {
+ /* make sure to remove the conflict's dependencies as well */
+ unsigned int cdindex = 0;
+ slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
+ avail_pkgs, installed_pkgs,
+ tran->install_pkgs, tran->remove_pkgs,
+ conflicts->pkgs[cindex]);
+ for (cdindex = 0; cdindex < conflict_deps->pkg_count; ++cdindex) {
+ slapt_pkg_info_t *dep = conflict_deps->pkgs[cdindex];
+ if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
+ slapt_add_remove_to_transaction(tran, dep);
+ }
+ }
+ slapt_free_pkg_list(conflict_deps);
+
+ slapt_add_remove_to_transaction(tran, conflicts->pkgs[cindex]);
+ }
+ }
+
+ if (slapt_cmp_pkgs(installed_pkg, pkg) == 0)
+ slapt_add_reinstall_to_transaction(tran, installed_pkg, pkg);
+ else
+ slapt_add_upgrade_to_transaction(tran, installed_pkg, pkg);
+
+ slapt_free_pkg_list(conflicts);
+
+ } else {
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"),
+ pkg->name);
+ slapt_add_exclude_to_transaction(tran, pkg);
+ }
- } else {
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- pkg->name);
- slapt_add_exclude_to_transaction(tran,pkg);
+ } else {
+ printf(gettext("%s is up to date.\n"), installed_pkg->name);
+ }
}
-
- } else {
- printf(gettext("%s is up to date.\n"),installed_pkg->name);
- }
-
}
- }
+ slapt_free_pkg_list(installed_pkgs);
+ slapt_free_pkg_list(avail_pkgs);
- slapt_free_pkg_list(installed_pkgs);
- slapt_free_pkg_list(avail_pkgs);
+ slapt_free_regex(pkg_regex);
- slapt_free_regex(pkg_regex);
-
- if (slapt_handle_transaction(global_config,tran) != 0) {
- exit(EXIT_FAILURE);
- }
+ if (slapt_handle_transaction(global_config, tran) != 0) {
+ exit(EXIT_FAILURE);
+ }
- slapt_free_transaction(tran);
- return;
+ slapt_free_transaction(tran);
+ return;
}
/* list pkgs */
void slapt_pkg_action_list(const int show)
{
- slapt_pkg_list_t *pkgs = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
- unsigned int i;
-
- pkgs = slapt_get_available_pkgs();
- installed_pkgs = slapt_get_installed_pkgs();
-
- if ( show == LIST || show == AVAILABLE ) {
- for (i = 0; i < pkgs->pkg_count; ++i ) {
- unsigned int bool_installed = 0;
- char *short_description = slapt_gen_short_pkg_description(pkgs->pkgs[i]);
-
- /* is it installed? */
- if (slapt_get_exact_pkg(installed_pkgs,pkgs->pkgs[i]->name,
- pkgs->pkgs[i]->version) != NULL )
- bool_installed = 1;
-
- printf("%s-%s [inst=%s]: %s\n",
- pkgs->pkgs[i]->name,
- pkgs->pkgs[i]->version,
- bool_installed == 1
- ? gettext("yes")
- : gettext("no"),
- (short_description == NULL) ? "" : short_description
- );
- free(short_description);
- }
- }
- if ( show == LIST || show == INSTALLED ) {
- for (i = 0; i < installed_pkgs->pkg_count;++i) {
- char *short_description = NULL;
-
- if ( show == LIST ) {
-
- if ( slapt_get_exact_pkg(pkgs,
- installed_pkgs->pkgs[i]->name,
- installed_pkgs->pkgs[i]->version
- ) != NULL
- ) {
- continue;
+ slapt_pkg_list_t *pkgs = NULL;
+ slapt_pkg_list_t *installed_pkgs = NULL;
+ unsigned int i;
+
+ pkgs = slapt_get_available_pkgs();
+ installed_pkgs = slapt_get_installed_pkgs();
+
+ if (show == LIST || show == AVAILABLE) {
+ for (i = 0; i < pkgs->pkg_count; ++i) {
+ unsigned int bool_installed = 0;
+ char *short_description = slapt_gen_short_pkg_description(pkgs->pkgs[i]);
+
+ /* is it installed? */
+ if (slapt_get_exact_pkg(installed_pkgs, pkgs->pkgs[i]->name,
+ pkgs->pkgs[i]->version) != NULL)
+ bool_installed = 1;
+
+ printf("%s-%s [inst=%s]: %s\n",
+ pkgs->pkgs[i]->name,
+ pkgs->pkgs[i]->version,
+ bool_installed == 1
+ ? gettext("yes")
+ : gettext("no"),
+ (short_description == NULL) ? "" : short_description);
+ free(short_description);
}
+ }
+ if (show == LIST || show == INSTALLED) {
+ for (i = 0; i < installed_pkgs->pkg_count; ++i) {
+ char *short_description = NULL;
+
+ if (show == LIST) {
+ if (slapt_get_exact_pkg(pkgs,
+ installed_pkgs->pkgs[i]->name,
+ installed_pkgs->pkgs[i]->version) != NULL) {
+ continue;
+ }
+ }
- }
-
- short_description =
- slapt_gen_short_pkg_description(installed_pkgs->pkgs[i]);
-
- printf("%s-%s [inst=%s]: %s\n",
- installed_pkgs->pkgs[i]->name,
- installed_pkgs->pkgs[i]->version,
- gettext("yes"),
- (short_description == NULL) ? "" : short_description
- );
- free(short_description);
+ short_description =
+ slapt_gen_short_pkg_description(installed_pkgs->pkgs[i]);
+ printf("%s-%s [inst=%s]: %s\n",
+ installed_pkgs->pkgs[i]->name,
+ installed_pkgs->pkgs[i]->version,
+ gettext("yes"),
+ (short_description == NULL) ? "" : short_description);
+ free(short_description);
+ }
}
- }
-
- slapt_free_pkg_list(pkgs);
- slapt_free_pkg_list(installed_pkgs);
+ slapt_free_pkg_list(pkgs);
+ slapt_free_pkg_list(installed_pkgs);
}
/* remove/uninstall pkg */
void slapt_pkg_action_remove(const slapt_rc_config *global_config,
const slapt_list_t *action_args)
{
- unsigned int i;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *avail_pkgs = NULL;
- slapt_regex_t *pkg_regex = NULL;
- slapt_transaction_t *tran = NULL;
-
- printf(gettext("Reading Package Lists..."));
- installed_pkgs = slapt_get_installed_pkgs();
- avail_pkgs = slapt_get_available_pkgs();
- printf(gettext("Done\n"));
-
- tran = slapt_init_transaction();
- if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
-
- for (i = 0; i < action_args->count; ++i) {
- unsigned int c;
- slapt_pkg_list_t *deps = NULL;
- char *arg = action_args->items[i];
- slapt_pkg_info_t *pkg = NULL;
+ unsigned int i;
+ slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_pkg_list_t *avail_pkgs = NULL;
+ slapt_regex_t *pkg_regex = NULL;
+ slapt_transaction_t *tran = NULL;
+
+ printf(gettext("Reading Package Lists..."));
+ installed_pkgs = slapt_get_installed_pkgs();
+ avail_pkgs = slapt_get_available_pkgs();
+ printf(gettext("Done\n"));
+
+ tran = slapt_init_transaction();
+ if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- /* Use regex to see if they specified a particular version */
- slapt_execute_regex(pkg_regex,arg);
+ for (i = 0; i < action_args->count; ++i) {
+ unsigned int c;
+ slapt_pkg_list_t *deps = NULL;
+ char *arg = action_args->items[i];
+ slapt_pkg_info_t *pkg = NULL;
- /* If so, parse it out and try to get that version only */
- if ( pkg_regex->reg_return == 0 ) {
- char *pkg_name,*pkg_version;
+ /* Use regex to see if they specified a particular version */
+ slapt_execute_regex(pkg_regex, arg);
- pkg_name = slapt_regex_extract_match(pkg_regex, arg, 1);
- pkg_version = slapt_regex_extract_match(pkg_regex, arg, 2);
- pkg = slapt_get_exact_pkg(installed_pkgs, pkg_name, pkg_version);
+ /* If so, parse it out and try to get that version only */
+ if (pkg_regex->reg_return == 0) {
+ char *pkg_name, *pkg_version;
- free(pkg_name);
- free(pkg_version);
+ pkg_name = slapt_regex_extract_match(pkg_regex, arg, 1);
+ pkg_version = slapt_regex_extract_match(pkg_regex, arg, 2);
+ pkg = slapt_get_exact_pkg(installed_pkgs, pkg_name, pkg_version);
- }
+ free(pkg_name);
+ free(pkg_version);
+ }
- /* If regex doesnt match */
- if ( pkg_regex->reg_return != 0 || pkg == NULL ) {
- /* make sure there is a package called arg */
- pkg = slapt_get_newest_pkg(installed_pkgs,arg);
+ /* If regex doesnt match */
+ if (pkg_regex->reg_return != 0 || pkg == NULL) {
+ /* make sure there is a package called arg */
+ pkg = slapt_get_newest_pkg(installed_pkgs, arg);
- if ( pkg == NULL ) {
- printf(gettext("%s is not installed.\n"),arg);
- continue;
- }
+ if (pkg == NULL) {
+ printf(gettext("%s is not installed.\n"), arg);
+ continue;
+ }
+ }
- }
+ deps = slapt_is_required_by(global_config,
+ avail_pkgs, installed_pkgs,
+ tran->install_pkgs, tran->remove_pkgs,
+ pkg);
- deps = slapt_is_required_by(global_config,
- avail_pkgs, installed_pkgs,
- tran->install_pkgs, tran->remove_pkgs,
- pkg);
+ for (c = 0; c < deps->pkg_count; ++c) {
+ slapt_pkg_info_t *dep = deps->pkgs[c];
- for (c = 0; c < deps->pkg_count; ++c) {
- slapt_pkg_info_t *dep = deps->pkgs[c];
+ if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
+ slapt_add_remove_to_transaction(tran, dep);
+ }
+ }
- if ( slapt_get_exact_pkg(installed_pkgs,dep->name, dep->version) != NULL) {
- slapt_add_remove_to_transaction(tran,dep);
- }
+ slapt_free_pkg_list(deps);
+ slapt_add_remove_to_transaction(tran, pkg);
}
- slapt_free_pkg_list(deps);
-
- slapt_add_remove_to_transaction(tran,pkg);
+ if (global_config->remove_obsolete == true) {
+ slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(
+ global_config, avail_pkgs, installed_pkgs);
- }
-
- if (global_config->remove_obsolete == true) {
- slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(
- global_config, avail_pkgs, installed_pkgs);
+ for (i = 0; i < obsolete->pkg_count; ++i) {
+ if (slapt_is_excluded(global_config, obsolete->pkgs[i]) != 1) {
+ slapt_add_remove_to_transaction(tran, obsolete->pkgs[i]);
+ } else {
+ slapt_add_exclude_to_transaction(tran, obsolete->pkgs[i]);
+ }
+ }
- for (i = 0; i < obsolete->pkg_count; ++i) {
- if ( slapt_is_excluded(global_config,obsolete->pkgs[i]) != 1 ) {
- slapt_add_remove_to_transaction(tran,obsolete->pkgs[i]);
- } else {
- slapt_add_exclude_to_transaction(tran,obsolete->pkgs[i]);
- }
+ slapt_free_pkg_list(obsolete);
}
- slapt_free_pkg_list(obsolete);
- }
-
- slapt_free_pkg_list(installed_pkgs);
- slapt_free_pkg_list(avail_pkgs);
- slapt_free_regex(pkg_regex);
+ slapt_free_pkg_list(installed_pkgs);
+ slapt_free_pkg_list(avail_pkgs);
+ slapt_free_regex(pkg_regex);
- if (slapt_handle_transaction(global_config,tran) != 0) {
- exit(EXIT_FAILURE);
- }
+ if (slapt_handle_transaction(global_config, tran) != 0) {
+ exit(EXIT_FAILURE);
+ }
- slapt_free_transaction(tran);
+ slapt_free_transaction(tran);
}
/* search for a pkg (support extended POSIX regex) */
void slapt_pkg_action_search(const char *pattern)
{
- unsigned int i;
- slapt_pkg_list_t *pkgs = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *matches = NULL,*i_matches = NULL;
-
- /* read in pkg data */
- pkgs = slapt_get_available_pkgs();
- installed_pkgs = slapt_get_installed_pkgs();
-
- matches = slapt_search_pkg_list(pkgs,pattern);
- i_matches = slapt_search_pkg_list(installed_pkgs,pattern);
-
- for (i = 0; i < matches->pkg_count; ++i) {
- char *short_description =
- slapt_gen_short_pkg_description(matches->pkgs[i]);
-
- printf("%s-%s [inst=%s]: %s\n",
- matches->pkgs[i]->name,
- matches->pkgs[i]->version,
- ( slapt_get_exact_pkg( installed_pkgs,
- matches->pkgs[i]->name,matches->pkgs[i]->version)
- != NULL )
- ? gettext("yes")
- : gettext("no"),
- short_description
- );
- free(short_description);
- }
-
- for (i = 0; i < i_matches->pkg_count; ++i) {
- char *short_description = NULL;
-
- if ( slapt_get_exact_pkg(matches,i_matches->pkgs[i]->name,
- i_matches->pkgs[i]->version) != NULL) {
- continue;
+ unsigned int i;
+ slapt_pkg_list_t *pkgs = NULL;
+ slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_pkg_list_t *matches = NULL, *i_matches = NULL;
+
+ /* read in pkg data */
+ pkgs = slapt_get_available_pkgs();
+ installed_pkgs = slapt_get_installed_pkgs();
+
+ matches = slapt_search_pkg_list(pkgs, pattern);
+ i_matches = slapt_search_pkg_list(installed_pkgs, pattern);
+
+ for (i = 0; i < matches->pkg_count; ++i) {
+ char *short_description =
+ slapt_gen_short_pkg_description(matches->pkgs[i]);
+
+ printf("%s-%s [inst=%s]: %s\n",
+ matches->pkgs[i]->name,
+ matches->pkgs[i]->version,
+ (slapt_get_exact_pkg(installed_pkgs,
+ matches->pkgs[i]->name, matches->pkgs[i]->version) != NULL)
+ ? gettext("yes")
+ : gettext("no"),
+ short_description);
+ free(short_description);
}
- short_description = slapt_gen_short_pkg_description(i_matches->pkgs[i]);
+ for (i = 0; i < i_matches->pkg_count; ++i) {
+ char *short_description = NULL;
+
+ if (slapt_get_exact_pkg(matches, i_matches->pkgs[i]->name,
+ i_matches->pkgs[i]->version) != NULL) {
+ continue;
+ }
- printf("%s-%s [inst=%s]: %s\n",
- i_matches->pkgs[i]->name,
- i_matches->pkgs[i]->version,
- gettext("yes"),
- short_description
- );
- free(short_description);
- }
+ short_description = slapt_gen_short_pkg_description(i_matches->pkgs[i]);
- slapt_free_pkg_list(matches);
- slapt_free_pkg_list(i_matches);
- slapt_free_pkg_list(pkgs);
- slapt_free_pkg_list(installed_pkgs);
+ printf("%s-%s [inst=%s]: %s\n",
+ i_matches->pkgs[i]->name,
+ i_matches->pkgs[i]->version,
+ gettext("yes"),
+ short_description);
+ free(short_description);
+ }
+ slapt_free_pkg_list(matches);
+ slapt_free_pkg_list(i_matches);
+ slapt_free_pkg_list(pkgs);
+ slapt_free_pkg_list(installed_pkgs);
}
/* show the details for a specific package */
void slapt_pkg_action_show(const char *pkg_name)
{
- slapt_pkg_list_t *avail_pkgs = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_regex_t *pkg_regex = NULL;
- unsigned int bool_installed = 0;
- slapt_pkg_info_t *pkg = NULL;
-
- avail_pkgs = slapt_get_available_pkgs();
- installed_pkgs = slapt_get_installed_pkgs();
+ slapt_pkg_list_t *avail_pkgs = NULL;
+ slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_regex_t *pkg_regex = NULL;
+ unsigned int bool_installed = 0;
+ slapt_pkg_info_t *pkg = NULL;
- if ( avail_pkgs == NULL || installed_pkgs == NULL )
- exit(EXIT_FAILURE);
+ avail_pkgs = slapt_get_available_pkgs();
+ installed_pkgs = slapt_get_installed_pkgs();
- if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL)
- exit(EXIT_FAILURE);
+ if (avail_pkgs == NULL || installed_pkgs == NULL)
+ exit(EXIT_FAILURE);
- /* Use regex to see if they specified a particular version */
- slapt_execute_regex(pkg_regex,pkg_name);
+ if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL)
+ exit(EXIT_FAILURE);
- /* If so, parse it out and try to get that version only */
- if ( pkg_regex->reg_return == 0 ) {
- char *p_name,*p_version;
+ /* Use regex to see if they specified a particular version */
+ slapt_execute_regex(pkg_regex, pkg_name);
- p_name = slapt_regex_extract_match(pkg_regex, pkg_name, 1);
- p_version = slapt_regex_extract_match(pkg_regex, pkg_name, 2);
+ /* If so, parse it out and try to get that version only */
+ if (pkg_regex->reg_return == 0) {
+ char *p_name, *p_version;
- pkg = slapt_get_exact_pkg(avail_pkgs, p_name, p_version);
+ p_name = slapt_regex_extract_match(pkg_regex, pkg_name, 1);
+ p_version = slapt_regex_extract_match(pkg_regex, pkg_name, 2);
- if ( pkg == NULL )
- pkg = slapt_get_exact_pkg(installed_pkgs,p_name,p_version);
+ pkg = slapt_get_exact_pkg(avail_pkgs, p_name, p_version);
- free(p_name);
- free(p_version);
+ if (pkg == NULL)
+ pkg = slapt_get_exact_pkg(installed_pkgs, p_name, p_version);
- }
+ free(p_name);
+ free(p_version);
+ }
- if ( pkg == NULL ) {
- slapt_pkg_info_t *installed_pkg = slapt_get_newest_pkg(installed_pkgs,pkg_name);
- pkg = slapt_get_newest_pkg(avail_pkgs,pkg_name);
- if ( pkg == NULL )
- pkg = installed_pkg;
- else if (pkg != NULL && installed_pkg != NULL) {
- if (slapt_cmp_pkgs(installed_pkg,pkg) > 0)
- pkg = installed_pkg;
+ if (pkg == NULL) {
+ slapt_pkg_info_t *installed_pkg = slapt_get_newest_pkg(installed_pkgs, pkg_name);
+ pkg = slapt_get_newest_pkg(avail_pkgs, pkg_name);
+ if (pkg == NULL)
+ pkg = installed_pkg;
+ else if (pkg != NULL && installed_pkg != NULL) {
+ if (slapt_cmp_pkgs(installed_pkg, pkg) > 0)
+ pkg = installed_pkg;
+ }
}
- }
-
- if ( pkg != NULL ) {
- char *changelog = slapt_get_pkg_changelog(pkg);
- char *description = strdup(pkg->description);
- slapt_clean_description(description,pkg->name);
-
- if ( slapt_get_exact_pkg(installed_pkgs,pkg->name,pkg->version) != NULL)
- bool_installed = 1;
-
- printf(gettext("Package Name: %s\n"),pkg->name);
- printf(gettext("Package Mirror: %s\n"),pkg->mirror);
- printf(gettext("Package Priority: %s\n"),slapt_priority_to_str(pkg->priority));
- printf(gettext("Package Location: %s\n"),pkg->location);
- printf(gettext("Package Version: %s\n"),pkg->version);
- printf(gettext("Package Size: %d K\n"),pkg->size_c);
- printf(gettext("Package Installed Size: %d K\n"),pkg->size_u);
- printf(gettext("Package Required: %s\n"),pkg->required);
- printf(gettext("Package Conflicts: %s\n"),pkg->conflicts);
- printf(gettext("Package Suggests: %s\n"),pkg->suggests);
- printf(gettext("Package MD5 Sum: %s\n"),pkg->md5);
- printf(gettext("Package Description:\n"));
- printf("%s",description);
-
- if (changelog != NULL) {
- printf("%s:\n",gettext("Package ChangeLog"));
- printf("%s\n\n", changelog);
- free(changelog);
+
+ if (pkg != NULL) {
+ char *changelog = slapt_get_pkg_changelog(pkg);
+ char *description = strdup(pkg->description);
+ slapt_clean_description(description, pkg->name);
+
+ if (slapt_get_exact_pkg(installed_pkgs, pkg->name, pkg->version) != NULL)
+ bool_installed = 1;
+
+ printf(gettext("Package Name: %s\n"), pkg->name);
+ printf(gettext("Package Mirror: %s\n"), pkg->mirror);
+ printf(gettext("Package Priority: %s\n"), slapt_priority_to_str(pkg->priority));
+ printf(gettext("Package Location: %s\n"), pkg->location);
+ printf(gettext("Package Version: %s\n"), pkg->version);
+ printf(gettext("Package Size: %d K\n"), pkg->size_c);
+ printf(gettext("Package Installed Size: %d K\n"), pkg->size_u);
+ printf(gettext("Package Required: %s\n"), pkg->required);
+ printf(gettext("Package Conflicts: %s\n"), pkg->conflicts);
+ printf(gettext("Package Suggests: %s\n"), pkg->suggests);
+ printf(gettext("Package MD5 Sum: %s\n"), pkg->md5);
+ printf(gettext("Package Description:\n"));
+ printf("%s", description);
+
+ if (changelog != NULL) {
+ printf("%s:\n", gettext("Package ChangeLog"));
+ printf("%s\n\n", changelog);
+ free(changelog);
+ }
+
+ printf(gettext("Package Installed: %s\n"),
+ bool_installed == 1
+ ? gettext("yes")
+ : gettext("no"));
+
+ free(description);
+ } else {
+ printf(gettext("No such package: %s\n"), pkg_name);
+ exit(EXIT_FAILURE);
}
- printf(gettext("Package Installed: %s\n"),
- bool_installed == 1
- ? gettext("yes")
- : gettext("no")
- );
-
- free(description);
- } else {
- printf(gettext("No such package: %s\n"),pkg_name);
- exit(EXIT_FAILURE);
- }
-
- slapt_free_pkg_list(avail_pkgs);
- slapt_free_pkg_list(installed_pkgs);
- slapt_free_regex(pkg_regex);
+ slapt_free_pkg_list(avail_pkgs);
+ slapt_free_pkg_list(installed_pkgs);
+ slapt_free_regex(pkg_regex);
}
/* upgrade all installed pkgs with available updates */
void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
{
- unsigned int i;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *avail_pkgs = NULL;
- slapt_transaction_t *tran = NULL;
-
- printf(gettext("Reading Package Lists..."));
- installed_pkgs = slapt_get_installed_pkgs();
- avail_pkgs = slapt_get_available_pkgs();
-
- if ( avail_pkgs == NULL || installed_pkgs == NULL )
- exit(EXIT_FAILURE);
-
- if ( avail_pkgs->pkg_count == 0 )
- exit(EXIT_FAILURE);
-
- printf(gettext("Done\n"));
- tran = slapt_init_transaction();
-
- if ( global_config->dist_upgrade == true ) {
- char *essential[] = {"pkgtools", "glibc-solibs", "glibc", "aaa_elflibs", "xz", "sed", "tar", "gzip", NULL};
- int epi = 0;
- slapt_pkg_info_t *newest_slaptget = NULL;
- slapt_pkg_list_t *matches =
- slapt_search_pkg_list(avail_pkgs,SLAPT_SLACK_BASE_SET_REGEX);
-
- /* make sure the essential packages are installed/upgraded first */
- while ( essential[epi] != NULL ) {
- slapt_pkg_info_t *inst_pkg = NULL;
- slapt_pkg_info_t *avail_pkg = NULL;
-
- inst_pkg = slapt_get_newest_pkg(installed_pkgs,essential[epi]);
- avail_pkg = slapt_get_newest_pkg(avail_pkgs,essential[epi]);
-
- /* can we upgrade */
- if ( inst_pkg != NULL && avail_pkg != NULL ) {
- if (slapt_cmp_pkgs(inst_pkg,avail_pkg) < 0 ) {
- slapt_add_upgrade_to_transaction(tran,inst_pkg,avail_pkg);
- }
- /* if not try to install (unless glibc, then that is upgrade only) */
- } else if ( strcmp(essential[epi], "glibc") != 0 && avail_pkg != NULL ) {
- slapt_add_install_to_transaction(tran,avail_pkg);
- }
+ unsigned int i;
+ slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_pkg_list_t *avail_pkgs = NULL;
+ slapt_transaction_t *tran = NULL;
- ++epi;
- }
+ printf(gettext("Reading Package Lists..."));
+ installed_pkgs = slapt_get_installed_pkgs();
+ avail_pkgs = slapt_get_available_pkgs();
- /* loop through SLAPT_SLACK_BASE_SET_REGEX packages */
- for (i = 0; i < matches->pkg_count; ++i) {
- slapt_pkg_info_t *installed_pkg = NULL;
- slapt_pkg_info_t *newer_avail_pkg = NULL;
- slapt_pkg_info_t *slapt_upgrade_pkg = NULL;
-
- installed_pkg = slapt_get_newest_pkg(
- installed_pkgs,
- matches->pkgs[i]->name
- );
- newer_avail_pkg = slapt_get_newest_pkg(
- avail_pkgs,
- matches->pkgs[i]->name
- );
- /*
- * if there is a newer available version (such as from patches/)
- * use it instead
- */
- if (slapt_cmp_pkgs(matches->pkgs[i],newer_avail_pkg) < 0 ) {
- slapt_upgrade_pkg = newer_avail_pkg;
- } else {
- slapt_upgrade_pkg = matches->pkgs[i];
- }
-
- /* add to install list if not already installed */
- if ( installed_pkg == NULL ) {
- if ( slapt_is_excluded(global_config,slapt_upgrade_pkg) == 1 ) {
- slapt_add_exclude_to_transaction(tran,slapt_upgrade_pkg);
- } else {
- slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran,avail_pkgs,installed_pkgs, slapt_upgrade_pkg);
-
- /* add install if all deps are good and it doesn't have conflicts */
- if (
- (slapt_add_deps_to_trans(global_config,tran,avail_pkgs, installed_pkgs,slapt_upgrade_pkg) == 0)
- && ( conflicts->pkg_count == 0 && global_config->ignore_dep != true)
- ) {
- slapt_add_install_to_transaction(tran,slapt_upgrade_pkg);
- } else {
- /* otherwise exclude */
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- slapt_upgrade_pkg->name);
- slapt_add_exclude_to_transaction(tran,slapt_upgrade_pkg);
- }
-
- slapt_free_pkg_list(conflicts);
+ if (avail_pkgs == NULL || installed_pkgs == NULL)
+ exit(EXIT_FAILURE);
- }
- /* even if it's installed, check to see that the packages are different */
- /* simply running a version comparison won't do it since sometimes the */
- /* arch is the only thing that changes */
- } else if (
- (slapt_cmp_pkgs(installed_pkg,slapt_upgrade_pkg) <= 0) &&
- strcmp(installed_pkg->version,slapt_upgrade_pkg->version) != 0
- ) {
-
- if ( slapt_is_excluded(global_config,installed_pkg) == 1
- || slapt_is_excluded(global_config,slapt_upgrade_pkg) == 1 ) {
- slapt_add_exclude_to_transaction(tran,slapt_upgrade_pkg);
- } else {
- slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran,avail_pkgs,installed_pkgs,
- slapt_upgrade_pkg);
-
- /* if all deps are added and there is no conflicts, add on */
- if (
- (slapt_add_deps_to_trans(global_config,tran,avail_pkgs,
- installed_pkgs,slapt_upgrade_pkg) == 0)
- && ( conflicts->pkg_count == 0 && global_config->ignore_dep != true)
- ) {
- slapt_add_upgrade_to_transaction(tran,installed_pkg,
- slapt_upgrade_pkg);
- } else {
- /* otherwise exclude */
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- slapt_upgrade_pkg->name);
- slapt_add_exclude_to_transaction(tran,slapt_upgrade_pkg);
- }
-
- slapt_free_pkg_list(conflicts);
- }
+ if (avail_pkgs->pkg_count == 0)
+ exit(EXIT_FAILURE);
- }
+ printf(gettext("Done\n"));
+ tran = slapt_init_transaction();
- }
+ if (global_config->dist_upgrade == true) {
+ char *essential[] = {"pkgtools", "glibc-solibs", "glibc", "aaa_elflibs", "xz", "sed", "tar", "gzip", NULL};
+ int epi = 0;
+ slapt_pkg_info_t *newest_slaptget = NULL;
+ slapt_pkg_list_t *matches =
+ slapt_search_pkg_list(avail_pkgs, SLAPT_SLACK_BASE_SET_REGEX);
- slapt_free_pkg_list(matches);
+ /* make sure the essential packages are installed/upgraded first */
+ while (essential[epi] != NULL) {
+ slapt_pkg_info_t *inst_pkg = NULL;
+ slapt_pkg_info_t *avail_pkg = NULL;
- /* remove obsolete packages if prompted to */
- if ( global_config->remove_obsolete == true ) {
- unsigned int r;
- slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(
- global_config, avail_pkgs, installed_pkgs);
+ inst_pkg = slapt_get_newest_pkg(installed_pkgs, essential[epi]);
+ avail_pkg = slapt_get_newest_pkg(avail_pkgs, essential[epi]);
- for (r = 0; r < obsolete->pkg_count; ++r) {
+ /* can we upgrade */
+ if (inst_pkg != NULL && avail_pkg != NULL) {
+ if (slapt_cmp_pkgs(inst_pkg, avail_pkg) < 0) {
+ slapt_add_upgrade_to_transaction(tran, inst_pkg, avail_pkg);
+ }
+ /* if not try to install (unless glibc, then that is upgrade only) */
+ } else if (strcmp(essential[epi], "glibc") != 0 && avail_pkg != NULL) {
+ slapt_add_install_to_transaction(tran, avail_pkg);
+ }
- if ( slapt_is_excluded(global_config,obsolete->pkgs[r]) != 1 ) {
- slapt_add_remove_to_transaction(tran,obsolete->pkgs[r]);
- } else {
- slapt_add_exclude_to_transaction(tran,obsolete->pkgs[r]);
+ ++epi;
}
- }
+ /* loop through SLAPT_SLACK_BASE_SET_REGEX packages */
+ for (i = 0; i < matches->pkg_count; ++i) {
+ slapt_pkg_info_t *installed_pkg = NULL;
+ slapt_pkg_info_t *newer_avail_pkg = NULL;
+ slapt_pkg_info_t *slapt_upgrade_pkg = NULL;
+
+ installed_pkg = slapt_get_newest_pkg(
+ installed_pkgs,
+ matches->pkgs[i]->name);
+ newer_avail_pkg = slapt_get_newest_pkg(
+ avail_pkgs,
+ matches->pkgs[i]->name);
+ /*
+ * if there is a newer available version (such as from patches/)
+ * use it instead
+ */
+ if (slapt_cmp_pkgs(matches->pkgs[i], newer_avail_pkg) < 0) {
+ slapt_upgrade_pkg = newer_avail_pkg;
+ } else {
+ slapt_upgrade_pkg = matches->pkgs[i];
+ }
+
+ /* add to install list if not already installed */
+ if (installed_pkg == NULL) {
+ if (slapt_is_excluded(global_config, slapt_upgrade_pkg) == 1) {
+ slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
+ } else {
+ slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, slapt_upgrade_pkg);
+
+ /* add install if all deps are good and it doesn't have conflicts */
+ if (
+ (slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, slapt_upgrade_pkg) == 0) && (conflicts->pkg_count == 0 && global_config->ignore_dep != true)) {
+ slapt_add_install_to_transaction(tran, slapt_upgrade_pkg);
+ } else {
+ /* otherwise exclude */
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"),
+ slapt_upgrade_pkg->name);
+ slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
+ }
+
+ slapt_free_pkg_list(conflicts);
+ }
+ /* even if it's installed, check to see that the packages are different */
+ /* simply running a version comparison won't do it since sometimes the */
+ /* arch is the only thing that changes */
+ } else if (
+ (slapt_cmp_pkgs(installed_pkg, slapt_upgrade_pkg) <= 0) &&
+ strcmp(installed_pkg->version, slapt_upgrade_pkg->version) != 0) {
+ if (slapt_is_excluded(global_config, installed_pkg) == 1 || slapt_is_excluded(global_config, slapt_upgrade_pkg) == 1) {
+ slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
+ } else {
+ slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs,
+ slapt_upgrade_pkg);
+
+ /* if all deps are added and there is no conflicts, add on */
+ if (
+ (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
+ installed_pkgs, slapt_upgrade_pkg) == 0) &&
+ (conflicts->pkg_count == 0 && global_config->ignore_dep != true)) {
+ slapt_add_upgrade_to_transaction(tran, installed_pkg,
+ slapt_upgrade_pkg);
+ } else {
+ /* otherwise exclude */
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"),
+ slapt_upgrade_pkg->name);
+ slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
+ }
+
+ slapt_free_pkg_list(conflicts);
+ }
+ }
+ }
+
+ slapt_free_pkg_list(matches);
+
+ /* remove obsolete packages if prompted to */
+ if (global_config->remove_obsolete == true) {
+ unsigned int r;
+ slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(
+ global_config, avail_pkgs, installed_pkgs);
+
+ for (r = 0; r < obsolete->pkg_count; ++r) {
+ if (slapt_is_excluded(global_config, obsolete->pkgs[r]) != 1) {
+ slapt_add_remove_to_transaction(tran, obsolete->pkgs[r]);
+ } else {
+ slapt_add_exclude_to_transaction(tran, obsolete->pkgs[r]);
+ }
+ }
- slapt_free_pkg_list(obsolete);
+ slapt_free_pkg_list(obsolete);
- }/* end if remove_obsolete */
+ } /* end if remove_obsolete */
- /* insurance so that all of slapt-get's requirements are also installed */
- newest_slaptget = slapt_get_newest_pkg(avail_pkgs,"slapt-get");
- if (newest_slaptget != NULL) {
- slapt_pkg_info_t *installed_slaptget = slapt_get_newest_pkg(installed_pkgs, "slapt-get");
- slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, newest_slaptget);
- if (installed_slaptget != NULL) /* should never be null */
- slapt_add_reinstall_to_transaction(tran,installed_slaptget, newest_slaptget);
+ /* insurance so that all of slapt-get's requirements are also installed */
+ newest_slaptget = slapt_get_newest_pkg(avail_pkgs, "slapt-get");
+ if (newest_slaptget != NULL) {
+ slapt_pkg_info_t *installed_slaptget = slapt_get_newest_pkg(installed_pkgs, "slapt-get");
+ slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, newest_slaptget);
+ if (installed_slaptget != NULL) /* should never be null */
+ slapt_add_reinstall_to_transaction(tran, installed_slaptget, newest_slaptget);
+ }
}
-
- }
- for (i = 0; i < installed_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *update_pkg = NULL;
- slapt_pkg_info_t *newer_installed_pkg = NULL;
+ for (i = 0; i < installed_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *update_pkg = NULL;
+ slapt_pkg_info_t *newer_installed_pkg = NULL;
- /*
+ /*
we need to see if there is another installed
package that is newer than this one
*/
- if ((newer_installed_pkg =
- slapt_get_newest_pkg(installed_pkgs,
- installed_pkgs->pkgs[i]->name)) != NULL) {
- if (slapt_cmp_pkgs(installed_pkgs->pkgs[i],newer_installed_pkg) < 0) {
- continue;
- }
- }
+ if ((newer_installed_pkg =
+ slapt_get_newest_pkg(installed_pkgs,
+ installed_pkgs->pkgs[i]->name)) != NULL) {
+ if (slapt_cmp_pkgs(installed_pkgs->pkgs[i], newer_installed_pkg) < 0) {
+ continue;
+ }
+ }
- /* see if we have an available update for the pkg */
- update_pkg = slapt_get_newest_pkg(
- avail_pkgs,
- installed_pkgs->pkgs[i]->name
- );
- if ( update_pkg != NULL ) {
- int cmp_r = 0;
-
- /* if the update has a newer version, attempt to upgrade */
- cmp_r = slapt_cmp_pkgs(installed_pkgs->pkgs[i],update_pkg);
- if (
- /* either it's greater, or we want to reinstall */
- cmp_r < 0 || (global_config->re_install == true) ||
- /*
+ /* see if we have an available update for the pkg */
+ update_pkg = slapt_get_newest_pkg(
+ avail_pkgs,
+ installed_pkgs->pkgs[i]->name);
+ if (update_pkg != NULL) {
+ int cmp_r = 0;
+
+ /* if the update has a newer version, attempt to upgrade */
+ cmp_r = slapt_cmp_pkgs(installed_pkgs->pkgs[i], update_pkg);
+ if (
+ /* either it's greater, or we want to reinstall */
+ cmp_r < 0 || (global_config->re_install == true) ||
+ /*
* or this is a dist upgrade and the versions are the save
* except for the arch
*/
- (
- global_config->dist_upgrade == true &&
- cmp_r == 0 &&
- cmp_pkg_arch(installed_pkgs->pkgs[i]->version,
- update_pkg->version) != 0
- )
- ) {
-
- if ( (slapt_is_excluded(global_config,update_pkg) == 1)
- || (slapt_is_excluded(global_config,installed_pkgs->pkgs[i]) == 1)
- ) {
- slapt_add_exclude_to_transaction(tran,update_pkg);
- } else {
- slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran,
- avail_pkgs,installed_pkgs, update_pkg);
-
- /* if all deps are added and there is no conflicts, add on */
- if (
- (slapt_add_deps_to_trans(global_config,tran,avail_pkgs,
- installed_pkgs,update_pkg) == 0)
- && ( global_config->ignore_dep == true
- || ( conflicts->pkg_count == 0 ) )
- ) {
-
- if (cmp_r == 0)
- slapt_add_reinstall_to_transaction(tran,installed_pkgs->pkgs[i], update_pkg);
- else
- slapt_add_upgrade_to_transaction(tran,installed_pkgs->pkgs[i], update_pkg);
-
- } else {
- /* otherwise exclude */
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- update_pkg->name);
- slapt_add_exclude_to_transaction(tran,update_pkg);
- }
-
- slapt_free_pkg_list(conflicts);
- }
-
- }
+ (
+ global_config->dist_upgrade == true &&
+ cmp_r == 0 &&
+ cmp_pkg_arch(installed_pkgs->pkgs[i]->version,
+ update_pkg->version) != 0)) {
+ if ((slapt_is_excluded(global_config, update_pkg) == 1) || (slapt_is_excluded(global_config, installed_pkgs->pkgs[i]) == 1)) {
+ slapt_add_exclude_to_transaction(tran, update_pkg);
+ } else {
+ slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran,
+ avail_pkgs, installed_pkgs, update_pkg);
+
+ /* if all deps are added and there is no conflicts, add on */
+ if (
+ (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
+ installed_pkgs, update_pkg) == 0) &&
+ (global_config->ignore_dep == true || (conflicts->pkg_count == 0))) {
+ if (cmp_r == 0)
+ slapt_add_reinstall_to_transaction(tran, installed_pkgs->pkgs[i], update_pkg);
+ else
+ slapt_add_upgrade_to_transaction(tran, installed_pkgs->pkgs[i], update_pkg);
+
+ } else {
+ /* otherwise exclude */
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"),
+ update_pkg->name);
+ slapt_add_exclude_to_transaction(tran, update_pkg);
+ }
+
+ slapt_free_pkg_list(conflicts);
+ }
+ }
- }/* end upgrade pkg found */
+ } /* end upgrade pkg found */
- }/* end for */
+ } /* end for */
- slapt_free_pkg_list(installed_pkgs);
- slapt_free_pkg_list(avail_pkgs);
+ slapt_free_pkg_list(installed_pkgs);
+ slapt_free_pkg_list(avail_pkgs);
- if (slapt_handle_transaction(global_config,tran) != 0) {
- exit(EXIT_FAILURE);
- }
+ if (slapt_handle_transaction(global_config, tran) != 0) {
+ exit(EXIT_FAILURE);
+ }
- slapt_free_transaction(tran);
+ slapt_free_transaction(tran);
}
-static int cmp_pkg_arch(const char *a,const char *b)
+static int cmp_pkg_arch(const char *a, const char *b)
{
- int r = 0;
- slapt_regex_t *a_arch_regex = NULL, *b_arch_regex = NULL;
-
- if ((a_arch_regex = slapt_init_regex(SLAPT_PKG_VER)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((b_arch_regex = slapt_init_regex(SLAPT_PKG_VER)) == NULL) {
- exit(EXIT_FAILURE);
- }
+ int r = 0;
+ slapt_regex_t *a_arch_regex = NULL, *b_arch_regex = NULL;
- slapt_execute_regex(a_arch_regex,a);
- slapt_execute_regex(b_arch_regex,b);
+ if ((a_arch_regex = slapt_init_regex(SLAPT_PKG_VER)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((b_arch_regex = slapt_init_regex(SLAPT_PKG_VER)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- if (a_arch_regex->reg_return != 0 || b_arch_regex->reg_return != 0) {
+ slapt_execute_regex(a_arch_regex, a);
+ slapt_execute_regex(b_arch_regex, b);
- slapt_free_regex(a_arch_regex);
- slapt_free_regex(b_arch_regex);
+ if (a_arch_regex->reg_return != 0 || b_arch_regex->reg_return != 0) {
+ slapt_free_regex(a_arch_regex);
+ slapt_free_regex(b_arch_regex);
- return strcmp(a,b);
+ return strcmp(a, b);
- } else {
- char *a_arch = slapt_regex_extract_match(a_arch_regex, a, 2);
- char *b_arch = slapt_regex_extract_match(a_arch_regex, b, 2);
+ } else {
+ char *a_arch = slapt_regex_extract_match(a_arch_regex, a, 2);
+ char *b_arch = slapt_regex_extract_match(a_arch_regex, b, 2);
- r = strcmp(a_arch,b_arch);
+ r = strcmp(a_arch, b_arch);
- free(a_arch);
- free(b_arch);
- }
+ free(a_arch);
+ free(b_arch);
+ }
- slapt_free_regex(a_arch_regex);
- slapt_free_regex(b_arch_regex);
+ slapt_free_regex(a_arch_regex);
+ slapt_free_regex(b_arch_regex);
- return r;
+ return r;
}
#ifdef SLAPT_HAS_GPGME
void slapt_pkg_action_add_keys(const slapt_rc_config *global_config)
{
- int rc = 0;
- unsigned int s = 0, compressed = 0;
- for(s = 0; s < global_config->sources->count; s++)
- {
- FILE *gpg_key = NULL;
- const char *source_url = global_config->sources->src[s]->url;
- printf(gettext("Retrieving GPG key [%s]..."), source_url);
- gpg_key = slapt_get_pkg_source_gpg_key (global_config, source_url, &compressed);
- if (gpg_key != NULL)
- {
- slapt_code_t r = slapt_add_pkg_source_gpg_key(gpg_key);
- if (r == SLAPT_GPG_KEY_UNCHANGED) {
- printf("%s.\n",gettext("GPG key already present"));
- } else if (r == SLAPT_GPG_KEY_IMPORTED) {
- printf("%s.\n",gettext("GPG key successfully imported"));
- } else {
- printf("%s.\n",gettext("GPG key could not be imported"));
- rc = 1;
- }
-
- fclose(gpg_key);
- }
-
- }
+ int rc = 0;
+ unsigned int s = 0, compressed = 0;
+ for (s = 0; s < global_config->sources->count; s++) {
+ FILE *gpg_key = NULL;
+ const char *source_url = global_config->sources->src[s]->url;
+ printf(gettext("Retrieving GPG key [%s]..."), source_url);
+ gpg_key = slapt_get_pkg_source_gpg_key(global_config, source_url, &compressed);
+ if (gpg_key != NULL) {
+ slapt_code_t r = slapt_add_pkg_source_gpg_key(gpg_key);
+ if (r == SLAPT_GPG_KEY_UNCHANGED) {
+ printf("%s.\n", gettext("GPG key already present"));
+ } else if (r == SLAPT_GPG_KEY_IMPORTED) {
+ printf("%s.\n", gettext("GPG key successfully imported"));
+ } else {
+ printf("%s.\n", gettext("GPG key could not be imported"));
+ rc = 1;
+ }
- if (rc) {
- exit(EXIT_FAILURE);
- }
+ fclose(gpg_key);
+ }
+ }
+ if (rc) {
+ exit(EXIT_FAILURE);
+ }
}
#endif
-void slapt_pkg_action_filelist( const char *pkg_name )
+void slapt_pkg_action_filelist(const char *pkg_name)
{
- slapt_regex_t *pkg_regex = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_info_t *pkg = NULL;
- char *filelist = NULL;
+ slapt_regex_t *pkg_regex = NULL;
+ slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_pkg_info_t *pkg = NULL;
+ char *filelist = NULL;
- installed_pkgs = slapt_get_installed_pkgs();
- if ( installed_pkgs == NULL )
- exit(EXIT_FAILURE);
+ installed_pkgs = slapt_get_installed_pkgs();
+ if (installed_pkgs == NULL)
+ exit(EXIT_FAILURE);
- if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL)
- exit(EXIT_FAILURE);
+ if ((pkg_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL)
+ exit(EXIT_FAILURE);
- /* Use regex to see if they specified a particular version */
- slapt_execute_regex(pkg_regex,pkg_name);
+ /* Use regex to see if they specified a particular version */
+ slapt_execute_regex(pkg_regex, pkg_name);
- /* If so, parse it out and try to get that version only */
- if ( pkg_regex->reg_return == 0 ) {
- char *p_name,*p_version;
+ /* If so, parse it out and try to get that version only */
+ if (pkg_regex->reg_return == 0) {
+ char *p_name, *p_version;
- p_name = slapt_regex_extract_match(pkg_regex, pkg_name, 1);
- p_version = slapt_regex_extract_match(pkg_regex, pkg_name, 2);
+ p_name = slapt_regex_extract_match(pkg_regex, pkg_name, 1);
+ p_version = slapt_regex_extract_match(pkg_regex, pkg_name, 2);
- pkg = slapt_get_exact_pkg(installed_pkgs,p_name,p_version);
+ pkg = slapt_get_exact_pkg(installed_pkgs, p_name, p_version);
- if ( pkg == NULL )
- exit(EXIT_FAILURE);
+ if (pkg == NULL)
+ exit(EXIT_FAILURE);
- free(p_name);
- free(p_version);
+ free(p_name);
+ free(p_version);
- } else {
- pkg = slapt_get_newest_pkg(installed_pkgs,pkg_name);
- if ( pkg == NULL )
- exit(EXIT_FAILURE);
- }
+ } else {
+ pkg = slapt_get_newest_pkg(installed_pkgs, pkg_name);
+ if (pkg == NULL)
+ exit(EXIT_FAILURE);
+ }
- filelist = slapt_get_pkg_filelist(pkg);
+ filelist = slapt_get_pkg_filelist(pkg);
- printf("%s\n",filelist);
+ printf("%s\n", filelist);
- free(filelist);
- slapt_free_regex(pkg_regex);
- slapt_free_pkg_list(installed_pkgs);
+ free(filelist);
+ slapt_free_regex(pkg_regex);
+ slapt_free_pkg_list(installed_pkgs);
}
diff --git a/src/action.h b/src/action.h
index 4279098..213c093 100644
--- a/src/action.h
+++ b/src/action.h
@@ -29,5 +29,4 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config);
void slapt_pkg_action_add_keys(const slapt_rc_config *global_config);
#endif
-void slapt_pkg_action_filelist( const char *pkg_name );
-
+void slapt_pkg_action_filelist(const char *pkg_name);
diff --git a/src/common.c b/src/common.c
index 0a2323d..a259376 100644
--- a/src/common.c
+++ b/src/common.c
@@ -18,519 +18,504 @@
#include "main.h"
-
-FILE *slapt_open_file(const char *file_name,const char *mode)
+FILE *slapt_open_file(const char *file_name, const char *mode)
{
- FILE *fh = NULL;
- if ( (fh = fopen(file_name,mode)) == NULL ) {
- fprintf(stderr,gettext("Failed to open %s\n"),file_name);
+ FILE *fh = NULL;
+ if ((fh = fopen(file_name, mode)) == NULL) {
+ fprintf(stderr, gettext("Failed to open %s\n"), file_name);
- if (errno)
- perror(file_name);
+ if (errno)
+ perror(file_name);
- return NULL;
- }
- return fh;
+ return NULL;
+ }
+ return fh;
}
/* initialize regex structure and compile the regular expression */
slapt_regex_t *slapt_init_regex(const char *regex_string)
{
- slapt_regex_t *r;
+ slapt_regex_t *r;
- if (regex_string == NULL)
- return NULL;
+ if (regex_string == NULL)
+ return NULL;
- r = slapt_malloc(sizeof *r);
+ r = slapt_malloc(sizeof *r);
- r->nmatch = SLAPT_MAX_REGEX_PARTS;
- r->reg_return = -1;
+ r->nmatch = SLAPT_MAX_REGEX_PARTS;
+ r->reg_return = -1;
- /* compile our regex */
- r->reg_return = regcomp(&r->regex, regex_string,
- REG_EXTENDED|REG_NEWLINE|REG_ICASE);
- if ( r->reg_return != 0 ) {
- size_t regerror_size;
- char errbuf[1024];
- size_t errbuf_size = 1024;
- fprintf(stderr, gettext("Failed to compile regex\n"));
+ /* compile our regex */
+ r->reg_return = regcomp(&r->regex, regex_string,
+ REG_EXTENDED | REG_NEWLINE | REG_ICASE);
+ if (r->reg_return != 0) {
+ size_t regerror_size;
+ char errbuf[1024];
+ size_t errbuf_size = 1024;
+ fprintf(stderr, gettext("Failed to compile regex\n"));
- if ( (regerror_size = regerror(r->reg_return,
- &r->regex,errbuf,errbuf_size)) != 0 ) {
- printf(gettext("Regex Error: %s\n"),errbuf);
+ if ((regerror_size = regerror(r->reg_return,
+ &r->regex, errbuf, errbuf_size)) != 0) {
+ printf(gettext("Regex Error: %s\n"), errbuf);
+ }
+ free(r);
+ return NULL;
}
- free(r);
- return NULL;
- }
- return r;
+ return r;
}
/*
execute the regular expression and set the return code
in the passed in structure
*/
-void slapt_execute_regex(slapt_regex_t *r,const char *string)
+void slapt_execute_regex(slapt_regex_t *r, const char *string)
{
- r->reg_return = regexec(&r->regex, string,
- r->nmatch,r->pmatch,0);
+ r->reg_return = regexec(&r->regex, string,
+ r->nmatch, r->pmatch, 0);
}
char *slapt_regex_extract_match(const slapt_regex_t *r, const char *src, const int i)
{
- regmatch_t m = r->pmatch[i];
- char *str = NULL;
+ regmatch_t m = r->pmatch[i];
+ char *str = NULL;
- if (m.rm_so != -1)
- {
- unsigned int len = m.rm_eo - m.rm_so + 1;
- str = malloc(sizeof *str * len);
+ if (m.rm_so != -1) {
+ unsigned int len = m.rm_eo - m.rm_so + 1;
+ str = malloc(sizeof *str * len);
- str = strncpy(str, src + m.rm_so, len);
- if (len > 0)
- str[len - 1] = '\0';
- }
+ str = strncpy(str, src + m.rm_so, len);
+ if (len > 0)
+ str[len - 1] = '\0';
+ }
- return str;
+ return str;
}
-
void slapt_free_regex(slapt_regex_t *r)
{
- regfree(&r->regex);
- free(r);
+ regfree(&r->regex);
+ free(r);
}
-void slapt_gen_md5_sum_of_file(FILE *f,char *result_sum)
+void slapt_gen_md5_sum_of_file(FILE *f, char *result_sum)
{
- EVP_MD_CTX *mdctx = NULL;
- const EVP_MD *md;
- unsigned char md_value[EVP_MAX_MD_SIZE];
- unsigned int md_len = 0, i;
- ssize_t getline_read;
- size_t getline_size;
- char *result_sum_tmp = NULL;
- char *getline_buffer = NULL;
+ EVP_MD_CTX *mdctx = NULL;
+ const EVP_MD *md;
+ unsigned char md_value[EVP_MAX_MD_SIZE];
+ unsigned int md_len = 0, i;
+ ssize_t getline_read;
+ size_t getline_size;
+ char *result_sum_tmp = NULL;
+ char *getline_buffer = NULL;
- md = EVP_md5();
+ md = EVP_md5();
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- mdctx = EVP_MD_CTX_new();
+ mdctx = EVP_MD_CTX_new();
#else
- mdctx = slapt_malloc(sizeof *mdctx);
- EVP_MD_CTX_init(mdctx);
+ mdctx = slapt_malloc(sizeof *mdctx);
+ EVP_MD_CTX_init(mdctx);
#endif
- EVP_DigestInit_ex(mdctx, md, NULL);
+ EVP_DigestInit_ex(mdctx, md, NULL);
- rewind(f);
+ rewind(f);
- while ( (getline_read = getline(&getline_buffer, &getline_size, f)) != EOF )
- EVP_DigestUpdate(mdctx, getline_buffer, getline_read);
+ while ((getline_read = getline(&getline_buffer, &getline_size, f)) != EOF)
+ EVP_DigestUpdate(mdctx, getline_buffer, getline_read);
- free(getline_buffer);
+ free(getline_buffer);
- EVP_DigestFinal_ex(mdctx, md_value, &md_len);
+ EVP_DigestFinal_ex(mdctx, md_value, &md_len);
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- EVP_MD_CTX_free(mdctx);
+ EVP_MD_CTX_free(mdctx);
#else
- free(mdctx);
+ free(mdctx);
#endif
- result_sum[0] = '\0';
+ result_sum[0] = '\0';
- for (i = 0; i < md_len; ++i) {
- char *p = slapt_malloc( sizeof *p * 3 );
+ for (i = 0; i < md_len; ++i) {
+ char *p = slapt_malloc(sizeof *p * 3);
- if ( snprintf(p,3,"%02x",md_value[i]) > 0 ) {
-
- if ( (result_sum_tmp = strncat(result_sum,p,3)) != NULL )
- result_sum = result_sum_tmp;
+ if (snprintf(p, 3, "%02x", md_value[i]) > 0) {
+ if ((result_sum_tmp = strncat(result_sum, p, 3)) != NULL)
+ result_sum = result_sum_tmp;
+ }
+ free(p);
}
-
- free(p);
- }
-
}
/* recursively create dirs */
void slapt_create_dir_structure(const char *dir_name)
{
- char *cwd = NULL;
- int position = 0,len = 0;
-
- cwd = getcwd(NULL,0);
- if ( cwd == NULL ) {
- fprintf(stderr,gettext("Failed to get cwd\n"));
- return;
- }
-
- len = strlen(dir_name);
- while ( position < len ) {
-
- char *pointer = NULL;
- char *dir_name_buffer = NULL;
-
- /* if no more directory delim, then this must be last dir */
- if ( strstr(dir_name + position,"/" ) == NULL ) {
-
- dir_name_buffer = strndup(
- dir_name + position,
- strlen(dir_name + position)
- );
-
- if ( strcmp(dir_name_buffer,".") != 0 ) {
- if ( (mkdir(dir_name_buffer,0755)) == -1) {
- if (errno != EEXIST) {
- fprintf(stderr,gettext("Failed to mkdir: %s\n"),dir_name_buffer);
- exit(EXIT_FAILURE);
- }
- }
- if ( (chdir(dir_name_buffer)) == -1 ) {
- fprintf(stderr,gettext("Failed to chdir to %s\n"),dir_name_buffer);
- exit(EXIT_FAILURE);
- }
- }/* don't create . */
+ char *cwd = NULL;
+ int position = 0, len = 0;
- free(dir_name_buffer);
- break;
- } else {
- if ( dir_name[position] == '/' ) {
- /* move on ahead */
- ++position;
- } else {
-
- /* figure our dir name and mk it */
- pointer = strchr(dir_name + position,'/');
- dir_name_buffer = strndup(
- dir_name + position,
- strlen(dir_name + position) - strlen(pointer)
- );
-
- if ( strcmp(dir_name_buffer,".") != 0 ) {
- if ( (mkdir(dir_name_buffer,0755)) == -1 ) {
- if (errno != EEXIST) {
- fprintf(stderr,gettext("Failed to mkdir: %s\n"),dir_name_buffer);
- exit(EXIT_FAILURE);
- }
- }
- if ( (chdir(dir_name_buffer)) == -1 ) {
- fprintf(stderr,gettext("Failed to chdir to %s\n"),dir_name_buffer);
- exit(EXIT_FAILURE);
- }
- } /* don't create . */
-
- free(dir_name_buffer);
- position += (strlen(dir_name + position) - strlen(pointer));
- }
+ cwd = getcwd(NULL, 0);
+ if (cwd == NULL) {
+ fprintf(stderr, gettext("Failed to get cwd\n"));
+ return;
}
- }/* end while */
- if ( (chdir(cwd)) == -1 ) {
- fprintf(stderr,gettext("Failed to chdir to %s\n"),cwd);
- return;
- }
+ len = strlen(dir_name);
+ while (position < len) {
+ char *pointer = NULL;
+ char *dir_name_buffer = NULL;
+
+ /* if no more directory delim, then this must be last dir */
+ if (strstr(dir_name + position, "/") == NULL) {
+ dir_name_buffer = strndup(
+ dir_name + position,
+ strlen(dir_name + position));
+
+ if (strcmp(dir_name_buffer, ".") != 0) {
+ if ((mkdir(dir_name_buffer, 0755)) == -1) {
+ if (errno != EEXIST) {
+ fprintf(stderr, gettext("Failed to mkdir: %s\n"), dir_name_buffer);
+ exit(EXIT_FAILURE);
+ }
+ }
+ if ((chdir(dir_name_buffer)) == -1) {
+ fprintf(stderr, gettext("Failed to chdir to %s\n"), dir_name_buffer);
+ exit(EXIT_FAILURE);
+ }
+ } /* don't create . */
+
+ free(dir_name_buffer);
+ break;
+ } else {
+ if (dir_name[position] == '/') {
+ /* move on ahead */
+ ++position;
+ } else {
+ /* figure our dir name and mk it */
+ pointer = strchr(dir_name + position, '/');
+ dir_name_buffer = strndup(
+ dir_name + position,
+ strlen(dir_name + position) - strlen(pointer));
+
+ if (strcmp(dir_name_buffer, ".") != 0) {
+ if ((mkdir(dir_name_buffer, 0755)) == -1) {
+ if (errno != EEXIST) {
+ fprintf(stderr, gettext("Failed to mkdir: %s\n"), dir_name_buffer);
+ exit(EXIT_FAILURE);
+ }
+ }
+ if ((chdir(dir_name_buffer)) == -1) {
+ fprintf(stderr, gettext("Failed to chdir to %s\n"), dir_name_buffer);
+ exit(EXIT_FAILURE);
+ }
+ } /* don't create . */
+
+ free(dir_name_buffer);
+ position += (strlen(dir_name + position) - strlen(pointer));
+ }
+ }
+ } /* end while */
+
+ if ((chdir(cwd)) == -1) {
+ fprintf(stderr, gettext("Failed to chdir to %s\n"), cwd);
+ return;
+ }
- free(cwd);
+ free(cwd);
}
int slapt_ask_yes_no(const char *format, ...)
{
- va_list arg_list;
- int answer, parsed_answer = 0;
+ va_list arg_list;
+ int answer, parsed_answer = 0;
- va_start(arg_list, format);
- vprintf(format, arg_list);
- va_end(arg_list);
+ va_start(arg_list, format);
+ vprintf(format, arg_list);
+ va_end(arg_list);
- while ((answer = fgetc(stdin)) != EOF) {
+ while ((answer = fgetc(stdin)) != EOF) {
+ if (answer == '\n')
+ break;
- if (answer == '\n')
- break;
-
- if ( ((tolower(answer) == 'y') ||
- (tolower(answer) == 'n')) && parsed_answer == 0)
- parsed_answer = tolower(answer);
-
- }
+ if (((tolower(answer) == 'y') ||
+ (tolower(answer) == 'n')) &&
+ parsed_answer == 0)
+ parsed_answer = tolower(answer);
+ }
- if (parsed_answer == 'y')
- return 1;
+ if (parsed_answer == 'y')
+ return 1;
- if (parsed_answer == 'n')
- return 0;
+ if (parsed_answer == 'n')
+ return 0;
- return -1;
+ return -1;
}
-char *slapt_str_replace_chr(const char *string,const char find,
+char *slapt_str_replace_chr(const char *string, const char find,
const char replace)
{
- unsigned int i,len = 0;
- char *clean = slapt_calloc( strlen(string) + 1, sizeof *clean);;
-
- len = strlen(string);
- for (i = 0;i < len; ++i) {
- if (string[i] == find ) {
- clean[i] = replace;
- } else {
- clean[i] = string[i];
+ unsigned int i, len = 0;
+ char *clean = slapt_calloc(strlen(string) + 1, sizeof *clean);
+ ;
+
+ len = strlen(string);
+ for (i = 0; i < len; ++i) {
+ if (string[i] == find) {
+ clean[i] = replace;
+ } else {
+ clean[i] = string[i];
+ }
}
- }
- clean[ strlen(string) ] = '\0';
+ clean[strlen(string)] = '\0';
- return clean;
+ return clean;
}
void *slapt_malloc(size_t s)
{
- void *p;
- if ( ! (p = malloc(s)) ) {
- fprintf(stderr,gettext("Failed to malloc\n"));
+ void *p;
+ if (!(p = malloc(s))) {
+ fprintf(stderr, gettext("Failed to malloc\n"));
- if ( errno )
- perror("malloc");
+ if (errno)
+ perror("malloc");
- exit(EXIT_FAILURE);
- }
- return p;
+ exit(EXIT_FAILURE);
+ }
+ return p;
}
-void *slapt_calloc(size_t n,size_t s)
+void *slapt_calloc(size_t n, size_t s)
{
- void *p;
- if ( ! (p = calloc(n,s)) ) {
- fprintf(stderr,gettext("Failed to calloc\n"));
+ void *p;
+ if (!(p = calloc(n, s))) {
+ fprintf(stderr, gettext("Failed to calloc\n"));
- if ( errno )
- perror("calloc");
+ if (errno)
+ perror("calloc");
- exit(EXIT_FAILURE);
- }
- return p;
+ exit(EXIT_FAILURE);
+ }
+ return p;
}
const char *slapt_strerror(slapt_code_t code)
{
- switch (code) {
+ switch (code) {
case SLAPT_OK:
- return "No error";
+ return "No error";
case SLAPT_MD5_CHECKSUM_MISMATCH:
- return gettext("MD5 checksum mismatch, override with --no-md5");
+ return gettext("MD5 checksum mismatch, override with --no-md5");
case SLAPT_MD5_CHECKSUM_MISSING:
- return gettext("Missing MD5 checksum, override with --no-md5");
+ return gettext("Missing MD5 checksum, override with --no-md5");
case SLAPT_DOWNLOAD_INCOMPLETE:
- return gettext("Incomplete download");
- #ifdef SLAPT_HAS_GPGME
+ return gettext("Incomplete download");
+#ifdef SLAPT_HAS_GPGME
case SLAPT_GPG_KEY_IMPORTED:
- return gettext("GPG key successfully imported");
+ return gettext("GPG key successfully imported");
case SLAPT_GPG_KEY_NOT_IMPORTED:
- return gettext("GPG key could not be imported");
+ return gettext("GPG key could not be imported");
case SLAPT_GPG_KEY_UNCHANGED:
- return gettext("GPG key already present");
+ return gettext("GPG key already present");
case SLAPT_CHECKSUMS_VERIFIED:
- return gettext("Checksums signature successfully verified");
+ return gettext("Checksums signature successfully verified");
case SLAPT_CHECKSUMS_NOT_VERIFIED_NULL_CONTEXT:
- return gettext("Not verified: null context");
+ return gettext("Not verified: null context");
case SLAPT_CHECKSUMS_NOT_VERIFIED_READ_CHECKSUMS:
- return gettext("Checksums not read");
+ return gettext("Checksums not read");
case SLAPT_CHECKSUMS_NOT_VERIFIED_READ_SIGNATURE:
- return gettext("Signature not read");
+ return gettext("Signature not read");
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_REVOKED:
- return gettext("Not Verified: key revoked");
+ return gettext("Not Verified: key revoked");
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_EXPIRED:
- return gettext("Not Verified: key expired");
+ return gettext("Not Verified: key expired");
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SIG_EXPIRED:
- return gettext("Not Verified: signature expired");
+ return gettext("Not Verified: signature expired");
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_MISSING:
- return gettext("Not Verified: missing CRL");
+ return gettext("Not Verified: missing CRL");
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_TOO_OLD:
- return gettext("Not Verified: CRL too old");
+ return gettext("Not Verified: CRL too old");
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_BAD_POLICY:
- return gettext("Not Verified: bad policy");
+ return gettext("Not Verified: bad policy");
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SYS_ERROR:
- return gettext("Not Verified: system error");
+ return gettext("Not Verified: system error");
case SLAPT_CHECKSUMS_NOT_VERIFIED:
- return gettext("Checksums signature could not be verified");
+ return gettext("Checksums signature could not be verified");
case SLAPT_CHECKSUMS_MISSING_KEY:
- return gettext("No key for verification");
- #endif
+ return gettext("No key for verification");
+#endif
default:
- return gettext("Unknown error");
- };
+ return gettext("Unknown error");
+ };
}
const char *slapt_priority_to_str(SLAPT_PRIORITY_T priority)
{
-
- switch(priority) {
+ switch (priority) {
case SLAPT_PRIORITY_DEFAULT:
- return gettext("Default");
+ return gettext("Default");
case SLAPT_PRIORITY_DEFAULT_PATCH:
- return gettext("Default Patch");
+ return gettext("Default Patch");
case SLAPT_PRIORITY_PREFERRED:
- return gettext("Preferred");
+ return gettext("Preferred");
case SLAPT_PRIORITY_PREFERRED_PATCH:
- return gettext("Preferred Patch");
+ return gettext("Preferred Patch");
case SLAPT_PRIORITY_OFFICIAL:
- return gettext("Official");
+ return gettext("Official");
case SLAPT_PRIORITY_OFFICIAL_PATCH:
- return gettext("Official Patch");
+ return gettext("Official Patch");
case SLAPT_PRIORITY_CUSTOM:
- return gettext("Custom");
+ return gettext("Custom");
case SLAPT_PRIORITY_CUSTOM_PATCH:
- return gettext("Custom Patch");
+ return gettext("Custom Patch");
default:
- return NULL;
- };
-
+ return NULL;
+ };
}
-bool slapt_disk_space_check (const char *path,double space_needed)
+bool slapt_disk_space_check(const char *path, double space_needed)
{
- struct statvfs statvfs_buf;
+ struct statvfs statvfs_buf;
- if (space_needed < 0)
- return true;
-
- space_needed *= 1024;
+ if (space_needed < 0)
+ return true;
- if (statvfs(path, &statvfs_buf) != 0) {
+ space_needed *= 1024;
- if (errno)
- perror("statvfs");
+ if (statvfs(path, &statvfs_buf) != 0) {
+ if (errno)
+ perror("statvfs");
- return false;
- } else {
- if (statvfs_buf.f_bavail < (space_needed / statvfs_buf.f_bsize))
- return false;
- }
+ return false;
+ } else {
+ if (statvfs_buf.f_bavail < (space_needed / statvfs_buf.f_bsize))
+ return false;
+ }
- return true;
+ return true;
}
slapt_list_t *slapt_init_list(void)
{
- slapt_list_t *list = slapt_malloc(sizeof *list);
- list->items = slapt_malloc(sizeof *list->items);
- list->count = 0;
+ slapt_list_t *list = slapt_malloc(sizeof *list);
+ list->items = slapt_malloc(sizeof *list->items);
+ list->count = 0;
- return list;
+ return list;
}
-void slapt_add_list_item(slapt_list_t *list,const char *item)
+void slapt_add_list_item(slapt_list_t *list, const char *item)
{
- char **realloc_tmp;
-
- realloc_tmp =
- realloc( list->items, sizeof *list->items * (list->count + 1) );
+ char **realloc_tmp;
- if ( realloc_tmp == NULL )
- return;
+ realloc_tmp =
+ realloc(list->items, sizeof *list->items * (list->count + 1));
- list->items = realloc_tmp;
- list->items[ list->count ] = strndup(item, strlen(item));
- list->items[ list->count ][strlen(item)] = '\0';
- ++list->count;
+ if (realloc_tmp == NULL)
+ return;
+ list->items = realloc_tmp;
+ list->items[list->count] = strndup(item, strlen(item));
+ list->items[list->count][strlen(item)] = '\0';
+ ++list->count;
}
void slapt_remove_list_item(slapt_list_t *list, const char *item)
{
- unsigned int i = 0;
- char *tmp = NULL;
+ unsigned int i = 0;
+ char *tmp = NULL;
- while (i < list->count) {
- if ( strcmp(item,list->items[i]) == 0 && tmp == NULL ) {
- tmp = list->items[i];
- }
- if ( tmp != NULL && (i+1 < list->count) ) {
- list->items[i] = list->items[i + 1];
+ while (i < list->count) {
+ if (strcmp(item, list->items[i]) == 0 && tmp == NULL) {
+ tmp = list->items[i];
+ }
+ if (tmp != NULL && (i + 1 < list->count)) {
+ list->items[i] = list->items[i + 1];
+ }
+ ++i;
}
- ++i;
- }
- if ( tmp != NULL ) {
- char **realloc_tmp;
- int count = list->count - 1;
- if ( count < 1 )
- count = 1;
-
- free(tmp);
-
- realloc_tmp = realloc(list->items, sizeof *list->items * count);
- if ( realloc_tmp != NULL ) {
- list->items = realloc_tmp;
- if (list->count > 0)
- --list->count;
+ if (tmp != NULL) {
+ char **realloc_tmp;
+ int count = list->count - 1;
+ if (count < 1)
+ count = 1;
+
+ free(tmp);
+
+ realloc_tmp = realloc(list->items, sizeof *list->items * count);
+ if (realloc_tmp != NULL) {
+ list->items = realloc_tmp;
+ if (list->count > 0)
+ --list->count;
+ }
}
-
- }
}
const char *slapt_search_list(slapt_list_t *list, const char *needle)
{
- unsigned int i;
+ unsigned int i;
- for (i = 0; i < list->count; i++) {
- if (strcmp (list->items[i], needle) == 0)
- return list->items[i];
- }
+ for (i = 0; i < list->count; i++) {
+ if (strcmp(list->items[i], needle) == 0)
+ return list->items[i];
+ }
- return NULL;
+ return NULL;
}
void slapt_free_list(slapt_list_t *list)
{
- unsigned int i;
+ unsigned int i;
- for (i = 0; i < list->count; ++i) {
- free(list->items[i]);
- }
- free(list->items);
- free(list);
+ for (i = 0; i < list->count; ++i) {
+ free(list->items[i]);
+ }
+ free(list->items);
+ free(list);
}
slapt_list_t *slapt_parse_delimited_list(char *line, char delim)
{
- slapt_list_t *list = slapt_init_list();
- int count = 0, position = 0, len = strlen(line);
+ slapt_list_t *list = slapt_init_list();
+ int count = 0, position = 0, len = strlen(line);
- while (isspace(line[position]) != 0)
- ++position;
+ while (isspace(line[position]) != 0)
+ ++position;
- while (position < len) {
- char *start = line + position;
- char *end = NULL, *ptr = NULL;
- int start_len = strlen(start), end_len = 0;
+ while (position < len) {
+ char *start = line + position;
+ char *end = NULL, *ptr = NULL;
+ int start_len = strlen(start), end_len = 0;
- if (strchr(start,delim) != NULL) {
- if (line[position] == delim || isspace(line[position]) != 0) {
- ++position;
- continue;
- }
- end = strchr(start,delim);
- }
+ if (strchr(start, delim) != NULL) {
+ if (line[position] == delim || isspace(line[position]) != 0) {
+ ++position;
+ continue;
+ }
+ end = strchr(start, delim);
+ }
- if (end != NULL)
- end_len = strlen(end);
+ if (end != NULL)
+ end_len = strlen(end);
- ptr = strndup(start, start_len - end_len);
+ ptr = strndup(start, start_len - end_len);
- slapt_add_list_item(list, ptr);
- free(ptr);
- ++count;
+ slapt_add_list_item(list, ptr);
+ free(ptr);
+ ++count;
- position += start_len - end_len;
- }
+ position += start_len - end_len;
+ }
- return list;
+ return list;
}
-char *slapt_strip_whitespace (const char * s)
+char *slapt_strip_whitespace(const char *s)
{
- int len = strlen (s);
- while (isspace(s[len - 1])) --len;
- while (*s && isspace(* s)) ++s, --len;
- return strndup (s, len);
+ int len = strlen(s);
+ while (isspace(s[len - 1]))
+ --len;
+ while (*s && isspace(*s))
+ ++s, --len;
+ return strndup(s, len);
}
-
diff --git a/src/common.h b/src/common.h
index a8fa75d..49f3b5c 100644
--- a/src/common.h
+++ b/src/common.h
@@ -16,33 +16,32 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
#define SLAPT_MAX_REGEX_PARTS 10
#define SLAPT_SLACK_BASE_SET_REGEX "^./slackware/a$"
typedef enum {
- SLAPT_OK = 0,
- SLAPT_MD5_CHECKSUM_MISMATCH,
- SLAPT_MD5_CHECKSUM_MISSING,
- #ifdef SLAPT_HAS_GPGME
- SLAPT_GPG_KEY_IMPORTED,
- SLAPT_GPG_KEY_NOT_IMPORTED,
- SLAPT_GPG_KEY_UNCHANGED,
- SLAPT_CHECKSUMS_VERIFIED,
- SLAPT_CHECKSUMS_MISSING_KEY,
- SLAPT_CHECKSUMS_NOT_VERIFIED,
- SLAPT_CHECKSUMS_NOT_VERIFIED_NULL_CONTEXT,
- SLAPT_CHECKSUMS_NOT_VERIFIED_READ_CHECKSUMS,
- SLAPT_CHECKSUMS_NOT_VERIFIED_READ_SIGNATURE,
- SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_REVOKED,
- SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_EXPIRED,
- SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SIG_EXPIRED,
- SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_MISSING,
- SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_TOO_OLD,
- SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_BAD_POLICY,
- SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SYS_ERROR,
- #endif
- SLAPT_DOWNLOAD_INCOMPLETE
+ SLAPT_OK = 0,
+ SLAPT_MD5_CHECKSUM_MISMATCH,
+ SLAPT_MD5_CHECKSUM_MISSING,
+#ifdef SLAPT_HAS_GPGME
+ SLAPT_GPG_KEY_IMPORTED,
+ SLAPT_GPG_KEY_NOT_IMPORTED,
+ SLAPT_GPG_KEY_UNCHANGED,
+ SLAPT_CHECKSUMS_VERIFIED,
+ SLAPT_CHECKSUMS_MISSING_KEY,
+ SLAPT_CHECKSUMS_NOT_VERIFIED,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_NULL_CONTEXT,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_READ_CHECKSUMS,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_READ_SIGNATURE,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_REVOKED,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_EXPIRED,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SIG_EXPIRED,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_MISSING,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_TOO_OLD,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_BAD_POLICY,
+ SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SYS_ERROR,
+#endif
+ SLAPT_DOWNLOAD_INCOMPLETE
} slapt_code_t;
typedef enum {
@@ -62,48 +61,48 @@ typedef enum {
#define SLAPT_PRIORITY_CUSTOM_TOKEN "CUSTOM"
typedef struct {
- regmatch_t pmatch[SLAPT_MAX_REGEX_PARTS];
- regex_t regex;
- size_t nmatch;
- int reg_return;
+ regmatch_t pmatch[SLAPT_MAX_REGEX_PARTS];
+ regex_t regex;
+ size_t nmatch;
+ int reg_return;
} slapt_regex_t;
typedef struct {
- char **items;
- unsigned int count;
+ char **items;
+ unsigned int count;
} slapt_list_t;
-FILE *slapt_open_file(const char *file_name,const char *mode);
+FILE *slapt_open_file(const char *file_name, const char *mode);
slapt_regex_t *slapt_init_regex(const char *regex_string);
-void slapt_execute_regex(slapt_regex_t *regex_t,const char *string);
+void slapt_execute_regex(slapt_regex_t *regex_t, const char *string);
/* extract the string from the match, starts with 1 (not 0) */
char *slapt_regex_extract_match(const slapt_regex_t *r, const char *src, const int i);
void slapt_free_regex(slapt_regex_t *regex_t);
void slapt_create_dir_structure(const char *dir_name);
/* generate an md5sum of filehandle */
-void slapt_gen_md5_sum_of_file(FILE *f,char *result_sum);
+void slapt_gen_md5_sum_of_file(FILE *f, char *result_sum);
/* Ask the user to answer yes or no.
* return 1 on yes, 0 on no, else -1.
*/
int slapt_ask_yes_no(const char *format, ...);
-char *slapt_str_replace_chr(const char *string,const char find,
+char *slapt_str_replace_chr(const char *string, const char find,
const char replace);
void *slapt_malloc(size_t s);
-void *slapt_calloc(size_t n,size_t s);
+void *slapt_calloc(size_t n, size_t s);
/* return human readable error */
const char *slapt_strerror(slapt_code_t code);
/* return human readable priority */
const char *slapt_priority_to_str(SLAPT_PRIORITY_T priority);
-bool slapt_disk_space_check (const char *path,double space_needed);
+bool slapt_disk_space_check(const char *path, double space_needed);
/* general list management */
slapt_list_t *slapt_parse_delimited_list(char *line, char delim);
slapt_list_t *slapt_init_list(void);
-void slapt_add_list_item(slapt_list_t *list,const char *item);
-void slapt_remove_list_item(slapt_list_t *list,const char *item);
+void slapt_add_list_item(slapt_list_t *list, const char *item);
+void slapt_remove_list_item(slapt_list_t *list, const char *item);
const char *slapt_search_list(slapt_list_t *list, const char *needle);
void slapt_free_list(slapt_list_t *list);
-char *slapt_strip_whitespace (const char * s);
+char *slapt_strip_whitespace(const char *s);
diff --git a/src/configuration.c b/src/configuration.c
index f55286b..efab692 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -20,432 +20,414 @@
/* parse the exclude list */
static slapt_list_t *parse_exclude(char *line);
-
slapt_rc_config *slapt_init_config(void)
{
- slapt_rc_config *global_config = slapt_malloc( sizeof *global_config );
-
- global_config->download_only = false;
- global_config->simulate = false;
- global_config->ignore_excludes = false;
- global_config->no_md5_check = false;
- global_config->dist_upgrade = false;
- global_config->ignore_dep = false;
- global_config->disable_dep_check = false;
- global_config->print_uris = false;
- global_config->dl_stats = false;
- global_config->no_prompt = false;
- global_config->prompt = false;
- global_config->re_install = false;
- global_config->remove_obsolete = false;
- global_config->no_upgrade = false;
- global_config->use_priority = false;
- global_config->working_dir[0] = '\0';
- global_config->progress_cb = NULL;
- global_config->gpgme_allow_unauth = false; /* even without GPGME */
-
- global_config->sources = slapt_init_source_list();
- global_config->exclude_list = slapt_init_list();
-
- global_config->retry = 1;
-
- return global_config;
+ slapt_rc_config *global_config = slapt_malloc(sizeof *global_config);
+
+ global_config->download_only = false;
+ global_config->simulate = false;
+ global_config->ignore_excludes = false;
+ global_config->no_md5_check = false;
+ global_config->dist_upgrade = false;
+ global_config->ignore_dep = false;
+ global_config->disable_dep_check = false;
+ global_config->print_uris = false;
+ global_config->dl_stats = false;
+ global_config->no_prompt = false;
+ global_config->prompt = false;
+ global_config->re_install = false;
+ global_config->remove_obsolete = false;
+ global_config->no_upgrade = false;
+ global_config->use_priority = false;
+ global_config->working_dir[0] = '\0';
+ global_config->progress_cb = NULL;
+ global_config->gpgme_allow_unauth = false; /* even without GPGME */
+
+ global_config->sources = slapt_init_source_list();
+ global_config->exclude_list = slapt_init_list();
+
+ global_config->retry = 1;
+
+ return global_config;
}
slapt_rc_config *slapt_read_rc_config(const char *file_name)
{
- FILE *rc = NULL;
- char *getline_buffer = NULL;
- size_t gb_length = 0;
- ssize_t g_size;
- slapt_rc_config *global_config = NULL;
-
- rc = slapt_open_file(file_name,"r");
- if ( rc == NULL )
- return NULL;
-
- global_config = slapt_init_config();
-
- while ( (g_size = getline(&getline_buffer,&gb_length,rc) ) != EOF ) {
- char *token_ptr = NULL;
- getline_buffer[g_size - 1] = '\0';
-
- /* check to see if it has our key and value separated by our token */
- /* and extract them */
- if ( (strchr(getline_buffer,'#') != NULL) && (strstr(getline_buffer, SLAPT_DISABLED_SOURCE_TOKEN) == NULL) )
- continue;
-
-
- if ( (token_ptr = strstr(getline_buffer,SLAPT_SOURCE_TOKEN)) != NULL ) {
- /* SOURCE URL */
-
- if ( strlen(token_ptr) > strlen(SLAPT_SOURCE_TOKEN) ) {
- slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_SOURCE_TOKEN));
- if (s != NULL) {
- slapt_add_source(global_config->sources,s);
- if (s->priority != SLAPT_PRIORITY_DEFAULT) {
- global_config->use_priority = true;
- }
- }
- }
-
- } else if ( (token_ptr = strstr(getline_buffer,SLAPT_DISABLED_SOURCE_TOKEN)) != NULL ) {
- /* DISABLED SOURCE */
-
- if (strlen(token_ptr) > strlen(SLAPT_DISABLED_SOURCE_TOKEN) ) {
- slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_DISABLED_SOURCE_TOKEN));
- if (s != NULL) {
- s->disabled = true;
- slapt_add_source(global_config->sources,s);
+ FILE *rc = NULL;
+ char *getline_buffer = NULL;
+ size_t gb_length = 0;
+ ssize_t g_size;
+ slapt_rc_config *global_config = NULL;
+
+ rc = slapt_open_file(file_name, "r");
+ if (rc == NULL)
+ return NULL;
+
+ global_config = slapt_init_config();
+
+ while ((g_size = getline(&getline_buffer, &gb_length, rc)) != EOF) {
+ char *token_ptr = NULL;
+ getline_buffer[g_size - 1] = '\0';
+
+ /* check to see if it has our key and value separated by our token */
+ /* and extract them */
+ if ((strchr(getline_buffer, '#') != NULL) && (strstr(getline_buffer, SLAPT_DISABLED_SOURCE_TOKEN) == NULL))
+ continue;
+
+ if ((token_ptr = strstr(getline_buffer, SLAPT_SOURCE_TOKEN)) != NULL) {
+ /* SOURCE URL */
+
+ if (strlen(token_ptr) > strlen(SLAPT_SOURCE_TOKEN)) {
+ slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_SOURCE_TOKEN));
+ if (s != NULL) {
+ slapt_add_source(global_config->sources, s);
+ if (s->priority != SLAPT_PRIORITY_DEFAULT) {
+ global_config->use_priority = true;
+ }
+ }
+ }
+
+ } else if ((token_ptr = strstr(getline_buffer, SLAPT_DISABLED_SOURCE_TOKEN)) != NULL) {
+ /* DISABLED SOURCE */
+
+ if (strlen(token_ptr) > strlen(SLAPT_DISABLED_SOURCE_TOKEN)) {
+ slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_DISABLED_SOURCE_TOKEN));
+ if (s != NULL) {
+ s->disabled = true;
+ slapt_add_source(global_config->sources, s);
+ }
+ }
+
+ } else if ((token_ptr = strstr(getline_buffer, SLAPT_WORKINGDIR_TOKEN)) != NULL) {
+ /* WORKING DIR */
+
+ if (strlen(token_ptr) > strlen(SLAPT_WORKINGDIR_TOKEN)) {
+ strncpy(
+ global_config->working_dir,
+ token_ptr + strlen(SLAPT_WORKINGDIR_TOKEN),
+ (strlen(token_ptr) - strlen(SLAPT_WORKINGDIR_TOKEN)));
+ global_config->working_dir[(strlen(token_ptr) - strlen(SLAPT_WORKINGDIR_TOKEN))] = '\0';
+ }
+
+ } else if ((token_ptr = strstr(getline_buffer, SLAPT_EXCLUDE_TOKEN)) != NULL) {
+ /* exclude list */
+ slapt_free_list(global_config->exclude_list);
+ global_config->exclude_list = parse_exclude(token_ptr);
}
- }
-
- } else if ( (token_ptr = strstr(getline_buffer,SLAPT_WORKINGDIR_TOKEN)) != NULL ) {
- /* WORKING DIR */
-
- if ( strlen(token_ptr) > strlen(SLAPT_WORKINGDIR_TOKEN) ) {
- strncpy(
- global_config->working_dir,
- token_ptr + strlen(SLAPT_WORKINGDIR_TOKEN),
- (strlen(token_ptr) - strlen(SLAPT_WORKINGDIR_TOKEN))
- );
- global_config->working_dir[
- (strlen(token_ptr) - strlen(SLAPT_WORKINGDIR_TOKEN))
- ] = '\0';
- }
-
- } else if ( (token_ptr = strstr(getline_buffer,SLAPT_EXCLUDE_TOKEN)) != NULL ) {
- /* exclude list */
- slapt_free_list(global_config->exclude_list);
- global_config->exclude_list = parse_exclude(token_ptr);
}
- }
-
- fclose(rc);
+ fclose(rc);
- if ( getline_buffer )
- free(getline_buffer);
+ if (getline_buffer)
+ free(getline_buffer);
- if ( strcmp(global_config->working_dir,"") == 0 ) {
- fprintf(stderr,gettext("WORKINGDIR directive not set within %s.\n"),
- file_name);
- return NULL;
- }
- if ( global_config->sources->count == 0 ) {
- fprintf(stderr,gettext("SOURCE directive not set within %s.\n"),file_name);
- return NULL;
- }
+ if (strcmp(global_config->working_dir, "") == 0) {
+ fprintf(stderr, gettext("WORKINGDIR directive not set within %s.\n"),
+ file_name);
+ return NULL;
+ }
+ if (global_config->sources->count == 0) {
+ fprintf(stderr, gettext("SOURCE directive not set within %s.\n"), file_name);
+ return NULL;
+ }
- return global_config;
+ return global_config;
}
void slapt_working_dir_init(const slapt_rc_config *global_config)
{
- DIR *working_dir;
- int mode = W_OK, r;
- char *cwd = NULL;
-
- if ( (working_dir = opendir(global_config->working_dir)) == NULL ) {
- cwd = getcwd (NULL, 0);
- if (cwd != NULL) {
- r = chdir ("/");
- if (r == 0)
- slapt_create_dir_structure (global_config->working_dir);
- r = chdir (cwd);
- free (cwd);
- } else {
- printf (gettext ("Failed to build working directory [%s]\n"),
- global_config->working_dir);
- exit (EXIT_FAILURE);
-
+ DIR *working_dir;
+ int mode = W_OK, r;
+ char *cwd = NULL;
+
+ if ((working_dir = opendir(global_config->working_dir)) == NULL) {
+ cwd = getcwd(NULL, 0);
+ if (cwd != NULL) {
+ r = chdir("/");
+ if (r == 0)
+ slapt_create_dir_structure(global_config->working_dir);
+ r = chdir(cwd);
+ free(cwd);
+ } else {
+ printf(gettext("Failed to build working directory [%s]\n"),
+ global_config->working_dir);
+ exit(EXIT_FAILURE);
+ }
}
- }
- if (working_dir != NULL)
- closedir(working_dir);
-
- /* allow read access if we are simulating */
- if (global_config->simulate)
- mode = R_OK;
+ if (working_dir != NULL)
+ closedir(working_dir);
- if ( access(global_config->working_dir,mode) == -1 ) {
+ /* allow read access if we are simulating */
+ if (global_config->simulate)
+ mode = R_OK;
- if ( errno )
- perror(global_config->working_dir);
+ if (access(global_config->working_dir, mode) == -1) {
+ if (errno)
+ perror(global_config->working_dir);
- fprintf(stderr,
- gettext("Please update permissions on %s or run with appropriate privileges\n"),
- global_config->working_dir);
- exit(EXIT_FAILURE);
- }
+ fprintf(stderr,
+ gettext("Please update permissions on %s or run with appropriate privileges\n"),
+ global_config->working_dir);
+ exit(EXIT_FAILURE);
+ }
- return;
+ return;
}
void slapt_free_rc_config(slapt_rc_config *global_config)
{
- slapt_free_list(global_config->exclude_list);
- slapt_free_source_list(global_config->sources);
- free(global_config);
+ slapt_free_list(global_config->exclude_list);
+ slapt_free_source_list(global_config->sources);
+ free(global_config);
}
static slapt_list_t *parse_exclude(char *line)
{
- /* skip ahead past the = */
- line = strchr(line,'=') + 1;
+ /* skip ahead past the = */
+ line = strchr(line, '=') + 1;
- return slapt_parse_delimited_list(line, ',');
+ return slapt_parse_delimited_list(line, ',');
}
slapt_source_list_t *slapt_init_source_list(void)
{
- slapt_source_list_t *list = slapt_malloc(sizeof *list);
- list->src = slapt_malloc(sizeof *list->src);
- list->count = 0;
+ slapt_source_list_t *list = slapt_malloc(sizeof *list);
+ list->src = slapt_malloc(sizeof *list->src);
+ list->count = 0;
- return list;
+ return list;
}
-void slapt_add_source(slapt_source_list_t *list,slapt_source_t *s)
+void slapt_add_source(slapt_source_list_t *list, slapt_source_t *s)
{
- slapt_source_t **realloc_tmp;
-
- if ( s == NULL )
- return;
+ slapt_source_t **realloc_tmp;
- realloc_tmp = realloc(list->src,sizeof *list->src * (list->count + 1) );
+ if (s == NULL)
+ return;
- if ( realloc_tmp == NULL )
- return;
+ realloc_tmp = realloc(list->src, sizeof *list->src * (list->count + 1));
- list->src = realloc_tmp;
+ if (realloc_tmp == NULL)
+ return;
- list->src[list->count] = s;
- ++list->count;
+ list->src = realloc_tmp;
+ list->src[list->count] = s;
+ ++list->count;
}
-void slapt_remove_source (slapt_source_list_t *list, const char *s)
+void slapt_remove_source(slapt_source_list_t *list, const char *s)
{
- slapt_source_t *src_to_discard = NULL;
- unsigned int i = 0;
+ slapt_source_t *src_to_discard = NULL;
+ unsigned int i = 0;
- while ( i < list->count ) {
- if ( strcmp(s,list->src[i]->url) == 0 && src_to_discard == NULL ) {
- src_to_discard = list->src[i];
- }
- if ( src_to_discard != NULL && (i+1 < list->count) ) {
- list->src[i] = list->src[i + 1];
+ while (i < list->count) {
+ if (strcmp(s, list->src[i]->url) == 0 && src_to_discard == NULL) {
+ src_to_discard = list->src[i];
+ }
+ if (src_to_discard != NULL && (i + 1 < list->count)) {
+ list->src[i] = list->src[i + 1];
+ }
+ ++i;
}
- ++i;
- }
- if ( src_to_discard != NULL ) {
- slapt_source_t **realloc_tmp;
- int count = list->count - 1;
+ if (src_to_discard != NULL) {
+ slapt_source_t **realloc_tmp;
+ int count = list->count - 1;
- if ( count < 1 )
- count = 1;
+ if (count < 1)
+ count = 1;
- slapt_free_source(src_to_discard);
+ slapt_free_source(src_to_discard);
- realloc_tmp = realloc(list->src,sizeof *list->src * count );
- if ( realloc_tmp != NULL ) {
- list->src = realloc_tmp;
- if (list->count > 0)
- --list->count;
+ realloc_tmp = realloc(list->src, sizeof *list->src * count);
+ if (realloc_tmp != NULL) {
+ list->src = realloc_tmp;
+ if (list->count > 0)
+ --list->count;
+ }
}
-
- }
-
}
void slapt_free_source_list(slapt_source_list_t *list)
{
- unsigned int i;
+ unsigned int i;
- for (i = 0; i < list->count; ++i) {
- slapt_free_source(list->src[i]);
- }
- free(list->src);
- free(list);
+ for (i = 0; i < list->count; ++i) {
+ slapt_free_source(list->src[i]);
+ }
+ free(list->src);
+ free(list);
}
bool slapt_is_interactive(const slapt_rc_config *global_config)
{
- bool interactive = global_config->progress_cb == NULL
- ? true
- : false;
+ bool interactive = global_config->progress_cb == NULL
+ ? true
+ : false;
- return interactive;
+ return interactive;
}
-
static void slapt_source_parse_attributes(slapt_source_t *s, const char *string)
{
- int offset = 0;
- int len = strlen(string);
-
- while (offset < len) {
- char *token = NULL;
-
- if (strchr(string + offset, ',') != NULL) {
- size_t token_len = strcspn(string + offset, ",");
- if (token_len > 0) {
- token = strndup(string + offset, token_len);
- offset += token_len + 1;
- }
- } else {
- token = strdup(string + offset);
- offset += len;
- }
+ int offset = 0;
+ int len = strlen(string);
+
+ while (offset < len) {
+ char *token = NULL;
+
+ if (strchr(string + offset, ',') != NULL) {
+ size_t token_len = strcspn(string + offset, ",");
+ if (token_len > 0) {
+ token = strndup(string + offset, token_len);
+ offset += token_len + 1;
+ }
+ } else {
+ token = strdup(string + offset);
+ offset += len;
+ }
- if (token != NULL) {
-
- if (strcmp(token,SLAPT_PRIORITY_DEFAULT_TOKEN) == 0) {
- s->priority = SLAPT_PRIORITY_DEFAULT;
- } else if (strcmp(token,SLAPT_PRIORITY_PREFERRED_TOKEN) == 0) {
- s->priority = SLAPT_PRIORITY_PREFERRED;
- } else if (strcmp(token,SLAPT_PRIORITY_OFFICIAL_TOKEN) == 0) {
- s->priority = SLAPT_PRIORITY_OFFICIAL;
- } else if (strcmp(token,SLAPT_PRIORITY_CUSTOM_TOKEN) == 0) {
- s->priority = SLAPT_PRIORITY_CUSTOM;
- } else {
- fprintf(stderr,"Unknown token: %s\n", token);
- }
-
- free(token);
+ if (token != NULL) {
+ if (strcmp(token, SLAPT_PRIORITY_DEFAULT_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_DEFAULT;
+ } else if (strcmp(token, SLAPT_PRIORITY_PREFERRED_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_PREFERRED;
+ } else if (strcmp(token, SLAPT_PRIORITY_OFFICIAL_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_OFFICIAL;
+ } else if (strcmp(token, SLAPT_PRIORITY_CUSTOM_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_CUSTOM;
+ } else {
+ fprintf(stderr, "Unknown token: %s\n", token);
+ }
+
+ free(token);
+ }
}
-
- }
-
}
slapt_source_t *slapt_init_source(const char *s)
{
- slapt_source_t *src;
- unsigned int source_len = 0;
- unsigned int attribute_len = 0;
- slapt_regex_t *attribute_regex = NULL;
- char *source_string = NULL;
- char *attribute_string = NULL;
-
- if (s == NULL)
- return NULL;
-
- src = slapt_malloc(sizeof *src);
- src->priority = SLAPT_PRIORITY_DEFAULT;
- src->disabled = false;
- source_string = slapt_strip_whitespace (s);
- source_len = strlen (source_string);
-
- /* parse for :[attr] in the source url */
- if ((attribute_regex = slapt_init_regex(SLAPT_SOURCE_ATTRIBUTE_REGEX)) == NULL) {
- exit(EXIT_FAILURE);
- }
- slapt_execute_regex(attribute_regex,source_string);
- if (attribute_regex->reg_return == 0) {
- /* if we find an attribute string, extract it */
- attribute_string = slapt_regex_extract_match(attribute_regex, source_string, 1);
- attribute_len = strlen(attribute_string);
- source_len -= attribute_len;
- }
- slapt_free_regex(attribute_regex);
-
-
- /* now add a trailing / if not already there */
- if ( source_string[source_len - 1] == '/' ) {
- src->url = strndup(source_string, source_len);
- } else {
- src->url = slapt_malloc(sizeof *src->url * (source_len + 2));
- src->url[0] = '\0';
-
- src->url = strncat(
- src->url,
- source_string,
- source_len
- );
-
- if (isblank(src->url[source_len - 1]) == 0) {
- src->url = strncat(src->url, "/", 1);
- } else {
- if (src->url[source_len - 2] == '/') {
- src->url[source_len - 2] = '/';
- src->url[source_len - 1] = '\0';
- } else {
- src->url[source_len - 1] = '/';
- }
+ slapt_source_t *src;
+ unsigned int source_len = 0;
+ unsigned int attribute_len = 0;
+ slapt_regex_t *attribute_regex = NULL;
+ char *source_string = NULL;
+ char *attribute_string = NULL;
+
+ if (s == NULL)
+ return NULL;
+
+ src = slapt_malloc(sizeof *src);
+ src->priority = SLAPT_PRIORITY_DEFAULT;
+ src->disabled = false;
+ source_string = slapt_strip_whitespace(s);
+ source_len = strlen(source_string);
+
+ /* parse for :[attr] in the source url */
+ if ((attribute_regex = slapt_init_regex(SLAPT_SOURCE_ATTRIBUTE_REGEX)) == NULL) {
+ exit(EXIT_FAILURE);
}
+ slapt_execute_regex(attribute_regex, source_string);
+ if (attribute_regex->reg_return == 0) {
+ /* if we find an attribute string, extract it */
+ attribute_string = slapt_regex_extract_match(attribute_regex, source_string, 1);
+ attribute_len = strlen(attribute_string);
+ source_len -= attribute_len;
+ }
+ slapt_free_regex(attribute_regex);
- src->url[source_len + 1] = '\0';
- }
+ /* now add a trailing / if not already there */
+ if (source_string[source_len - 1] == '/') {
+ src->url = strndup(source_string, source_len);
+ } else {
+ src->url = slapt_malloc(sizeof *src->url * (source_len + 2));
+ src->url[0] = '\0';
+
+ src->url = strncat(
+ src->url,
+ source_string,
+ source_len);
+
+ if (isblank(src->url[source_len - 1]) == 0) {
+ src->url = strncat(src->url, "/", 1);
+ } else {
+ if (src->url[source_len - 2] == '/') {
+ src->url[source_len - 2] = '/';
+ src->url[source_len - 1] = '\0';
+ } else {
+ src->url[source_len - 1] = '/';
+ }
+ }
+
+ src->url[source_len + 1] = '\0';
+ }
- free(source_string);
+ free(source_string);
- /* now parse the attribute string */
- if (attribute_string != NULL) {
- slapt_source_parse_attributes(src, attribute_string + 1);
- free(attribute_string);
- }
+ /* now parse the attribute string */
+ if (attribute_string != NULL) {
+ slapt_source_parse_attributes(src, attribute_string + 1);
+ free(attribute_string);
+ }
- return src;
+ return src;
}
void slapt_free_source(slapt_source_t *src)
{
- free(src->url);
- free(src);
+ free(src->url);
+ free(src);
}
int slapt_write_rc_config(const slapt_rc_config *global_config, const char *location)
{
- unsigned int i;
- FILE *rc;
+ unsigned int i;
+ FILE *rc;
- rc = slapt_open_file(location,"w+");
- if (rc == NULL)
- return -1;
+ rc = slapt_open_file(location, "w+");
+ if (rc == NULL)
+ return -1;
- fprintf(rc,"%s%s\n",SLAPT_WORKINGDIR_TOKEN,global_config->working_dir);
+ fprintf(rc, "%s%s\n", SLAPT_WORKINGDIR_TOKEN, global_config->working_dir);
- fprintf(rc,"%s",SLAPT_EXCLUDE_TOKEN);
- for (i = 0;i < global_config->exclude_list->count;++i) {
- if ( i+1 == global_config->exclude_list->count) {
- fprintf(rc,"%s",global_config->exclude_list->items[i]);
- }else{
- fprintf(rc,"%s,",global_config->exclude_list->items[i]);
+ fprintf(rc, "%s", SLAPT_EXCLUDE_TOKEN);
+ for (i = 0; i < global_config->exclude_list->count; ++i) {
+ if (i + 1 == global_config->exclude_list->count) {
+ fprintf(rc, "%s", global_config->exclude_list->items[i]);
+ } else {
+ fprintf(rc, "%s,", global_config->exclude_list->items[i]);
+ }
}
- }
- fprintf(rc,"\n");
-
- for (i = 0; i < global_config->sources->count;++i) {
- slapt_source_t *src = global_config->sources->src[i];
- SLAPT_PRIORITY_T priority = src->priority;
- const char *token = SLAPT_SOURCE_TOKEN;
-
- if (global_config->sources->src[i]->disabled == true)
- token = SLAPT_DISABLED_SOURCE_TOKEN;
-
- if (priority > SLAPT_PRIORITY_DEFAULT) {
- const char *priority_token;
-
- if (priority == SLAPT_PRIORITY_PREFERRED)
- priority_token = SLAPT_PRIORITY_PREFERRED_TOKEN;
- else if (priority == SLAPT_PRIORITY_OFFICIAL)
- priority_token = SLAPT_PRIORITY_OFFICIAL_TOKEN;
- else if (priority == SLAPT_PRIORITY_CUSTOM)
- priority_token = SLAPT_PRIORITY_CUSTOM_TOKEN;
- else
- priority_token = SLAPT_PRIORITY_DEFAULT_TOKEN;
-
- fprintf(rc,"%s%s:%s\n",token, src->url, priority_token);
- } else {
- fprintf(rc,"%s%s\n",token, src->url);
+ fprintf(rc, "\n");
+
+ for (i = 0; i < global_config->sources->count; ++i) {
+ slapt_source_t *src = global_config->sources->src[i];
+ SLAPT_PRIORITY_T priority = src->priority;
+ const char *token = SLAPT_SOURCE_TOKEN;
+
+ if (global_config->sources->src[i]->disabled == true)
+ token = SLAPT_DISABLED_SOURCE_TOKEN;
+
+ if (priority > SLAPT_PRIORITY_DEFAULT) {
+ const char *priority_token;
+
+ if (priority == SLAPT_PRIORITY_PREFERRED)
+ priority_token = SLAPT_PRIORITY_PREFERRED_TOKEN;
+ else if (priority == SLAPT_PRIORITY_OFFICIAL)
+ priority_token = SLAPT_PRIORITY_OFFICIAL_TOKEN;
+ else if (priority == SLAPT_PRIORITY_CUSTOM)
+ priority_token = SLAPT_PRIORITY_CUSTOM_TOKEN;
+ else
+ priority_token = SLAPT_PRIORITY_DEFAULT_TOKEN;
+
+ fprintf(rc, "%s%s:%s\n", token, src->url, priority_token);
+ } else {
+ fprintf(rc, "%s%s\n", token, src->url);
+ }
}
- }
- fclose(rc);
+ fclose(rc);
- return 0;
+ return 0;
}
-
diff --git a/src/configuration.h b/src/configuration.h
index 0a00ff1..c5fb74f 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -24,38 +24,38 @@
#define SLAPT_SOURCE_ATTRIBUTE_REGEX "(:[A-Z_,]+)$"
typedef struct {
- char *url;
- SLAPT_PRIORITY_T priority;
- bool disabled;
+ char *url;
+ SLAPT_PRIORITY_T priority;
+ bool disabled;
} slapt_source_t;
typedef struct {
- slapt_source_t **src;
- unsigned int count;
+ slapt_source_t **src;
+ unsigned int count;
} slapt_source_list_t;
typedef struct {
- char working_dir[SLAPT_WORKINGDIR_TOKEN_LEN];
- slapt_source_list_t *sources;
- slapt_list_t *exclude_list;
- int(*progress_cb)(void *,double,double,double,double);
- bool download_only;
- bool dist_upgrade;
- bool simulate;
- bool no_prompt;
- bool prompt;
- bool re_install;
- bool ignore_excludes;
- bool no_md5_check;
- bool ignore_dep;
- bool disable_dep_check;
- bool print_uris;
- bool dl_stats;
- bool remove_obsolete;
- bool no_upgrade;
- unsigned int retry;
- bool use_priority;
- bool gpgme_allow_unauth;
+ char working_dir[SLAPT_WORKINGDIR_TOKEN_LEN];
+ slapt_source_list_t *sources;
+ slapt_list_t *exclude_list;
+ int (*progress_cb)(void *, double, double, double, double);
+ bool download_only;
+ bool dist_upgrade;
+ bool simulate;
+ bool no_prompt;
+ bool prompt;
+ bool re_install;
+ bool ignore_excludes;
+ bool no_md5_check;
+ bool ignore_dep;
+ bool disable_dep_check;
+ bool print_uris;
+ bool dl_stats;
+ bool remove_obsolete;
+ bool no_upgrade;
+ unsigned int retry;
+ bool use_priority;
+ bool gpgme_allow_unauth;
} slapt_rc_config;
/* initialize slapt_rc_config */
@@ -78,7 +78,7 @@ void slapt_free_source(slapt_source_t *src);
*/
slapt_source_list_t *slapt_init_source_list(void);
void slapt_add_source(slapt_source_list_t *list, slapt_source_t *s);
-void slapt_remove_source (slapt_source_list_t *list, const char *s);
+void slapt_remove_source(slapt_source_list_t *list, const char *s);
void slapt_free_source_list(slapt_source_list_t *list);
bool slapt_is_interactive(const slapt_rc_config *);
diff --git a/src/curl.c b/src/curl.c
index 9ab0a0a..5b2c267 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -21,487 +21,472 @@ static size_t write_header_callback(void *buffer,
size_t size, size_t nmemb, void *userp);
struct head_data_t {
- char *data;
- size_t size;
+ char *data;
+ size_t size;
};
-int slapt_download_data(FILE *fh,const char *url,size_t bytes,long *filetime,
- const slapt_rc_config *global_config)
+int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime,
+ const slapt_rc_config *global_config)
{
- CURL *ch = NULL;
- CURLcode response;
- int return_code = 0;
- struct curl_slist *headers = NULL;
- struct slapt_progress_data *cb_data = slapt_init_progress_data();
- cb_data->bytes = bytes;
-
- ch = curl_easy_init();
- curl_easy_setopt(ch, CURLOPT_URL, url);
- curl_easy_setopt(ch, CURLOPT_WRITEDATA, fh);
- curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 0);
- curl_easy_setopt(ch, CURLOPT_USERAGENT, PACKAGE);
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV, 0);
+ CURL *ch = NULL;
+ CURLcode response;
+ int return_code = 0;
+ struct curl_slist *headers = NULL;
+ struct slapt_progress_data *cb_data = slapt_init_progress_data();
+ cb_data->bytes = bytes;
+
+ ch = curl_easy_init();
+ curl_easy_setopt(ch, CURLOPT_URL, url);
+ curl_easy_setopt(ch, CURLOPT_WRITEDATA, fh);
+ curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 0);
+ curl_easy_setopt(ch, CURLOPT_USERAGENT, PACKAGE);
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV, 0);
/* this is a check for slack 9.0's curl libs */
#ifdef CURLOPT_FTP_USE_EPRT
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
#endif
- curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
#ifdef CURLOPT_HTTPAUTH
- curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
+ curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
#endif
#ifdef CURLFTPMETHOD_NOCWD
- curl_easy_setopt(ch, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
+ curl_easy_setopt(ch, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
#endif
- curl_easy_setopt(ch, CURLOPT_FILETIME, 1);
- curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1);
-
- /* ugh, if someone wants to do this */
- if (getenv(SLAPT_NO_SSL_VERIFYPEER))
- curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 0);
-
- headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
-
- if (global_config->dl_stats != true) {
- if (global_config->progress_cb == NULL) {
- curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, slapt_progress_callback );
- } else {
- curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION,
- global_config->progress_cb );
+ curl_easy_setopt(ch, CURLOPT_FILETIME, 1);
+ curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1);
+
+ /* ugh, if someone wants to do this */
+ if (getenv(SLAPT_NO_SSL_VERIFYPEER))
+ curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 0);
+
+ headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
+
+ if (global_config->dl_stats != true) {
+ if (global_config->progress_cb == NULL) {
+ curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, slapt_progress_callback);
+ } else {
+ curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION,
+ global_config->progress_cb);
+ }
+ curl_easy_setopt(ch, CURLOPT_PROGRESSDATA, cb_data);
}
- curl_easy_setopt(ch, CURLOPT_PROGRESSDATA, cb_data);
- }
- /* resume */
- if (bytes > 0) {
- fseek(fh,0,SEEK_END);
- curl_easy_setopt(ch, CURLOPT_RESUME_FROM, bytes);
- }
+ /* resume */
+ if (bytes > 0) {
+ fseek(fh, 0, SEEK_END);
+ curl_easy_setopt(ch, CURLOPT_RESUME_FROM, bytes);
+ }
- if ((response = curl_easy_perform(ch)) != CURLE_OK) {
- return_code = response;
- }
+ if ((response = curl_easy_perform(ch)) != CURLE_OK) {
+ return_code = response;
+ }
- if ( filetime != NULL )
- curl_easy_getinfo(ch, CURLINFO_FILETIME, filetime);
+ if (filetime != NULL)
+ curl_easy_getinfo(ch, CURLINFO_FILETIME, filetime);
- /*
+ /*
* need to use curl_easy_cleanup() so that we don't
* have tons of open connections, getting rejected
* by ftp servers for being naughty.
*/
- curl_easy_cleanup(ch);
- /* can't do a curl_free() after curl_easy_cleanup() */
- /* curl_free(ch); */
- curl_slist_free_all(headers);
- slapt_free_progress_data(cb_data);
+ curl_easy_cleanup(ch);
+ /* can't do a curl_free() after curl_easy_cleanup() */
+ /* curl_free(ch); */
+ curl_slist_free_all(headers);
+ slapt_free_progress_data(cb_data);
- return return_code;
+ return return_code;
}
static size_t write_header_callback(void *buffer, size_t size,
size_t nmemb, void *userp)
{
- char *tmp;
- register int a_size = size * nmemb;
- struct head_data_t *head_t = (struct head_data_t *)userp;
-
- tmp = (char *)realloc( head_t->data, head_t->size + a_size + 1);
- if (tmp != NULL) {
- head_t->data = tmp;
- memcpy(&(head_t->data[head_t->size]),buffer,a_size);
- head_t->size += a_size;
- head_t->data[head_t->size] = '\0';
- }
-
- return nmemb;
+ char *tmp;
+ register int a_size = size * nmemb;
+ struct head_data_t *head_t = (struct head_data_t *)userp;
+
+ tmp = (char *)realloc(head_t->data, head_t->size + a_size + 1);
+ if (tmp != NULL) {
+ head_t->data = tmp;
+ memcpy(&(head_t->data[head_t->size]), buffer, a_size);
+ head_t->size += a_size;
+ head_t->data[head_t->size] = '\0';
+ }
+
+ return nmemb;
}
char *slapt_head_request(const char *url)
{
- CURL *ch = NULL;
- CURLcode response;
- struct head_data_t head_t;
- struct curl_slist *headers = NULL;
-
- head_t.data = slapt_malloc( sizeof *head_t.data );
- head_t.size = 0;
-
- ch = curl_easy_init();
- curl_easy_setopt(ch, CURLOPT_URL, url);
- curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, write_header_callback);
- curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1);
- curl_easy_setopt(ch, CURLOPT_USERAGENT, PACKAGE );
- curl_easy_setopt(ch, CURLOPT_FILE, &head_t);
- curl_easy_setopt(ch, CURLOPT_HEADER, 1);
- curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV , 0);
+ CURL *ch = NULL;
+ CURLcode response;
+ struct head_data_t head_t;
+ struct curl_slist *headers = NULL;
+
+ head_t.data = slapt_malloc(sizeof *head_t.data);
+ head_t.size = 0;
+
+ ch = curl_easy_init();
+ curl_easy_setopt(ch, CURLOPT_URL, url);
+ curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, write_header_callback);
+ curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1);
+ curl_easy_setopt(ch, CURLOPT_USERAGENT, PACKAGE);
+ curl_easy_setopt(ch, CURLOPT_FILE, &head_t);
+ curl_easy_setopt(ch, CURLOPT_HEADER, 1);
+ curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV, 0);
/* this is a check for slack 9.0's curl libs */
#ifdef CURLOPT_FTP_USE_EPRT
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
#endif
- curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
#ifdef CURLOPT_HTTPAUTH
- curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
+ curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
#endif
#ifdef CURLFTPMETHOD_NOCWD
- curl_easy_setopt(ch, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
+ curl_easy_setopt(ch, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
#endif
- curl_easy_setopt(ch, CURLOPT_FILETIME, 1 );
- curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1 );
+ curl_easy_setopt(ch, CURLOPT_FILETIME, 1);
+ curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1);
- headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
+ headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
+
+ if ((response = curl_easy_perform(ch)) != 0) {
+ free(head_t.data);
+ curl_easy_cleanup(ch);
+ curl_slist_free_all(headers);
+ return NULL;
+ }
- if ((response = curl_easy_perform(ch)) != 0) {
- free(head_t.data);
curl_easy_cleanup(ch);
curl_slist_free_all(headers);
- return NULL;
- }
-
- curl_easy_cleanup(ch);
- curl_slist_free_all(headers);
- return head_t.data;
-
+ return head_t.data;
}
const char *slapt_get_mirror_data_from_source(FILE *fh,
- const slapt_rc_config *global_config,
- const char *base_url,
- const char *filename)
+ const slapt_rc_config *global_config,
+ const char *base_url,
+ const char *filename)
{
- int return_code = 0;
- char *url = NULL;
-
- url = slapt_calloc(
- strlen(base_url) + strlen(filename) + 1, sizeof *url
- );
-
- strncpy(url,base_url,strlen(base_url) );
- url[ strlen(base_url) ] = '\0';
- strncat(url,filename,strlen(filename) );
-
- return_code = slapt_download_data(fh,url,0,NULL,global_config);
-
- free(url);
- /* make sure we are back at the front of the file */
- /* DISABLED */
- /* rewind(fh); */
- return return_code != 0
- ? curl_easy_strerror(return_code)
- : NULL;
+ int return_code = 0;
+ char *url = NULL;
+
+ url = slapt_calloc(
+ strlen(base_url) + strlen(filename) + 1, sizeof *url);
+
+ strncpy(url, base_url, strlen(base_url));
+ url[strlen(base_url)] = '\0';
+ strncat(url, filename, strlen(filename));
+
+ return_code = slapt_download_data(fh, url, 0, NULL, global_config);
+
+ free(url);
+ /* make sure we are back at the front of the file */
+ /* DISABLED */
+ /* rewind(fh); */
+ return return_code != 0
+ ? curl_easy_strerror(return_code)
+ : NULL;
}
const char *slapt_download_pkg(const slapt_rc_config *global_config,
slapt_pkg_info_t *pkg, const char *note)
{
- FILE *fh = NULL;
- char *file_name = NULL;
- char *url = NULL;
- size_t f_size = 0;
- slapt_code_t verify = SLAPT_OK;
- int dl_return = -1, dl_total_size = 0;
- bool is_interactive = slapt_is_interactive(global_config);
- long filetime = 0;
-
- if (pkg == NULL) {
- fprintf(stderr,"slapt_download_pkg() called without a package!\n");
- exit(EXIT_FAILURE);
- }
-
- if (slapt_verify_downloaded_pkg(global_config,pkg) == SLAPT_OK)
- return NULL;
-
- if (pkg->mirror == NULL || strlen(pkg->mirror) == 0) {
- fprintf(stderr,"slapt_download_pkg() called with a package that does not have a mirror!\n");
- exit(EXIT_FAILURE);
- }
-
- /* chdir(global_config->working_dir); */ /* just in case */
- slapt_create_dir_structure(pkg->location);
-
- /* build the url, file name, and get the file size if the file is present */
- url = slapt_gen_pkg_url(pkg);
- file_name = slapt_gen_pkg_file_name(global_config,pkg);
- f_size = slapt_get_pkg_file_size(global_config,pkg);
- dl_total_size = pkg->size_c - (f_size/1024);
-
- /* if file on disk is larger than the supposed size, unlink it */
- if (dl_total_size < 0) {
- if (unlink(file_name) == -1) {
- fprintf(stderr,gettext("Failed to unlink %s\n"),file_name);
-
- if (errno)
- perror(file_name);
-
- exit(EXIT_FAILURE);
+ FILE *fh = NULL;
+ char *file_name = NULL;
+ char *url = NULL;
+ size_t f_size = 0;
+ slapt_code_t verify = SLAPT_OK;
+ int dl_return = -1, dl_total_size = 0;
+ bool is_interactive = slapt_is_interactive(global_config);
+ long filetime = 0;
+
+ if (pkg == NULL) {
+ fprintf(stderr, "slapt_download_pkg() called without a package!\n");
+ exit(EXIT_FAILURE);
}
- dl_total_size = pkg->size_c;
- f_size = 0;
- }
-
- if (global_config->progress_cb == NULL) {
-
- if (note != NULL)
- printf("%s ", note);
-
- printf(gettext("Get %s %s %s [%.1f%s]..."),
- pkg->mirror,pkg->name,pkg->version,
- ( dl_total_size > 1024 ) ? dl_total_size / 1024.0 : dl_total_size,
- ( dl_total_size > 1024 ) ? "MB" : "kB"
- );
- if (global_config->dl_stats == true)
- printf("\n");
- }
-
- /* open the file to write, append if already present */
- fh = slapt_open_file(file_name,"a+b");
- if (fh == NULL) {
- exit(EXIT_FAILURE);
- }
-
- /* download the file to our file handle */
- dl_return = slapt_download_data(fh,url,f_size,&filetime,global_config);
- if (dl_return == 0) {
-
- if (is_interactive)
- printf(gettext("Done\n"));
-
- } else if (dl_return == CURLE_HTTP_RANGE_ERROR ||
- dl_return == CURLE_FTP_BAD_DOWNLOAD_RESUME ||
- dl_return == CURLE_PARTIAL_FILE) {
- /*
- * this is for errors trying to resume. unlink the file and
- * try again.
- */
- printf("\r");
- fclose(fh);
- if (unlink(file_name) == -1) {
- fprintf(stderr,gettext("Failed to unlink %s\n"),file_name);
+ if (slapt_verify_downloaded_pkg(global_config, pkg) == SLAPT_OK)
+ return NULL;
- if (errno)
- perror(file_name);
-
- exit(EXIT_FAILURE);
+ if (pkg->mirror == NULL || strlen(pkg->mirror) == 0) {
+ fprintf(stderr, "slapt_download_pkg() called with a package that does not have a mirror!\n");
+ exit(EXIT_FAILURE);
}
- free(file_name);
- free(url);
+ /* chdir(global_config->working_dir); */ /* just in case */
+ slapt_create_dir_structure(pkg->location);
- /* if we set retry, make sure this counts as a retry */
- if (global_config->retry > 1)
- return curl_easy_strerror(dl_return);
- else
- return slapt_download_pkg(global_config,pkg, note);
+ /* build the url, file name, and get the file size if the file is present */
+ url = slapt_gen_pkg_url(pkg);
+ file_name = slapt_gen_pkg_file_name(global_config, pkg);
+ f_size = slapt_get_pkg_file_size(global_config, pkg);
+ dl_total_size = pkg->size_c - (f_size / 1024);
- } else {
- fclose(fh);
- #if SLAPT_DO_NOT_UNLINK_BAD_FILES == 0
- /* if the d/l fails, unlink the empty file */
- if (unlink(file_name) == -1) {
- fprintf(stderr,gettext("Failed to unlink %s\n"),file_name);
+ /* if file on disk is larger than the supposed size, unlink it */
+ if (dl_total_size < 0) {
+ if (unlink(file_name) == -1) {
+ fprintf(stderr, gettext("Failed to unlink %s\n"), file_name);
- if (errno)
- perror(file_name);
+ if (errno)
+ perror(file_name);
+ exit(EXIT_FAILURE);
+ }
+ dl_total_size = pkg->size_c;
+ f_size = 0;
}
- #endif
- free(url);
- free(file_name);
- return curl_easy_strerror(dl_return);
+ if (global_config->progress_cb == NULL) {
+ if (note != NULL)
+ printf("%s ", note);
+
+ printf(gettext("Get %s %s %s [%.1f%s]..."),
+ pkg->mirror, pkg->name, pkg->version,
+ (dl_total_size > 1024) ? dl_total_size / 1024.0 : dl_total_size,
+ (dl_total_size > 1024) ? "MB" : "kB");
+ if (global_config->dl_stats == true)
+ printf("\n");
+ }
+
+ /* open the file to write, append if already present */
+ fh = slapt_open_file(file_name, "a+b");
+ if (fh == NULL) {
+ exit(EXIT_FAILURE);
+ }
- }
+ /* download the file to our file handle */
+ dl_return = slapt_download_data(fh, url, f_size, &filetime, global_config);
+ if (dl_return == 0) {
+ if (is_interactive)
+ printf(gettext("Done\n"));
- fclose(fh);
- free(url);
+ } else if (dl_return == CURLE_HTTP_RANGE_ERROR ||
+ dl_return == CURLE_FTP_BAD_DOWNLOAD_RESUME ||
+ dl_return == CURLE_PARTIAL_FILE) {
+ /*
+ * this is for errors trying to resume. unlink the file and
+ * try again.
+ */
+ printf("\r");
+ fclose(fh);
- /* preserve the file access and modification time */
- if ( filetime > 0 ) {
- struct utimbuf times;
- times.actime = (time_t)filetime;
- times.modtime = (time_t)filetime;
- utime(file_name, &times); /* set the time we got */
- }
+ if (unlink(file_name) == -1) {
+ fprintf(stderr, gettext("Failed to unlink %s\n"), file_name);
- /* check to make sure we have the complete file */
- verify = slapt_verify_downloaded_pkg(global_config,pkg);
- if (verify == SLAPT_OK) {
+ if (errno)
+ perror(file_name);
- free(file_name);
- return NULL;
+ exit(EXIT_FAILURE);
+ }
- } else {
+ free(file_name);
+ free(url);
- #if SLAPT_DO_NOT_UNLINK_BAD_FILES == 0
- /* if the checksum fails, unlink the bogus file */
- if (unlink(file_name) == -1) {
- fprintf(stderr,gettext("Failed to unlink %s\n"),file_name);
+ /* if we set retry, make sure this counts as a retry */
+ if (global_config->retry > 1)
+ return curl_easy_strerror(dl_return);
+ else
+ return slapt_download_pkg(global_config, pkg, note);
- if (errno)
- perror("unlink");
+ } else {
+ fclose(fh);
+#if SLAPT_DO_NOT_UNLINK_BAD_FILES == 0
+ /* if the d/l fails, unlink the empty file */
+ if (unlink(file_name) == -1) {
+ fprintf(stderr, gettext("Failed to unlink %s\n"), file_name);
+
+ if (errno)
+ perror(file_name);
+ }
+#endif
+ free(url);
+ free(file_name);
+ return curl_easy_strerror(dl_return);
}
- #endif
- free(file_name);
- return slapt_strerror(verify);
- }
+ fclose(fh);
+ free(url);
+
+ /* preserve the file access and modification time */
+ if (filetime > 0) {
+ struct utimbuf times;
+ times.actime = (time_t)filetime;
+ times.modtime = (time_t)filetime;
+ utime(file_name, &times); /* set the time we got */
+ }
+
+ /* check to make sure we have the complete file */
+ verify = slapt_verify_downloaded_pkg(global_config, pkg);
+ if (verify == SLAPT_OK) {
+ free(file_name);
+ return NULL;
+
+ } else {
+#if SLAPT_DO_NOT_UNLINK_BAD_FILES == 0
+ /* if the checksum fails, unlink the bogus file */
+ if (unlink(file_name) == -1) {
+ fprintf(stderr, gettext("Failed to unlink %s\n"), file_name);
+
+ if (errno)
+ perror("unlink");
+ }
+#endif
+ free(file_name);
+ return slapt_strerror(verify);
+ }
}
int slapt_progress_callback(void *clientp, double dltotal, double dlnow,
- double ultotal, double ulnow)
+ double ultotal, double ulnow)
{
- size_t percent = 0;
- struct slapt_progress_data *cb_data = (struct slapt_progress_data *)clientp;
- size_t bytes = cb_data->bytes;
- (void) ultotal;
- (void) ulnow;
-
- if ((dltotal + bytes) == 0) {
- percent = 0;
- } else {
- percent = ((bytes + dlnow)*100)/(dltotal + bytes);
- }
- printf("%3d%%\b\b\b\b",(int)percent);
- return 0;
+ size_t percent = 0;
+ struct slapt_progress_data *cb_data = (struct slapt_progress_data *)clientp;
+ size_t bytes = cb_data->bytes;
+ (void)ultotal;
+ (void)ulnow;
+
+ if ((dltotal + bytes) == 0) {
+ percent = 0;
+ } else {
+ percent = ((bytes + dlnow) * 100) / (dltotal + bytes);
+ }
+ printf("%3d%%\b\b\b\b", (int)percent);
+ return 0;
}
void slapt_write_head_cache(const char *cache, const char *cache_filename)
{
- char *head_filename;
- FILE *tmp;
+ char *head_filename;
+ FILE *tmp;
- head_filename = slapt_gen_head_cache_filename(cache_filename);
+ head_filename = slapt_gen_head_cache_filename(cache_filename);
- /* store the last modified date */
- if ((tmp = slapt_open_file(head_filename,"w")) == NULL)
- exit(EXIT_FAILURE);
+ /* store the last modified date */
+ if ((tmp = slapt_open_file(head_filename, "w")) == NULL)
+ exit(EXIT_FAILURE);
- fprintf(tmp,"%s",cache);
- fclose(tmp);
-
- free(head_filename);
+ fprintf(tmp, "%s", cache);
+ fclose(tmp);
+ free(head_filename);
}
char *slapt_read_head_cache(const char *cache_filename)
{
- char *head_filename;
- FILE *tmp;
- char *getline_buffer = NULL;
- size_t gl_n;
- ssize_t gl_return_size;
+ char *head_filename;
+ FILE *tmp;
+ char *getline_buffer = NULL;
+ size_t gl_n;
+ ssize_t gl_return_size;
- head_filename = slapt_gen_head_cache_filename(cache_filename);
+ head_filename = slapt_gen_head_cache_filename(cache_filename);
- tmp = slapt_open_file(head_filename,"a+");
- free(head_filename);
+ tmp = slapt_open_file(head_filename, "a+");
+ free(head_filename);
- if (tmp == NULL)
- exit(EXIT_FAILURE);
+ if (tmp == NULL)
+ exit(EXIT_FAILURE);
- rewind(tmp);
- gl_return_size = getline(&getline_buffer, &gl_n, tmp);
- fclose(tmp);
+ rewind(tmp);
+ gl_return_size = getline(&getline_buffer, &gl_n, tmp);
+ fclose(tmp);
- if (gl_return_size == -1) {
- free(getline_buffer);
- return NULL;
- }
+ if (gl_return_size == -1) {
+ free(getline_buffer);
+ return NULL;
+ }
- return getline_buffer;
+ return getline_buffer;
}
char *slapt_gen_head_cache_filename(const char *filename_from_url)
{
- char *head_filename;
+ char *head_filename;
- head_filename = slapt_calloc(
- strlen(filename_from_url) + strlen(SLAPT_HEAD_FILE_EXT) + 1,
- sizeof *head_filename
- );
- strncat(head_filename,filename_from_url,strlen(filename_from_url));
- strncat(head_filename,SLAPT_HEAD_FILE_EXT,strlen(SLAPT_HEAD_FILE_EXT));
+ head_filename = slapt_calloc(
+ strlen(filename_from_url) + strlen(SLAPT_HEAD_FILE_EXT) + 1,
+ sizeof *head_filename);
+ strncat(head_filename, filename_from_url, strlen(filename_from_url));
+ strncat(head_filename, SLAPT_HEAD_FILE_EXT, strlen(SLAPT_HEAD_FILE_EXT));
- return head_filename;
+ return head_filename;
}
void slapt_clear_head_cache(const char *cache_filename)
{
- char *head_filename;
- FILE *tmp;
+ char *head_filename;
+ FILE *tmp;
- head_filename = slapt_gen_head_cache_filename(cache_filename);
+ head_filename = slapt_gen_head_cache_filename(cache_filename);
- tmp = slapt_open_file(head_filename,"w");
+ tmp = slapt_open_file(head_filename, "w");
- if (tmp == NULL)
- exit(EXIT_FAILURE);
-
- fclose(tmp);
- free(head_filename);
+ if (tmp == NULL)
+ exit(EXIT_FAILURE);
+ fclose(tmp);
+ free(head_filename);
}
/* do a head request on the mirror data to find out if it's new */
-char *slapt_head_mirror_data(const char *wurl,const char *file)
+char *slapt_head_mirror_data(const char *wurl, const char *file)
{
- char *request_header = NULL;
- char *request_header_ptr = NULL;
- char *delim_ptr = NULL;
- char *head_data = NULL;
- int request_header_len = 0;
- char *url;
-
- /* build url */
- url = slapt_calloc(strlen(wurl) + strlen(file) + 1, sizeof *url);
- url[0] = '\0';
- strncat(url,wurl,strlen(wurl));
- strncat(url,file,strlen(file));
-
- /* retrieve the header info */
- head_data = slapt_head_request(url);
- free(url);
- if (head_data == NULL) {
- return NULL;
- }
-
- /* extract the last modified date for storage and later comparison */
- request_header_ptr = strstr(head_data,"Last-Modified");
- if (request_header_ptr == NULL) {
- /* this is ftp, in which case the Content-Length will have to do */
- request_header_ptr = strstr(head_data,"Content-Length");
- if (request_header_ptr == NULL || strstr(wurl,"ftp") == NULL) {
- free(head_data);
- return NULL;
- }/* give up finally */
- }
- delim_ptr = strpbrk(request_header_ptr,"\r\n");
- if (delim_ptr == NULL) {
- free(head_data);
- return NULL;
- }
+ char *request_header = NULL;
+ char *request_header_ptr = NULL;
+ char *delim_ptr = NULL;
+ char *head_data = NULL;
+ int request_header_len = 0;
+ char *url;
+
+ /* build url */
+ url = slapt_calloc(strlen(wurl) + strlen(file) + 1, sizeof *url);
+ url[0] = '\0';
+ strncat(url, wurl, strlen(wurl));
+ strncat(url, file, strlen(file));
+
+ /* retrieve the header info */
+ head_data = slapt_head_request(url);
+ free(url);
+ if (head_data == NULL) {
+ return NULL;
+ }
- request_header_len = strlen(request_header_ptr) - strlen(delim_ptr);
- request_header = slapt_calloc(request_header_len + 1, sizeof *request_header);
- memcpy(request_header,request_header_ptr,request_header_len);
+ /* extract the last modified date for storage and later comparison */
+ request_header_ptr = strstr(head_data, "Last-Modified");
+ if (request_header_ptr == NULL) {
+ /* this is ftp, in which case the Content-Length will have to do */
+ request_header_ptr = strstr(head_data, "Content-Length");
+ if (request_header_ptr == NULL || strstr(wurl, "ftp") == NULL) {
+ free(head_data);
+ return NULL;
+ } /* give up finally */
+ }
+ delim_ptr = strpbrk(request_header_ptr, "\r\n");
+ if (delim_ptr == NULL) {
+ free(head_data);
+ return NULL;
+ }
- free(head_data);
- return request_header;
+ request_header_len = strlen(request_header_ptr) - strlen(delim_ptr);
+ request_header = slapt_calloc(request_header_len + 1, sizeof *request_header);
+ memcpy(request_header, request_header_ptr, request_header_len);
+
+ free(head_data);
+ return request_header;
}
struct slapt_progress_data *slapt_init_progress_data(void)
{
- struct slapt_progress_data *d = malloc( sizeof *d );
- d->bytes = 0;
- d->start = time(NULL);
- return d;
+ struct slapt_progress_data *d = malloc(sizeof *d);
+ d->bytes = 0;
+ d->start = time(NULL);
+ return d;
}
void slapt_free_progress_data(struct slapt_progress_data *d)
{
- free(d);
+ free(d);
}
-
diff --git a/src/curl.h b/src/curl.h
index 8936530..6f6bfe8 100644
--- a/src/curl.h
+++ b/src/curl.h
@@ -23,7 +23,7 @@
returns curl code
*/
int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime,
- const slapt_rc_config *global_config);
+ const slapt_rc_config *global_config);
/*
retrieves the head data for the url, returns (char *) or NULL on error
@@ -49,13 +49,13 @@ const char *slapt_download_pkg(const slapt_rc_config *global_config,
this is the default progress callback if global_config->progress_cb == NULL
*/
int slapt_progress_callback(void *clientp, double dltotal, double dlnow,
- double ultotal, double ulnow);
+ double ultotal, double ulnow);
/*
do a head request on the mirror data to find out if it's new
returns (char *) or NULL
*/
-char *slapt_head_mirror_data(const char *wurl,const char *file);
+char *slapt_head_mirror_data(const char *wurl, const char *file);
/*
clear head cache storage file
*/
@@ -70,12 +70,10 @@ void slapt_write_head_cache(const char *cache, const char *cache_filename);
*/
char *slapt_read_head_cache(const char *cache_filename);
-struct slapt_progress_data
-{
- size_t bytes;
- time_t start;
+struct slapt_progress_data {
+ size_t bytes;
+ time_t start;
};
struct slapt_progress_data *slapt_init_progress_data(void);
void slapt_free_progress_data(struct slapt_progress_data *d);
-
diff --git a/src/gpgme.c b/src/gpgme.c
index 3ffd285..89c9510 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -20,318 +20,307 @@
static gpgme_ctx_t *_slapt_init_gpgme_ctx(void)
{
- gpgme_error_t e;
- gpgme_ctx_t *ctx = slapt_malloc(sizeof *ctx);
+ gpgme_error_t e;
+ gpgme_ctx_t *ctx = slapt_malloc(sizeof *ctx);
+
+ e = gpgme_new(ctx);
+ if (e != GPG_ERR_NO_ERROR) {
+ fprintf(stderr, "GPGME: %s\n", gpgme_strerror(e));
+ free(ctx);
+ return NULL;
+ }
- e = gpgme_new(ctx);
- if (e != GPG_ERR_NO_ERROR)
- {
- fprintf (stderr, "GPGME: %s\n", gpgme_strerror (e));
- free(ctx);
- return NULL;
- }
-
- e = gpgme_set_protocol (*ctx, GPGME_PROTOCOL_OpenPGP);
- if (e != GPG_ERR_NO_ERROR)
- {
- fprintf (stderr, "GPGME: %s\n", gpgme_strerror (e));
- gpgme_release (*ctx);
- free(ctx);
- return NULL;
- }
+ e = gpgme_set_protocol(*ctx, GPGME_PROTOCOL_OpenPGP);
+ if (e != GPG_ERR_NO_ERROR) {
+ fprintf(stderr, "GPGME: %s\n", gpgme_strerror(e));
+ gpgme_release(*ctx);
+ free(ctx);
+ return NULL;
+ }
- gpgme_set_armor (*ctx, 1);
+ gpgme_set_armor(*ctx, 1);
- return ctx;
+ return ctx;
}
static void _slapt_free_gpgme_ctx(gpgme_ctx_t *ctx)
{
- gpgme_release(*ctx);
- free(ctx);
+ gpgme_release(*ctx);
+ free(ctx);
}
-
-FILE *slapt_get_pkg_source_checksums_signature (const slapt_rc_config *global_config,
- const char *url,
- unsigned int *compressed)
+FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_config,
+ const char *url,
+ unsigned int *compressed)
{
- FILE *tmp_checksum_f = NULL;
- char *checksum_head = NULL;
- bool interactive = slapt_is_interactive(global_config);
- char *location_uncompressed = SLAPT_CHECKSUM_ASC_FILE;
- char *location_compressed = SLAPT_CHECKSUM_ASC_FILE_GZ;
- char *filename = NULL;
- char *local_head = NULL;
- char *location;
- int checksums_compressed = *compressed;
-
- if (checksums_compressed == 1) {
- location = location_compressed;
- *compressed = 1;
- } else {
- location = location_uncompressed;
- *compressed = 0;
- }
-
- filename = slapt_gen_filename_from_url(url,location);
- local_head = slapt_read_head_cache(filename);
- checksum_head = slapt_head_mirror_data(url,location);
-
- if (checksum_head == NULL)
- {
- if (interactive == true)
- printf(gettext("Not Found\n"));
- free(filename);
- free(local_head);
- if (checksum_head != NULL)
- free(checksum_head);
- return NULL;
- }
-
- if (checksum_head != NULL && local_head != NULL &&
- strcmp(checksum_head,local_head) == 0) {
- if ((tmp_checksum_f = slapt_open_file(filename,"r")) == NULL)
- exit(EXIT_FAILURE);
-
- if (global_config->progress_cb == NULL)
- printf(gettext("Cached\n"));
-
- } else {
- const char *err = NULL;
-
- if (global_config->dl_stats == true)
- printf("\n");
+ FILE *tmp_checksum_f = NULL;
+ char *checksum_head = NULL;
+ bool interactive = slapt_is_interactive(global_config);
+ char *location_uncompressed = SLAPT_CHECKSUM_ASC_FILE;
+ char *location_compressed = SLAPT_CHECKSUM_ASC_FILE_GZ;
+ char *filename = NULL;
+ char *local_head = NULL;
+ char *location;
+ int checksums_compressed = *compressed;
+
+ if (checksums_compressed == 1) {
+ location = location_compressed;
+ *compressed = 1;
+ } else {
+ location = location_uncompressed;
+ *compressed = 0;
+ }
- if ((tmp_checksum_f = slapt_open_file(filename,"w+b")) == NULL)
- exit(EXIT_FAILURE);
+ filename = slapt_gen_filename_from_url(url, location);
+ local_head = slapt_read_head_cache(filename);
+ checksum_head = slapt_head_mirror_data(url, location);
+
+ if (checksum_head == NULL) {
+ if (interactive == true)
+ printf(gettext("Not Found\n"));
+ free(filename);
+ free(local_head);
+ if (checksum_head != NULL)
+ free(checksum_head);
+ return NULL;
+ }
- err = slapt_get_mirror_data_from_source(tmp_checksum_f,
- global_config,url,
- location);
- if (!err) {
+ if (checksum_head != NULL && local_head != NULL &&
+ strcmp(checksum_head, local_head) == 0) {
+ if ((tmp_checksum_f = slapt_open_file(filename, "r")) == NULL)
+ exit(EXIT_FAILURE);
- if (interactive == true)
- printf(gettext("Done\n"));
+ if (global_config->progress_cb == NULL)
+ printf(gettext("Cached\n"));
} else {
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- slapt_clear_head_cache(filename);
- fclose(tmp_checksum_f);
- free(filename);
- free(local_head);
- if (checksum_head != NULL)
- free(checksum_head);
- return NULL;
+ const char *err = NULL;
+
+ if (global_config->dl_stats == true)
+ printf("\n");
+
+ if ((tmp_checksum_f = slapt_open_file(filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
+
+ err = slapt_get_mirror_data_from_source(tmp_checksum_f,
+ global_config, url,
+ location);
+ if (!err) {
+ if (interactive == true)
+ printf(gettext("Done\n"));
+
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ slapt_clear_head_cache(filename);
+ fclose(tmp_checksum_f);
+ free(filename);
+ free(local_head);
+ if (checksum_head != NULL)
+ free(checksum_head);
+ return NULL;
+ }
+ /* make sure we are back at the front of the file */
+ rewind(tmp_checksum_f);
+
+ /* if all is good, write it */
+ if (checksum_head != NULL)
+ slapt_write_head_cache(checksum_head, filename);
}
- /* make sure we are back at the front of the file */
- rewind(tmp_checksum_f);
-
- /* if all is good, write it */
- if (checksum_head != NULL)
- slapt_write_head_cache(checksum_head,filename);
- }
+ free(filename);
+ free(local_head);
- free(filename);
- free(local_head);
-
- if (checksum_head != NULL)
- free(checksum_head);
+ if (checksum_head != NULL)
+ free(checksum_head);
- return tmp_checksum_f;
+ return tmp_checksum_f;
}
FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
const char *url,
unsigned int *compressed)
{
- FILE *tmp_key_f = NULL;
- char *key_head = NULL;
- char *filename = slapt_gen_filename_from_url(url,SLAPT_GPG_KEY);
- char *local_head = slapt_read_head_cache(filename);
- bool interactive = global_config->progress_cb == NULL && global_config->dl_stats == false
- ? true
- : false;
-
- *compressed = 0;
- key_head = slapt_head_mirror_data(url,SLAPT_GPG_KEY);
-
- if (key_head == NULL) {
- if (interactive == true)
- printf(gettext("Not Found\n"));
- free(filename);
- free(local_head);
- if (key_head != NULL)
- free(key_head);
- return NULL;
- }
-
- if (key_head != NULL && local_head != NULL &&
- strcmp(key_head,local_head) == 0) {
-
- if ((tmp_key_f = slapt_open_file(filename,"r")) == NULL)
- exit(EXIT_FAILURE);
-
- if (global_config->progress_cb == NULL)
- printf(gettext("Cached\n"));
-
- } else {
- const char *err = NULL;
-
- if ((tmp_key_f = slapt_open_file(filename,"w+b")) == NULL)
- exit(EXIT_FAILURE);
-
- err = slapt_get_mirror_data_from_source(tmp_key_f,
- global_config, url,
- SLAPT_GPG_KEY);
-
- if (!err) {
- if (interactive == true)
- printf(gettext("Done\n"));
- } else{
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- slapt_clear_head_cache(filename);
- fclose(tmp_key_f);
- free(filename);
- free(local_head);
- if (key_head != NULL)
- free(key_head);
- return NULL;
+ FILE *tmp_key_f = NULL;
+ char *key_head = NULL;
+ char *filename = slapt_gen_filename_from_url(url, SLAPT_GPG_KEY);
+ char *local_head = slapt_read_head_cache(filename);
+ bool interactive = global_config->progress_cb == NULL && global_config->dl_stats == false
+ ? true
+ : false;
+
+ *compressed = 0;
+ key_head = slapt_head_mirror_data(url, SLAPT_GPG_KEY);
+
+ if (key_head == NULL) {
+ if (interactive == true)
+ printf(gettext("Not Found\n"));
+ free(filename);
+ free(local_head);
+ if (key_head != NULL)
+ free(key_head);
+ return NULL;
}
- rewind(tmp_key_f);
+ if (key_head != NULL && local_head != NULL &&
+ strcmp(key_head, local_head) == 0) {
+ if ((tmp_key_f = slapt_open_file(filename, "r")) == NULL)
+ exit(EXIT_FAILURE);
- /* if all is good, write it */
- if (key_head != NULL)
- slapt_write_head_cache(key_head, filename);
+ if (global_config->progress_cb == NULL)
+ printf(gettext("Cached\n"));
- }
+ } else {
+ const char *err = NULL;
+
+ if ((tmp_key_f = slapt_open_file(filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
+
+ err = slapt_get_mirror_data_from_source(tmp_key_f,
+ global_config, url,
+ SLAPT_GPG_KEY);
+
+ if (!err) {
+ if (interactive == true)
+ printf(gettext("Done\n"));
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ slapt_clear_head_cache(filename);
+ fclose(tmp_key_f);
+ free(filename);
+ free(local_head);
+ if (key_head != NULL)
+ free(key_head);
+ return NULL;
+ }
+
+ rewind(tmp_key_f);
+
+ /* if all is good, write it */
+ if (key_head != NULL)
+ slapt_write_head_cache(key_head, filename);
+ }
- free(filename);
- free(local_head);
+ free(filename);
+ free(local_head);
- if (key_head != NULL)
- free(key_head);
+ if (key_head != NULL)
+ free(key_head);
- return tmp_key_f;
+ return tmp_key_f;
}
-slapt_code_t slapt_add_pkg_source_gpg_key (FILE *key)
+slapt_code_t slapt_add_pkg_source_gpg_key(FILE *key)
{
- gpgme_error_t e;
- gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
- gpgme_import_result_t import_result;
- gpgme_data_t key_data;
- slapt_code_t imported = SLAPT_GPG_KEY_NOT_IMPORTED;
+ gpgme_error_t e;
+ gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
+ gpgme_import_result_t import_result;
+ gpgme_data_t key_data;
+ slapt_code_t imported = SLAPT_GPG_KEY_NOT_IMPORTED;
+
+ if (ctx == NULL)
+ return imported;
+
+ e = gpgme_data_new_from_stream(&key_data, key);
+ if (e != GPG_ERR_NO_ERROR) {
+ fprintf(stderr, "GPGME: %s\n", gpgme_strerror(e));
+ _slapt_free_gpgme_ctx(ctx);
+ return imported;
+ }
- if (ctx == NULL)
- return imported;
+ e = gpgme_op_import(*ctx, key_data);
+ if (e) {
+ fprintf(stderr, "GPGME: %s\n", gpgme_strerror(e));
+ gpgme_data_release(key_data);
+ _slapt_free_gpgme_ctx(ctx);
+ return imported;
+ }
- e = gpgme_data_new_from_stream (&key_data, key);
- if (e != GPG_ERR_NO_ERROR)
- {
- fprintf (stderr, "GPGME: %s\n", gpgme_strerror (e));
- _slapt_free_gpgme_ctx(ctx);
- return imported;
- }
+ import_result = gpgme_op_import_result(*ctx);
+ if (import_result != NULL) {
+ if (import_result->unchanged > 0)
+ imported = SLAPT_GPG_KEY_UNCHANGED;
+ else if (import_result->imported > 0)
+ imported = SLAPT_GPG_KEY_IMPORTED;
+ }
- e = gpgme_op_import(*ctx, key_data);
- if (e)
- {
- fprintf (stderr, "GPGME: %s\n", gpgme_strerror (e));
- gpgme_data_release (key_data);
+ gpgme_data_release(key_data);
_slapt_free_gpgme_ctx(ctx);
return imported;
- }
-
- import_result = gpgme_op_import_result(*ctx);
- if (import_result != NULL)
- {
- if (import_result->unchanged > 0)
- imported = SLAPT_GPG_KEY_UNCHANGED;
- else if (import_result->imported > 0)
- imported = SLAPT_GPG_KEY_IMPORTED;
- }
-
- gpgme_data_release (key_data);
- _slapt_free_gpgme_ctx(ctx);
- return imported;
}
static slapt_code_t _slapt_gpg_get_gpgme_error(gpgme_sigsum_t sum)
{
- switch (sum)
- {
- case GPGME_SIGSUM_KEY_REVOKED: return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_REVOKED;
- case GPGME_SIGSUM_KEY_EXPIRED: return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_EXPIRED;
- case GPGME_SIGSUM_SIG_EXPIRED: return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SIG_EXPIRED;
- case GPGME_SIGSUM_CRL_MISSING: return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_MISSING;
- case GPGME_SIGSUM_CRL_TOO_OLD: return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_TOO_OLD;
- case GPGME_SIGSUM_BAD_POLICY: return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_BAD_POLICY;
- case GPGME_SIGSUM_SYS_ERROR: return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SYS_ERROR;
- default: break;
- }
-
- return SLAPT_CHECKSUMS_NOT_VERIFIED;
-}
+ switch (sum) {
+ case GPGME_SIGSUM_KEY_REVOKED:
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_REVOKED;
+ case GPGME_SIGSUM_KEY_EXPIRED:
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_EXPIRED;
+ case GPGME_SIGSUM_SIG_EXPIRED:
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SIG_EXPIRED;
+ case GPGME_SIGSUM_CRL_MISSING:
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_MISSING;
+ case GPGME_SIGSUM_CRL_TOO_OLD:
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_TOO_OLD;
+ case GPGME_SIGSUM_BAD_POLICY:
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_BAD_POLICY;
+ case GPGME_SIGSUM_SYS_ERROR:
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SYS_ERROR;
+ default:
+ break;
+ }
+ return SLAPT_CHECKSUMS_NOT_VERIFIED;
+}
slapt_code_t slapt_gpg_verify_checksums(FILE *checksums,
FILE *signature)
{
- gpgme_error_t e;
- gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
- gpgme_data_t chk_data, asc_data;
- slapt_code_t verified = SLAPT_CHECKSUMS_NOT_VERIFIED;
-
- if (ctx == NULL)
- return SLAPT_CHECKSUMS_NOT_VERIFIED_NULL_CONTEXT;
-
- e = gpgme_data_new_from_stream (&chk_data, checksums);
- if (e != GPG_ERR_NO_ERROR)
- {
- _slapt_free_gpgme_ctx(ctx);
- return SLAPT_CHECKSUMS_NOT_VERIFIED_READ_CHECKSUMS;
- }
+ gpgme_error_t e;
+ gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
+ gpgme_data_t chk_data, asc_data;
+ slapt_code_t verified = SLAPT_CHECKSUMS_NOT_VERIFIED;
+
+ if (ctx == NULL)
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_NULL_CONTEXT;
+
+ e = gpgme_data_new_from_stream(&chk_data, checksums);
+ if (e != GPG_ERR_NO_ERROR) {
+ _slapt_free_gpgme_ctx(ctx);
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_READ_CHECKSUMS;
+ }
- e = gpgme_data_new_from_stream (&asc_data, signature);
- if (e != GPG_ERR_NO_ERROR)
- {
- gpgme_data_release (chk_data);
- _slapt_free_gpgme_ctx(ctx);
- return SLAPT_CHECKSUMS_NOT_VERIFIED_READ_SIGNATURE;
- }
-
- e = gpgme_op_verify (*ctx, asc_data, chk_data, NULL);
-
- if (e == GPG_ERR_NO_ERROR)
- {
- gpgme_verify_result_t verify_result = gpgme_op_verify_result (*ctx);
- if (verify_result != NULL)
- {
- gpgme_signature_t sig = verify_result->signatures;
- gpgme_sigsum_t sum = sig->summary;
- gpgme_error_t status = sig->status;
-
- if (sum & GPGME_SIGSUM_VALID || status == GPG_ERR_NO_ERROR) {
- verified = SLAPT_CHECKSUMS_VERIFIED;
- } else if (sum & GPGME_SIGSUM_KEY_MISSING) {
- verified = SLAPT_CHECKSUMS_MISSING_KEY;
- } else {
- verified = _slapt_gpg_get_gpgme_error(sum);
- }
+ e = gpgme_data_new_from_stream(&asc_data, signature);
+ if (e != GPG_ERR_NO_ERROR) {
+ gpgme_data_release(chk_data);
+ _slapt_free_gpgme_ctx(ctx);
+ return SLAPT_CHECKSUMS_NOT_VERIFIED_READ_SIGNATURE;
+ }
+ e = gpgme_op_verify(*ctx, asc_data, chk_data, NULL);
+
+ if (e == GPG_ERR_NO_ERROR) {
+ gpgme_verify_result_t verify_result = gpgme_op_verify_result(*ctx);
+ if (verify_result != NULL) {
+ gpgme_signature_t sig = verify_result->signatures;
+ gpgme_sigsum_t sum = sig->summary;
+ gpgme_error_t status = sig->status;
+
+ if (sum & GPGME_SIGSUM_VALID || status == GPG_ERR_NO_ERROR) {
+ verified = SLAPT_CHECKSUMS_VERIFIED;
+ } else if (sum & GPGME_SIGSUM_KEY_MISSING) {
+ verified = SLAPT_CHECKSUMS_MISSING_KEY;
+ } else {
+ verified = _slapt_gpg_get_gpgme_error(sum);
+ }
+ }
+ } else {
+ /* if gnupg|gnupg2 is missing: "GPGME: Invalid crypto engine" */
+ fprintf(stderr, "GPGME: %s\n", gpgme_strerror(e));
}
- } else {
- /* if gnupg|gnupg2 is missing: "GPGME: Invalid crypto engine" */
- fprintf (stderr, "GPGME: %s\n", gpgme_strerror (e));
- }
- gpgme_data_release (chk_data);
- gpgme_data_release (asc_data);
- _slapt_free_gpgme_ctx(ctx);
+ gpgme_data_release(chk_data);
+ gpgme_data_release(asc_data);
+ _slapt_free_gpgme_ctx(ctx);
- return verified;
+ return verified;
}
-
diff --git a/src/gpgme.h b/src/gpgme.h
index d4efa1e..f61872b 100644
--- a/src/gpgme.h
+++ b/src/gpgme.h
@@ -27,15 +27,14 @@
#define SLAPT_CHECKSUM_ASC_FILE_GZ "CHECKSUMS.md5.gz.asc"
/* retrieve the signature of the CHECKSUMS.md5 file */
-FILE *slapt_get_pkg_source_checksums_signature (const slapt_rc_config *global_config,
- const char *url,
- unsigned int *compressed);
+FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_config,
+ const char *url,
+ unsigned int *compressed);
/* retrieve the package sources GPG-KEY */
FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
const char *url,
unsigned int *compressed);
/* Add the GPG-KEY to the local keyring */
-slapt_code_t slapt_add_pkg_source_gpg_key (FILE *key);
+slapt_code_t slapt_add_pkg_source_gpg_key(FILE *key);
/* Verify the signature is valid for the checksum file */
slapt_code_t slapt_gpg_verify_checksums(FILE *checksums, FILE *signature);
-
diff --git a/src/main.c b/src/main.c
index 13d6231..277f51a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,480 +23,474 @@ static void version_info(void);
extern char *optarg;
extern int optind, opterr, optopt;
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
{
- slapt_rc_config *global_config, *initial_config; /* our config struct */
- slapt_list_t *paa;
-
- int c = 0;
- enum slapt_action do_action = 0;
- int option_index = 0;
- static struct option long_options[] = {
- {"update", 0, 0, SLAPT_UPDATE_OPT},
- {"u", 0, 0, SLAPT_UPDATE_OPT},
- {"upgrade", 0, 0, SLAPT_UPGRADE_OPT},
- {"install", 0, 0, SLAPT_INSTALL_OPT},
- {"i", 0, 0, SLAPT_INSTALL_OPT},
- {"remove", 0, 0, SLAPT_REMOVE_OPT},
- {"show", 0, 0, SLAPT_SHOW_OPT},
- {"search", 0, 0, SLAPT_SEARCH_OPT},
- {"list", 0, 0, SLAPT_LIST_OPT},
- {"installed", 0, 0, SLAPT_INSTALLED_OPT},
- {"clean", 0, 0, SLAPT_CLEAN_OPT},
- {"download-only", 0, 0, SLAPT_DOWNLOAD_ONLY_OPT},
- {"d", 0, 0, SLAPT_DOWNLOAD_ONLY_OPT},
- {"simulate", 0, 0, SLAPT_SIMULATE_OPT},
- {"s", 0, 0, SLAPT_SIMULATE_OPT},
- {"version", 0, 0, SLAPT_VERSION_OPT},
- {"no-prompt", 0, 0, SLAPT_NO_PROMPT_OPT},
- {"y", 0, 0, SLAPT_NO_PROMPT_OPT},
- {"prompt", 0, 0, SLAPT_PROMPT_OPT},
- {"p", 0, 0, SLAPT_PROMPT_OPT},
- {"reinstall", 0, 0, SLAPT_REINSTALL_OPT},
- {"ignore-excludes", 0, 0, SLAPT_IGNORE_EXCLUDES_OPT},
- {"no-md5", 0, 0, SLAPT_NO_MD5_OPT},
- {"dist-upgrade",0, 0, SLAPT_DIST_UPGRADE_OPT},
- {"help",0, 0, SLAPT_HELP_OPT},
- {"h",0, 0, SLAPT_HELP_OPT},
- {"ignore-dep",0, 0, SLAPT_IGNORE_DEP_OPT},
- {"no-dep",0, 0, SLAPT_NO_DEP_OPT},
- {"print-uris",0, 0, SLAPT_PRINT_URIS_OPT},
- {"show-stats",0, 0, SLAPT_SHOW_STATS_OPT},
- {"S",0, 0, SLAPT_SHOW_STATS_OPT},
- {"config",1, 0, SLAPT_CONFIG_OPT},
- {"c",1, 0, SLAPT_CONFIG_OPT},
- {"autoclean", 0, 0, SLAPT_AUTOCLEAN_OPT},
- {"remove-obsolete", 0, 0, SLAPT_OBSOLETE_OPT},
- {"available", 0, 0, SLAPT_AVAILABLE_OPT},
- {"retry", 1, 0, SLAPT_RETRY_OPT},
- {"no-upgrade", 0, 0, SLAPT_NO_UPGRADE_OPT},
- {"install-set", 0, 0, SLAPT_INSTALL_DISK_SET_OPT},
- #ifdef SLAPT_HAS_GPGME
- {"add-keys", 0, 0, SLAPT_ADD_KEYS_OPT},
- {"allow-unauthenticated", 0, 0, SLAPT_ALLOW_UNAUTH},
- #endif
- {"filelist", 0, 0, SLAPT_FILELIST},
- {0, 0, 0, 0},
- };
- char *custom_rc_location = NULL;
-
- setbuf(stdout,NULL);
-
- #ifdef ENABLE_NLS
- setlocale(LC_ALL,"");
- bindtextdomain(GETTEXT_PACKAGE,PACKAGE_LOCALE_DIR);
- textdomain(GETTEXT_PACKAGE);
- #endif
-
- #ifdef SLAPT_HAS_GPGME
- gpgme_check_version (NULL);
- #ifdef ENABLE_NLS
- gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
- #endif
- #endif
-
- if ( argc < 2 ) {
- usage();
- exit(EXIT_FAILURE);
- }
-
- initial_config = slapt_init_config();
- if ( initial_config == NULL ) {
- exit(EXIT_FAILURE);
- }
-
- curl_global_init(CURL_GLOBAL_ALL);
-
- while ((c = getopt_long_only(argc,argv,"",long_options,
- &option_index)) != -1) {
- switch(c) {
- case SLAPT_UPDATE_OPT: /* update */
- do_action = UPDATE;
- break;
- case SLAPT_INSTALL_OPT: /* install */
- do_action = INSTALL;
- break;
- case SLAPT_REMOVE_OPT: /* remove */
- do_action = REMOVE;
- break;
- case SLAPT_SHOW_OPT: /* show */
- do_action = SHOW;
- initial_config->simulate = true; /* allow read access */
- break;
- case SLAPT_SEARCH_OPT: /* search */
- do_action = SEARCH;
- initial_config->simulate = true; /* allow read access */
- break;
- case SLAPT_LIST_OPT: /* list */
- do_action = LIST;
- initial_config->simulate = true; /* allow read access */
- break;
- case SLAPT_INSTALLED_OPT: /* installed */
- do_action = INSTALLED;
- initial_config->simulate = true; /* allow read access */
- break;
- case SLAPT_CLEAN_OPT: /* clean */
- do_action = CLEAN;
- break;
- case SLAPT_UPGRADE_OPT: /* upgrade */
- do_action = UPGRADE;
- break;
- case SLAPT_DOWNLOAD_ONLY_OPT: /* download only flag */
- initial_config->download_only = true;
- break;
- case SLAPT_SIMULATE_OPT: /* simulate */
- initial_config->simulate = true;
- break;
- case SLAPT_VERSION_OPT: /* version */
- version_info();
- slapt_free_rc_config(initial_config);
- curl_global_cleanup();
- exit(EXIT_SUCCESS);
- case SLAPT_NO_PROMPT_OPT: /* auto */
- initial_config->no_prompt = true;
- break;
- case SLAPT_PROMPT_OPT: /* always prompt */
- initial_config->prompt = true;
- break;
- case SLAPT_REINSTALL_OPT: /* reinstall */
- initial_config->re_install = true;
- break;
- case SLAPT_IGNORE_EXCLUDES_OPT: /* ignore-excludes */
- initial_config->ignore_excludes = true;
- break;
- case SLAPT_NO_MD5_OPT: /* no-md5 */
- initial_config->no_md5_check = true;
- break;
- case SLAPT_DIST_UPGRADE_OPT: /* dist-upgrade */
- initial_config->dist_upgrade = true;
- do_action = UPGRADE;
- break;
- case SLAPT_HELP_OPT: /* help */
+ slapt_rc_config *global_config, *initial_config; /* our config struct */
+ slapt_list_t *paa;
+
+ int c = 0;
+ enum slapt_action do_action = 0;
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"update", 0, 0, SLAPT_UPDATE_OPT},
+ {"u", 0, 0, SLAPT_UPDATE_OPT},
+ {"upgrade", 0, 0, SLAPT_UPGRADE_OPT},
+ {"install", 0, 0, SLAPT_INSTALL_OPT},
+ {"i", 0, 0, SLAPT_INSTALL_OPT},
+ {"remove", 0, 0, SLAPT_REMOVE_OPT},
+ {"show", 0, 0, SLAPT_SHOW_OPT},
+ {"search", 0, 0, SLAPT_SEARCH_OPT},
+ {"list", 0, 0, SLAPT_LIST_OPT},
+ {"installed", 0, 0, SLAPT_INSTALLED_OPT},
+ {"clean", 0, 0, SLAPT_CLEAN_OPT},
+ {"download-only", 0, 0, SLAPT_DOWNLOAD_ONLY_OPT},
+ {"d", 0, 0, SLAPT_DOWNLOAD_ONLY_OPT},
+ {"simulate", 0, 0, SLAPT_SIMULATE_OPT},
+ {"s", 0, 0, SLAPT_SIMULATE_OPT},
+ {"version", 0, 0, SLAPT_VERSION_OPT},
+ {"no-prompt", 0, 0, SLAPT_NO_PROMPT_OPT},
+ {"y", 0, 0, SLAPT_NO_PROMPT_OPT},
+ {"prompt", 0, 0, SLAPT_PROMPT_OPT},
+ {"p", 0, 0, SLAPT_PROMPT_OPT},
+ {"reinstall", 0, 0, SLAPT_REINSTALL_OPT},
+ {"ignore-excludes", 0, 0, SLAPT_IGNORE_EXCLUDES_OPT},
+ {"no-md5", 0, 0, SLAPT_NO_MD5_OPT},
+ {"dist-upgrade", 0, 0, SLAPT_DIST_UPGRADE_OPT},
+ {"help", 0, 0, SLAPT_HELP_OPT},
+ {"h", 0, 0, SLAPT_HELP_OPT},
+ {"ignore-dep", 0, 0, SLAPT_IGNORE_DEP_OPT},
+ {"no-dep", 0, 0, SLAPT_NO_DEP_OPT},
+ {"print-uris", 0, 0, SLAPT_PRINT_URIS_OPT},
+ {"show-stats", 0, 0, SLAPT_SHOW_STATS_OPT},
+ {"S", 0, 0, SLAPT_SHOW_STATS_OPT},
+ {"config", 1, 0, SLAPT_CONFIG_OPT},
+ {"c", 1, 0, SLAPT_CONFIG_OPT},
+ {"autoclean", 0, 0, SLAPT_AUTOCLEAN_OPT},
+ {"remove-obsolete", 0, 0, SLAPT_OBSOLETE_OPT},
+ {"available", 0, 0, SLAPT_AVAILABLE_OPT},
+ {"retry", 1, 0, SLAPT_RETRY_OPT},
+ {"no-upgrade", 0, 0, SLAPT_NO_UPGRADE_OPT},
+ {"install-set", 0, 0, SLAPT_INSTALL_DISK_SET_OPT},
+#ifdef SLAPT_HAS_GPGME
+ {"add-keys", 0, 0, SLAPT_ADD_KEYS_OPT},
+ {"allow-unauthenticated", 0, 0, SLAPT_ALLOW_UNAUTH},
+#endif
+ {"filelist", 0, 0, SLAPT_FILELIST},
+ {0, 0, 0, 0},
+ };
+ char *custom_rc_location = NULL;
+
+ setbuf(stdout, NULL);
+
+#ifdef ENABLE_NLS
+ setlocale(LC_ALL, "");
+ bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
+ textdomain(GETTEXT_PACKAGE);
+#endif
+
+#ifdef SLAPT_HAS_GPGME
+ gpgme_check_version(NULL);
+#ifdef ENABLE_NLS
+ gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
+#endif
+#endif
+
+ if (argc < 2) {
usage();
- slapt_free_rc_config(initial_config);
- curl_global_cleanup();
- exit(EXIT_SUCCESS);
- case SLAPT_IGNORE_DEP_OPT: /* ignore-dep */
- initial_config->ignore_dep = true;
- break;
- case SLAPT_NO_DEP_OPT: /* no-dep */
- initial_config->disable_dep_check = true;
- break;
- case SLAPT_PRINT_URIS_OPT: /* print-uris */
- initial_config->print_uris = true;
- break;
- case SLAPT_SHOW_STATS_OPT: /* download-stats */
- initial_config->dl_stats = true;
- break;
- case SLAPT_CONFIG_OPT: /* override rc location */
- custom_rc_location = strdup(optarg);
- break;
- case SLAPT_RETRY_OPT: /* set number of retry attempts */
- initial_config->retry = (atoi(optarg) > 0) ? atoi(optarg) : 1;
- break;
- case SLAPT_NO_UPGRADE_OPT: /* do not attempt to upgrade */
- initial_config->no_upgrade = true;
- break;
- case SLAPT_AUTOCLEAN_OPT: /* clean old old package versions */
- do_action = AUTOCLEAN;
- break;
- case SLAPT_OBSOLETE_OPT: /* remove obsolete packages */
- initial_config->remove_obsolete = true;
- break;
- case SLAPT_AVAILABLE_OPT: /* show available packages */
- do_action = AVAILABLE;
- initial_config->simulate = true; /* allow read access */
- break;
- case SLAPT_INSTALL_DISK_SET_OPT: /* install a disk set */
- do_action = INSTALL_DISK_SET;
- break;
- #ifdef SLAPT_HAS_GPGME
- case SLAPT_ADD_KEYS_OPT: /* retrieve GPG keys for sources */
- do_action = ADD_KEYS;
- break;
- case SLAPT_ALLOW_UNAUTH: /* allow unauthenticated key */
- initial_config->gpgme_allow_unauth = true;
- break;
- #endif
- case SLAPT_FILELIST:
- do_action = FILELIST;
- initial_config->simulate = true; /* allow read access */
- break;
- default:
- usage();
- slapt_free_rc_config(initial_config);
- curl_global_cleanup();
exit(EXIT_FAILURE);
}
- }
-
- /* load up the configuration file */
- if (custom_rc_location == NULL) {
- global_config = slapt_read_rc_config(RC_LOCATION);
- } else {
- global_config = slapt_read_rc_config(custom_rc_location);
- free(custom_rc_location);
- }
-
- if ( global_config == NULL ) {
- exit(EXIT_FAILURE);
- }
-
- /* preserve existing command line options */
- global_config->disable_dep_check = initial_config->disable_dep_check;
- global_config->dist_upgrade = initial_config->dist_upgrade;
- global_config->dl_stats = initial_config->dl_stats;
- global_config->download_only = initial_config->download_only;
- global_config->ignore_dep = initial_config->ignore_dep;
- global_config->ignore_excludes = initial_config->ignore_excludes;
- global_config->no_md5_check = initial_config->no_md5_check;
- global_config->no_prompt = initial_config->no_prompt;
- global_config->no_upgrade = initial_config->no_upgrade;
- global_config->print_uris = initial_config->print_uris;
- global_config->prompt = initial_config->prompt;
- global_config->re_install = initial_config->re_install;
- global_config->remove_obsolete = initial_config->remove_obsolete;
- global_config->retry = initial_config->retry;
- global_config->simulate = initial_config->simulate;
- global_config->gpgme_allow_unauth = initial_config->gpgme_allow_unauth;
-
- slapt_free_rc_config(initial_config);
-
- /* Check optional arguments presence */
- switch(do_action) {
+ initial_config = slapt_init_config();
+ if (initial_config == NULL) {
+ exit(EXIT_FAILURE);
+ }
+
+ curl_global_init(CURL_GLOBAL_ALL);
+
+ while ((c = getopt_long_only(argc, argv, "", long_options,
+ &option_index)) != -1) {
+ switch (c) {
+ case SLAPT_UPDATE_OPT: /* update */
+ do_action = UPDATE;
+ break;
+ case SLAPT_INSTALL_OPT: /* install */
+ do_action = INSTALL;
+ break;
+ case SLAPT_REMOVE_OPT: /* remove */
+ do_action = REMOVE;
+ break;
+ case SLAPT_SHOW_OPT: /* show */
+ do_action = SHOW;
+ initial_config->simulate = true; /* allow read access */
+ break;
+ case SLAPT_SEARCH_OPT: /* search */
+ do_action = SEARCH;
+ initial_config->simulate = true; /* allow read access */
+ break;
+ case SLAPT_LIST_OPT: /* list */
+ do_action = LIST;
+ initial_config->simulate = true; /* allow read access */
+ break;
+ case SLAPT_INSTALLED_OPT: /* installed */
+ do_action = INSTALLED;
+ initial_config->simulate = true; /* allow read access */
+ break;
+ case SLAPT_CLEAN_OPT: /* clean */
+ do_action = CLEAN;
+ break;
+ case SLAPT_UPGRADE_OPT: /* upgrade */
+ do_action = UPGRADE;
+ break;
+ case SLAPT_DOWNLOAD_ONLY_OPT: /* download only flag */
+ initial_config->download_only = true;
+ break;
+ case SLAPT_SIMULATE_OPT: /* simulate */
+ initial_config->simulate = true;
+ break;
+ case SLAPT_VERSION_OPT: /* version */
+ version_info();
+ slapt_free_rc_config(initial_config);
+ curl_global_cleanup();
+ exit(EXIT_SUCCESS);
+ case SLAPT_NO_PROMPT_OPT: /* auto */
+ initial_config->no_prompt = true;
+ break;
+ case SLAPT_PROMPT_OPT: /* always prompt */
+ initial_config->prompt = true;
+ break;
+ case SLAPT_REINSTALL_OPT: /* reinstall */
+ initial_config->re_install = true;
+ break;
+ case SLAPT_IGNORE_EXCLUDES_OPT: /* ignore-excludes */
+ initial_config->ignore_excludes = true;
+ break;
+ case SLAPT_NO_MD5_OPT: /* no-md5 */
+ initial_config->no_md5_check = true;
+ break;
+ case SLAPT_DIST_UPGRADE_OPT: /* dist-upgrade */
+ initial_config->dist_upgrade = true;
+ do_action = UPGRADE;
+ break;
+ case SLAPT_HELP_OPT: /* help */
+ usage();
+ slapt_free_rc_config(initial_config);
+ curl_global_cleanup();
+ exit(EXIT_SUCCESS);
+ case SLAPT_IGNORE_DEP_OPT: /* ignore-dep */
+ initial_config->ignore_dep = true;
+ break;
+ case SLAPT_NO_DEP_OPT: /* no-dep */
+ initial_config->disable_dep_check = true;
+ break;
+ case SLAPT_PRINT_URIS_OPT: /* print-uris */
+ initial_config->print_uris = true;
+ break;
+ case SLAPT_SHOW_STATS_OPT: /* download-stats */
+ initial_config->dl_stats = true;
+ break;
+ case SLAPT_CONFIG_OPT: /* override rc location */
+ custom_rc_location = strdup(optarg);
+ break;
+ case SLAPT_RETRY_OPT: /* set number of retry attempts */
+ initial_config->retry = (atoi(optarg) > 0) ? atoi(optarg) : 1;
+ break;
+ case SLAPT_NO_UPGRADE_OPT: /* do not attempt to upgrade */
+ initial_config->no_upgrade = true;
+ break;
+ case SLAPT_AUTOCLEAN_OPT: /* clean old old package versions */
+ do_action = AUTOCLEAN;
+ break;
+ case SLAPT_OBSOLETE_OPT: /* remove obsolete packages */
+ initial_config->remove_obsolete = true;
+ break;
+ case SLAPT_AVAILABLE_OPT: /* show available packages */
+ do_action = AVAILABLE;
+ initial_config->simulate = true; /* allow read access */
+ break;
+ case SLAPT_INSTALL_DISK_SET_OPT: /* install a disk set */
+ do_action = INSTALL_DISK_SET;
+ break;
+#ifdef SLAPT_HAS_GPGME
+ case SLAPT_ADD_KEYS_OPT: /* retrieve GPG keys for sources */
+ do_action = ADD_KEYS;
+ break;
+ case SLAPT_ALLOW_UNAUTH: /* allow unauthenticated key */
+ initial_config->gpgme_allow_unauth = true;
+ break;
+#endif
+ case SLAPT_FILELIST:
+ do_action = FILELIST;
+ initial_config->simulate = true; /* allow read access */
+ break;
+ default:
+ usage();
+ slapt_free_rc_config(initial_config);
+ curl_global_cleanup();
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /* load up the configuration file */
+ if (custom_rc_location == NULL) {
+ global_config = slapt_read_rc_config(RC_LOCATION);
+ } else {
+ global_config = slapt_read_rc_config(custom_rc_location);
+ free(custom_rc_location);
+ }
+
+ if (global_config == NULL) {
+ exit(EXIT_FAILURE);
+ }
+
+ /* preserve existing command line options */
+ global_config->disable_dep_check = initial_config->disable_dep_check;
+ global_config->dist_upgrade = initial_config->dist_upgrade;
+ global_config->dl_stats = initial_config->dl_stats;
+ global_config->download_only = initial_config->download_only;
+ global_config->ignore_dep = initial_config->ignore_dep;
+ global_config->ignore_excludes = initial_config->ignore_excludes;
+ global_config->no_md5_check = initial_config->no_md5_check;
+ global_config->no_prompt = initial_config->no_prompt;
+ global_config->no_upgrade = initial_config->no_upgrade;
+ global_config->print_uris = initial_config->print_uris;
+ global_config->prompt = initial_config->prompt;
+ global_config->re_install = initial_config->re_install;
+ global_config->remove_obsolete = initial_config->remove_obsolete;
+ global_config->retry = initial_config->retry;
+ global_config->simulate = initial_config->simulate;
+ global_config->gpgme_allow_unauth = initial_config->gpgme_allow_unauth;
+
+ slapt_free_rc_config(initial_config);
+
+ /* Check optional arguments presence */
+ switch (do_action) {
/* can't simulate update, clean, autoclean, or add keys */
case CLEAN:
case AUTOCLEAN:
- #ifdef SLAPT_HAS_GPGME
+#ifdef SLAPT_HAS_GPGME
case ADD_KEYS:
- #endif
+#endif
case UPDATE:
- global_config->simulate = false;
- break;
+ global_config->simulate = false;
+ break;
/* remove obsolete can take the place of arguments */
case INSTALL:
case INSTALL_DISK_SET:
case REMOVE:
if (global_config->remove_obsolete == true)
- break;
+ break;
/* fall through */
/* show, search, filelist must have arguments */
case SHOW:
case SEARCH:
case FILELIST:
- if ( optind >= argc )
- do_action = 0;
- break;
+ if (optind >= argc)
+ do_action = 0;
+ break;
default:
- if (optind < argc)
- do_action = USAGE;
- break;
- }
-
- if ( do_action == USAGE ) {
- usage();
- slapt_free_rc_config(global_config);
- curl_global_cleanup();
- exit(EXIT_FAILURE);
- }
-
- /* create the working directory if needed */
- slapt_working_dir_init(global_config);
- if ((chdir(global_config->working_dir)) == -1) {
- fprintf(stderr,gettext("Failed to chdir: %s\n"),global_config->working_dir);
- exit(EXIT_FAILURE);
- }
+ if (optind < argc)
+ do_action = USAGE;
+ break;
+ }
- switch(do_action) {
- case UPDATE:
- if ( slapt_update_pkg_cache(global_config) == 1 ) {
+ if (do_action == USAGE) {
+ usage();
slapt_free_rc_config(global_config);
curl_global_cleanup();
exit(EXIT_FAILURE);
- }
- break;
+ }
+
+ /* create the working directory if needed */
+ slapt_working_dir_init(global_config);
+ if ((chdir(global_config->working_dir)) == -1) {
+ fprintf(stderr, gettext("Failed to chdir: %s\n"), global_config->working_dir);
+ exit(EXIT_FAILURE);
+ }
+
+ switch (do_action) {
+ case UPDATE:
+ if (slapt_update_pkg_cache(global_config) == 1) {
+ slapt_free_rc_config(global_config);
+ curl_global_cleanup();
+ exit(EXIT_FAILURE);
+ }
+ break;
case INSTALL:
- paa = slapt_init_list();
- while (optind < argc) {
- slapt_add_list_item(paa,argv[optind]);
- ++optind;
- }
- slapt_pkg_action_install( global_config, paa );
- slapt_free_list(paa);
- break;
- case INSTALL_DISK_SET:
- {
+ paa = slapt_init_list();
+ while (optind < argc) {
+ slapt_add_list_item(paa, argv[optind]);
+ ++optind;
+ }
+ slapt_pkg_action_install(global_config, paa);
+ slapt_free_list(paa);
+ break;
+ case INSTALL_DISK_SET: {
unsigned int set_i;
slapt_pkg_list_t *set_pkgs = slapt_init_pkg_list();
slapt_pkg_list_t *avail_pkgs = slapt_get_available_pkgs();
while (optind < argc) {
- unsigned int search_i;
- slapt_pkg_list_t *matches = NULL;
- char *search = slapt_malloc(sizeof *search * (strlen(argv[optind]) + 3));
-
- snprintf(search,strlen(argv[optind]) + 3,"/%s$",argv[optind]);
- matches = slapt_search_pkg_list(avail_pkgs,search);
- free(search);
-
- for (search_i = 0; search_i < matches->pkg_count; ++search_i) {
- if (slapt_is_excluded(global_config,matches->pkgs[search_i]) == 0) {
- slapt_add_pkg_to_pkg_list(set_pkgs,matches->pkgs[search_i]);
+ unsigned int search_i;
+ slapt_pkg_list_t *matches = NULL;
+ char *search = slapt_malloc(sizeof *search * (strlen(argv[optind]) + 3));
+
+ snprintf(search, strlen(argv[optind]) + 3, "/%s$", argv[optind]);
+ matches = slapt_search_pkg_list(avail_pkgs, search);
+ free(search);
+
+ for (search_i = 0; search_i < matches->pkg_count; ++search_i) {
+ if (slapt_is_excluded(global_config, matches->pkgs[search_i]) == 0) {
+ slapt_add_pkg_to_pkg_list(set_pkgs, matches->pkgs[search_i]);
+ }
}
- }
-
- slapt_free_pkg_list(matches);
- ++optind;
+ slapt_free_pkg_list(matches);
+ ++optind;
}
paa = slapt_init_list();
for (set_i = 0; set_i < set_pkgs->pkg_count; ++set_i) {
- slapt_add_list_item(paa,set_pkgs->pkgs[set_i]->name);
+ slapt_add_list_item(paa, set_pkgs->pkgs[set_i]->name);
}
slapt_free_pkg_list(set_pkgs);
slapt_free_pkg_list(avail_pkgs);
- slapt_pkg_action_install( global_config, paa );
+ slapt_pkg_action_install(global_config, paa);
slapt_free_list(paa);
- }
- break;
+ } break;
case REMOVE:
- paa = slapt_init_list();
- while (optind < argc) {
- slapt_add_list_item(paa,argv[optind]);
- ++optind;
- }
- slapt_pkg_action_remove( global_config, paa );
- slapt_free_list(paa);
- break;
+ paa = slapt_init_list();
+ while (optind < argc) {
+ slapt_add_list_item(paa, argv[optind]);
+ ++optind;
+ }
+ slapt_pkg_action_remove(global_config, paa);
+ slapt_free_list(paa);
+ break;
case SHOW:
- while (optind < argc) {
- slapt_pkg_action_show( argv[optind++] );
- }
- break;
+ while (optind < argc) {
+ slapt_pkg_action_show(argv[optind++]);
+ }
+ break;
case SEARCH:
- while (optind < argc) {
- slapt_pkg_action_search( argv[optind++] );
- }
- break;
+ while (optind < argc) {
+ slapt_pkg_action_search(argv[optind++]);
+ }
+ break;
case UPGRADE:
- slapt_pkg_action_upgrade_all(global_config);
- break;
+ slapt_pkg_action_upgrade_all(global_config);
+ break;
case LIST:
- slapt_pkg_action_list(LIST);
- break;
+ slapt_pkg_action_list(LIST);
+ break;
case INSTALLED:
- slapt_pkg_action_list(INSTALLED);
- break;
+ slapt_pkg_action_list(INSTALLED);
+ break;
case CLEAN:
- /* clean out local cache */
- slapt_clean_pkg_dir(global_config->working_dir);
- if ((chdir(global_config->working_dir)) == -1) {
- fprintf(stderr,gettext("Failed to chdir: %s\n"),global_config->working_dir);
- exit(EXIT_FAILURE);
- }
- break;
+ /* clean out local cache */
+ slapt_clean_pkg_dir(global_config->working_dir);
+ if ((chdir(global_config->working_dir)) == -1) {
+ fprintf(stderr, gettext("Failed to chdir: %s\n"), global_config->working_dir);
+ exit(EXIT_FAILURE);
+ }
+ break;
case AUTOCLEAN:
- slapt_purge_old_cached_pkgs(global_config, NULL, NULL);
- break;
+ slapt_purge_old_cached_pkgs(global_config, NULL, NULL);
+ break;
case AVAILABLE:
- slapt_pkg_action_list(AVAILABLE);
- break;
- #ifdef SLAPT_HAS_GPGME
+ slapt_pkg_action_list(AVAILABLE);
+ break;
+#ifdef SLAPT_HAS_GPGME
case ADD_KEYS:
- slapt_pkg_action_add_keys(global_config);
- break;
- #endif
+ slapt_pkg_action_add_keys(global_config);
+ break;
+#endif
case FILELIST:
- while (optind < argc) {
- slapt_pkg_action_filelist( argv[optind++] );
- }
- break;
+ while (optind < argc) {
+ slapt_pkg_action_filelist(argv[optind++]);
+ }
+ break;
case USAGE:
default:
- printf("main.c(l.%d): This should never be reached\n", __LINE__);
- exit(255);
- }
+ printf("main.c(l.%d): This should never be reached\n", __LINE__);
+ exit(255);
+ }
- slapt_free_rc_config(global_config);
- curl_global_cleanup();
- return EXIT_SUCCESS;
+ slapt_free_rc_config(global_config);
+ curl_global_cleanup();
+ return EXIT_SUCCESS;
}
void usage(void)
{
- printf("%s - Jason Woodward <woodwardj at jaos dot org>\n",PACKAGE);
- printf(gettext("An implementation of the Debian APT system to Slackware\n"));
- printf(gettext("Usage:\n"));
- printf(gettext("%s [option(s)] [target]\n"),PACKAGE);
- printf("\n");
- printf(gettext("Targets:\n"));
- printf(" -u, --update %s\n",gettext("retrieve pkg data from MIRROR"));
- printf(" --upgrade %s\n",gettext("upgrade installed pkgs"));
- printf(" --dist-upgrade %s\n",gettext("upgrade to newer release"));
- printf(" -i, --install %s\n",gettext("[pkg name(s)] - install specified pkg(s)"));
- printf(" --install-set %s\n",gettext("[disk set(s)] - install specified disk set(s)"));
- printf(" --remove %s\n",gettext("[pkg name(s)] - remove specified pkg(s)"));
- printf(" --show %s\n",gettext("[pkg name(s)] - show pkg(s) description"));
- printf(" --filelist %s\n",gettext("[pkg name(s)] - show pkg(s) installed files"));
- printf(" --search %s\n",gettext("[expression] - search available pkgs"));
- printf(" --list %s\n",gettext("list pkgs"));
- printf(" --available %s\n",gettext("list available pkgs"));
- printf(" --installed %s\n",gettext("list installed pkgs"));
- printf(" --clean %s\n",gettext("purge cached pkgs"));
- printf(" --autoclean %s\n",gettext("only purge cache of older, unreacheable pkgs"));
- #ifdef SLAPT_HAS_GPGME
- printf(" --add-keys %s\n",gettext("retrieve GPG keys for sources"));
- #endif
- printf(" -h, --help %s\n",gettext("display this help and exit"));
- printf(" --version %s\n",gettext("print version and license info"));
- printf("\n");
- printf(gettext("Options:\n"));
- printf(" -d, --download-only %s\n",gettext("only download pkg on install/upgrade"));
- printf(" -s, --simulate %s\n",gettext("show pkgs to be installed/upgraded"));
- printf(" -y, --no-prompt %s\n",gettext("do not prompt during install/upgrade"));
- printf(" -p, --prompt %s\n",gettext("always prompt during install/upgrade"));
- printf(" --reinstall %s\n",gettext("reinstall the pkg"));
- printf(" --ignore-excludes %s\n",gettext("install/upgrade excludes"));
- printf(" --no-md5 %s\n",gettext("do not perform md5 check sum"));
- printf(" --no-dep %s\n",gettext("skip dependency check"));
- printf(" --ignore-dep %s\n",gettext("ignore dependency failures"));
- printf(" --print-uris %s\n",gettext("print URIs only, do not download"));
- printf(" -S, --show-stats %s\n",gettext("show download statistics"));
- printf(" -c, --config [] %s\n",gettext("specify alternate slapt-getrc location"));
- printf(" --remove-obsolete %s\n",gettext("remove obsolete packages"));
- printf(" --retry [] %s\n",gettext("specify number of download retry attempts"));
- printf(" --no-upgrade %s\n",gettext("install package, do not attempt to upgrade"));
- #ifdef SLAPT_HAS_GPGME
- printf(" --allow-unauthenticated %s\n",gettext("allow unauthenticated packages"));
- #endif
+ printf("%s - Jason Woodward <woodwardj at jaos dot org>\n", PACKAGE);
+ printf(gettext("An implementation of the Debian APT system to Slackware\n"));
+ printf(gettext("Usage:\n"));
+ printf(gettext("%s [option(s)] [target]\n"), PACKAGE);
+ printf("\n");
+ printf(gettext("Targets:\n"));
+ printf(" -u, --update %s\n", gettext("retrieve pkg data from MIRROR"));
+ printf(" --upgrade %s\n", gettext("upgrade installed pkgs"));
+ printf(" --dist-upgrade %s\n", gettext("upgrade to newer release"));
+ printf(" -i, --install %s\n", gettext("[pkg name(s)] - install specified pkg(s)"));
+ printf(" --install-set %s\n", gettext("[disk set(s)] - install specified disk set(s)"));
+ printf(" --remove %s\n", gettext("[pkg name(s)] - remove specified pkg(s)"));
+ printf(" --show %s\n", gettext("[pkg name(s)] - show pkg(s) description"));
+ printf(" --filelist %s\n", gettext("[pkg name(s)] - show pkg(s) installed files"));
+ printf(" --search %s\n", gettext("[expression] - search available pkgs"));
+ printf(" --list %s\n", gettext("list pkgs"));
+ printf(" --available %s\n", gettext("list available pkgs"));
+ printf(" --installed %s\n", gettext("list installed pkgs"));
+ printf(" --clean %s\n", gettext("purge cached pkgs"));
+ printf(" --autoclean %s\n", gettext("only purge cache of older, unreacheable pkgs"));
+#ifdef SLAPT_HAS_GPGME
+ printf(" --add-keys %s\n", gettext("retrieve GPG keys for sources"));
+#endif
+ printf(" -h, --help %s\n", gettext("display this help and exit"));
+ printf(" --version %s\n", gettext("print version and license info"));
+ printf("\n");
+ printf(gettext("Options:\n"));
+ printf(" -d, --download-only %s\n", gettext("only download pkg on install/upgrade"));
+ printf(" -s, --simulate %s\n", gettext("show pkgs to be installed/upgraded"));
+ printf(" -y, --no-prompt %s\n", gettext("do not prompt during install/upgrade"));
+ printf(" -p, --prompt %s\n", gettext("always prompt during install/upgrade"));
+ printf(" --reinstall %s\n", gettext("reinstall the pkg"));
+ printf(" --ignore-excludes %s\n", gettext("install/upgrade excludes"));
+ printf(" --no-md5 %s\n", gettext("do not perform md5 check sum"));
+ printf(" --no-dep %s\n", gettext("skip dependency check"));
+ printf(" --ignore-dep %s\n", gettext("ignore dependency failures"));
+ printf(" --print-uris %s\n", gettext("print URIs only, do not download"));
+ printf(" -S, --show-stats %s\n", gettext("show download statistics"));
+ printf(" -c, --config [] %s\n", gettext("specify alternate slapt-getrc location"));
+ printf(" --remove-obsolete %s\n", gettext("remove obsolete packages"));
+ printf(" --retry [] %s\n", gettext("specify number of download retry attempts"));
+ printf(" --no-upgrade %s\n", gettext("install package, do not attempt to upgrade"));
+#ifdef SLAPT_HAS_GPGME
+ printf(" --allow-unauthenticated %s\n", gettext("allow unauthenticated packages"));
+#endif
}
void version_info(void)
{
- printf(gettext("%s version %s\n"),PACKAGE,VERSION);
- printf("\n");
- printf("This program is free software; you can redistribute it and/or modify\n");
- printf("it under the terms of the GNU General Public License as published by\n");
- printf("the Free Software Foundation; either version 2 of the License, or\n");
- printf("any later version.\n");
- printf("This program is distributed in the hope that it will be useful,\n");
- printf("\n");
- printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
- printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
- printf("GNU Library General Public License for more details.\n");
- printf("\n");
- printf("You should have received a copy of the GNU General Public License\n");
- printf("along with this program; if not, write to the Free Software\n");
- printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
-
+ printf(gettext("%s version %s\n"), PACKAGE, VERSION);
+ printf("\n");
+ printf("This program is free software; you can redistribute it and/or modify\n");
+ printf("it under the terms of the GNU General Public License as published by\n");
+ printf("the Free Software Foundation; either version 2 of the License, or\n");
+ printf("any later version.\n");
+ printf("This program is distributed in the hope that it will be useful,\n");
+ printf("\n");
+ printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
+ printf("GNU Library General Public License for more details.\n");
+ printf("\n");
+ printf("You should have received a copy of the GNU General Public License\n");
+ printf("along with this program; if not, write to the Free Software\n");
+ printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
}
-
diff --git a/src/main.h b/src/main.h
index 5faad93..ad77a88 100644
--- a/src/main.h
+++ b/src/main.h
@@ -17,7 +17,7 @@
*/
#ifndef _GNU_SOURCE
- #define _GNU_SOURCE
+#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
@@ -49,17 +49,28 @@
#include "transaction.h"
#include "action.h"
#ifdef SLAPT_HAS_GPGME
- #include "gpgme.h"
+#include "gpgme.h"
#endif
enum slapt_action {
- USAGE = 0, UPDATE, INSTALL, REMOVE, SHOW, SEARCH, UPGRADE,
- LIST, INSTALLED, CLEAN, SHOWVERSION, AUTOCLEAN, AVAILABLE,
- #ifdef SLAPT_HAS_GPGME
- ADD_KEYS,
- #endif
- INSTALL_DISK_SET,
- FILELIST
+ USAGE = 0,
+ UPDATE,
+ INSTALL,
+ REMOVE,
+ SHOW,
+ SEARCH,
+ UPGRADE,
+ LIST,
+ INSTALLED,
+ CLEAN,
+ SHOWVERSION,
+ AUTOCLEAN,
+ AVAILABLE,
+#ifdef SLAPT_HAS_GPGME
+ ADD_KEYS,
+#endif
+ INSTALL_DISK_SET,
+ FILELIST
};
#define SLAPT_UPDATE_OPT 'u'
@@ -93,11 +104,10 @@ enum slapt_action {
#define SLAPT_RETRY_OPT 'R'
#define SLAPT_NO_UPGRADE_OPT 'N'
#ifdef SLAPT_HAS_GPGME
- #define SLAPT_ADD_KEYS_OPT 'k'
- #define SLAPT_ALLOW_UNAUTH 'U'
+#define SLAPT_ADD_KEYS_OPT 'k'
+#define SLAPT_ALLOW_UNAUTH 'U'
#endif
#define SLAPT_FILELIST 'f'
#define SLAPT_DO_NOT_UNLINK_BAD_FILES 1
#define SLACKWARE_EXTRA_TESTING_PASTURE_WORKAROUND 1
-
diff --git a/src/package.c b/src/package.c
index f513fef..06bac75 100644
--- a/src/package.c
+++ b/src/package.c
@@ -19,12 +19,12 @@
#include "main.h"
struct slapt_pkg_version_parts {
- char **parts;
- unsigned int count;
+ char **parts;
+ unsigned int count;
};
/* used by qsort */
-static int pkg_compare (const void *a, const void *b);
+static int pkg_compare(const void *a, const void *b);
/* analyze the pkg version hunk by hunk */
static struct slapt_pkg_version_parts *break_down_pkg_version(const char *version);
/* parse the meta lines */
@@ -46,7 +46,7 @@ static slapt_pkg_info_t *find_or_requirement(slapt_pkg_list_t *avail_pkgs,
slapt_pkg_list_t *installed_pkgs,
char *required_str);
/* uncompress compressed package data */
-static FILE *slapt_gunzip_file (const char *file_name,FILE *dest_file);
+static FILE *slapt_gunzip_file(const char *file_name, FILE *dest_file);
#ifdef SLAPT_HAS_GPGME
/* check if signature is unauthenticated by "acceptable" reasons */
@@ -56,1727 +56,1655 @@ bool slapt_pkg_sign_is_unauthenticated(slapt_code_t code);
/* parse the PACKAGES.TXT file */
slapt_pkg_list_t *slapt_get_available_pkgs(void)
{
- FILE *pkg_list_fh;
- slapt_pkg_list_t *list = NULL;
+ FILE *pkg_list_fh;
+ slapt_pkg_list_t *list = NULL;
- /* open pkg list */
- pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L,"r");
- if (pkg_list_fh == NULL) {
- fprintf(stderr,gettext("Perhaps you want to run --update?\n"));
- list = slapt_init_pkg_list();
- return list; /* return an empty list */
- }
- list = slapt_parse_packages_txt(pkg_list_fh);
- fclose(pkg_list_fh);
+ /* open pkg list */
+ pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L, "r");
+ if (pkg_list_fh == NULL) {
+ fprintf(stderr, gettext("Perhaps you want to run --update?\n"));
+ list = slapt_init_pkg_list();
+ return list; /* return an empty list */
+ }
+ list = slapt_parse_packages_txt(pkg_list_fh);
+ fclose(pkg_list_fh);
- /* this is pointless to do if we wrote the data sorted, but this
+ /* this is pointless to do if we wrote the data sorted, but this
ensures upgrades from older, presorting slapt-gets still work
as expected. */
- qsort( list->pkgs, list->pkg_count, sizeof(list->pkgs[0]), pkg_compare );
+ qsort(list->pkgs, list->pkg_count, sizeof(list->pkgs[0]), pkg_compare);
- list->ordered = true;
+ list->ordered = true;
- return list;
+ return list;
}
slapt_pkg_list_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
{
- slapt_regex_t *name_regex = NULL,
- *mirror_regex = NULL,
- *priority_regex = NULL,
- *location_regex = NULL,
- *size_c_regex = NULL,
- *size_u_regex = NULL;
- ssize_t bytes_read;
- slapt_pkg_list_t *list = NULL;
- long f_pos = 0;
- size_t getline_len = 0;
- char *getline_buffer = NULL;
- char *char_pointer = NULL;
-
- list = slapt_init_pkg_list();
-
- /* compile our regexen */
- if ((name_regex = slapt_init_regex(SLAPT_PKG_NAME_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((mirror_regex = slapt_init_regex(SLAPT_PKG_MIRROR_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((priority_regex = slapt_init_regex(SLAPT_PKG_PRIORITY_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((location_regex = slapt_init_regex(SLAPT_PKG_LOCATION_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((size_c_regex = slapt_init_regex(SLAPT_PKG_SIZEC_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((size_u_regex = slapt_init_regex(SLAPT_PKG_SIZEU_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
-
- while ((bytes_read = getline(&getline_buffer,&getline_len,
- pkg_list_fh)) != EOF) {
-
- slapt_pkg_info_t *tmp_pkg;
+ slapt_regex_t *name_regex = NULL,
+ *mirror_regex = NULL,
+ *priority_regex = NULL,
+ *location_regex = NULL,
+ *size_c_regex = NULL,
+ *size_u_regex = NULL;
+ ssize_t bytes_read;
+ slapt_pkg_list_t *list = NULL;
+ long f_pos = 0;
+ size_t getline_len = 0;
+ char *getline_buffer = NULL;
+ char *char_pointer = NULL;
- getline_buffer[bytes_read - 1] = '\0';
-
- /* pull out package data */
- if (strstr(getline_buffer,"PACKAGE NAME") == NULL)
- continue;
-
- slapt_execute_regex(name_regex,getline_buffer);
+ list = slapt_init_pkg_list();
- /* skip this line if we didn't find a package name */
- if (name_regex->reg_return != 0) {
- fprintf(stderr,gettext("regex failed on [%s]\n"),getline_buffer);
- continue;
+ /* compile our regexen */
+ if ((name_regex = slapt_init_regex(SLAPT_PKG_NAME_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((mirror_regex = slapt_init_regex(SLAPT_PKG_MIRROR_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((priority_regex = slapt_init_regex(SLAPT_PKG_PRIORITY_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((location_regex = slapt_init_regex(SLAPT_PKG_LOCATION_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((size_c_regex = slapt_init_regex(SLAPT_PKG_SIZEC_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((size_u_regex = slapt_init_regex(SLAPT_PKG_SIZEU_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
}
- /* otherwise keep going and parse out the rest of the pkg data */
- tmp_pkg = slapt_init_pkg();
+ while ((bytes_read = getline(&getline_buffer, &getline_len,
+ pkg_list_fh)) != EOF) {
+ slapt_pkg_info_t *tmp_pkg;
- /* pkg name base */
- tmp_pkg->name = slapt_regex_extract_match(name_regex, getline_buffer, 1);
- /* pkg version */
- tmp_pkg->version = slapt_regex_extract_match(name_regex, getline_buffer, 2);
- /* file extension */
- tmp_pkg->file_ext = slapt_regex_extract_match(name_regex, getline_buffer, 3);
+ getline_buffer[bytes_read - 1] = '\0';
- /* mirror */
- f_pos = ftell(pkg_list_fh);
- if (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) {
+ /* pull out package data */
+ if (strstr(getline_buffer, "PACKAGE NAME") == NULL)
+ continue;
- slapt_execute_regex(mirror_regex,getline_buffer);
+ slapt_execute_regex(name_regex, getline_buffer);
- if (mirror_regex->reg_return == 0) {
- tmp_pkg->mirror = slapt_regex_extract_match(mirror_regex, getline_buffer, 1);
- } else {
- /* mirror isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
- }
+ /* skip this line if we didn't find a package name */
+ if (name_regex->reg_return != 0) {
+ fprintf(stderr, gettext("regex failed on [%s]\n"), getline_buffer);
+ continue;
+ }
+ /* otherwise keep going and parse out the rest of the pkg data */
- /* priority */
- f_pos = ftell(pkg_list_fh);
- if (getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF) {
+ tmp_pkg = slapt_init_pkg();
- slapt_execute_regex(priority_regex, getline_buffer);
+ /* pkg name base */
+ tmp_pkg->name = slapt_regex_extract_match(name_regex, getline_buffer, 1);
+ /* pkg version */
+ tmp_pkg->version = slapt_regex_extract_match(name_regex, getline_buffer, 2);
+ /* file extension */
+ tmp_pkg->file_ext = slapt_regex_extract_match(name_regex, getline_buffer, 3);
- if (priority_regex->reg_return == 0) {
- char *priority_string = slapt_regex_extract_match(priority_regex, getline_buffer, 1);
- if (priority_string != NULL) {
- tmp_pkg->priority = atoi(priority_string);
- free(priority_string);
- }
- } else {
- /* priority isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
- }
+ /* mirror */
+ f_pos = ftell(pkg_list_fh);
+ if (getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF) {
+ slapt_execute_regex(mirror_regex, getline_buffer);
- /* location */
- if ((getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)) {
+ if (mirror_regex->reg_return == 0) {
+ tmp_pkg->mirror = slapt_regex_extract_match(mirror_regex, getline_buffer, 1);
+ } else {
+ /* mirror isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+ }
- slapt_execute_regex(location_regex,getline_buffer);
+ /* priority */
+ f_pos = ftell(pkg_list_fh);
+ if (getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF) {
+ slapt_execute_regex(priority_regex, getline_buffer);
+
+ if (priority_regex->reg_return == 0) {
+ char *priority_string = slapt_regex_extract_match(priority_regex, getline_buffer, 1);
+ if (priority_string != NULL) {
+ tmp_pkg->priority = atoi(priority_string);
+ free(priority_string);
+ }
+ } else {
+ /* priority isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+ }
- if (location_regex->reg_return == 0) {
+ /* location */
+ if ((getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF)) {
+ slapt_execute_regex(location_regex, getline_buffer);
- tmp_pkg->location = slapt_regex_extract_match(location_regex, getline_buffer, 1);
+ if (location_regex->reg_return == 0) {
+ tmp_pkg->location = slapt_regex_extract_match(location_regex, getline_buffer, 1);
#if SLACKWARE_EXTRA_TESTING_PASTURE_WORKAROUND == 1
- /*
+ /*
extra, testing, and pasture support
they add in extraneous /extra/, /testing/, or /pasture/ in the
PACKAGES.TXT location. this fixes the downloads and md5 checksum
matching
*/
- if (strstr(tmp_pkg->location,"./testing/") != NULL) {
- char *tmp_location = slapt_malloc(
- sizeof *tmp_location *
- (strlen(tmp_pkg->location) - 7) /* ./testing - 2 */
- );
- tmp_location[0] = '.';
- tmp_location[1] = '\0';
- strncat(tmp_location,
- &tmp_pkg->location[0] + 9, /* ./testing */
- strlen(tmp_pkg->location) - 9 /* ./testing */
- );
- free(tmp_pkg->location);
- tmp_pkg->location = tmp_location;
- } else if (strstr(tmp_pkg->location,"./extra/") != NULL) {
- char *tmp_location = slapt_malloc(
- sizeof *tmp_location *
- (strlen(tmp_pkg->location) - 5 ) /* ./extra/ - 2 */
- );
- tmp_location[0] = '.';
- tmp_location[1] = '\0';
- strncat(tmp_location,
- &tmp_pkg->location[0] + 7, /* ./extra */
- strlen(tmp_pkg->location) - 7 /* ./extra */
- );
- free(tmp_pkg->location);
- tmp_pkg->location = tmp_location;
- } else if (strstr(tmp_pkg->location,"./pasture") != NULL) {
- char *tmp_location = slapt_malloc(
- sizeof *tmp_location *
- (strlen(tmp_pkg->location) - 7) /* ./pasture - 2 */
- );
- tmp_location[0] = '.';
- tmp_location[1] = '\0';
- strncat(tmp_location,
- &tmp_pkg->location[0] + 9, /* ./pasture */
- strlen(tmp_pkg->location) - 9 /* ./pasture */
- );
- free(tmp_pkg->location);
- tmp_pkg->location = tmp_location;
- }
+ if (strstr(tmp_pkg->location, "./testing/") != NULL) {
+ char *tmp_location = slapt_malloc(
+ sizeof *tmp_location *
+ (strlen(tmp_pkg->location) - 7) /* ./testing - 2 */
+ );
+ tmp_location[0] = '.';
+ tmp_location[1] = '\0';
+ strncat(tmp_location,
+ &tmp_pkg->location[0] + 9, /* ./testing */
+ strlen(tmp_pkg->location) - 9 /* ./testing */
+ );
+ free(tmp_pkg->location);
+ tmp_pkg->location = tmp_location;
+ } else if (strstr(tmp_pkg->location, "./extra/") != NULL) {
+ char *tmp_location = slapt_malloc(
+ sizeof *tmp_location *
+ (strlen(tmp_pkg->location) - 5) /* ./extra/ - 2 */
+ );
+ tmp_location[0] = '.';
+ tmp_location[1] = '\0';
+ strncat(tmp_location,
+ &tmp_pkg->location[0] + 7, /* ./extra */
+ strlen(tmp_pkg->location) - 7 /* ./extra */
+ );
+ free(tmp_pkg->location);
+ tmp_pkg->location = tmp_location;
+ } else if (strstr(tmp_pkg->location, "./pasture") != NULL) {
+ char *tmp_location = slapt_malloc(
+ sizeof *tmp_location *
+ (strlen(tmp_pkg->location) - 7) /* ./pasture - 2 */
+ );
+ tmp_location[0] = '.';
+ tmp_location[1] = '\0';
+ strncat(tmp_location,
+ &tmp_pkg->location[0] + 9, /* ./pasture */
+ strlen(tmp_pkg->location) - 9 /* ./pasture */
+ );
+ free(tmp_pkg->location);
+ tmp_pkg->location = tmp_location;
+ }
#endif
- } else {
- fprintf(stderr,gettext("regexec failed to parse location\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
- }
- } else {
- fprintf(stderr,gettext("getline reached EOF attempting to read location\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
- }
-
- /* size_c */
- if ((getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)) {
-
- char *size_c = NULL;
-
- slapt_execute_regex(size_c_regex,getline_buffer);
+ } else {
+ fprintf(stderr, gettext("regexec failed to parse location\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
+ }
+ } else {
+ fprintf(stderr, gettext("getline reached EOF attempting to read location\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
+ }
- if (size_c_regex->reg_return == 0) {
- size_c = slapt_regex_extract_match(size_c_regex, getline_buffer, 1);
- tmp_pkg->size_c = strtol(size_c, (char **)NULL, 10);
- free(size_c);
- } else {
- fprintf(stderr,gettext("regexec failed to parse size_c\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
- }
- } else {
- fprintf(stderr,gettext("getline reached EOF attempting to read size_c\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
- }
+ /* size_c */
+ if ((getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF)) {
+ char *size_c = NULL;
- /* size_u */
- if ((getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)) {
+ slapt_execute_regex(size_c_regex, getline_buffer);
- char *size_u = NULL;
+ if (size_c_regex->reg_return == 0) {
+ size_c = slapt_regex_extract_match(size_c_regex, getline_buffer, 1);
+ tmp_pkg->size_c = strtol(size_c, (char **)NULL, 10);
+ free(size_c);
+ } else {
+ fprintf(stderr, gettext("regexec failed to parse size_c\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
+ }
+ } else {
+ fprintf(stderr, gettext("getline reached EOF attempting to read size_c\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
+ }
- slapt_execute_regex(size_u_regex,getline_buffer);
+ /* size_u */
+ if ((getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF)) {
+ char *size_u = NULL;
- if (size_u_regex->reg_return == 0) {
- size_u = slapt_regex_extract_match(size_u_regex, getline_buffer, 1);
- tmp_pkg->size_u = strtol(size_u, (char **)NULL, 10);
- free(size_u);
- } else {
- fprintf(stderr,gettext("regexec failed to parse size_u\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
- }
- } else {
- fprintf(stderr,gettext("getline reached EOF attempting to read size_u\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
- }
-
- /* required, if provided */
- f_pos = ftell(pkg_list_fh);
- if (
- ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
- ((char_pointer = strstr(getline_buffer,"PACKAGE REQUIRED")) != NULL)
- ) {
- char *tmp_realloc = NULL;
- size_t req_len = 18; /* "PACKAGE REQUIRED" + 2 */
- getline_buffer[bytes_read - 1] = '\0';
+ slapt_execute_regex(size_u_regex, getline_buffer);
- tmp_realloc = realloc(
- tmp_pkg->required,
- sizeof *tmp_pkg->required * (strlen(char_pointer + req_len) + 1)
- );
- if (tmp_realloc != NULL) {
- tmp_pkg->required = tmp_realloc;
- strncpy(tmp_pkg->required,char_pointer + req_len,
- strlen(char_pointer + req_len));
- tmp_pkg->required[ strlen(char_pointer + req_len) ] = '\0';
+ if (size_u_regex->reg_return == 0) {
+ size_u = slapt_regex_extract_match(size_u_regex, getline_buffer, 1);
+ tmp_pkg->size_u = strtol(size_u, (char **)NULL, 10);
+ free(size_u);
+ } else {
+ fprintf(stderr, gettext("regexec failed to parse size_u\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
+ }
+ } else {
+ fprintf(stderr, gettext("getline reached EOF attempting to read size_u\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
}
- } else {
- /* required isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* conflicts, if provided */
- f_pos = ftell(pkg_list_fh);
- if (
- ((bytes_read = getline(&getline_buffer,&getline_len,
- pkg_list_fh)) != EOF) &&
- ((char_pointer = strstr(getline_buffer,"PACKAGE CONFLICTS")) != NULL)
- ) {
- char *tmp_realloc = NULL;
- size_t req_len = 19; /* "PACKAGE CONFLICTS" + 2 */
- getline_buffer[bytes_read - 1] = '\0';
- tmp_realloc = realloc(tmp_pkg->conflicts,
- sizeof *tmp_pkg->conflicts * (strlen(char_pointer + req_len) + 1)
- );
- if (tmp_realloc != NULL) {
- tmp_pkg->conflicts = tmp_realloc;
- strncpy(tmp_pkg->conflicts,char_pointer + req_len,
- strlen(char_pointer + req_len));
- tmp_pkg->conflicts[ strlen(char_pointer + req_len) ] = '\0';
+ /* required, if provided */
+ f_pos = ftell(pkg_list_fh);
+ if (
+ ((bytes_read = getline(&getline_buffer, &getline_len, pkg_list_fh)) != EOF) &&
+ ((char_pointer = strstr(getline_buffer, "PACKAGE REQUIRED")) != NULL)) {
+ char *tmp_realloc = NULL;
+ size_t req_len = 18; /* "PACKAGE REQUIRED" + 2 */
+ getline_buffer[bytes_read - 1] = '\0';
+
+ tmp_realloc = realloc(
+ tmp_pkg->required,
+ sizeof *tmp_pkg->required * (strlen(char_pointer + req_len) + 1));
+ if (tmp_realloc != NULL) {
+ tmp_pkg->required = tmp_realloc;
+ strncpy(tmp_pkg->required, char_pointer + req_len,
+ strlen(char_pointer + req_len));
+ tmp_pkg->required[strlen(char_pointer + req_len)] = '\0';
+ }
+ } else {
+ /* required isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
}
- } else {
- /* conflicts isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* suggests, if provided */
- f_pos = ftell(pkg_list_fh);
- if (
- ((bytes_read = getline(&getline_buffer,&getline_len,
- pkg_list_fh)) != EOF) &&
- ((char_pointer = strstr(getline_buffer,"PACKAGE SUGGESTS")) != NULL)
- ) {
- char *tmp_realloc = NULL;
- size_t req_len = 18; /* "PACKAGE SUGGESTS" + 2 */
- getline_buffer[bytes_read - 1] = '\0';
- tmp_realloc = realloc(tmp_pkg->suggests,
- sizeof *tmp_pkg->suggests * (strlen(char_pointer + req_len) + 1)
- );
- if (tmp_realloc != NULL) {
- tmp_pkg->suggests = tmp_realloc;
- strncpy(tmp_pkg->suggests,char_pointer + req_len,
- strlen(char_pointer + req_len));
- tmp_pkg->suggests[ strlen(char_pointer + req_len) ] = '\0';
- }
- } else {
- /* suggests isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* md5 checksum */
- f_pos = ftell(pkg_list_fh);
- if (
- ((bytes_read = getline(&getline_buffer,&getline_len,
- pkg_list_fh)) != EOF) &&
- (strstr(getline_buffer,"PACKAGE MD5") != NULL)
- ) {
- char *md5sum;
- getline_buffer[bytes_read - 1] = '\0';
- md5sum = (char *)strpbrk(getline_buffer,":") + 1;
- while (*md5sum != 0 && isspace(*md5sum)) {
- md5sum++;
- }
- /* don't overflow the buffer */
- if (strlen(md5sum) > SLAPT_MD5_STR_LEN) {
- fprintf(stderr, gettext("md5 sum too long\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
+ /* conflicts, if provided */
+ f_pos = ftell(pkg_list_fh);
+ if (
+ ((bytes_read = getline(&getline_buffer, &getline_len,
+ pkg_list_fh)) != EOF) &&
+ ((char_pointer = strstr(getline_buffer, "PACKAGE CONFLICTS")) != NULL)) {
+ char *tmp_realloc = NULL;
+ size_t req_len = 19; /* "PACKAGE CONFLICTS" + 2 */
+ getline_buffer[bytes_read - 1] = '\0';
+
+ tmp_realloc = realloc(tmp_pkg->conflicts,
+ sizeof *tmp_pkg->conflicts * (strlen(char_pointer + req_len) + 1));
+ if (tmp_realloc != NULL) {
+ tmp_pkg->conflicts = tmp_realloc;
+ strncpy(tmp_pkg->conflicts, char_pointer + req_len,
+ strlen(char_pointer + req_len));
+ tmp_pkg->conflicts[strlen(char_pointer + req_len)] = '\0';
+ }
+ } else {
+ /* conflicts isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
}
- strncpy(tmp_pkg->md5,md5sum,SLAPT_MD5_STR_LEN);
- tmp_pkg->md5[SLAPT_MD5_STR_LEN - 1] = '\0';
- } else {
- /* md5 sum isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* description */
- if (
- (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) &&
- (strstr(getline_buffer,"PACKAGE DESCRIPTION") != NULL)
- ) {
+ /* suggests, if provided */
+ f_pos = ftell(pkg_list_fh);
+ if (
+ ((bytes_read = getline(&getline_buffer, &getline_len,
+ pkg_list_fh)) != EOF) &&
+ ((char_pointer = strstr(getline_buffer, "PACKAGE SUGGESTS")) != NULL)) {
+ char *tmp_realloc = NULL;
+ size_t req_len = 18; /* "PACKAGE SUGGESTS" + 2 */
+ getline_buffer[bytes_read - 1] = '\0';
+
+ tmp_realloc = realloc(tmp_pkg->suggests,
+ sizeof *tmp_pkg->suggests * (strlen(char_pointer + req_len) + 1));
+ if (tmp_realloc != NULL) {
+ tmp_pkg->suggests = tmp_realloc;
+ strncpy(tmp_pkg->suggests, char_pointer + req_len,
+ strlen(char_pointer + req_len));
+ tmp_pkg->suggests[strlen(char_pointer + req_len)] = '\0';
+ }
+ } else {
+ /* suggests isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
- while (1) {
- char *tmp_desc = NULL;
+ /* md5 checksum */
+ f_pos = ftell(pkg_list_fh);
+ if (
+ ((bytes_read = getline(&getline_buffer, &getline_len,
+ pkg_list_fh)) != EOF) &&
+ (strstr(getline_buffer, "PACKAGE MD5") != NULL)) {
+ char *md5sum;
+ getline_buffer[bytes_read - 1] = '\0';
+ md5sum = (char *)strpbrk(getline_buffer, ":") + 1;
+ while (*md5sum != 0 && isspace(*md5sum)) {
+ md5sum++;
+ }
+ /* don't overflow the buffer */
+ if (strlen(md5sum) > SLAPT_MD5_STR_LEN) {
+ fprintf(stderr, gettext("md5 sum too long\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
+ }
- if ((bytes_read = getline(&getline_buffer,&getline_len,
- pkg_list_fh)) == EOF) {
- break;
+ strncpy(tmp_pkg->md5, md5sum, SLAPT_MD5_STR_LEN);
+ tmp_pkg->md5[SLAPT_MD5_STR_LEN - 1] = '\0';
+ } else {
+ /* md5 sum isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
}
- if (strcmp(getline_buffer,"\n") == 0) {
- break;
+ /* description */
+ if (
+ (getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF) &&
+ (strstr(getline_buffer, "PACKAGE DESCRIPTION") != NULL)) {
+ while (1) {
+ char *tmp_desc = NULL;
+
+ if ((bytes_read = getline(&getline_buffer, &getline_len,
+ pkg_list_fh)) == EOF) {
+ break;
+ }
+
+ if (strcmp(getline_buffer, "\n") == 0) {
+ break;
+ }
+
+ tmp_desc = realloc(tmp_pkg->description,
+ sizeof *tmp_pkg->description *
+ (strlen(tmp_pkg->description) + bytes_read + 1));
+ if (tmp_desc == NULL) {
+ break;
+ }
+ tmp_pkg->description = tmp_desc;
+ strncat(tmp_pkg->description, getline_buffer, bytes_read);
+ }
+ } else {
+ fprintf(stderr, gettext("error attempting to read pkg description\n"));
+ slapt_free_pkg(tmp_pkg);
+ continue;
}
- tmp_desc = realloc(tmp_pkg->description,
- sizeof *tmp_pkg->description *
- (strlen(tmp_pkg->description) + bytes_read + 1)
- );
- if (tmp_desc == NULL) {
- break;
+ /* fillin details */
+ if (tmp_pkg->location == NULL) {
+ tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->location[0] = '\0';
+ }
+ if (tmp_pkg->description == NULL) {
+ tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->description);
+ tmp_pkg->description[0] = '\0';
+ }
+ if (tmp_pkg->mirror == NULL) {
+ tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->mirror);
+ tmp_pkg->mirror[0] = '\0';
}
- tmp_pkg->description = tmp_desc;
- strncat(tmp_pkg->description,getline_buffer,bytes_read);
-
- }
- } else {
- fprintf(stderr,gettext("error attempting to read pkg description\n"));
- slapt_free_pkg(tmp_pkg);
- continue;
- }
- /* fillin details */
- if (tmp_pkg->location == NULL) {
- tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->location[0] = '\0';
- }
- if (tmp_pkg->description == NULL) {
- tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->description);
- tmp_pkg->description[0] = '\0';
- }
- if (tmp_pkg->mirror == NULL) {
- tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->mirror);
- tmp_pkg->mirror[0] = '\0';
+ slapt_add_pkg_to_pkg_list(list, tmp_pkg);
+ tmp_pkg = NULL;
}
- slapt_add_pkg_to_pkg_list(list,tmp_pkg);
- tmp_pkg = NULL;
- }
+ if (getline_buffer)
+ free(getline_buffer);
- if (getline_buffer)
- free(getline_buffer);
+ slapt_free_regex(name_regex);
+ slapt_free_regex(mirror_regex);
+ slapt_free_regex(priority_regex);
+ slapt_free_regex(location_regex);
+ slapt_free_regex(size_c_regex);
+ slapt_free_regex(size_u_regex);
- slapt_free_regex(name_regex);
- slapt_free_regex(mirror_regex);
- slapt_free_regex(priority_regex);
- slapt_free_regex(location_regex);
- slapt_free_regex(size_c_regex);
- slapt_free_regex(size_u_regex);
-
- list->free_pkgs = true;
- return list;
+ list->free_pkgs = true;
+ return list;
}
char *slapt_gen_short_pkg_description(slapt_pkg_info_t *pkg)
{
- char *short_description = NULL;
- size_t string_size = 0;
+ char *short_description = NULL;
+ size_t string_size = 0;
- if (strchr(pkg->description,'\n') != NULL) {
- string_size = strlen(pkg->description) -
- (strlen(pkg->name) + 2) - strlen(strchr(pkg->description,'\n'));
- }
+ if (strchr(pkg->description, '\n') != NULL) {
+ string_size = strlen(pkg->description) -
+ (strlen(pkg->name) + 2) - strlen(strchr(pkg->description, '\n'));
+ }
- /* quit now if the description is going to be empty */
- if ((int)string_size < 1)
- return NULL;
+ /* quit now if the description is going to be empty */
+ if ((int)string_size < 1)
+ return NULL;
- short_description = strndup(
- pkg->description + (strlen(pkg->name) + 2),
- string_size
- );
+ short_description = strndup(
+ pkg->description + (strlen(pkg->name) + 2),
+ string_size);
- return short_description;
+ return short_description;
}
-
slapt_pkg_list_t *slapt_get_installed_pkgs(void)
{
- DIR *pkg_log_dir;
- char *pkg_log_dirname = NULL;
- struct dirent *file;
- slapt_regex_t *ip_regex = NULL,
- *compressed_size_reg = NULL,
- *uncompressed_size_reg = NULL;
- slapt_pkg_list_t *list = NULL;
- size_t pls = 1;
-
- list = slapt_init_pkg_list();
-
- if ((ip_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((compressed_size_reg = slapt_init_regex(SLAPT_PKG_LOG_SIZEC_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
- if ((uncompressed_size_reg = slapt_init_regex(SLAPT_PKG_LOG_SIZEU_PATTERN)) == NULL) {
- exit(EXIT_FAILURE);
- }
+ DIR *pkg_log_dir;
+ char *pkg_log_dirname = NULL;
+ struct dirent *file;
+ slapt_regex_t *ip_regex = NULL,
+ *compressed_size_reg = NULL,
+ *uncompressed_size_reg = NULL;
+ slapt_pkg_list_t *list = NULL;
+ size_t pls = 1;
- pkg_log_dirname = slapt_gen_package_log_dir_name();
+ list = slapt_init_pkg_list();
- if ((pkg_log_dir = opendir(pkg_log_dirname)) == NULL) {
+ if ((ip_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((compressed_size_reg = slapt_init_regex(SLAPT_PKG_LOG_SIZEC_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if ((uncompressed_size_reg = slapt_init_regex(SLAPT_PKG_LOG_SIZEU_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- if (errno)
- perror(pkg_log_dirname);
+ pkg_log_dirname = slapt_gen_package_log_dir_name();
- free(pkg_log_dirname);
- return list;
- }
+ if ((pkg_log_dir = opendir(pkg_log_dirname)) == NULL) {
+ if (errno)
+ perror(pkg_log_dirname);
- while ((file = readdir(pkg_log_dir)) != NULL) {
- slapt_pkg_info_t *tmp_pkg = NULL;
- FILE *pkg_f = NULL;
- char *pkg_f_name = NULL;
- struct stat stat_buf;
- char *pkg_data = NULL;
+ free(pkg_log_dirname);
+ return list;
+ }
- slapt_execute_regex(ip_regex,file->d_name);
+ while ((file = readdir(pkg_log_dir)) != NULL) {
+ slapt_pkg_info_t *tmp_pkg = NULL;
+ FILE *pkg_f = NULL;
+ char *pkg_f_name = NULL;
+ struct stat stat_buf;
+ char *pkg_data = NULL;
- /* skip if it doesn't match our regex */
- if (ip_regex->reg_return != 0)
- continue;
+ slapt_execute_regex(ip_regex, file->d_name);
- tmp_pkg = slapt_init_pkg();
+ /* skip if it doesn't match our regex */
+ if (ip_regex->reg_return != 0)
+ continue;
- tmp_pkg->name = slapt_regex_extract_match(ip_regex, file->d_name, 1);
- tmp_pkg->version = slapt_regex_extract_match(ip_regex, file->d_name, 2);
+ tmp_pkg = slapt_init_pkg();
- tmp_pkg->file_ext = slapt_malloc(sizeof *tmp_pkg->file_ext * 1);
- tmp_pkg->file_ext[0] = '\0';
+ tmp_pkg->name = slapt_regex_extract_match(ip_regex, file->d_name, 1);
+ tmp_pkg->version = slapt_regex_extract_match(ip_regex, file->d_name, 2);
- /* build the package filename including the package directory */
- pkg_f_name = slapt_malloc(
- sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(file->d_name) + 2)
- );
- pkg_f_name[0] = '\0';
- strncat(pkg_f_name,pkg_log_dirname,strlen(pkg_log_dirname));
- strncat(pkg_f_name,"/",1);
- strncat(pkg_f_name,file->d_name,strlen(file->d_name));
+ tmp_pkg->file_ext = slapt_malloc(sizeof *tmp_pkg->file_ext * 1);
+ tmp_pkg->file_ext[0] = '\0';
- /*
+ /* build the package filename including the package directory */
+ pkg_f_name = slapt_malloc(
+ sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(file->d_name) + 2));
+ pkg_f_name[0] = '\0';
+ strncat(pkg_f_name, pkg_log_dirname, strlen(pkg_log_dirname));
+ strncat(pkg_f_name, "/", 1);
+ strncat(pkg_f_name, file->d_name, strlen(file->d_name));
+
+ /*
open the package log file so that we can mmap it and parse out the
package attributes.
*/
- pkg_f = slapt_open_file(pkg_f_name,"r");
- if (pkg_f == NULL)
- exit(EXIT_FAILURE);
-
- /* used with mmap */
- if (stat(pkg_f_name,&stat_buf) == -1) {
-
- if (errno)
- perror(pkg_f_name);
-
- fprintf(stderr,"stat failed: %s\n",pkg_f_name);
- exit(EXIT_FAILURE);
- }
+ pkg_f = slapt_open_file(pkg_f_name, "r");
+ if (pkg_f == NULL)
+ exit(EXIT_FAILURE);
- /* don't mmap empty files */
- if ((int)stat_buf.st_size < 1) {
- slapt_free_pkg(tmp_pkg);
- free(pkg_f_name);
- fclose(pkg_f);
- continue;
- } else {
- /* only mmap what we need */
- pls = (size_t)stat_buf.st_size;
- if (pls > SLAPT_MAX_MMAP_SIZE)
- pls = SLAPT_MAX_MMAP_SIZE;
- }
+ /* used with mmap */
+ if (stat(pkg_f_name, &stat_buf) == -1) {
+ if (errno)
+ perror(pkg_f_name);
- pkg_data = (char *)mmap(0,pls,
- PROT_READ|PROT_WRITE,MAP_PRIVATE,fileno(pkg_f),0);
- if (pkg_data == (void *)-1) {
+ fprintf(stderr, "stat failed: %s\n", pkg_f_name);
+ exit(EXIT_FAILURE);
+ }
- if (errno)
- perror(pkg_f_name);
+ /* don't mmap empty files */
+ if ((int)stat_buf.st_size < 1) {
+ slapt_free_pkg(tmp_pkg);
+ free(pkg_f_name);
+ fclose(pkg_f);
+ continue;
+ } else {
+ /* only mmap what we need */
+ pls = (size_t)stat_buf.st_size;
+ if (pls > SLAPT_MAX_MMAP_SIZE)
+ pls = SLAPT_MAX_MMAP_SIZE;
+ }
- fprintf(stderr,"mmap failed: %s\n",pkg_f_name);
- exit(EXIT_FAILURE);
- }
+ pkg_data = (char *)mmap(0, pls,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE, fileno(pkg_f), 0);
+ if (pkg_data == (void *)-1) {
+ if (errno)
+ perror(pkg_f_name);
- fclose(pkg_f);
+ fprintf(stderr, "mmap failed: %s\n", pkg_f_name);
+ exit(EXIT_FAILURE);
+ }
- /* add \0 for strlen to work */
- pkg_data[pls - 1] = '\0';
+ fclose(pkg_f);
+
+ /* add \0 for strlen to work */
+ pkg_data[pls - 1] = '\0';
+
+ /* pull out compressed size */
+ slapt_execute_regex(compressed_size_reg, pkg_data);
+ if (compressed_size_reg->reg_return == 0) {
+ char *size_c = slapt_regex_extract_match(compressed_size_reg, pkg_data, 1);
+ char *unit = slapt_regex_extract_match(compressed_size_reg, pkg_data, 2);
+ double c = strtof(size_c, (char **)NULL);
+ if (strcmp(unit, "M") == 0)
+ c *= 1024;
+ tmp_pkg->size_c = round(c);
+ free(size_c);
+ free(unit);
+ }
- /* pull out compressed size */
- slapt_execute_regex(compressed_size_reg,pkg_data);
- if (compressed_size_reg->reg_return == 0) {
- char *size_c = slapt_regex_extract_match(compressed_size_reg, pkg_data, 1);
- char *unit = slapt_regex_extract_match(compressed_size_reg, pkg_data, 2);
- double c = strtof(size_c, (char **)NULL);
- if ( strcmp(unit, "M") == 0 )
- c *= 1024;
- tmp_pkg->size_c = round(c);
- free(size_c);
- free(unit);
- }
+ /* pull out uncompressed size */
+ slapt_execute_regex(uncompressed_size_reg, pkg_data);
+ if (uncompressed_size_reg->reg_return == 0) {
+ char *size_u = slapt_regex_extract_match(uncompressed_size_reg, pkg_data, 1);
+ char *unit = slapt_regex_extract_match(uncompressed_size_reg, pkg_data, 2);
+ double u = strtof(size_u, (char **)NULL);
+ if (strcmp(unit, "M") == 0)
+ u *= 1024;
+ tmp_pkg->size_u = round(u);
+ free(size_u);
+ free(unit);
+ }
- /* pull out uncompressed size */
- slapt_execute_regex(uncompressed_size_reg,pkg_data);
- if (uncompressed_size_reg->reg_return == 0 ) {
- char *size_u = slapt_regex_extract_match(uncompressed_size_reg, pkg_data, 1);
- char *unit = slapt_regex_extract_match(uncompressed_size_reg, pkg_data, 2);
- double u = strtof(size_u, (char **)NULL);
- if ( strcmp(unit, "M") == 0 )
- u *= 1024;
- tmp_pkg->size_u = round(u);
- free(size_u);
- free(unit);
- }
+ /* Ignore the location for installed packages */
- /* Ignore the location for installed packages */
+ if (strstr(pkg_data, "PACKAGE DESCRIPTION") != NULL) {
+ char *desc_p = strstr(pkg_data, "PACKAGE DESCRIPTION");
+ char *nl = strchr(desc_p, '\n');
+ char *filelist_p = NULL;
- if (strstr(pkg_data,"PACKAGE DESCRIPTION") != NULL) {
- char *desc_p = strstr(pkg_data,"PACKAGE DESCRIPTION");
- char *nl = strchr(desc_p,'\n');
- char *filelist_p = NULL;
+ if (nl != NULL)
+ desc_p = ++nl;
- if (nl != NULL)
- desc_p = ++nl;
+ filelist_p = strstr(desc_p, "FILE LIST");
+ if (filelist_p != NULL) {
+ char *tmp_desc = NULL;
+ size_t len = strlen(desc_p) - strlen(filelist_p) + 1;
- filelist_p = strstr(desc_p,"FILE LIST");
- if (filelist_p != NULL) {
- char *tmp_desc = NULL;
- size_t len = strlen(desc_p) - strlen(filelist_p) + 1;
+ tmp_desc = realloc(tmp_pkg->description,
+ sizeof *tmp_pkg->description *
+ (strlen(tmp_pkg->description) + len + 1));
+ if (tmp_desc != NULL) {
+ tmp_pkg->description = tmp_desc;
+ strncpy(tmp_pkg->description, desc_p, len - 1);
+ tmp_pkg->description[len - 1] = '\0';
+ }
- tmp_desc = realloc(tmp_pkg->description,
- sizeof *tmp_pkg->description *
- (strlen(tmp_pkg->description) + len + 1)
- );
- if (tmp_desc != NULL) {
- tmp_pkg->description = tmp_desc;
- strncpy(tmp_pkg->description,desc_p,len - 1);
- tmp_pkg->description[len - 1] = '\0';
+ } else {
+ char *tmp_desc = NULL;
+ size_t len = strlen(desc_p) + 1;
+
+ tmp_desc = realloc(tmp_pkg->description,
+ sizeof *tmp_pkg->description *
+ (strlen(tmp_pkg->description) + len + 1));
+ if (tmp_desc != NULL) {
+ tmp_pkg->description = tmp_desc;
+ strncpy(tmp_pkg->description, desc_p, len - 1);
+ tmp_pkg->description[len - 1] = '\0';
+ }
+ }
}
- } else {
- char *tmp_desc = NULL;
- size_t len = strlen(desc_p) + 1;
+ /* munmap now that we are done */
+ if (munmap(pkg_data, pls) == -1) {
+ if (errno)
+ perror(pkg_f_name);
- tmp_desc = realloc(tmp_pkg->description,
- sizeof *tmp_pkg->description *
- (strlen(tmp_pkg->description) + len + 1)
- );
- if (tmp_desc != NULL) {
- tmp_pkg->description = tmp_desc;
- strncpy(tmp_pkg->description,desc_p,len - 1);
- tmp_pkg->description[len - 1] = '\0';
+ fprintf(stderr, "munmap failed: %s\n", pkg_f_name);
+ exit(EXIT_FAILURE);
}
+ free(pkg_f_name);
- }
-
- }
-
- /* munmap now that we are done */
- if (munmap(pkg_data,pls) == -1) {
- if (errno)
- perror(pkg_f_name);
-
- fprintf(stderr,"munmap failed: %s\n",pkg_f_name);
- exit(EXIT_FAILURE);
- }
- free(pkg_f_name);
-
- /* fillin details */
- if (tmp_pkg->location == NULL) {
- tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->location[0] = '\0';
- }
- if (tmp_pkg->description == NULL) {
- tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->description);
- tmp_pkg->description[0] = '\0';
- }
- if (tmp_pkg->mirror == NULL) {
- tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->mirror);
- tmp_pkg->mirror[0] = '\0';
- }
+ /* fillin details */
+ if (tmp_pkg->location == NULL) {
+ tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->location[0] = '\0';
+ }
+ if (tmp_pkg->description == NULL) {
+ tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->description);
+ tmp_pkg->description[0] = '\0';
+ }
+ if (tmp_pkg->mirror == NULL) {
+ tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->mirror);
+ tmp_pkg->mirror[0] = '\0';
+ }
- /* mark as installed */
- tmp_pkg->installed = true;
+ /* mark as installed */
+ tmp_pkg->installed = true;
- slapt_add_pkg_to_pkg_list(list,tmp_pkg);
- tmp_pkg = NULL;
+ slapt_add_pkg_to_pkg_list(list, tmp_pkg);
+ tmp_pkg = NULL;
- }/* end while */
- closedir(pkg_log_dir);
- slapt_free_regex(ip_regex);
- free(pkg_log_dirname);
- slapt_free_regex(compressed_size_reg);
- slapt_free_regex(uncompressed_size_reg);
+ } /* end while */
+ closedir(pkg_log_dir);
+ slapt_free_regex(ip_regex);
+ free(pkg_log_dirname);
+ slapt_free_regex(compressed_size_reg);
+ slapt_free_regex(uncompressed_size_reg);
- list->free_pkgs = true;
+ list->free_pkgs = true;
- qsort( list->pkgs, list->pkg_count, sizeof(list->pkgs[0]), pkg_compare );
+ qsort(list->pkgs, list->pkg_count, sizeof(list->pkgs[0]), pkg_compare);
- list->ordered = true;
+ list->ordered = true;
- return list;
+ return list;
}
/* lookup newest package from pkg_list */
slapt_pkg_info_t *slapt_get_newest_pkg(slapt_pkg_list_t *pkg_list,
const char *pkg_name)
{
- unsigned int i;
- slapt_pkg_info_t *pkg = NULL;
-
- for (i = 0; i < pkg_list->pkg_count; ++i ) {
+ unsigned int i;
+ slapt_pkg_info_t *pkg = NULL;
- /* if pkg has same name as our requested pkg */
- if ((strcmp(pkg_list->pkgs[i]->name,pkg_name)) == 0) {
- if ((pkg == NULL) || (slapt_cmp_pkgs(pkg,pkg_list->pkgs[i]) < 0) ) {
- pkg = pkg_list->pkgs[i];
- }
+ for (i = 0; i < pkg_list->pkg_count; ++i) {
+ /* if pkg has same name as our requested pkg */
+ if ((strcmp(pkg_list->pkgs[i]->name, pkg_name)) == 0) {
+ if ((pkg == NULL) || (slapt_cmp_pkgs(pkg, pkg_list->pkgs[i]) < 0)) {
+ pkg = pkg_list->pkgs[i];
+ }
+ }
}
- }
-
- return pkg;
+ return pkg;
}
slapt_pkg_info_t *slapt_get_exact_pkg(slapt_pkg_list_t *list,
const char *name,
const char *version)
{
+ if (list->ordered) {
+ int min = 0, max = list->pkg_count - 1;
- if (list->ordered) {
- int min = 0, max = list->pkg_count - 1;
-
- while (max >= min)
- {
- int pivot = (min + max) / 2;
- int name_cmp = strcmp(list->pkgs[pivot]->name, name);
-
- if ( name_cmp == 0 ) {
+ while (max >= min) {
+ int pivot = (min + max) / 2;
+ int name_cmp = strcmp(list->pkgs[pivot]->name, name);
- int version_cmp = strverscmp(list->pkgs[pivot]->version, version);
+ if (name_cmp == 0) {
+ int version_cmp = strverscmp(list->pkgs[pivot]->version, version);
- if ( version_cmp == 0 ) {
+ if (version_cmp == 0) {
+ return list->pkgs[pivot];
- return list->pkgs[pivot];
+ } else {
+ if (version_cmp < 0)
+ min = pivot + 1;
+ else
+ max = pivot - 1;
+ }
- } else {
-
- if ( version_cmp < 0 )
- min = pivot + 1;
- else
- max = pivot - 1;
-
+ } else {
+ if (name_cmp < 0)
+ min = pivot + 1;
+ else
+ max = pivot - 1;
+ }
}
- } else {
-
- if ( name_cmp < 0 )
- min = pivot + 1;
- else
- max = pivot - 1;
-
- }
-
- }
-
- } else {
- unsigned int i;
+ } else {
+ unsigned int i;
- for (i = 0; i < list->pkg_count;i++) {
- if ((strcmp(name,list->pkgs[i]->name)==0) &&
- (strcmp(version,list->pkgs[i]->version)==0) ) {
- return list->pkgs[i];
- }
+ for (i = 0; i < list->pkg_count; i++) {
+ if ((strcmp(name, list->pkgs[i]->name) == 0) &&
+ (strcmp(version, list->pkgs[i]->version) == 0)) {
+ return list->pkgs[i];
+ }
+ }
}
- }
-
- return NULL;
+ return NULL;
}
int slapt_install_pkg(const slapt_rc_config *global_config,
slapt_pkg_info_t *pkg)
{
- char *pkg_file_name = NULL;
- char *command = NULL;
- int cmd_return = 0;
-
- /* build the file name */
- pkg_file_name = slapt_gen_pkg_file_name(global_config,pkg);
-
- /* build and execute our command */
- command = slapt_calloc(
- strlen(SLAPT_INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof *command
- );
- command[0] = '\0';
- command = strncat(command,SLAPT_INSTALL_CMD,strlen(SLAPT_INSTALL_CMD));
- command = strncat(command,pkg_file_name,strlen(pkg_file_name));
-
- if ((cmd_return = system(command)) != 0) {
- printf(gettext("Failed to execute command: [%s]\n"),command);
- free(command);
- free(pkg_file_name);
- return -1;
- }
+ char *pkg_file_name = NULL;
+ char *command = NULL;
+ int cmd_return = 0;
+
+ /* build the file name */
+ pkg_file_name = slapt_gen_pkg_file_name(global_config, pkg);
+
+ /* build and execute our command */
+ command = slapt_calloc(
+ strlen(SLAPT_INSTALL_CMD) + strlen(pkg_file_name) + 1, sizeof *command);
+ command[0] = '\0';
+ command = strncat(command, SLAPT_INSTALL_CMD, strlen(SLAPT_INSTALL_CMD));
+ command = strncat(command, pkg_file_name, strlen(pkg_file_name));
+
+ if ((cmd_return = system(command)) != 0) {
+ printf(gettext("Failed to execute command: [%s]\n"), command);
+ free(command);
+ free(pkg_file_name);
+ return -1;
+ }
- free(pkg_file_name);
- free(command);
- return cmd_return;
+ free(pkg_file_name);
+ free(command);
+ return cmd_return;
}
int slapt_upgrade_pkg(const slapt_rc_config *global_config,
slapt_pkg_info_t *pkg)
{
- char *pkg_file_name = NULL;
- char *command = NULL;
- int cmd_return = 0;
-
- /* build the file name */
- pkg_file_name = slapt_gen_pkg_file_name(global_config,pkg);
-
- /* build and execute our command */
- command = slapt_calloc(
- strlen(SLAPT_UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof *command
- );
- command[0] = '\0';
- command = strncat(command,SLAPT_UPGRADE_CMD,strlen(SLAPT_UPGRADE_CMD));
- command = strncat(command,pkg_file_name,strlen(pkg_file_name));
-
- if ((cmd_return = system(command)) != 0) {
- printf(gettext("Failed to execute command: [%s]\n"),command);
- free(command);
- free(pkg_file_name);
- return -1;
- }
+ char *pkg_file_name = NULL;
+ char *command = NULL;
+ int cmd_return = 0;
+
+ /* build the file name */
+ pkg_file_name = slapt_gen_pkg_file_name(global_config, pkg);
+
+ /* build and execute our command */
+ command = slapt_calloc(
+ strlen(SLAPT_UPGRADE_CMD) + strlen(pkg_file_name) + 1, sizeof *command);
+ command[0] = '\0';
+ command = strncat(command, SLAPT_UPGRADE_CMD, strlen(SLAPT_UPGRADE_CMD));
+ command = strncat(command, pkg_file_name, strlen(pkg_file_name));
+
+ if ((cmd_return = system(command)) != 0) {
+ printf(gettext("Failed to execute command: [%s]\n"), command);
+ free(command);
+ free(pkg_file_name);
+ return -1;
+ }
- free(pkg_file_name);
- free(command);
- return cmd_return;
+ free(pkg_file_name);
+ free(command);
+ return cmd_return;
}
-int slapt_remove_pkg(const slapt_rc_config *global_config,slapt_pkg_info_t *pkg)
+int slapt_remove_pkg(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg)
{
- char *command = NULL;
- int cmd_return = 0;
-
- (void)global_config;
-
- /* build and execute our command */
- command = slapt_calloc(
- strlen(SLAPT_REMOVE_CMD) + strlen(pkg->name) + strlen(pkg->version) + 2,
- sizeof *command
- );
- command[0] = '\0';
- command = strncat(command,SLAPT_REMOVE_CMD,strlen(SLAPT_REMOVE_CMD));
- command = strncat(command,pkg->name,strlen(pkg->name));
- command = strncat(command,"-",1);
- command = strncat(command,pkg->version,strlen(pkg->version));
- if ((cmd_return = system(command)) != 0) {
- printf(gettext("Failed to execute command: [%s]\n"),command);
- free(command);
- return -1;
- }
+ char *command = NULL;
+ int cmd_return = 0;
+
+ (void)global_config;
+
+ /* build and execute our command */
+ command = slapt_calloc(
+ strlen(SLAPT_REMOVE_CMD) + strlen(pkg->name) + strlen(pkg->version) + 2,
+ sizeof *command);
+ command[0] = '\0';
+ command = strncat(command, SLAPT_REMOVE_CMD, strlen(SLAPT_REMOVE_CMD));
+ command = strncat(command, pkg->name, strlen(pkg->name));
+ command = strncat(command, "-", 1);
+ command = strncat(command, pkg->version, strlen(pkg->version));
+ if ((cmd_return = system(command)) != 0) {
+ printf(gettext("Failed to execute command: [%s]\n"), command);
+ free(command);
+ return -1;
+ }
- free(command);
- return cmd_return;
+ free(command);
+ return cmd_return;
}
void slapt_free_pkg(slapt_pkg_info_t *pkg)
{
- if (pkg->required != NULL)
- free(pkg->required);
+ if (pkg->required != NULL)
+ free(pkg->required);
- if (pkg->conflicts != NULL)
- free(pkg->conflicts);
+ if (pkg->conflicts != NULL)
+ free(pkg->conflicts);
- if (pkg->suggests != NULL)
- free(pkg->suggests);
+ if (pkg->suggests != NULL)
+ free(pkg->suggests);
- if (pkg->name != NULL)
- free(pkg->name);
+ if (pkg->name != NULL)
+ free(pkg->name);
- if (pkg->file_ext != NULL)
- free(pkg->file_ext);
+ if (pkg->file_ext != NULL)
+ free(pkg->file_ext);
- if (pkg->version != NULL)
- free(pkg->version);
+ if (pkg->version != NULL)
+ free(pkg->version);
- if (pkg->mirror != NULL)
- free(pkg->mirror);
+ if (pkg->mirror != NULL)
+ free(pkg->mirror);
- if (pkg->location != NULL)
- free(pkg->location);
+ if (pkg->location != NULL)
+ free(pkg->location);
- if (pkg->description != NULL)
- free(pkg->description);
+ if (pkg->description != NULL)
+ free(pkg->description);
- free(pkg);
+ free(pkg);
}
void slapt_free_pkg_list(slapt_pkg_list_t *list)
{
- unsigned int i;
- if (list->free_pkgs == true) {
- for (i = 0;i < list->pkg_count;i++) {
- slapt_free_pkg(list->pkgs[i]);
+ unsigned int i;
+ if (list->free_pkgs == true) {
+ for (i = 0; i < list->pkg_count; i++) {
+ slapt_free_pkg(list->pkgs[i]);
+ }
}
- }
- free(list->pkgs);
- free(list);
+ free(list->pkgs);
+ free(list);
}
int slapt_is_excluded(const slapt_rc_config *global_config,
slapt_pkg_info_t *pkg)
{
- unsigned int i,pkg_not_excluded = 0, pkg_slapt_is_excluded = 1;
- int name_reg_ret = -1,version_reg_ret = -1,location_reg_ret = -1;
+ unsigned int i, pkg_not_excluded = 0, pkg_slapt_is_excluded = 1;
+ int name_reg_ret = -1, version_reg_ret = -1, location_reg_ret = -1;
- if (global_config->ignore_excludes == true)
- return pkg_not_excluded;
+ if (global_config->ignore_excludes == true)
+ return pkg_not_excluded;
- /* maybe EXCLUDE= isn't defined in our rc? */
- if (global_config->exclude_list->count == 0)
- return pkg_not_excluded;
+ /* maybe EXCLUDE= isn't defined in our rc? */
+ if (global_config->exclude_list->count == 0)
+ return pkg_not_excluded;
- for (i = 0; i < global_config->exclude_list->count;i++) {
- slapt_regex_t *exclude_reg = NULL;
+ for (i = 0; i < global_config->exclude_list->count; i++) {
+ slapt_regex_t *exclude_reg = NULL;
- /* return if its an exact match */
- if ((strncmp(global_config->exclude_list->items[i],
- pkg->name,strlen(pkg->name)) == 0))
- return pkg_slapt_is_excluded;
+ /* return if its an exact match */
+ if ((strncmp(global_config->exclude_list->items[i],
+ pkg->name, strlen(pkg->name)) == 0))
+ return pkg_slapt_is_excluded;
- /*
+ /*
this regex has to be init'd and free'd within the loop b/c the regex is pulled
from the exclude list
*/
- if ((exclude_reg =
- slapt_init_regex(global_config->exclude_list->items[i])) == NULL) {
- fprintf(stderr,"\n\nugh %s\n\n",global_config->exclude_list->items[i]);
- continue;
- }
+ if ((exclude_reg =
+ slapt_init_regex(global_config->exclude_list->items[i])) == NULL) {
+ fprintf(stderr, "\n\nugh %s\n\n", global_config->exclude_list->items[i]);
+ continue;
+ }
- slapt_execute_regex(exclude_reg,pkg->name);
- name_reg_ret = exclude_reg->reg_return;
+ slapt_execute_regex(exclude_reg, pkg->name);
+ name_reg_ret = exclude_reg->reg_return;
- slapt_execute_regex(exclude_reg,pkg->version);
- version_reg_ret = exclude_reg->reg_return;
+ slapt_execute_regex(exclude_reg, pkg->version);
+ version_reg_ret = exclude_reg->reg_return;
- slapt_execute_regex(exclude_reg,pkg->location);
- location_reg_ret = exclude_reg->reg_return;
+ slapt_execute_regex(exclude_reg, pkg->location);
+ location_reg_ret = exclude_reg->reg_return;
- slapt_free_regex(exclude_reg);
+ slapt_free_regex(exclude_reg);
- if (name_reg_ret == 0 || version_reg_ret == 0 || location_reg_ret == 0) {
- return pkg_slapt_is_excluded;
+ if (name_reg_ret == 0 || version_reg_ret == 0 || location_reg_ret == 0) {
+ return pkg_slapt_is_excluded;
+ }
}
- }
-
- return pkg_not_excluded;
+ return pkg_not_excluded;
}
void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file)
{
- slapt_regex_t *md5sum_regex = NULL;
- ssize_t getline_read;
- size_t getline_len = 0;
- char *getline_buffer = NULL;
- unsigned int a;
-
- if ((md5sum_regex = slapt_init_regex(SLAPT_MD5SUM_REGEX)) == NULL) {
- exit(EXIT_FAILURE);
- }
+ slapt_regex_t *md5sum_regex = NULL;
+ ssize_t getline_read;
+ size_t getline_len = 0;
+ char *getline_buffer = NULL;
+ unsigned int a;
+
+ if ((md5sum_regex = slapt_init_regex(SLAPT_MD5SUM_REGEX)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- while ((getline_read = getline(&getline_buffer,&getline_len,
- checksum_file)) != EOF) {
-
- if (
- (strstr(getline_buffer,".tgz") == NULL) &&
- (strstr(getline_buffer,".tlz") == NULL) &&
- (strstr(getline_buffer,".txz") == NULL) &&
- (strstr(getline_buffer,".ikg") == NULL) &&
- (strstr(getline_buffer,".tbz") == NULL)
- )
- continue;
- if (strstr(getline_buffer,".asc") != NULL)
- continue;
-
- slapt_execute_regex(md5sum_regex,getline_buffer);
-
- if (md5sum_regex->reg_return == 0) {
- char *sum, *location, *name, *version;
-
- /* md5 sum */
- sum = slapt_regex_extract_match(md5sum_regex, getline_buffer, 1);
- /* location/directory */
- location = slapt_regex_extract_match(md5sum_regex, getline_buffer, 2);
- /* pkg name */
- name = slapt_regex_extract_match(md5sum_regex, getline_buffer, 3);
- /* pkg version */
- version = slapt_regex_extract_match(md5sum_regex, getline_buffer, 4);
-
- /* see if we can match up name, version, and location */
- for (a = 0;a < pkgs->pkg_count;a++) {
+ while ((getline_read = getline(&getline_buffer, &getline_len,
+ checksum_file)) != EOF) {
if (
- (strcmp(pkgs->pkgs[a]->name,name) == 0) &&
- (slapt_cmp_pkg_versions(pkgs->pkgs[a]->version,version) == 0) &&
- (strcmp(pkgs->pkgs[a]->location,location) == 0)
- ) {
- memcpy(pkgs->pkgs[a]->md5, sum,SLAPT_MD5_STR_LEN);
- break;
- }
- }
+ (strstr(getline_buffer, ".tgz") == NULL) &&
+ (strstr(getline_buffer, ".tlz") == NULL) &&
+ (strstr(getline_buffer, ".txz") == NULL) &&
+ (strstr(getline_buffer, ".ikg") == NULL) &&
+ (strstr(getline_buffer, ".tbz") == NULL))
+ continue;
+ if (strstr(getline_buffer, ".asc") != NULL)
+ continue;
+
+ slapt_execute_regex(md5sum_regex, getline_buffer);
+
+ if (md5sum_regex->reg_return == 0) {
+ char *sum, *location, *name, *version;
+
+ /* md5 sum */
+ sum = slapt_regex_extract_match(md5sum_regex, getline_buffer, 1);
+ /* location/directory */
+ location = slapt_regex_extract_match(md5sum_regex, getline_buffer, 2);
+ /* pkg name */
+ name = slapt_regex_extract_match(md5sum_regex, getline_buffer, 3);
+ /* pkg version */
+ version = slapt_regex_extract_match(md5sum_regex, getline_buffer, 4);
+
+ /* see if we can match up name, version, and location */
+ for (a = 0; a < pkgs->pkg_count; a++) {
+ if (
+ (strcmp(pkgs->pkgs[a]->name, name) == 0) &&
+ (slapt_cmp_pkg_versions(pkgs->pkgs[a]->version, version) == 0) &&
+ (strcmp(pkgs->pkgs[a]->location, location) == 0)) {
+ memcpy(pkgs->pkgs[a]->md5, sum, SLAPT_MD5_STR_LEN);
+ break;
+ }
+ }
- free(sum);
- free(name);
- free(version);
- free(location);
+ free(sum);
+ free(name);
+ free(version);
+ free(location);
+ }
}
- }
- if (getline_buffer)
- free(getline_buffer);
+ if (getline_buffer)
+ free(getline_buffer);
- slapt_free_regex(md5sum_regex);
- rewind(checksum_file);
+ slapt_free_regex(md5sum_regex);
+ rewind(checksum_file);
- return;
+ return;
}
static void slapt_free_pkg_version_parts(struct slapt_pkg_version_parts *parts)
{
- unsigned int i;
- for (i = 0;i < parts->count;i++) {
- free(parts->parts[i]);
- }
- free(parts->parts);
- free(parts);
+ unsigned int i;
+ for (i = 0; i < parts->count; i++) {
+ free(parts->parts[i]);
+ }
+ free(parts->parts);
+ free(parts);
}
int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b)
{
- int greater = 1,lesser = -1,equal = 0;
+ int greater = 1, lesser = -1, equal = 0;
- /* if either of the two packages is installed, we look
+ /* if either of the two packages is installed, we look
for the same version to bail out early if possible */
- if (a->installed == true || b->installed == true)
- if (strcasecmp(a->version,b->version) == 0)
- return equal;
+ if (a->installed == true || b->installed == true)
+ if (strcasecmp(a->version, b->version) == 0)
+ return equal;
- /* check the priorities */
- if(a->priority > b->priority)
- return greater;
- else if(a->priority < b->priority)
- return lesser;
+ /* check the priorities */
+ if (a->priority > b->priority)
+ return greater;
+ else if (a->priority < b->priority)
+ return lesser;
- return slapt_cmp_pkg_versions(a->version, b->version);
+ return slapt_cmp_pkg_versions(a->version, b->version);
}
int slapt_cmp_pkg_versions(const char *a, const char *b)
{
- unsigned int position = 0;
- int greater = 1,lesser = -1,equal = 0;
- struct slapt_pkg_version_parts *a_parts;
- struct slapt_pkg_version_parts *b_parts;
-
- /* bail out early if possible */
- if (strcasecmp(a,b) == 0)
- return equal;
+ unsigned int position = 0;
+ int greater = 1, lesser = -1, equal = 0;
+ struct slapt_pkg_version_parts *a_parts;
+ struct slapt_pkg_version_parts *b_parts;
- a_parts = break_down_pkg_version(a);
- b_parts = break_down_pkg_version(b);
+ /* bail out early if possible */
+ if (strcasecmp(a, b) == 0)
+ return equal;
- while (position < a_parts->count && position < b_parts->count) {
- if (strcasecmp(a_parts->parts[position],b_parts->parts[position]) != 0) {
+ a_parts = break_down_pkg_version(a);
+ b_parts = break_down_pkg_version(b);
- /*
+ while (position < a_parts->count && position < b_parts->count) {
+ if (strcasecmp(a_parts->parts[position], b_parts->parts[position]) != 0) {
+ /*
* if the integer value of the version part is the same
* and the # of version parts is the same (fixes 3.8.1p1-i486-1
* to 3.8p1-i486-1)
- */
- if ((atoi(a_parts->parts[position]) == atoi(b_parts->parts[position])) &&
- (a_parts->count == b_parts->count)) {
-
- if (strverscmp(a_parts->parts[position],b_parts->parts[position]) < 0) {
- slapt_free_pkg_version_parts(a_parts);
- slapt_free_pkg_version_parts(b_parts);
- return lesser;
- }
- if (strverscmp(a_parts->parts[position],b_parts->parts[position]) > 0) {
- slapt_free_pkg_version_parts(a_parts);
- slapt_free_pkg_version_parts(b_parts);
- return greater;
- }
-
- }
-
- if (atoi(a_parts->parts[position]) < atoi(b_parts->parts[position])) {
- slapt_free_pkg_version_parts(a_parts);
- slapt_free_pkg_version_parts(b_parts);
- return lesser;
- }
+ */
+ if ((atoi(a_parts->parts[position]) == atoi(b_parts->parts[position])) &&
+ (a_parts->count == b_parts->count)) {
+ if (strverscmp(a_parts->parts[position], b_parts->parts[position]) < 0) {
+ slapt_free_pkg_version_parts(a_parts);
+ slapt_free_pkg_version_parts(b_parts);
+ return lesser;
+ }
+ if (strverscmp(a_parts->parts[position], b_parts->parts[position]) > 0) {
+ slapt_free_pkg_version_parts(a_parts);
+ slapt_free_pkg_version_parts(b_parts);
+ return greater;
+ }
+ }
- if (atoi(a_parts->parts[position]) > atoi(b_parts->parts[position])) {
- slapt_free_pkg_version_parts(a_parts);
- slapt_free_pkg_version_parts(b_parts);
- return greater;
- }
+ if (atoi(a_parts->parts[position]) < atoi(b_parts->parts[position])) {
+ slapt_free_pkg_version_parts(a_parts);
+ slapt_free_pkg_version_parts(b_parts);
+ return lesser;
+ }
+ if (atoi(a_parts->parts[position]) > atoi(b_parts->parts[position])) {
+ slapt_free_pkg_version_parts(a_parts);
+ slapt_free_pkg_version_parts(b_parts);
+ return greater;
+ }
+ }
+ ++position;
}
- ++position;
- }
- /*
+ /*
* if we got this far, we know that some or all of the version
* parts are equal in both packages. If pkg-a has 3 version parts
* and pkg-b has 2, then we assume pkg-a to be greater.
*/
- if (a_parts->count != b_parts->count) {
- if (a_parts->count > b_parts->count) {
- slapt_free_pkg_version_parts(a_parts);
- slapt_free_pkg_version_parts(b_parts);
- return greater;
- } else {
- slapt_free_pkg_version_parts(a_parts);
- slapt_free_pkg_version_parts(b_parts);
- return lesser;
+ if (a_parts->count != b_parts->count) {
+ if (a_parts->count > b_parts->count) {
+ slapt_free_pkg_version_parts(a_parts);
+ slapt_free_pkg_version_parts(b_parts);
+ return greater;
+ } else {
+ slapt_free_pkg_version_parts(a_parts);
+ slapt_free_pkg_version_parts(b_parts);
+ return lesser;
+ }
}
- }
- slapt_free_pkg_version_parts(a_parts);
- slapt_free_pkg_version_parts(b_parts);
+ slapt_free_pkg_version_parts(a_parts);
+ slapt_free_pkg_version_parts(b_parts);
- /*
+ /*
* Now we check to see that the version follows the standard slackware
* convention. If it does, we will compare the build portions.
*/
- /* make sure the packages have at least two separators */
- if ((index(a,'-') != rindex(a,'-')) && (index(b,'-') != rindex(b,'-'))) {
- char *a_build,*b_build;
-
- /* pointer to build portions */
- a_build = rindex(a,'-');
- b_build = rindex(b,'-');
-
- if (a_build != NULL && b_build != NULL) {
- /* they are equal if the integer values are equal */
- /* for instance, "1rob" and "1" will be equal */
- if (atoi(a_build) == atoi(b_build)) {
+ /* make sure the packages have at least two separators */
+ if ((index(a, '-') != rindex(a, '-')) && (index(b, '-') != rindex(b, '-'))) {
+ char *a_build, *b_build;
+
+ /* pointer to build portions */
+ a_build = rindex(a, '-');
+ b_build = rindex(b, '-');
+
+ if (a_build != NULL && b_build != NULL) {
+ /* they are equal if the integer values are equal */
+ /* for instance, "1rob" and "1" will be equal */
+ if (atoi(a_build) == atoi(b_build)) {
/* prefer our architecture in x86/x86_64 multilib settings */
#if defined(__x86_64__)
- if ((strcmp(a_build,b_build) == 0) && (strcmp(a,b) != 0) && (strstr(a,"-x86_64") != NULL && (strstr(b,"-x86_64-") == NULL)))
- return greater;
- if ((strcmp(a_build,b_build) == 0) && (strcmp(a,b) != 0) && (strstr(a,"-x86_64") == NULL && (strstr(b,"-x86_64-") != NULL)))
- return lesser;
+ if ((strcmp(a_build, b_build) == 0) && (strcmp(a, b) != 0) && (strstr(a, "-x86_64") != NULL && (strstr(b, "-x86_64-") == NULL)))
+ return greater;
+ if ((strcmp(a_build, b_build) == 0) && (strcmp(a, b) != 0) && (strstr(a, "-x86_64") == NULL && (strstr(b, "-x86_64-") != NULL)))
+ return lesser;
#elif defined(__i386__)
- if ((strcmp(a_build,b_build) == 0) && (strcmp(a,b) != 0) && (strstr(a,"-x86_64") == NULL && (strstr(b,"-x86_64-") != NULL)))
- return greater;
- if ((strcmp(a_build,b_build) == 0) && (strcmp(a,b) != 0) && (strstr(a,"-x86_64") != NULL && (strstr(b,"-x86_64-") == NULL)))
- return lesser;
+ if ((strcmp(a_build, b_build) == 0) && (strcmp(a, b) != 0) && (strstr(a, "-x86_64") == NULL && (strstr(b, "-x86_64-") != NULL)))
+ return greater;
+ if ((strcmp(a_build, b_build) == 0) && (strcmp(a, b) != 0) && (strstr(a, "-x86_64") != NULL && (strstr(b, "-x86_64-") == NULL)))
+ return lesser;
#endif
- return equal;
- }
-
- if (atoi(a_build) < atoi(b_build))
- return greater;
+ return equal;
+ }
- if (atoi(a_build) > atoi(b_build))
- return lesser;
+ if (atoi(a_build) < atoi(b_build))
+ return greater;
+ if (atoi(a_build) > atoi(b_build))
+ return lesser;
+ }
}
- }
-
- /*
+ /*
* If both have the same # of version parts, non-standard version convention,
* then we fall back on strverscmp.
*/
- if (strchr(a,'-') == NULL && strchr(b,'-') == NULL)
- return strverscmp(a,b);
+ if (strchr(a, '-') == NULL && strchr(b, '-') == NULL)
+ return strverscmp(a, b);
- return equal;
+ return equal;
}
static struct slapt_pkg_version_parts *break_down_pkg_version(const char *version)
{
- int pos = 0,sv_size = 0;
- char *pointer,*short_version;
- struct slapt_pkg_version_parts *pvp;
-
- pvp = slapt_malloc(sizeof *pvp);
- pvp->parts = slapt_malloc(sizeof *pvp->parts);
- pvp->count = 0;
-
- /* generate a short version, leave out arch and release */
- if ((pointer = strchr(version,'-')) == NULL) {
- sv_size = strlen(version) + 1;
- short_version = slapt_malloc(sizeof *short_version * sv_size);
- memcpy(short_version,version,sv_size);
- short_version[sv_size - 1] = '\0';
- } else {
- sv_size = (strlen(version) - strlen(pointer) + 1);
- short_version = slapt_malloc(sizeof *short_version * sv_size);
- memcpy(short_version,version,sv_size);
- short_version[sv_size - 1] = '\0';
- pointer = NULL;
- }
-
- while (pos < (sv_size - 1) ) {
- char **tmp;
-
- tmp = realloc(pvp->parts, sizeof *pvp->parts * (pvp->count + 1) );
- if (tmp == NULL) {
- fprintf(stderr,gettext("Failed to realloc %s\n"),"pvp->parts");
- exit(EXIT_FAILURE);
- }
- pvp->parts = tmp;
-
- /* check for . as a seperator */
- if ((pointer = strchr(short_version + pos,'.')) != NULL) {
- int b_count = (strlen(short_version + pos) - strlen(pointer) + 1);
- pvp->parts[pvp->count] = slapt_malloc(
- sizeof *pvp->parts[pvp->count] * b_count);
-
- memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
- pvp->parts[pvp->count][b_count - 1] = '\0';
- ++pvp->count;
- pointer = NULL;
- pos += b_count;
- /* check for _ as a seperator */
- } else if ((pointer = strchr(short_version + pos,'_')) != NULL) {
- int b_count = (strlen(short_version + pos) - strlen(pointer) + 1);
- pvp->parts[pvp->count] = slapt_malloc(
- sizeof *pvp->parts[pvp->count] * b_count);
-
- memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
- pvp->parts[pvp->count][b_count - 1] = '\0';
- ++pvp->count;
- pointer = NULL;
- pos += b_count;
- /* must be the end of the string */
+ int pos = 0, sv_size = 0;
+ char *pointer, *short_version;
+ struct slapt_pkg_version_parts *pvp;
+
+ pvp = slapt_malloc(sizeof *pvp);
+ pvp->parts = slapt_malloc(sizeof *pvp->parts);
+ pvp->count = 0;
+
+ /* generate a short version, leave out arch and release */
+ if ((pointer = strchr(version, '-')) == NULL) {
+ sv_size = strlen(version) + 1;
+ short_version = slapt_malloc(sizeof *short_version * sv_size);
+ memcpy(short_version, version, sv_size);
+ short_version[sv_size - 1] = '\0';
} else {
- int b_count = (strlen(short_version + pos) + 1);
- pvp->parts[pvp->count] = slapt_malloc(
- sizeof *pvp->parts[pvp->count] * b_count);
+ sv_size = (strlen(version) - strlen(pointer) + 1);
+ short_version = slapt_malloc(sizeof *short_version * sv_size);
+ memcpy(short_version, version, sv_size);
+ short_version[sv_size - 1] = '\0';
+ pointer = NULL;
+ }
- memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
- pvp->parts[pvp->count][b_count - 1] = '\0';
- ++pvp->count;
- pos += b_count;
+ while (pos < (sv_size - 1)) {
+ char **tmp;
+
+ tmp = realloc(pvp->parts, sizeof *pvp->parts * (pvp->count + 1));
+ if (tmp == NULL) {
+ fprintf(stderr, gettext("Failed to realloc %s\n"), "pvp->parts");
+ exit(EXIT_FAILURE);
+ }
+ pvp->parts = tmp;
+
+ /* check for . as a seperator */
+ if ((pointer = strchr(short_version + pos, '.')) != NULL) {
+ int b_count = (strlen(short_version + pos) - strlen(pointer) + 1);
+ pvp->parts[pvp->count] = slapt_malloc(
+ sizeof *pvp->parts[pvp->count] * b_count);
+
+ memcpy(pvp->parts[pvp->count], short_version + pos, b_count - 1);
+ pvp->parts[pvp->count][b_count - 1] = '\0';
+ ++pvp->count;
+ pointer = NULL;
+ pos += b_count;
+ /* check for _ as a seperator */
+ } else if ((pointer = strchr(short_version + pos, '_')) != NULL) {
+ int b_count = (strlen(short_version + pos) - strlen(pointer) + 1);
+ pvp->parts[pvp->count] = slapt_malloc(
+ sizeof *pvp->parts[pvp->count] * b_count);
+
+ memcpy(pvp->parts[pvp->count], short_version + pos, b_count - 1);
+ pvp->parts[pvp->count][b_count - 1] = '\0';
+ ++pvp->count;
+ pointer = NULL;
+ pos += b_count;
+ /* must be the end of the string */
+ } else {
+ int b_count = (strlen(short_version + pos) + 1);
+ pvp->parts[pvp->count] = slapt_malloc(
+ sizeof *pvp->parts[pvp->count] * b_count);
+
+ memcpy(pvp->parts[pvp->count], short_version + pos, b_count - 1);
+ pvp->parts[pvp->count][b_count - 1] = '\0';
+ ++pvp->count;
+ pos += b_count;
+ }
}
- }
- free(short_version);
- return pvp;
+ free(short_version);
+ return pvp;
}
-void slapt_write_pkg_data(const char *source_url,FILE *d_file,
+void slapt_write_pkg_data(const char *source_url, FILE *d_file,
slapt_pkg_list_t *pkgs)
{
- unsigned int i;
-
- for (i=0;i < pkgs->pkg_count;i++) {
+ unsigned int i;
- fprintf(d_file,"PACKAGE NAME: %s-%s%s\n",
- pkgs->pkgs[i]->name,pkgs->pkgs[i]->version,pkgs->pkgs[i]->file_ext);
- if (pkgs->pkgs[i]->mirror != NULL && strlen(pkgs->pkgs[i]->mirror) > 0) {
- fprintf(d_file,"PACKAGE MIRROR: %s\n",pkgs->pkgs[i]->mirror);
- } else {
- fprintf(d_file,"PACKAGE MIRROR: %s\n",source_url);
- }
- fprintf(d_file,"PACKAGE PRIORITY: %d\n", pkgs->pkgs[i]->priority);
- fprintf(d_file,"PACKAGE LOCATION: %s\n",pkgs->pkgs[i]->location);
- fprintf(d_file,"PACKAGE SIZE (compressed): %d K\n",pkgs->pkgs[i]->size_c);
- fprintf(d_file,"PACKAGE SIZE (uncompressed): %d K\n",pkgs->pkgs[i]->size_u);
- fprintf(d_file,"PACKAGE REQUIRED: %s\n",pkgs->pkgs[i]->required);
- fprintf(d_file,"PACKAGE CONFLICTS: %s\n",pkgs->pkgs[i]->conflicts);
- fprintf(d_file,"PACKAGE SUGGESTS: %s\n",pkgs->pkgs[i]->suggests);
- fprintf(d_file,"PACKAGE MD5SUM: %s\n",pkgs->pkgs[i]->md5);
- fprintf(d_file,"PACKAGE DESCRIPTION:\n");
- /* do we have to make up an empty description? */
- if (strlen(pkgs->pkgs[i]->description) < strlen(pkgs->pkgs[i]->name)) {
- fprintf(d_file,"%s: no description\n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n\n",pkgs->pkgs[i]->name);
- } else {
- fprintf(d_file,"%s\n",pkgs->pkgs[i]->description);
+ for (i = 0; i < pkgs->pkg_count; i++) {
+ fprintf(d_file, "PACKAGE NAME: %s-%s%s\n",
+ pkgs->pkgs[i]->name, pkgs->pkgs[i]->version, pkgs->pkgs[i]->file_ext);
+ if (pkgs->pkgs[i]->mirror != NULL && strlen(pkgs->pkgs[i]->mirror) > 0) {
+ fprintf(d_file, "PACKAGE MIRROR: %s\n", pkgs->pkgs[i]->mirror);
+ } else {
+ fprintf(d_file, "PACKAGE MIRROR: %s\n", source_url);
+ }
+ fprintf(d_file, "PACKAGE PRIORITY: %d\n", pkgs->pkgs[i]->priority);
+ fprintf(d_file, "PACKAGE LOCATION: %s\n", pkgs->pkgs[i]->location);
+ fprintf(d_file, "PACKAGE SIZE (compressed): %d K\n", pkgs->pkgs[i]->size_c);
+ fprintf(d_file, "PACKAGE SIZE (uncompressed): %d K\n", pkgs->pkgs[i]->size_u);
+ fprintf(d_file, "PACKAGE REQUIRED: %s\n", pkgs->pkgs[i]->required);
+ fprintf(d_file, "PACKAGE CONFLICTS: %s\n", pkgs->pkgs[i]->conflicts);
+ fprintf(d_file, "PACKAGE SUGGESTS: %s\n", pkgs->pkgs[i]->suggests);
+ fprintf(d_file, "PACKAGE MD5SUM: %s\n", pkgs->pkgs[i]->md5);
+ fprintf(d_file, "PACKAGE DESCRIPTION:\n");
+ /* do we have to make up an empty description? */
+ if (strlen(pkgs->pkgs[i]->description) < strlen(pkgs->pkgs[i]->name)) {
+ fprintf(d_file, "%s: no description\n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
+ fprintf(d_file, "%s: \n\n", pkgs->pkgs[i]->name);
+ } else {
+ fprintf(d_file, "%s\n", pkgs->pkgs[i]->description);
+ }
}
-
- }
}
slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,
- const char *pattern)
+ const char *pattern)
{
- unsigned int i;
- int name_r = -1,desc_r = -1,loc_r = -1,version_r = -1;
- slapt_regex_t *search_regex = NULL;
- slapt_pkg_list_t *matches = NULL;
+ unsigned int i;
+ int name_r = -1, desc_r = -1, loc_r = -1, version_r = -1;
+ slapt_regex_t *search_regex = NULL;
+ slapt_pkg_list_t *matches = NULL;
- matches = slapt_init_pkg_list();
+ matches = slapt_init_pkg_list();
- if ((search_regex = slapt_init_regex(pattern)) == NULL)
- return matches;
+ if ((search_regex = slapt_init_regex(pattern)) == NULL)
+ return matches;
- for (i = 0; i < list->pkg_count; i++ ) {
- if (strcmp(list->pkgs[i]->name, pattern) == 0) {
- slapt_add_pkg_to_pkg_list(matches,list->pkgs[i]);
- continue;
- }
+ for (i = 0; i < list->pkg_count; i++) {
+ if (strcmp(list->pkgs[i]->name, pattern) == 0) {
+ slapt_add_pkg_to_pkg_list(matches, list->pkgs[i]);
+ continue;
+ }
- slapt_execute_regex(search_regex,list->pkgs[i]->name);
- name_r = search_regex->reg_return;
+ slapt_execute_regex(search_regex, list->pkgs[i]->name);
+ name_r = search_regex->reg_return;
- slapt_execute_regex(search_regex,list->pkgs[i]->version);
- version_r = search_regex->reg_return;
+ slapt_execute_regex(search_regex, list->pkgs[i]->version);
+ version_r = search_regex->reg_return;
- if (list->pkgs[i]->description != NULL) {
- slapt_execute_regex(search_regex,list->pkgs[i]->description);
- desc_r = search_regex->reg_return;
- }
+ if (list->pkgs[i]->description != NULL) {
+ slapt_execute_regex(search_regex, list->pkgs[i]->description);
+ desc_r = search_regex->reg_return;
+ }
- if (list->pkgs[i]->location != NULL) {
- slapt_execute_regex(search_regex,list->pkgs[i]->location);
- loc_r = search_regex->reg_return;
- }
+ if (list->pkgs[i]->location != NULL) {
+ slapt_execute_regex(search_regex, list->pkgs[i]->location);
+ loc_r = search_regex->reg_return;
+ }
- /* search pkg name, pkg description, pkg location */
- if (name_r == 0 || version_r == 0 || desc_r == 0 || loc_r == 0) {
- slapt_add_pkg_to_pkg_list(matches,list->pkgs[i]);
+ /* search pkg name, pkg description, pkg location */
+ if (name_r == 0 || version_r == 0 || desc_r == 0 || loc_r == 0) {
+ slapt_add_pkg_to_pkg_list(matches, list->pkgs[i]);
+ }
}
- }
- slapt_free_regex(search_regex);
+ slapt_free_regex(search_regex);
- return matches;
+ return matches;
}
/* lookup dependencies for pkg */
int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,slapt_pkg_info_t *pkg,
- slapt_pkg_list_t *deps,
- slapt_pkg_err_list_t *conflict_err,
- slapt_pkg_err_list_t *missing_err)
+ slapt_pkg_list_t *avail_pkgs,
+ slapt_pkg_list_t *installed_pkgs, slapt_pkg_info_t *pkg,
+ slapt_pkg_list_t *deps,
+ slapt_pkg_err_list_t *conflict_err,
+ slapt_pkg_err_list_t *missing_err)
{
- unsigned int i = 0;
- slapt_list_t *dep_parts = NULL;
+ unsigned int i = 0;
+ slapt_list_t *dep_parts = NULL;
- /*
+ /*
* don't go any further if the required member is empty
* or disable_dep_check is set
*/
- if (global_config->disable_dep_check == true ||
- strcmp(pkg->required,"") == 0 ||
- strcmp(pkg->required," ") == 0 ||
- strcmp(pkg->required," ") == 0
- )
- return 0;
+ if (global_config->disable_dep_check == true ||
+ strcmp(pkg->required, "") == 0 ||
+ strcmp(pkg->required, " ") == 0 ||
+ strcmp(pkg->required, " ") == 0)
+ return 0;
- if (deps == NULL)
- deps = slapt_init_pkg_list();
+ if (deps == NULL)
+ deps = slapt_init_pkg_list();
- if (conflict_err == NULL)
- conflict_err = slapt_init_pkg_err_list();
+ if (conflict_err == NULL)
+ conflict_err = slapt_init_pkg_err_list();
- if (missing_err == NULL)
- missing_err = slapt_init_pkg_err_list();
+ if (missing_err == NULL)
+ missing_err = slapt_init_pkg_err_list();
- /* parse dep line */
- dep_parts = slapt_parse_delimited_list(pkg->required, ',');
- for (i = 0; i < dep_parts->count; i++) {
- slapt_pkg_info_t *tmp_pkg = NULL;
-
- if (strchr(dep_parts->items[i],'|') != NULL) {
- tmp_pkg = find_or_requirement(avail_pkgs,installed_pkgs,dep_parts->items[i]);
- } else {
- tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,dep_parts->items[i]);
- }
+ /* parse dep line */
+ dep_parts = slapt_parse_delimited_list(pkg->required, ',');
+ for (i = 0; i < dep_parts->count; i++) {
+ slapt_pkg_info_t *tmp_pkg = NULL;
- if (tmp_pkg == NULL) {
- /* if we can't find a required dep, return -1 */
- slapt_add_pkg_err_to_list(missing_err,pkg->name,dep_parts->items[i]);
- slapt_free_list(dep_parts);
- return -1;
- }
+ if (strchr(dep_parts->items[i], '|') != NULL) {
+ tmp_pkg = find_or_requirement(avail_pkgs, installed_pkgs, dep_parts->items[i]);
+ } else {
+ tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, dep_parts->items[i]);
+ }
- /* if this pkg is excluded */
- if ((slapt_is_excluded(global_config,tmp_pkg) == 1) && (global_config->ignore_dep == false)) {
- if (slapt_get_exact_pkg(installed_pkgs,tmp_pkg->name, tmp_pkg->version) == NULL) {
- slapt_add_pkg_err_to_list(conflict_err,pkg->name,tmp_pkg->name);
- slapt_free_list(dep_parts);
- return -1;
- }
- }
+ if (tmp_pkg == NULL) {
+ /* if we can't find a required dep, return -1 */
+ slapt_add_pkg_err_to_list(missing_err, pkg->name, dep_parts->items[i]);
+ slapt_free_list(dep_parts);
+ return -1;
+ }
- /* if tmp_pkg is not already in the deps pkg_list */
- if ((slapt_get_newest_pkg(deps,tmp_pkg->name) == NULL)) {
- int dep_check_return;
+ /* if this pkg is excluded */
+ if ((slapt_is_excluded(global_config, tmp_pkg) == 1) && (global_config->ignore_dep == false)) {
+ if (slapt_get_exact_pkg(installed_pkgs, tmp_pkg->name, tmp_pkg->version) == NULL) {
+ slapt_add_pkg_err_to_list(conflict_err, pkg->name, tmp_pkg->name);
+ slapt_free_list(dep_parts);
+ return -1;
+ }
+ }
- /* add tmp_pkg to deps so that we don't needlessly recurse */
- slapt_add_pkg_to_pkg_list(deps,tmp_pkg);
+ /* if tmp_pkg is not already in the deps pkg_list */
+ if ((slapt_get_newest_pkg(deps, tmp_pkg->name) == NULL)) {
+ int dep_check_return;
- /* now check to see if tmp_pkg has dependencies */
- dep_check_return = slapt_get_pkg_dependencies(
- global_config,avail_pkgs,installed_pkgs,tmp_pkg,
- deps,conflict_err,missing_err
- );
+ /* add tmp_pkg to deps so that we don't needlessly recurse */
+ slapt_add_pkg_to_pkg_list(deps, tmp_pkg);
- if (dep_check_return == -1 && global_config->ignore_dep == false) {
- slapt_free_list(dep_parts);
- return -1;
- } else {
- /* now move the package to the end after it's dependencies */
- slapt_pkg_info_t *tmp = NULL;
- unsigned int i = 0;
+ /* now check to see if tmp_pkg has dependencies */
+ dep_check_return = slapt_get_pkg_dependencies(
+ global_config, avail_pkgs, installed_pkgs, tmp_pkg,
+ deps, conflict_err, missing_err);
- while (i < deps->pkg_count) {
+ if (dep_check_return == -1 && global_config->ignore_dep == false) {
+ slapt_free_list(dep_parts);
+ return -1;
+ } else {
+ /* now move the package to the end after it's dependencies */
+ slapt_pkg_info_t *tmp = NULL;
+ unsigned int i = 0;
- if (strcmp(deps->pkgs[i]->name,tmp_pkg->name) == 0 && tmp == NULL)
- tmp = deps->pkgs[i];
+ while (i < deps->pkg_count) {
+ if (strcmp(deps->pkgs[i]->name, tmp_pkg->name) == 0 && tmp == NULL)
+ tmp = deps->pkgs[i];
- /* move all subsequent packages up */
- if (tmp != NULL && (i+1 < deps->pkg_count))
- deps->pkgs[i] = deps->pkgs[i + 1];
+ /* move all subsequent packages up */
+ if (tmp != NULL && (i + 1 < deps->pkg_count))
+ deps->pkgs[i] = deps->pkgs[i + 1];
- ++i;
- }
+ ++i;
+ }
- /*
+ /*
* now put the pkg we found at the end...
* note no resizing is necessary, we just moved the location
*/
- if (tmp != NULL)
- deps->pkgs[deps->pkg_count - 1] = tmp;
- }
-
- } /* end already exists in dep check */
+ if (tmp != NULL)
+ deps->pkgs[deps->pkg_count - 1] = tmp;
+ }
- }
+ } /* end already exists in dep check */
+ }
- slapt_free_list(dep_parts);
- return 0;
+ slapt_free_list(dep_parts);
+ return 0;
}
/* lookup conflicts for package */
slapt_pkg_list_t *slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_info_t *pkg)
+ slapt_pkg_list_t *installed_pkgs,
+ slapt_pkg_info_t *pkg)
{
- slapt_pkg_list_t *conflicts = NULL;
- int position = 0,len = 0;
- char *pointer = NULL;
- char *buffer = NULL;
+ slapt_pkg_list_t *conflicts = NULL;
+ int position = 0, len = 0;
+ char *pointer = NULL;
+ char *buffer = NULL;
- conflicts = slapt_init_pkg_list();
+ conflicts = slapt_init_pkg_list();
- /*
+ /*
* don't go any further if the required member is empty
*/
- if (strcmp(pkg->conflicts,"") == 0 ||
- strcmp(pkg->conflicts," ") == 0 ||
- strcmp(pkg->conflicts," ") == 0
- )
- return conflicts;
-
- /* parse conflict line */
- len = strlen(pkg->conflicts);
- while (position < len) {
- slapt_pkg_info_t *tmp_pkg = NULL;
+ if (strcmp(pkg->conflicts, "") == 0 ||
+ strcmp(pkg->conflicts, " ") == 0 ||
+ strcmp(pkg->conflicts, " ") == 0)
+ return conflicts;
- /* either the last or there was only one to begin with */
- if (strstr(pkg->conflicts + position,",") == NULL) {
- pointer = pkg->conflicts + position;
+ /* parse conflict line */
+ len = strlen(pkg->conflicts);
+ while (position < len) {
+ slapt_pkg_info_t *tmp_pkg = NULL;
- /* parse the conflict entry and try to lookup a package */
- tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,pointer);
+ /* either the last or there was only one to begin with */
+ if (strstr(pkg->conflicts + position, ",") == NULL) {
+ pointer = pkg->conflicts + position;
- position += strlen(pointer);
- } else {
+ /* parse the conflict entry and try to lookup a package */
+ tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, pointer);
- /* if we have a comma, skip it */
- if (pkg->conflicts[position] == ',' ) {
- ++position;
- continue;
- }
+ position += strlen(pointer);
+ } else {
+ /* if we have a comma, skip it */
+ if (pkg->conflicts[position] == ',') {
+ ++position;
+ continue;
+ }
- /* build the buffer to contain the conflict entry */
- pointer = strchr(pkg->conflicts + position,',');
- buffer = strndup(
- pkg->conflicts + position,
- strlen(pkg->conflicts + position) - strlen(pointer)
- );
+ /* build the buffer to contain the conflict entry */
+ pointer = strchr(pkg->conflicts + position, ',');
+ buffer = strndup(
+ pkg->conflicts + position,
+ strlen(pkg->conflicts + position) - strlen(pointer));
- /* parse the conflict entry and try to lookup a package */
- tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,buffer);
+ /* parse the conflict entry and try to lookup a package */
+ tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, buffer);
- position += strlen(pkg->conflicts + position) - strlen(pointer);
- free(buffer);
- }
+ position += strlen(pkg->conflicts + position) - strlen(pointer);
+ free(buffer);
+ }
- if (tmp_pkg != NULL) {
- slapt_add_pkg_to_pkg_list(conflicts,tmp_pkg);
- }
+ if (tmp_pkg != NULL) {
+ slapt_add_pkg_to_pkg_list(conflicts, tmp_pkg);
+ }
- }/* end while */
+ } /* end while */
- return conflicts;
+ return conflicts;
}
static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
slapt_pkg_list_t *installed_pkgs,
char *dep_entry)
{
- unsigned int i;
- slapt_regex_t *parse_dep_regex = NULL;
- char *tmp_pkg_name = NULL,*tmp_pkg_ver = NULL;
- char tmp_pkg_cond[3];
- slapt_pkg_info_t *newest_avail_pkg;
- slapt_pkg_info_t *newest_installed_pkg;
- int tmp_cond_len = 0;
-
- if ((parse_dep_regex = slapt_init_regex(SLAPT_REQUIRED_REGEX)) == NULL) {
- exit(EXIT_FAILURE);
- }
+ unsigned int i;
+ slapt_regex_t *parse_dep_regex = NULL;
+ char *tmp_pkg_name = NULL, *tmp_pkg_ver = NULL;
+ char tmp_pkg_cond[3];
+ slapt_pkg_info_t *newest_avail_pkg;
+ slapt_pkg_info_t *newest_installed_pkg;
+ int tmp_cond_len = 0;
+
+ if ((parse_dep_regex = slapt_init_regex(SLAPT_REQUIRED_REGEX)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- /* regex to pull out pieces */
- slapt_execute_regex(parse_dep_regex,dep_entry);
+ /* regex to pull out pieces */
+ slapt_execute_regex(parse_dep_regex, dep_entry);
- /* if the regex failed, just skip out */
- if (parse_dep_regex->reg_return != 0) {
- slapt_free_regex(parse_dep_regex);
- return NULL;
- }
+ /* if the regex failed, just skip out */
+ if (parse_dep_regex->reg_return != 0) {
+ slapt_free_regex(parse_dep_regex);
+ return NULL;
+ }
- tmp_cond_len = parse_dep_regex->pmatch[2].rm_eo - parse_dep_regex->pmatch[2].rm_so;
+ tmp_cond_len = parse_dep_regex->pmatch[2].rm_eo - parse_dep_regex->pmatch[2].rm_so;
- tmp_pkg_name = slapt_regex_extract_match(parse_dep_regex, dep_entry, 1);
+ tmp_pkg_name = slapt_regex_extract_match(parse_dep_regex, dep_entry, 1);
- newest_avail_pkg = slapt_get_newest_pkg(avail_pkgs,tmp_pkg_name);
- newest_installed_pkg = slapt_get_newest_pkg(installed_pkgs,tmp_pkg_name);
+ newest_avail_pkg = slapt_get_newest_pkg(avail_pkgs, tmp_pkg_name);
+ newest_installed_pkg = slapt_get_newest_pkg(installed_pkgs, tmp_pkg_name);
- /* if there is no conditional and version, return newest */
- if (tmp_cond_len == 0 ) {
- if (newest_installed_pkg != NULL) {
- slapt_free_regex(parse_dep_regex);
- free(tmp_pkg_name);
- return newest_installed_pkg;
- }
- if (newest_avail_pkg != NULL) {
- slapt_free_regex(parse_dep_regex);
- free(tmp_pkg_name);
- return newest_avail_pkg;
+ /* if there is no conditional and version, return newest */
+ if (tmp_cond_len == 0) {
+ if (newest_installed_pkg != NULL) {
+ slapt_free_regex(parse_dep_regex);
+ free(tmp_pkg_name);
+ return newest_installed_pkg;
+ }
+ if (newest_avail_pkg != NULL) {
+ slapt_free_regex(parse_dep_regex);
+ free(tmp_pkg_name);
+ return newest_avail_pkg;
+ }
}
- }
- if (tmp_cond_len > 3 ) {
- fprintf(stderr, gettext("pkg conditional too long\n"));
- slapt_free_regex(parse_dep_regex);
- free(tmp_pkg_name);
- return NULL;
- }
+ if (tmp_cond_len > 3) {
+ fprintf(stderr, gettext("pkg conditional too long\n"));
+ slapt_free_regex(parse_dep_regex);
+ free(tmp_pkg_name);
+ return NULL;
+ }
- strncpy(tmp_pkg_cond,
- dep_entry + parse_dep_regex->pmatch[2].rm_so,
- tmp_cond_len
- );
- tmp_pkg_cond[ tmp_cond_len ] = '\0';
+ strncpy(tmp_pkg_cond,
+ dep_entry + parse_dep_regex->pmatch[2].rm_so,
+ tmp_cond_len);
+ tmp_pkg_cond[tmp_cond_len] = '\0';
- tmp_pkg_ver = slapt_regex_extract_match(parse_dep_regex, dep_entry, 3);
+ tmp_pkg_ver = slapt_regex_extract_match(parse_dep_regex, dep_entry, 3);
- slapt_free_regex(parse_dep_regex);
+ slapt_free_regex(parse_dep_regex);
- /*
+ /*
* check the newest version of tmp_pkg_name (in newest_installed_pkg)
* before we try looping through installed_pkgs
*/
- if (newest_installed_pkg != NULL) {
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if ((strchr(tmp_pkg_cond,'=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver,newest_installed_pkg->version) == 0) ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_installed_pkg;
- }
+ if (newest_installed_pkg != NULL) {
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if ((strchr(tmp_pkg_cond, '=') != NULL) &&
+ (slapt_cmp_pkg_versions(tmp_pkg_ver, newest_installed_pkg->version) == 0)) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_installed_pkg;
+ }
- /* if "<" */
- if (strchr(tmp_pkg_cond,'<') != NULL) {
- if (slapt_cmp_pkg_versions(newest_installed_pkg->version,tmp_pkg_ver) < 0 ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_installed_pkg;
- }
- }
+ /* if "<" */
+ if (strchr(tmp_pkg_cond, '<') != NULL) {
+ if (slapt_cmp_pkg_versions(newest_installed_pkg->version, tmp_pkg_ver) < 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_installed_pkg;
+ }
+ }
- /* if ">" */
- if (strchr(tmp_pkg_cond,'>') != NULL) {
- if (slapt_cmp_pkg_versions(newest_installed_pkg->version,tmp_pkg_ver) > 0 ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_installed_pkg;
- }
+ /* if ">" */
+ if (strchr(tmp_pkg_cond, '>') != NULL) {
+ if (slapt_cmp_pkg_versions(newest_installed_pkg->version, tmp_pkg_ver) > 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_installed_pkg;
+ }
+ }
}
- }
+ for (i = 0; i < installed_pkgs->pkg_count; i++) {
+ if (strcmp(tmp_pkg_name, installed_pkgs->pkgs[i]->name) != 0)
+ continue;
- for (i = 0; i < installed_pkgs->pkg_count; i++) {
-
- if (strcmp(tmp_pkg_name,installed_pkgs->pkgs[i]->name) != 0 )
- continue;
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if ((strchr(tmp_pkg_cond,'=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver,installed_pkgs->pkgs[i]->version) == 0) ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
- }
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if ((strchr(tmp_pkg_cond, '=') != NULL) &&
+ (slapt_cmp_pkg_versions(tmp_pkg_ver, installed_pkgs->pkgs[i]->version) == 0)) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return installed_pkgs->pkgs[i];
+ }
- /* if "<" */
- if (strchr(tmp_pkg_cond,'<') != NULL) {
- if (slapt_cmp_pkg_versions(installed_pkgs->pkgs[i]->version,
- tmp_pkg_ver) < 0 ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
- }
- }
+ /* if "<" */
+ if (strchr(tmp_pkg_cond, '<') != NULL) {
+ if (slapt_cmp_pkg_versions(installed_pkgs->pkgs[i]->version,
+ tmp_pkg_ver) < 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return installed_pkgs->pkgs[i];
+ }
+ }
- /* if ">" */
- if (strchr(tmp_pkg_cond,'>') != NULL) {
- if (slapt_cmp_pkg_versions(installed_pkgs->pkgs[i]->version,
- tmp_pkg_ver) > 0 ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
- }
+ /* if ">" */
+ if (strchr(tmp_pkg_cond, '>') != NULL) {
+ if (slapt_cmp_pkg_versions(installed_pkgs->pkgs[i]->version,
+ tmp_pkg_ver) > 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return installed_pkgs->pkgs[i];
+ }
+ }
}
- }
-
- /*
+ /*
* check the newest version of tmp_pkg_name (in newest_avail_pkg)
* before we try looping through avail_pkgs
*/
- if (newest_avail_pkg != NULL) {
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if ((strchr(tmp_pkg_cond,'=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver,newest_avail_pkg->version) == 0) ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_avail_pkg;
- }
+ if (newest_avail_pkg != NULL) {
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if ((strchr(tmp_pkg_cond, '=') != NULL) &&
+ (slapt_cmp_pkg_versions(tmp_pkg_ver, newest_avail_pkg->version) == 0)) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_avail_pkg;
+ }
- /* if "<" */
- if (strchr(tmp_pkg_cond,'<') != NULL) {
- if (slapt_cmp_pkg_versions(newest_avail_pkg->version,tmp_pkg_ver) < 0 ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_avail_pkg;
- }
- }
+ /* if "<" */
+ if (strchr(tmp_pkg_cond, '<') != NULL) {
+ if (slapt_cmp_pkg_versions(newest_avail_pkg->version, tmp_pkg_ver) < 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_avail_pkg;
+ }
+ }
- /* if ">" */
- if (strchr(tmp_pkg_cond,'>') != NULL) {
- if (slapt_cmp_pkg_versions(newest_avail_pkg->version,tmp_pkg_ver) > 0 ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_avail_pkg;
- }
+ /* if ">" */
+ if (strchr(tmp_pkg_cond, '>') != NULL) {
+ if (slapt_cmp_pkg_versions(newest_avail_pkg->version, tmp_pkg_ver) > 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_avail_pkg;
+ }
+ }
}
- }
-
- /* loop through avail_pkgs */
- for (i = 0; i < avail_pkgs->pkg_count; i++) {
+ /* loop through avail_pkgs */
+ for (i = 0; i < avail_pkgs->pkg_count; i++) {
+ if (strcmp(tmp_pkg_name, avail_pkgs->pkgs[i]->name) != 0)
+ continue;
- if (strcmp(tmp_pkg_name,avail_pkgs->pkgs[i]->name) != 0 )
- continue;
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if ((strchr(tmp_pkg_cond,'=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver,avail_pkgs->pkgs[i]->version) == 0)) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
- }
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if ((strchr(tmp_pkg_cond, '=') != NULL) &&
+ (slapt_cmp_pkg_versions(tmp_pkg_ver, avail_pkgs->pkgs[i]->version) == 0)) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return avail_pkgs->pkgs[i];
+ }
- /* if "<" */
- if (strchr(tmp_pkg_cond,'<') != NULL) {
- if (slapt_cmp_pkg_versions(avail_pkgs->pkgs[i]->version,tmp_pkg_ver) < 0) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
- }
- }
+ /* if "<" */
+ if (strchr(tmp_pkg_cond, '<') != NULL) {
+ if (slapt_cmp_pkg_versions(avail_pkgs->pkgs[i]->version, tmp_pkg_ver) < 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return avail_pkgs->pkgs[i];
+ }
+ }
- /* if ">" */
- if (strchr(tmp_pkg_cond,'>') != NULL) {
- if (slapt_cmp_pkg_versions(avail_pkgs->pkgs[i]->version,tmp_pkg_ver) > 0 ) {
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
- }
+ /* if ">" */
+ if (strchr(tmp_pkg_cond, '>') != NULL) {
+ if (slapt_cmp_pkg_versions(avail_pkgs->pkgs[i]->version, tmp_pkg_ver) > 0) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return avail_pkgs->pkgs[i];
+ }
+ }
}
- }
-
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
- return NULL;
+ return NULL;
}
slapt_pkg_list_t *slapt_is_required_by(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_list_t *pkgs_to_install,
- slapt_pkg_list_t *pkgs_to_remove,
- slapt_pkg_info_t *pkg)
+ slapt_pkg_list_t *avail,
+ slapt_pkg_list_t *installed_pkgs,
+ slapt_pkg_list_t *pkgs_to_install,
+ slapt_pkg_list_t *pkgs_to_remove,
+ slapt_pkg_info_t *pkg)
{
- slapt_pkg_list_t *required_by_list = slapt_init_pkg_list();
+ slapt_pkg_list_t *required_by_list = slapt_init_pkg_list();
- /*
+ /*
* don't go any further if disable_dep_check is set
*/
- if (global_config->disable_dep_check == true)
- return required_by_list;
+ if (global_config->disable_dep_check == true)
+ return required_by_list;
- required_by(avail,installed_pkgs,pkgs_to_install,pkgs_to_remove,pkg,required_by_list);
+ required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, pkg, required_by_list);
- return required_by_list;
+ return required_by_list;
}
static char *escape_package_name(slapt_pkg_info_t *pkg)
{
- unsigned int name_len = 0, escape_count = 0, i;
- char *escaped_name = NULL, *escaped_ptr;
- char p;
-
- escaped_ptr = pkg->name;
- while ( (p = *escaped_ptr++) )
- {
- if (p == '+')
- escape_count++;
- }
- escaped_ptr = NULL;
+ unsigned int name_len = 0, escape_count = 0, i;
+ char *escaped_name = NULL, *escaped_ptr;
+ char p;
- escaped_name = slapt_malloc(sizeof *escaped_name * (strlen(pkg->name) + escape_count + 1) );
+ escaped_ptr = pkg->name;
+ while ((p = *escaped_ptr++)) {
+ if (p == '+')
+ escape_count++;
+ }
+ escaped_ptr = NULL;
- name_len = strlen(pkg->name);
- for (i = 0, escaped_ptr = escaped_name; i < name_len && pkg->name[i]; i++) {
- if (pkg->name[i] == '+' ) {
- *escaped_ptr++ = '\\';
- *escaped_ptr++ = pkg->name[i];
- } else {
- *escaped_ptr++ = pkg->name[i];
+ escaped_name = slapt_malloc(sizeof *escaped_name * (strlen(pkg->name) + escape_count + 1));
+
+ name_len = strlen(pkg->name);
+ for (i = 0, escaped_ptr = escaped_name; i < name_len && pkg->name[i]; i++) {
+ if (pkg->name[i] == '+') {
+ *escaped_ptr++ = '\\';
+ *escaped_ptr++ = pkg->name[i];
+ } else {
+ *escaped_ptr++ = pkg->name[i];
+ }
+ *escaped_ptr = '\0';
}
- *escaped_ptr = '\0';
- }
- return escaped_name;
+ return escaped_name;
}
static void required_by(slapt_pkg_list_t *avail,
@@ -1786,107 +1714,103 @@ static void required_by(slapt_pkg_list_t *avail,
slapt_pkg_info_t *pkg,
slapt_pkg_list_t *required_by_list)
{
- unsigned int i;
- slapt_regex_t *required_by_reg = NULL;
- char *pkg_name = escape_package_name(pkg);
- int reg_str_len = strlen(pkg_name) + 31;
- char *reg = slapt_malloc(sizeof *reg * reg_str_len);
- /* add word boundary to search */
- int sprintf_r = snprintf(reg, (size_t)reg_str_len, "[^a-zA-Z0-9\\-]*%s[^a-zA-Z0-9\\-]*", pkg_name);
-
- if (sprintf_r < 0) {
- fprintf(stderr,"sprintf error for %s\n", pkg_name);
- exit(EXIT_FAILURE);
- }
-
- reg[reg_str_len-1] = '\0';
- if ((required_by_reg = slapt_init_regex(reg)) == NULL) {
- exit(EXIT_FAILURE);
- }
-
- free(pkg_name);
- free(reg);
-
- for (i = 0; i < avail->pkg_count;i++) {
- slapt_pkg_info_t *pkg_ptr = avail->pkgs[i];
- slapt_list_t *dep_list = NULL;
- unsigned int d = 0;
-
- if (strcmp(pkg_ptr->required,"") == 0 )
- continue;
- if (strcmp(pkg_ptr->required," ") == 0 )
- continue;
- if (strcmp(pkg_ptr->required," ") == 0 )
- continue;
- if (strstr(pkg_ptr->required, pkg->name) == NULL)
- continue;
-
- slapt_execute_regex(required_by_reg,pkg_ptr->required);
- if (required_by_reg->reg_return != 0 )
- continue;
-
- /* check for the offending dependency entry and see if we have an alternative */
- dep_list = slapt_parse_delimited_list(pkg_ptr->required,',');
- for (d = 0; d < dep_list->count; d++) {
- slapt_list_t *satisfies = NULL;
- unsigned int s = 0;
- bool has_alternative = false, found = false;
-
- /* found our package in the list of dependencies */
- if (strstr(dep_list->items[d], pkg->name) == NULL)
- continue;
-
- /* not an |or, just add it */
- if (strchr(dep_list->items[d],'|') == NULL) {
- if (strcmp(dep_list->items[d], pkg->name) != 0)
- continue;
- if (slapt_get_exact_pkg(required_by_list, pkg_ptr->name, pkg_ptr->version) == NULL) {
- slapt_add_pkg_to_pkg_list(required_by_list,pkg_ptr);
- required_by(avail,installed_pkgs,pkgs_to_install,pkgs_to_remove, pkg_ptr, required_by_list );
- }
- break;
- }
-
- /* we need to find out if we have something else that satisfies the dependency */
- satisfies = slapt_parse_delimited_list(dep_list->items[d],'|');
- for (s = 0; s < satisfies->count; s++) {
- slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail,installed_pkgs,satisfies->items[s]);
- if (tmp_pkg == NULL)
- continue;
-
- if (strcmp(tmp_pkg->name,pkg->name) == 0) {
- found = true;
- continue;
- }
+ unsigned int i;
+ slapt_regex_t *required_by_reg = NULL;
+ char *pkg_name = escape_package_name(pkg);
+ int reg_str_len = strlen(pkg_name) + 31;
+ char *reg = slapt_malloc(sizeof *reg * reg_str_len);
+ /* add word boundary to search */
+ int sprintf_r = snprintf(reg, (size_t)reg_str_len, "[^a-zA-Z0-9\\-]*%s[^a-zA-Z0-9\\-]*", pkg_name);
+
+ if (sprintf_r < 0) {
+ fprintf(stderr, "sprintf error for %s\n", pkg_name);
+ exit(EXIT_FAILURE);
+ }
- if (slapt_get_exact_pkg(installed_pkgs,tmp_pkg->name, tmp_pkg->version) != NULL) {
- if (slapt_get_exact_pkg(pkgs_to_remove,tmp_pkg->name, tmp_pkg->version) == NULL) {
- has_alternative = true;
- break;
- }
- } else if (slapt_get_exact_pkg(pkgs_to_install, tmp_pkg->name, tmp_pkg->version) != NULL) {
- has_alternative = true;
- break;
- }
+ reg[reg_str_len - 1] = '\0';
+ if ((required_by_reg = slapt_init_regex(reg)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- }
- slapt_free_list(satisfies);
+ free(pkg_name);
+ free(reg);
+
+ for (i = 0; i < avail->pkg_count; i++) {
+ slapt_pkg_info_t *pkg_ptr = avail->pkgs[i];
+ slapt_list_t *dep_list = NULL;
+ unsigned int d = 0;
+
+ if (strcmp(pkg_ptr->required, "") == 0)
+ continue;
+ if (strcmp(pkg_ptr->required, " ") == 0)
+ continue;
+ if (strcmp(pkg_ptr->required, " ") == 0)
+ continue;
+ if (strstr(pkg_ptr->required, pkg->name) == NULL)
+ continue;
+
+ slapt_execute_regex(required_by_reg, pkg_ptr->required);
+ if (required_by_reg->reg_return != 0)
+ continue;
+
+ /* check for the offending dependency entry and see if we have an alternative */
+ dep_list = slapt_parse_delimited_list(pkg_ptr->required, ',');
+ for (d = 0; d < dep_list->count; d++) {
+ slapt_list_t *satisfies = NULL;
+ unsigned int s = 0;
+ bool has_alternative = false, found = false;
+
+ /* found our package in the list of dependencies */
+ if (strstr(dep_list->items[d], pkg->name) == NULL)
+ continue;
+
+ /* not an |or, just add it */
+ if (strchr(dep_list->items[d], '|') == NULL) {
+ if (strcmp(dep_list->items[d], pkg->name) != 0)
+ continue;
+ if (slapt_get_exact_pkg(required_by_list, pkg_ptr->name, pkg_ptr->version) == NULL) {
+ slapt_add_pkg_to_pkg_list(required_by_list, pkg_ptr);
+ required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, pkg_ptr, required_by_list);
+ }
+ break;
+ }
- /* we couldn't find an installed pkg that satisfies the |or */
- if (has_alternative == false && found == true) {
- if (slapt_get_exact_pkg(required_by_list, pkg_ptr->name, pkg_ptr->version) == NULL) {
- slapt_add_pkg_to_pkg_list(required_by_list,pkg_ptr);
- required_by(avail,installed_pkgs,pkgs_to_install,pkgs_to_remove, pkg_ptr, required_by_list );
+ /* we need to find out if we have something else that satisfies the dependency */
+ satisfies = slapt_parse_delimited_list(dep_list->items[d], '|');
+ for (s = 0; s < satisfies->count; s++) {
+ slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail, installed_pkgs, satisfies->items[s]);
+ if (tmp_pkg == NULL)
+ continue;
+
+ if (strcmp(tmp_pkg->name, pkg->name) == 0) {
+ found = true;
+ continue;
+ }
+
+ if (slapt_get_exact_pkg(installed_pkgs, tmp_pkg->name, tmp_pkg->version) != NULL) {
+ if (slapt_get_exact_pkg(pkgs_to_remove, tmp_pkg->name, tmp_pkg->version) == NULL) {
+ has_alternative = true;
+ break;
+ }
+ } else if (slapt_get_exact_pkg(pkgs_to_install, tmp_pkg->name, tmp_pkg->version) != NULL) {
+ has_alternative = true;
+ break;
+ }
+ }
+ slapt_free_list(satisfies);
+
+ /* we couldn't find an installed pkg that satisfies the |or */
+ if (has_alternative == false && found == true) {
+ if (slapt_get_exact_pkg(required_by_list, pkg_ptr->name, pkg_ptr->version) == NULL) {
+ slapt_add_pkg_to_pkg_list(required_by_list, pkg_ptr);
+ required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, pkg_ptr, required_by_list);
+ }
+ }
}
- }
-
+ slapt_free_list(dep_list);
}
- slapt_free_list(dep_list);
-
-
- }
- slapt_free_regex(required_by_reg);
+ slapt_free_regex(required_by_reg);
}
slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
@@ -1894,431 +1818,408 @@ slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
const char *version,
const char *location)
{
+ if (list->ordered) {
+ int min = 0, max = list->pkg_count - 1;
- if (list->ordered) {
- int min = 0, max = list->pkg_count - 1;
-
- while (max >= min)
- {
- int pivot = (min + max) / 2;
- int name_cmp = strcmp(list->pkgs[pivot]->name, name);
-
- if ( name_cmp == 0 ) {
-
- int version_cmp = strverscmp(list->pkgs[pivot]->version, version);
-
- if ( version_cmp == 0 ) {
-
- int location_cmp = strcmp(list->pkgs[pivot]->location, location);
-
- if ( location_cmp == 0 ) {
+ while (max >= min) {
+ int pivot = (min + max) / 2;
+ int name_cmp = strcmp(list->pkgs[pivot]->name, name);
- return list->pkgs[pivot];
+ if (name_cmp == 0) {
+ int version_cmp = strverscmp(list->pkgs[pivot]->version, version);
- } else {
+ if (version_cmp == 0) {
+ int location_cmp = strcmp(list->pkgs[pivot]->location, location);
- if (location_cmp < 0 )
- min = pivot + 1;
- else
- max = pivot - 1;
+ if (location_cmp == 0) {
+ return list->pkgs[pivot];
- }
+ } else {
+ if (location_cmp < 0)
+ min = pivot + 1;
+ else
+ max = pivot - 1;
+ }
+ } else {
+ if (version_cmp < 0)
+ min = pivot + 1;
+ else
+ max = pivot - 1;
+ }
- } else {
-
- if ( version_cmp < 0 )
- min = pivot + 1;
- else
- max = pivot - 1;
-
+ } else {
+ if (name_cmp < 0)
+ min = pivot + 1;
+ else
+ max = pivot - 1;
+ }
}
- } else {
-
- if ( name_cmp < 0 )
- min = pivot + 1;
- else
- max = pivot - 1;
-
- }
-
- }
-
- } else {
- unsigned int i;
-
- for (i = 0; i < list->pkg_count; i++) {
-
- if (strcmp(list->pkgs[i]->name,name) == 0 ) {
- if (version != NULL) {
- if (strcmp(list->pkgs[i]->version,version) == 0) {
- if (location != NULL) {
- if (strcmp(list->pkgs[i]->location,location) == 0) {
- return list->pkgs[i];
- }
- } else {
- return list->pkgs[i];
+ } else {
+ unsigned int i;
+
+ for (i = 0; i < list->pkg_count; i++) {
+ if (strcmp(list->pkgs[i]->name, name) == 0) {
+ if (version != NULL) {
+ if (strcmp(list->pkgs[i]->version, version) == 0) {
+ if (location != NULL) {
+ if (strcmp(list->pkgs[i]->location, location) == 0) {
+ return list->pkgs[i];
+ }
+ } else {
+ return list->pkgs[i];
+ }
+ }
+ }
}
- }
}
- }
}
- }
- return NULL;
+ return NULL;
}
/* update package data from mirror url */
int slapt_update_pkg_cache(const slapt_rc_config *global_config)
{
- unsigned int i,source_dl_failed = 0;
- slapt_pkg_list_t *new_pkgs = slapt_init_pkg_list();
- new_pkgs->free_pkgs = true;
-
- /* go through each package source and download the meta data */
- for (i = 0; i < global_config->sources->count; i++) {
- unsigned int compressed = 0;
- slapt_pkg_list_t *available_pkgs = NULL;
- slapt_pkg_list_t *patch_pkgs = NULL;
- FILE *tmp_checksum_f = NULL;
- #ifdef SLAPT_HAS_GPGME
- FILE *tmp_signature_f = NULL;
- FILE *tmp_checksum_to_verify_f = NULL;
- #endif
- const char *source_url = global_config->sources->src[i]->url;
- SLAPT_PRIORITY_T source_priority = global_config->sources->src[i]->priority;
-
- if (global_config->sources->src[i]->disabled == true)
- continue;
-
- /* download our SLAPT_PKG_LIST */
- printf(gettext("Retrieving package data [%s]..."), source_url);
-
- available_pkgs = slapt_get_pkg_source_packages(global_config, source_url, &compressed);
- if (available_pkgs == NULL) {
- source_dl_failed = 1;
- continue;
- }
-
- /* download SLAPT_PATCHES_LIST */
- printf(gettext("Retrieving patch list [%s]..."), source_url);
-
- patch_pkgs = slapt_get_pkg_source_patches(global_config, source_url, &compressed);
-
-
- /* download checksum file */
- printf(gettext("Retrieving checksum list [%s]..."), source_url);
- tmp_checksum_f = slapt_get_pkg_source_checksums(global_config, source_url, &compressed);
+ unsigned int i, source_dl_failed = 0;
+ slapt_pkg_list_t *new_pkgs = slapt_init_pkg_list();
+ new_pkgs->free_pkgs = true;
+
+ /* go through each package source and download the meta data */
+ for (i = 0; i < global_config->sources->count; i++) {
+ unsigned int compressed = 0;
+ slapt_pkg_list_t *available_pkgs = NULL;
+ slapt_pkg_list_t *patch_pkgs = NULL;
+ FILE *tmp_checksum_f = NULL;
+#ifdef SLAPT_HAS_GPGME
+ FILE *tmp_signature_f = NULL;
+ FILE *tmp_checksum_to_verify_f = NULL;
+#endif
+ const char *source_url = global_config->sources->src[i]->url;
+ SLAPT_PRIORITY_T source_priority = global_config->sources->src[i]->priority;
- #ifdef SLAPT_HAS_GPGME
- printf(gettext("Retrieving checksum signature [%s]..."), source_url);
- tmp_signature_f = slapt_get_pkg_source_checksums_signature (global_config,source_url, &compressed);
+ if (global_config->sources->src[i]->disabled == true)
+ continue;
- /* if we downloaded the compressed checksums, open it raw (w/o gunzipping) */
- if (compressed == 1)
- {
- char *filename = slapt_gen_filename_from_url(source_url, SLAPT_CHECKSUM_FILE_GZ);
- tmp_checksum_to_verify_f = slapt_open_file(filename,"r");
- free(filename);
- } else {
- tmp_checksum_to_verify_f = tmp_checksum_f;
- }
-
- if (tmp_signature_f != NULL && tmp_checksum_to_verify_f != NULL) {
- slapt_code_t verified = SLAPT_CHECKSUMS_NOT_VERIFIED;
- printf(gettext("Verifying checksum signature [%s]..."), source_url);
- verified = slapt_gpg_verify_checksums(tmp_checksum_to_verify_f, tmp_signature_f);
- if (verified == SLAPT_CHECKSUMS_VERIFIED) {
- printf("%s\n",gettext("Verified"));
- } else if (verified == SLAPT_CHECKSUMS_MISSING_KEY) {
- printf("%s\n",gettext("No key for verification"));
- } else if ((global_config->gpgme_allow_unauth == true) && (slapt_pkg_sign_is_unauthenticated(verified) == true)) {
- printf("%s%s\n", slapt_strerror(verified), gettext(", but accepted as an exception"));
- } else {
- printf("%s\n",gettext(slapt_strerror(verified)));
- source_dl_failed = 1;
- fclose(tmp_checksum_f);
- tmp_checksum_f = NULL;
- }
- }
-
- if (tmp_signature_f)
- fclose(tmp_signature_f);
-
- /* if we opened the raw gzipped checksums, close it here */
- if (compressed == 1) {
- fclose(tmp_checksum_to_verify_f);
- } else {
- if (tmp_checksum_f)
- rewind(tmp_checksum_f);
- }
- #endif
+ /* download our SLAPT_PKG_LIST */
+ printf(gettext("Retrieving package data [%s]..."), source_url);
- if (source_dl_failed != 1) {
- printf(gettext("Retrieving ChangeLog.txt [%s]..."), source_url);
- slapt_get_pkg_source_changelog(global_config, source_url, &compressed);
- }
+ available_pkgs = slapt_get_pkg_source_packages(global_config, source_url, &compressed);
+ if (available_pkgs == NULL) {
+ source_dl_failed = 1;
+ continue;
+ }
- if (tmp_checksum_f != NULL) {
- unsigned int pkg_i;
+ /* download SLAPT_PATCHES_LIST */
+ printf(gettext("Retrieving patch list [%s]..."), source_url);
- /* now map md5 checksums to packages */
- printf(gettext("Reading Package Lists..."));
+ patch_pkgs = slapt_get_pkg_source_patches(global_config, source_url, &compressed);
- slapt_get_md5sums(available_pkgs, tmp_checksum_f);
+ /* download checksum file */
+ printf(gettext("Retrieving checksum list [%s]..."), source_url);
+ tmp_checksum_f = slapt_get_pkg_source_checksums(global_config, source_url, &compressed);
- for (pkg_i = 0; pkg_i < available_pkgs->pkg_count; ++pkg_i) {
- slapt_pkg_info_t *p = available_pkgs->pkgs[pkg_i];
- int mirror_len = -1;
+#ifdef SLAPT_HAS_GPGME
+ printf(gettext("Retrieving checksum signature [%s]..."), source_url);
+ tmp_signature_f = slapt_get_pkg_source_checksums_signature(global_config, source_url, &compressed);
+
+ /* if we downloaded the compressed checksums, open it raw (w/o gunzipping) */
+ if (compressed == 1) {
+ char *filename = slapt_gen_filename_from_url(source_url, SLAPT_CHECKSUM_FILE_GZ);
+ tmp_checksum_to_verify_f = slapt_open_file(filename, "r");
+ free(filename);
+ } else {
+ tmp_checksum_to_verify_f = tmp_checksum_f;
+ }
- /* honor the mirror if it was set in the PACKAGES.TXT */
- if (p->mirror == NULL || (mirror_len = strlen(p->mirror)) == 0) {
+ if (tmp_signature_f != NULL && tmp_checksum_to_verify_f != NULL) {
+ slapt_code_t verified = SLAPT_CHECKSUMS_NOT_VERIFIED;
+ printf(gettext("Verifying checksum signature [%s]..."), source_url);
+ verified = slapt_gpg_verify_checksums(tmp_checksum_to_verify_f, tmp_signature_f);
+ if (verified == SLAPT_CHECKSUMS_VERIFIED) {
+ printf("%s\n", gettext("Verified"));
+ } else if (verified == SLAPT_CHECKSUMS_MISSING_KEY) {
+ printf("%s\n", gettext("No key for verification"));
+ } else if ((global_config->gpgme_allow_unauth == true) && (slapt_pkg_sign_is_unauthenticated(verified) == true)) {
+ printf("%s%s\n", slapt_strerror(verified), gettext(", but accepted as an exception"));
+ } else {
+ printf("%s\n", gettext(slapt_strerror(verified)));
+ source_dl_failed = 1;
+ fclose(tmp_checksum_f);
+ tmp_checksum_f = NULL;
+ }
+ }
- if (mirror_len == 0)
- free(p->mirror);
+ if (tmp_signature_f)
+ fclose(tmp_signature_f);
- p->mirror = strdup(source_url);
+ /* if we opened the raw gzipped checksums, close it here */
+ if (compressed == 1) {
+ fclose(tmp_checksum_to_verify_f);
+ } else {
+ if (tmp_checksum_f)
+ rewind(tmp_checksum_f);
}
+#endif
- /* set the priority of the package based on the source */
- p->priority = source_priority;
+ if (source_dl_failed != 1) {
+ printf(gettext("Retrieving ChangeLog.txt [%s]..."), source_url);
+ slapt_get_pkg_source_changelog(global_config, source_url, &compressed);
+ }
- slapt_add_pkg_to_pkg_list(new_pkgs,p);
- }
- available_pkgs->free_pkgs = false;
+ if (tmp_checksum_f != NULL) {
+ unsigned int pkg_i;
- if (patch_pkgs) {
- slapt_get_md5sums(patch_pkgs, tmp_checksum_f);
- for (pkg_i = 0; pkg_i < patch_pkgs->pkg_count; ++pkg_i) {
- slapt_pkg_info_t *p = patch_pkgs->pkgs[pkg_i];
- int mirror_len = -1;
+ /* now map md5 checksums to packages */
+ printf(gettext("Reading Package Lists..."));
- /* honor the mirror if it was set in the PACKAGES.TXT */
- if (p->mirror == NULL || (mirror_len = strlen(p->mirror)) == 0) {
+ slapt_get_md5sums(available_pkgs, tmp_checksum_f);
- if (mirror_len == 0)
- free(p->mirror);
+ for (pkg_i = 0; pkg_i < available_pkgs->pkg_count; ++pkg_i) {
+ slapt_pkg_info_t *p = available_pkgs->pkgs[pkg_i];
+ int mirror_len = -1;
- p->mirror = strdup(source_url);
- }
+ /* honor the mirror if it was set in the PACKAGES.TXT */
+ if (p->mirror == NULL || (mirror_len = strlen(p->mirror)) == 0) {
+ if (mirror_len == 0)
+ free(p->mirror);
- /* set the priority of the package based on the source, plus 1 for the patch priority */
- if (global_config->use_priority == true)
- p->priority = source_priority + 1;
- else
- p->priority = source_priority;
+ p->mirror = strdup(source_url);
+ }
- slapt_add_pkg_to_pkg_list(new_pkgs,p);
- }
- patch_pkgs->free_pkgs = false;
- }
+ /* set the priority of the package based on the source */
+ p->priority = source_priority;
- printf(gettext("Done\n"));
+ slapt_add_pkg_to_pkg_list(new_pkgs, p);
+ }
+ available_pkgs->free_pkgs = false;
+
+ if (patch_pkgs) {
+ slapt_get_md5sums(patch_pkgs, tmp_checksum_f);
+ for (pkg_i = 0; pkg_i < patch_pkgs->pkg_count; ++pkg_i) {
+ slapt_pkg_info_t *p = patch_pkgs->pkgs[pkg_i];
+ int mirror_len = -1;
+
+ /* honor the mirror if it was set in the PACKAGES.TXT */
+ if (p->mirror == NULL || (mirror_len = strlen(p->mirror)) == 0) {
+ if (mirror_len == 0)
+ free(p->mirror);
+
+ p->mirror = strdup(source_url);
+ }
+
+ /* set the priority of the package based on the source, plus 1 for the patch priority */
+ if (global_config->use_priority == true)
+ p->priority = source_priority + 1;
+ else
+ p->priority = source_priority;
+
+ slapt_add_pkg_to_pkg_list(new_pkgs, p);
+ }
+ patch_pkgs->free_pkgs = false;
+ }
- fclose(tmp_checksum_f);
- } else {
- source_dl_failed = 1;
- }
+ printf(gettext("Done\n"));
+ fclose(tmp_checksum_f);
+ } else {
+ source_dl_failed = 1;
+ }
- if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ if (available_pkgs)
+ slapt_free_pkg_list(available_pkgs);
- if (patch_pkgs)
- slapt_free_pkg_list(patch_pkgs);
+ if (patch_pkgs)
+ slapt_free_pkg_list(patch_pkgs);
- }/* end for loop */
+ } /* end for loop */
- /* if all our downloads where a success, write to SLAPT_PKG_LIST_L */
- if (source_dl_failed != 1 ) {
- FILE *pkg_list_fh;
+ /* if all our downloads where a success, write to SLAPT_PKG_LIST_L */
+ if (source_dl_failed != 1) {
+ FILE *pkg_list_fh;
- if ((pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L,"w+")) == NULL)
- exit(EXIT_FAILURE);
+ if ((pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L, "w+")) == NULL)
+ exit(EXIT_FAILURE);
- qsort( new_pkgs->pkgs, new_pkgs->pkg_count, sizeof(new_pkgs->pkgs[0]), pkg_compare );
+ qsort(new_pkgs->pkgs, new_pkgs->pkg_count, sizeof(new_pkgs->pkgs[0]), pkg_compare);
- slapt_write_pkg_data(NULL,pkg_list_fh,new_pkgs);
+ slapt_write_pkg_data(NULL, pkg_list_fh, new_pkgs);
- fclose(pkg_list_fh);
+ fclose(pkg_list_fh);
- } else {
- printf(gettext("Sources failed to download, correct sources and rerun --update\n"));
- }
+ } else {
+ printf(gettext("Sources failed to download, correct sources and rerun --update\n"));
+ }
- slapt_free_pkg_list(new_pkgs);
+ slapt_free_pkg_list(new_pkgs);
- return source_dl_failed;
+ return source_dl_failed;
}
#ifdef SLAPT_HAS_GPGME
bool slapt_pkg_sign_is_unauthenticated(slapt_code_t code)
{
- switch (code)
- {
+ switch (code) {
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_REVOKED:
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_KEY_EXPIRED:
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_SIG_EXPIRED:
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_MISSING:
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_CRL_TOO_OLD:
case SLAPT_CHECKSUMS_NOT_VERIFIED_GPGME_BAD_POLICY:
- return true;
+ return true;
default:
- break;
- }
+ break;
+ }
- return false;
+ return false;
}
#endif
slapt_pkg_list_t *slapt_init_pkg_list(void)
{
- slapt_pkg_list_t *list = NULL;
+ slapt_pkg_list_t *list = NULL;
- list = slapt_malloc(sizeof *list);
- list->pkgs = slapt_malloc(sizeof *list->pkgs);
- list->pkg_count = 0;
- list->free_pkgs = false;
- list->ordered = false;
+ list = slapt_malloc(sizeof *list);
+ list->pkgs = slapt_malloc(sizeof *list->pkgs);
+ list->pkg_count = 0;
+ list->free_pkgs = false;
+ list->ordered = false;
- return list;
+ return list;
}
void slapt_add_pkg_to_pkg_list(slapt_pkg_list_t *list,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_info_t **realloc_tmp;
-
- /* grow our struct array */
- realloc_tmp = realloc(list->pkgs,
- sizeof *list->pkgs * (list->pkg_count + 1)
- );
- if (realloc_tmp == NULL) {
- fprintf(stderr,gettext("Failed to realloc %s\n"),"pkgs");
- exit(EXIT_FAILURE);
- }
+ slapt_pkg_info_t **realloc_tmp;
- list->pkgs = realloc_tmp;
- list->pkgs[list->pkg_count] = pkg;
- ++list->pkg_count;
+ /* grow our struct array */
+ realloc_tmp = realloc(list->pkgs,
+ sizeof *list->pkgs * (list->pkg_count + 1));
+ if (realloc_tmp == NULL) {
+ fprintf(stderr, gettext("Failed to realloc %s\n"), "pkgs");
+ exit(EXIT_FAILURE);
+ }
+ list->pkgs = realloc_tmp;
+ list->pkgs[list->pkg_count] = pkg;
+ ++list->pkg_count;
}
slapt_pkg_info_t *slapt_init_pkg(void)
{
- slapt_pkg_info_t *pkg;
+ slapt_pkg_info_t *pkg;
- pkg = slapt_malloc(sizeof *pkg);
+ pkg = slapt_malloc(sizeof *pkg);
- pkg->size_c = 0;
- pkg->size_u = 0;
+ pkg->size_c = 0;
+ pkg->size_u = 0;
- pkg->name = NULL;
- pkg->version = NULL;
- pkg->mirror = NULL;
- pkg->location = NULL;
- pkg->file_ext = NULL;
+ pkg->name = NULL;
+ pkg->version = NULL;
+ pkg->mirror = NULL;
+ pkg->location = NULL;
+ pkg->file_ext = NULL;
- pkg->description = slapt_malloc(sizeof *pkg->description);
- pkg->description[0] = '\0';
+ pkg->description = slapt_malloc(sizeof *pkg->description);
+ pkg->description[0] = '\0';
- pkg->required = slapt_malloc(sizeof *pkg->required);
- pkg->required[0] = '\0';
+ pkg->required = slapt_malloc(sizeof *pkg->required);
+ pkg->required[0] = '\0';
- pkg->conflicts = slapt_malloc(sizeof *pkg->conflicts);
- pkg->conflicts[0] = '\0';
+ pkg->conflicts = slapt_malloc(sizeof *pkg->conflicts);
+ pkg->conflicts[0] = '\0';
- pkg->suggests = slapt_malloc(sizeof *pkg->suggests);
- pkg->suggests[0] = '\0';
+ pkg->suggests = slapt_malloc(sizeof *pkg->suggests);
+ pkg->suggests[0] = '\0';
- pkg->md5[0] = '\0';
+ pkg->md5[0] = '\0';
- pkg->priority = SLAPT_PRIORITY_DEFAULT;
+ pkg->priority = SLAPT_PRIORITY_DEFAULT;
- pkg->installed = false;
+ pkg->installed = false;
- return pkg;
+ return pkg;
}
/* generate the package file name */
char *slapt_gen_pkg_file_name(const slapt_rc_config *global_config,
slapt_pkg_info_t *pkg)
{
- char *file_name = NULL;
-
- /* build the file name */
- file_name = slapt_calloc(
- strlen(global_config->working_dir) + strlen(pkg->location) +
- strlen(pkg->name) + strlen(pkg->version)+strlen(pkg->file_ext) + 4,
- sizeof *file_name
- );
- file_name = strncpy(file_name,
- global_config->working_dir,strlen(global_config->working_dir)
- );
- file_name[ strlen(global_config->working_dir) ] = '\0';
- file_name = strncat(file_name,"/",1);
- file_name = strncat(file_name,pkg->location,strlen(pkg->location));
- file_name = strncat(file_name,"/",1);
- file_name = strncat(file_name,pkg->name,strlen(pkg->name));
- file_name = strncat(file_name,"-",1);
- file_name = strncat(file_name,pkg->version,strlen(pkg->version));
- file_name = strncat(file_name,pkg->file_ext,strlen(pkg->file_ext));
-
- return file_name;
+ char *file_name = NULL;
+
+ /* build the file name */
+ file_name = slapt_calloc(
+ strlen(global_config->working_dir) + strlen(pkg->location) +
+ strlen(pkg->name) + strlen(pkg->version) + strlen(pkg->file_ext) + 4,
+ sizeof *file_name);
+ file_name = strncpy(file_name,
+ global_config->working_dir, strlen(global_config->working_dir));
+ file_name[strlen(global_config->working_dir)] = '\0';
+ file_name = strncat(file_name, "/", 1);
+ file_name = strncat(file_name, pkg->location, strlen(pkg->location));
+ file_name = strncat(file_name, "/", 1);
+ file_name = strncat(file_name, pkg->name, strlen(pkg->name));
+ file_name = strncat(file_name, "-", 1);
+ file_name = strncat(file_name, pkg->version, strlen(pkg->version));
+ file_name = strncat(file_name, pkg->file_ext, strlen(pkg->file_ext));
+
+ return file_name;
}
/* generate the download url for a package */
char *slapt_gen_pkg_url(slapt_pkg_info_t *pkg)
{
- char *url = NULL;
- char *file_name = NULL;
+ char *url = NULL;
+ char *file_name = NULL;
- /* build the file name */
- file_name = slapt_stringify_pkg(pkg);
+ /* build the file name */
+ file_name = slapt_stringify_pkg(pkg);
- /* build the url */
- url = slapt_calloc(strlen(pkg->mirror) + strlen(pkg->location) +
- strlen(file_name) + 2, sizeof *url);
+ /* build the url */
+ url = slapt_calloc(strlen(pkg->mirror) + strlen(pkg->location) +
+ strlen(file_name) + 2,
+ sizeof *url);
- url = strncpy(url,pkg->mirror,strlen(pkg->mirror));
- url[strlen(pkg->mirror)] = '\0';
- url = strncat(url,pkg->location,strlen(pkg->location));
- url = strncat(url,"/",1);
- url = strncat(url,file_name,strlen(file_name));
+ url = strncpy(url, pkg->mirror, strlen(pkg->mirror));
+ url[strlen(pkg->mirror)] = '\0';
+ url = strncat(url, pkg->location, strlen(pkg->location));
+ url = strncat(url, "/", 1);
+ url = strncat(url, file_name, strlen(file_name));
- free(file_name);
- return url;
+ free(file_name);
+ return url;
}
/* find out the pkg file size (post download) */
size_t slapt_get_pkg_file_size(const slapt_rc_config *global_config,
slapt_pkg_info_t *pkg)
{
- char *file_name = NULL;
- struct stat file_stat;
- size_t file_size = 0;
+ char *file_name = NULL;
+ struct stat file_stat;
+ size_t file_size = 0;
- /* build the file name */
- file_name = slapt_gen_pkg_file_name(global_config,pkg);
+ /* build the file name */
+ file_name = slapt_gen_pkg_file_name(global_config, pkg);
- if (stat(file_name,&file_stat) == 0 ) {
- file_size = file_stat.st_size;
- }
- free(file_name);
+ if (stat(file_name, &file_stat) == 0) {
+ file_size = file_stat.st_size;
+ }
+ free(file_name);
- return file_size;
+ return file_size;
}
/* package is already downloaded and cached, md5sum if applicable is ok */
slapt_code_t slapt_verify_downloaded_pkg(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg)
+ slapt_pkg_info_t *pkg)
{
- char *file_name = NULL;
- FILE *fh_test = NULL;
- char md5sum_f[SLAPT_MD5_STR_LEN];
+ char *file_name = NULL;
+ FILE *fh_test = NULL;
+ char md5sum_f[SLAPT_MD5_STR_LEN];
- /*
+ /*
size_t file_size = 0;
check the file size first so we don't run an md5 checksum
on an incomplete file
@@ -2335,210 +2236,197 @@ slapt_code_t slapt_verify_downloaded_pkg(const slapt_rc_config *global_config,
}
*/
- /* if not checking the md5 checksum and the sizes match, assume its good */
- if (global_config->no_md5_check == true)
- return SLAPT_OK;
+ /* if not checking the md5 checksum and the sizes match, assume its good */
+ if (global_config->no_md5_check == true)
+ return SLAPT_OK;
- /* check to see that we actually have an md5 checksum */
- if (strcmp(pkg->md5,"") == 0) {
- return SLAPT_MD5_CHECKSUM_MISSING;
- }
+ /* check to see that we actually have an md5 checksum */
+ if (strcmp(pkg->md5, "") == 0) {
+ return SLAPT_MD5_CHECKSUM_MISSING;
+ }
- /* build the file name */
- file_name = slapt_gen_pkg_file_name(global_config,pkg);
+ /* build the file name */
+ file_name = slapt_gen_pkg_file_name(global_config, pkg);
- /* return if we can't open the file */
- if ((fh_test = fopen(file_name,"r") ) == NULL) {
+ /* return if we can't open the file */
+ if ((fh_test = fopen(file_name, "r")) == NULL) {
+ free(file_name);
+ return SLAPT_DOWNLOAD_INCOMPLETE;
+ }
free(file_name);
- return SLAPT_DOWNLOAD_INCOMPLETE;
- }
- free(file_name);
-
- /* generate the md5 checksum */
- slapt_gen_md5_sum_of_file(fh_test,md5sum_f);
- fclose(fh_test);
- /* check to see if the md5sum is correct */
- if (strcmp(md5sum_f,pkg->md5) == 0 )
- return SLAPT_OK;
+ /* generate the md5 checksum */
+ slapt_gen_md5_sum_of_file(fh_test, md5sum_f);
+ fclose(fh_test);
- return SLAPT_MD5_CHECKSUM_MISMATCH;
+ /* check to see if the md5sum is correct */
+ if (strcmp(md5sum_f, pkg->md5) == 0)
+ return SLAPT_OK;
+ return SLAPT_MD5_CHECKSUM_MISMATCH;
}
-char *slapt_gen_filename_from_url(const char *url,const char *file)
+char *slapt_gen_filename_from_url(const char *url, const char *file)
{
- char *filename,*cleaned;
+ char *filename, *cleaned;
- filename = slapt_calloc(strlen(url) + strlen(file) + 2 , sizeof *filename);
- filename[0] = '.';
- strncat(filename,url,strlen(url));
- strncat(filename,file,strlen(file));
+ filename = slapt_calloc(strlen(url) + strlen(file) + 2, sizeof *filename);
+ filename[0] = '.';
+ strncat(filename, url, strlen(url));
+ strncat(filename, file, strlen(file));
- cleaned = slapt_str_replace_chr(filename,'/','#');
+ cleaned = slapt_str_replace_chr(filename, '/', '#');
- free(filename);
+ free(filename);
- return cleaned;
+ return cleaned;
}
void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
const char *dir_name,
slapt_pkg_list_t *avail_pkgs)
{
- DIR *dir;
- struct dirent *file;
- struct stat file_stat;
- slapt_regex_t *cached_pkgs_regex = NULL;
- int local_pkg_list = 0;
-
- if (avail_pkgs == NULL) {
- avail_pkgs = slapt_get_available_pkgs();
- local_pkg_list = 1;
- }
-
- if (dir_name == NULL)
- dir_name = (char *)global_config->working_dir;
-
- if ((cached_pkgs_regex = slapt_init_regex(SLAPT_PKG_PARSE_REGEX)) == NULL) {
- exit(EXIT_FAILURE);
- }
-
- if ((dir = opendir(dir_name)) == NULL) {
-
- if (errno)
- perror(dir_name);
+ DIR *dir;
+ struct dirent *file;
+ struct stat file_stat;
+ slapt_regex_t *cached_pkgs_regex = NULL;
+ int local_pkg_list = 0;
- fprintf(stderr,gettext("Failed to opendir %s\n"),dir_name);
- return;
- }
-
- if (chdir(dir_name) == -1 ) {
-
- if (errno)
- perror(dir_name);
-
- fprintf(stderr,gettext("Failed to chdir: %s\n"),dir_name);
- closedir(dir);
- return;
- }
+ if (avail_pkgs == NULL) {
+ avail_pkgs = slapt_get_available_pkgs();
+ local_pkg_list = 1;
+ }
- while ((file = readdir(dir)) ) {
+ if (dir_name == NULL)
+ dir_name = (char *)global_config->working_dir;
- /* make sure we don't have . or .. */
- if ((strcmp(file->d_name,"..")) == 0 || (strcmp(file->d_name,".") == 0))
- continue;
+ if ((cached_pkgs_regex = slapt_init_regex(SLAPT_PKG_PARSE_REGEX)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- /* setup file_stat struct */
- if ((lstat(file->d_name,&file_stat)) == -1)
- continue;
+ if ((dir = opendir(dir_name)) == NULL) {
+ if (errno)
+ perror(dir_name);
- /* if its a directory, recurse */
- if (S_ISDIR(file_stat.st_mode) ) {
- slapt_purge_old_cached_pkgs(global_config,file->d_name,avail_pkgs);
- if ((chdir("..")) == -1 ) {
- fprintf(stderr,gettext("Failed to chdir: %s\n"),dir_name);
+ fprintf(stderr, gettext("Failed to opendir %s\n"), dir_name);
return;
- }
- continue;
}
- /* if its a package */
- if (strstr(file->d_name,".t") != NULL) {
-
- slapt_execute_regex(cached_pkgs_regex,file->d_name);
-
- /* if our regex matches */
- if (cached_pkgs_regex->reg_return == 0 ) {
- char *tmp_pkg_name,*tmp_pkg_version;
- slapt_pkg_info_t *tmp_pkg;
+ if (chdir(dir_name) == -1) {
+ if (errno)
+ perror(dir_name);
- tmp_pkg_name = slapt_regex_extract_match(cached_pkgs_regex, file->d_name, 1);
- tmp_pkg_version = slapt_regex_extract_match(cached_pkgs_regex, file->d_name, 2);
- tmp_pkg = slapt_get_exact_pkg(avail_pkgs,tmp_pkg_name,tmp_pkg_version);
-
- free(tmp_pkg_name);
- free(tmp_pkg_version);
+ fprintf(stderr, gettext("Failed to chdir: %s\n"), dir_name);
+ closedir(dir);
+ return;
+ }
- if (tmp_pkg == NULL) {
+ while ((file = readdir(dir))) {
+ /* make sure we don't have . or .. */
+ if ((strcmp(file->d_name, "..")) == 0 || (strcmp(file->d_name, ".") == 0))
+ continue;
- if (global_config->no_prompt == true) {
- unlink(file->d_name);
- } else {
- if (slapt_ask_yes_no(gettext("Delete %s ? [y/N]"),file->d_name) == 1)
- unlink(file->d_name);
- }
+ /* setup file_stat struct */
+ if ((lstat(file->d_name, &file_stat)) == -1)
+ continue;
+ /* if its a directory, recurse */
+ if (S_ISDIR(file_stat.st_mode)) {
+ slapt_purge_old_cached_pkgs(global_config, file->d_name, avail_pkgs);
+ if ((chdir("..")) == -1) {
+ fprintf(stderr, gettext("Failed to chdir: %s\n"), dir_name);
+ return;
+ }
+ continue;
}
- tmp_pkg = NULL;
-
- }
+ /* if its a package */
+ if (strstr(file->d_name, ".t") != NULL) {
+ slapt_execute_regex(cached_pkgs_regex, file->d_name);
+
+ /* if our regex matches */
+ if (cached_pkgs_regex->reg_return == 0) {
+ char *tmp_pkg_name, *tmp_pkg_version;
+ slapt_pkg_info_t *tmp_pkg;
+
+ tmp_pkg_name = slapt_regex_extract_match(cached_pkgs_regex, file->d_name, 1);
+ tmp_pkg_version = slapt_regex_extract_match(cached_pkgs_regex, file->d_name, 2);
+ tmp_pkg = slapt_get_exact_pkg(avail_pkgs, tmp_pkg_name, tmp_pkg_version);
+
+ free(tmp_pkg_name);
+ free(tmp_pkg_version);
+
+ if (tmp_pkg == NULL) {
+ if (global_config->no_prompt == true) {
+ unlink(file->d_name);
+ } else {
+ if (slapt_ask_yes_no(gettext("Delete %s ? [y/N]"), file->d_name) == 1)
+ unlink(file->d_name);
+ }
+ }
+ tmp_pkg = NULL;
+ }
+ }
}
+ closedir(dir);
- }
- closedir(dir);
-
- slapt_free_regex(cached_pkgs_regex);
- if (local_pkg_list == 1 ) {
- slapt_free_pkg_list(avail_pkgs);
- }
-
+ slapt_free_regex(cached_pkgs_regex);
+ if (local_pkg_list == 1) {
+ slapt_free_pkg_list(avail_pkgs);
+ }
}
void slapt_clean_pkg_dir(const char *dir_name)
{
- DIR *dir;
- struct dirent *file;
- struct stat file_stat;
- slapt_regex_t *cached_pkgs_regex = NULL;
+ DIR *dir;
+ struct dirent *file;
+ struct stat file_stat;
+ slapt_regex_t *cached_pkgs_regex = NULL;
- if ((dir = opendir(dir_name)) == NULL) {
- fprintf(stderr,gettext("Failed to opendir %s\n"),dir_name);
- return;
- }
-
- if (chdir(dir_name) == -1 ) {
- fprintf(stderr,gettext("Failed to chdir: %s\n"),dir_name);
- closedir(dir);
- return;
- }
+ if ((dir = opendir(dir_name)) == NULL) {
+ fprintf(stderr, gettext("Failed to opendir %s\n"), dir_name);
+ return;
+ }
- if ((cached_pkgs_regex = slapt_init_regex(SLAPT_PKG_PARSE_REGEX)) == NULL) {
- exit(EXIT_FAILURE);
- }
+ if (chdir(dir_name) == -1) {
+ fprintf(stderr, gettext("Failed to chdir: %s\n"), dir_name);
+ closedir(dir);
+ return;
+ }
- while ((file = readdir(dir))) {
+ if ((cached_pkgs_regex = slapt_init_regex(SLAPT_PKG_PARSE_REGEX)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- /* make sure we don't have . or .. */
- if ((strcmp(file->d_name,"..")) == 0 || (strcmp(file->d_name,".") == 0))
- continue;
+ while ((file = readdir(dir))) {
+ /* make sure we don't have . or .. */
+ if ((strcmp(file->d_name, "..")) == 0 || (strcmp(file->d_name, ".") == 0))
+ continue;
- if ((lstat(file->d_name,&file_stat)) == -1)
- continue;
+ if ((lstat(file->d_name, &file_stat)) == -1)
+ continue;
- /* if its a directory, recurse */
- if (S_ISDIR(file_stat.st_mode) ) {
- slapt_clean_pkg_dir(file->d_name);
- if ((chdir("..")) == -1) {
- fprintf(stderr,gettext("Failed to chdir: %s\n"),dir_name);
- return;
- }
- continue;
- }
- if (strstr(file->d_name,".t") !=NULL) {
- slapt_execute_regex(cached_pkgs_regex,file->d_name);
+ /* if its a directory, recurse */
+ if (S_ISDIR(file_stat.st_mode)) {
+ slapt_clean_pkg_dir(file->d_name);
+ if ((chdir("..")) == -1) {
+ fprintf(stderr, gettext("Failed to chdir: %s\n"), dir_name);
+ return;
+ }
+ continue;
+ }
+ if (strstr(file->d_name, ".t") != NULL) {
+ slapt_execute_regex(cached_pkgs_regex, file->d_name);
- /* if our regex matches */
- if (cached_pkgs_regex->reg_return == 0 ) {
- unlink(file->d_name);
- }
+ /* if our regex matches */
+ if (cached_pkgs_regex->reg_return == 0) {
+ unlink(file->d_name);
+ }
+ }
}
- }
- closedir(dir);
-
- slapt_free_regex(cached_pkgs_regex);
+ closedir(dir);
+ slapt_free_regex(cached_pkgs_regex);
}
/* find dependency from "or" requirement */
@@ -2546,1015 +2434,984 @@ static slapt_pkg_info_t *find_or_requirement(slapt_pkg_list_t *avail_pkgs,
slapt_pkg_list_t *installed_pkgs,
char *required_str)
{
- slapt_pkg_info_t *pkg = NULL;
- unsigned int i = 0;
- slapt_list_t *alternates = slapt_parse_delimited_list(required_str,'|');
-
- for (i = 0; i < alternates->count; i++) {
- slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,alternates->items[i]);
-
- if (tmp_pkg != NULL) {
- /* installed packages are preferred */
- if (slapt_get_exact_pkg(installed_pkgs,tmp_pkg->name, tmp_pkg->version) != NULL) {
- pkg = tmp_pkg;
- break;
- } else {
- /* otherwise remember the first package found and continue on */
- if (pkg == NULL) {
- pkg = tmp_pkg;
+ slapt_pkg_info_t *pkg = NULL;
+ unsigned int i = 0;
+ slapt_list_t *alternates = slapt_parse_delimited_list(required_str, '|');
+
+ for (i = 0; i < alternates->count; i++) {
+ slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, alternates->items[i]);
+
+ if (tmp_pkg != NULL) {
+ /* installed packages are preferred */
+ if (slapt_get_exact_pkg(installed_pkgs, tmp_pkg->name, tmp_pkg->version) != NULL) {
+ pkg = tmp_pkg;
+ break;
+ } else {
+ /* otherwise remember the first package found and continue on */
+ if (pkg == NULL) {
+ pkg = tmp_pkg;
+ }
+ }
}
- }
}
- }
-
- slapt_free_list(alternates);
- return pkg;
+ slapt_free_list(alternates);
+ return pkg;
}
-slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst,slapt_pkg_info_t *src)
+slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst, slapt_pkg_info_t *src)
{
- dst = memcpy(dst,src, sizeof *src);
+ dst = memcpy(dst, src, sizeof *src);
- if (src->name != NULL)
- dst->name = strndup(src->name,strlen(src->name));
+ if (src->name != NULL)
+ dst->name = strndup(src->name, strlen(src->name));
- if (src->version != NULL)
- dst->version = strndup(src->version,strlen(src->version));
+ if (src->version != NULL)
+ dst->version = strndup(src->version, strlen(src->version));
- if (src->file_ext != NULL)
- dst->file_ext = strndup(src->file_ext,strlen(src->file_ext));
+ if (src->file_ext != NULL)
+ dst->file_ext = strndup(src->file_ext, strlen(src->file_ext));
- if (src->mirror != NULL)
- dst->mirror = strndup(src->mirror,strlen(src->mirror));
+ if (src->mirror != NULL)
+ dst->mirror = strndup(src->mirror, strlen(src->mirror));
- if (src->location != NULL)
- dst->location = strndup(src->location,strlen(src->location));
+ if (src->location != NULL)
+ dst->location = strndup(src->location, strlen(src->location));
- if (src->description != NULL)
- dst->description = strndup(src->description,strlen(src->description));
+ if (src->description != NULL)
+ dst->description = strndup(src->description, strlen(src->description));
- if (src->suggests != NULL)
- dst->suggests = strndup(src->suggests, strlen(src->suggests));
+ if (src->suggests != NULL)
+ dst->suggests = strndup(src->suggests, strlen(src->suggests));
- if (src->conflicts != NULL)
- dst->conflicts = strndup(src->conflicts, strlen(src->conflicts));
+ if (src->conflicts != NULL)
+ dst->conflicts = strndup(src->conflicts, strlen(src->conflicts));
- if (src->required != NULL)
- dst->required = strndup(src->required, strlen(src->required));
+ if (src->required != NULL)
+ dst->required = strndup(src->required, strlen(src->required));
- return dst;
+ return dst;
}
slapt_pkg_err_list_t *slapt_init_pkg_err_list(void)
{
- slapt_pkg_err_list_t *l = slapt_malloc(sizeof *l);
- l->errs = slapt_malloc(sizeof *l->errs);
- l->err_count = 0;
+ slapt_pkg_err_list_t *l = slapt_malloc(sizeof *l);
+ l->errs = slapt_malloc(sizeof *l->errs);
+ l->err_count = 0;
- return l;
+ return l;
}
void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,
- const char *pkg,const char *err)
+ const char *pkg, const char *err)
{
- slapt_pkg_err_t **tmp;
-
- if (slapt_search_pkg_err_list(l,pkg,err) == 1)
- return;
+ slapt_pkg_err_t **tmp;
- tmp = realloc(l->errs, sizeof *l->errs * (l->err_count + 1) );
- if (tmp == NULL)
- return;
+ if (slapt_search_pkg_err_list(l, pkg, err) == 1)
+ return;
- l->errs = tmp;
+ tmp = realloc(l->errs, sizeof *l->errs * (l->err_count + 1));
+ if (tmp == NULL)
+ return;
- l->errs[l->err_count] = slapt_malloc(sizeof *l->errs[l->err_count]);
- l->errs[l->err_count]->pkg = strdup(pkg);
- l->errs[l->err_count]->error = strdup(err);
+ l->errs = tmp;
- ++l->err_count;
+ l->errs[l->err_count] = slapt_malloc(sizeof *l->errs[l->err_count]);
+ l->errs[l->err_count]->pkg = strdup(pkg);
+ l->errs[l->err_count]->error = strdup(err);
+ ++l->err_count;
}
int slapt_search_pkg_err_list(slapt_pkg_err_list_t *l,
- const char *pkg, const char *err)
+ const char *pkg, const char *err)
{
- unsigned int i,found = 1, not_found = 0;
- for (i = 0; i < l->err_count; ++i) {
- if (strcmp(l->errs[i]->pkg,pkg) == 0 &&
- strcmp(l->errs[i]->error,err) == 0
- ) {
- return found;
+ unsigned int i, found = 1, not_found = 0;
+ for (i = 0; i < l->err_count; ++i) {
+ if (strcmp(l->errs[i]->pkg, pkg) == 0 &&
+ strcmp(l->errs[i]->error, err) == 0) {
+ return found;
+ }
}
- }
- return not_found;
+ return not_found;
}
void slapt_free_pkg_err_list(slapt_pkg_err_list_t *l)
{
- unsigned int i;
+ unsigned int i;
- for (i = 0; i < l->err_count; ++i) {
- free(l->errs[i]->pkg);
- free(l->errs[i]->error);
- free(l->errs[i]);
- }
- free(l->errs);
- free(l);
+ for (i = 0; i < l->err_count; ++i) {
+ free(l->errs[i]->pkg);
+ free(l->errs[i]->error);
+ free(l->errs[i]);
+ }
+ free(l->errs);
+ free(l);
}
/* FIXME this sucks... it needs to check file headers and more */
-static FILE *slapt_gunzip_file (const char *file_name,FILE *dest_file)
+static FILE *slapt_gunzip_file(const char *file_name, FILE *dest_file)
{
- gzFile data = NULL;
- char buffer[SLAPT_MAX_ZLIB_BUFFER];
+ gzFile data = NULL;
+ char buffer[SLAPT_MAX_ZLIB_BUFFER];
- if (dest_file == NULL)
- if ((dest_file = tmpfile()) == NULL)
- exit(EXIT_FAILURE);
+ if (dest_file == NULL)
+ if ((dest_file = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- if ((data = gzopen(file_name,"rb")) == NULL)
- exit(EXIT_FAILURE);
+ if ((data = gzopen(file_name, "rb")) == NULL)
+ exit(EXIT_FAILURE);
- while (gzgets(data,buffer,SLAPT_MAX_ZLIB_BUFFER) != Z_NULL) {
- fprintf(dest_file,"%s",buffer);
- }
- gzclose(data);
- rewind(dest_file);
+ while (gzgets(data, buffer, SLAPT_MAX_ZLIB_BUFFER) != Z_NULL) {
+ fprintf(dest_file, "%s", buffer);
+ }
+ gzclose(data);
+ rewind(dest_file);
- return dest_file;
+ return dest_file;
}
-slapt_pkg_list_t *slapt_get_pkg_source_packages (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed)
+slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed)
{
- slapt_pkg_list_t *available_pkgs = NULL;
- char *pkg_head = NULL;
- bool is_interactive = slapt_is_interactive(global_config);
+ slapt_pkg_list_t *available_pkgs = NULL;
+ char *pkg_head = NULL;
+ bool is_interactive = slapt_is_interactive(global_config);
- *compressed = 0;
+ *compressed = 0;
- /* try gzipped package list */
- if ((pkg_head = slapt_head_mirror_data(url,SLAPT_PKG_LIST_GZ)) != NULL) {
- char *pkg_filename = slapt_gen_filename_from_url(url,SLAPT_PKG_LIST_GZ);
- char *pkg_local_head = slapt_read_head_cache(pkg_filename);
+ /* try gzipped package list */
+ if ((pkg_head = slapt_head_mirror_data(url, SLAPT_PKG_LIST_GZ)) != NULL) {
+ char *pkg_filename = slapt_gen_filename_from_url(url, SLAPT_PKG_LIST_GZ);
+ char *pkg_local_head = slapt_read_head_cache(pkg_filename);
- /* is it cached ? */
- if (pkg_local_head != NULL && strcmp(pkg_head,pkg_local_head) == 0) {
- FILE *tmp_pkg_f = NULL;
+ /* is it cached ? */
+ if (pkg_local_head != NULL && strcmp(pkg_head, pkg_local_head) == 0) {
+ FILE *tmp_pkg_f = NULL;
- if ((tmp_pkg_f = tmpfile()) == NULL)
- exit(EXIT_FAILURE);
+ if ((tmp_pkg_f = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- slapt_gunzip_file(pkg_filename,tmp_pkg_f);
+ slapt_gunzip_file(pkg_filename, tmp_pkg_f);
- available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
- fclose(tmp_pkg_f);
+ available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
+ fclose(tmp_pkg_f);
- if (available_pkgs == NULL || available_pkgs->pkg_count < 1 ) {
- slapt_clear_head_cache(pkg_filename);
- fprintf(stderr,gettext("Failed to parse package data from %s\n"),
- pkg_filename
- );
+ if (available_pkgs == NULL || available_pkgs->pkg_count < 1) {
+ slapt_clear_head_cache(pkg_filename);
+ fprintf(stderr, gettext("Failed to parse package data from %s\n"),
+ pkg_filename);
- if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ if (available_pkgs)
+ slapt_free_pkg_list(available_pkgs);
- free(pkg_filename);
- free(pkg_local_head);
- return NULL;
- }
+ free(pkg_filename);
+ free(pkg_local_head);
+ return NULL;
+ }
- if (is_interactive)
- printf(gettext("Cached\n"));
+ if (is_interactive)
+ printf(gettext("Cached\n"));
- } else {
- FILE *tmp_pkg_f = NULL;
- const char *err = NULL;
+ } else {
+ FILE *tmp_pkg_f = NULL;
+ const char *err = NULL;
- if (global_config->dl_stats == true)
- printf("\n");
+ if (global_config->dl_stats == true)
+ printf("\n");
- if ((tmp_pkg_f = slapt_open_file(pkg_filename,"w+b")) == NULL)
- exit(EXIT_FAILURE);
+ if ((tmp_pkg_f = slapt_open_file(pkg_filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
- /* retrieve the compressed package data */
- err = slapt_get_mirror_data_from_source(tmp_pkg_f,
- global_config,url,
- SLAPT_PKG_LIST_GZ);
- if (!err) {
- FILE *tmp_pkg_uncompressed_f = NULL;
+ /* retrieve the compressed package data */
+ err = slapt_get_mirror_data_from_source(tmp_pkg_f,
+ global_config, url,
+ SLAPT_PKG_LIST_GZ);
+ if (!err) {
+ FILE *tmp_pkg_uncompressed_f = NULL;
- fclose(tmp_pkg_f);
+ fclose(tmp_pkg_f);
- if ((tmp_pkg_uncompressed_f = tmpfile()) == NULL)
- exit(EXIT_FAILURE);
+ if ((tmp_pkg_uncompressed_f = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- slapt_gunzip_file(pkg_filename,tmp_pkg_uncompressed_f);
+ slapt_gunzip_file(pkg_filename, tmp_pkg_uncompressed_f);
- /* parse packages from what we downloaded */
- available_pkgs = slapt_parse_packages_txt(tmp_pkg_uncompressed_f);
+ /* parse packages from what we downloaded */
+ available_pkgs = slapt_parse_packages_txt(tmp_pkg_uncompressed_f);
- fclose(tmp_pkg_uncompressed_f);
+ fclose(tmp_pkg_uncompressed_f);
- /* if we can't parse any packages out of this */
- if (available_pkgs == NULL || available_pkgs->pkg_count < 1 ) {
- slapt_clear_head_cache(pkg_filename);
+ /* if we can't parse any packages out of this */
+ if (available_pkgs == NULL || available_pkgs->pkg_count < 1) {
+ slapt_clear_head_cache(pkg_filename);
- fprintf(stderr,gettext("Failed to parse package data from %s\n"),url);
+ fprintf(stderr, gettext("Failed to parse package data from %s\n"), url);
- if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ if (available_pkgs)
+ slapt_free_pkg_list(available_pkgs);
- free(pkg_filename);
- free(pkg_local_head);
- return NULL;
- }
+ free(pkg_filename);
+ free(pkg_local_head);
+ return NULL;
+ }
- /* commit the head data for later comparisons */
- if (pkg_head != NULL)
- slapt_write_head_cache(pkg_head,pkg_filename);
+ /* commit the head data for later comparisons */
+ if (pkg_head != NULL)
+ slapt_write_head_cache(pkg_head, pkg_filename);
- if (is_interactive)
- printf(gettext("Done\n"));
+ if (is_interactive)
+ printf(gettext("Done\n"));
+
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ fclose(tmp_pkg_f);
+ slapt_clear_head_cache(pkg_filename);
+ free(pkg_filename);
+ free(pkg_local_head);
+ return NULL;
+ }
+ }
- } else {
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- fclose(tmp_pkg_f);
- slapt_clear_head_cache(pkg_filename);
free(pkg_filename);
free(pkg_local_head);
- return NULL;
- }
+ *compressed = 1;
- }
-
- free(pkg_filename);
- free(pkg_local_head);
- *compressed = 1;
-
- } else { /* fall back to uncompressed package list */
- char *pkg_filename = slapt_gen_filename_from_url(url,SLAPT_PKG_LIST);
- char *pkg_local_head = slapt_read_head_cache(pkg_filename);
- /*
+ } else { /* fall back to uncompressed package list */
+ char *pkg_filename = slapt_gen_filename_from_url(url, SLAPT_PKG_LIST);
+ char *pkg_local_head = slapt_read_head_cache(pkg_filename);
+ /*
we go ahead and run the head request, not caring if it failed.
If the subsequent download fails as well, it will give a nice
error message of why.
*/
- pkg_head = slapt_head_mirror_data(url,SLAPT_PKG_LIST);
+ pkg_head = slapt_head_mirror_data(url, SLAPT_PKG_LIST);
- /* is it cached ? */
- if (pkg_head != NULL && pkg_local_head != NULL &&
- strcmp(pkg_head,pkg_local_head) == 0) {
- FILE *tmp_pkg_f = NULL;
- if ((tmp_pkg_f = slapt_open_file(pkg_filename,"r")) == NULL)
- exit(EXIT_FAILURE);
+ /* is it cached ? */
+ if (pkg_head != NULL && pkg_local_head != NULL &&
+ strcmp(pkg_head, pkg_local_head) == 0) {
+ FILE *tmp_pkg_f = NULL;
+ if ((tmp_pkg_f = slapt_open_file(pkg_filename, "r")) == NULL)
+ exit(EXIT_FAILURE);
- available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
- fclose(tmp_pkg_f);
+ available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
+ fclose(tmp_pkg_f);
- if (is_interactive)
- printf(gettext("Cached\n"));
+ if (is_interactive)
+ printf(gettext("Cached\n"));
- } else {
- FILE *tmp_pkg_f = NULL;
- const char *err = NULL;
+ } else {
+ FILE *tmp_pkg_f = NULL;
+ const char *err = NULL;
- if (global_config->dl_stats == true)
- printf("\n");
+ if (global_config->dl_stats == true)
+ printf("\n");
- if ((tmp_pkg_f = slapt_open_file(pkg_filename,"w+b")) == NULL)
- exit(EXIT_FAILURE);
+ if ((tmp_pkg_f = slapt_open_file(pkg_filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
- /* retrieve the uncompressed package data */
- err = slapt_get_mirror_data_from_source(tmp_pkg_f,
- global_config,url,
- SLAPT_PKG_LIST);
- if (!err) {
- rewind(tmp_pkg_f); /* make sure we are back at the front of the file */
+ /* retrieve the uncompressed package data */
+ err = slapt_get_mirror_data_from_source(tmp_pkg_f,
+ global_config, url,
+ SLAPT_PKG_LIST);
+ if (!err) {
+ rewind(tmp_pkg_f); /* make sure we are back at the front of the file */
- /* parse packages from what we downloaded */
- available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
+ /* parse packages from what we downloaded */
+ available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
- /* if we can't parse any packages out of this */
- if (available_pkgs == NULL || available_pkgs->pkg_count < 1 ) {
- slapt_clear_head_cache(pkg_filename);
+ /* if we can't parse any packages out of this */
+ if (available_pkgs == NULL || available_pkgs->pkg_count < 1) {
+ slapt_clear_head_cache(pkg_filename);
- fprintf(stderr,gettext("Failed to parse package data from %s\n"),url);
+ fprintf(stderr, gettext("Failed to parse package data from %s\n"), url);
- if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ if (available_pkgs)
+ slapt_free_pkg_list(available_pkgs);
- fclose(tmp_pkg_f);
- free(pkg_filename);
- free(pkg_local_head);
- slapt_clear_head_cache(pkg_filename);
- return NULL;
- }
+ fclose(tmp_pkg_f);
+ free(pkg_filename);
+ free(pkg_local_head);
+ slapt_clear_head_cache(pkg_filename);
+ return NULL;
+ }
- /* commit the head data for later comparisons */
- if (pkg_head != NULL)
- slapt_write_head_cache(pkg_head,pkg_filename);
+ /* commit the head data for later comparisons */
+ if (pkg_head != NULL)
+ slapt_write_head_cache(pkg_head, pkg_filename);
- if (is_interactive)
- printf(gettext("Done\n"));
+ if (is_interactive)
+ printf(gettext("Done\n"));
+
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ slapt_clear_head_cache(pkg_filename);
+ free(pkg_filename);
+ free(pkg_local_head);
+ fclose(tmp_pkg_f);
+ return NULL;
+ }
+
+ fclose(tmp_pkg_f);
+ }
- } else {
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- slapt_clear_head_cache(pkg_filename);
free(pkg_filename);
free(pkg_local_head);
- fclose(tmp_pkg_f);
- return NULL;
- }
-
- fclose(tmp_pkg_f);
}
+ if (pkg_head != NULL)
+ free(pkg_head);
- free(pkg_filename);
- free(pkg_local_head);
-
- }
- if (pkg_head != NULL)
- free(pkg_head);
-
- return available_pkgs;
+ return available_pkgs;
}
-slapt_pkg_list_t *slapt_get_pkg_source_patches (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed)
+slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed)
{
- slapt_pkg_list_t *patch_pkgs = NULL;
- char *patch_head = NULL;
- bool is_interactive = slapt_is_interactive(global_config);
- *compressed = 0;
+ slapt_pkg_list_t *patch_pkgs = NULL;
+ char *patch_head = NULL;
+ bool is_interactive = slapt_is_interactive(global_config);
+ *compressed = 0;
- if ((patch_head = slapt_head_mirror_data(url,SLAPT_PATCHES_LIST_GZ)) != NULL) {
- char *patch_filename = slapt_gen_filename_from_url(url,SLAPT_PATCHES_LIST_GZ);
- char *patch_local_head = slapt_read_head_cache(patch_filename);
+ if ((patch_head = slapt_head_mirror_data(url, SLAPT_PATCHES_LIST_GZ)) != NULL) {
+ char *patch_filename = slapt_gen_filename_from_url(url, SLAPT_PATCHES_LIST_GZ);
+ char *patch_local_head = slapt_read_head_cache(patch_filename);
- if (patch_local_head != NULL && strcmp(patch_head,patch_local_head) == 0) {
- FILE *tmp_patch_f = NULL;
+ if (patch_local_head != NULL && strcmp(patch_head, patch_local_head) == 0) {
+ FILE *tmp_patch_f = NULL;
- if ((tmp_patch_f = tmpfile()) == NULL)
- exit(EXIT_FAILURE);
+ if ((tmp_patch_f = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- slapt_gunzip_file(patch_filename,tmp_patch_f);
+ slapt_gunzip_file(patch_filename, tmp_patch_f);
- patch_pkgs = slapt_parse_packages_txt(tmp_patch_f);
- fclose(tmp_patch_f);
+ patch_pkgs = slapt_parse_packages_txt(tmp_patch_f);
+ fclose(tmp_patch_f);
- if (is_interactive)
- printf(gettext("Cached\n"));
+ if (is_interactive)
+ printf(gettext("Cached\n"));
- } else {
- FILE *tmp_patch_f = NULL;
- const char *err = NULL;
+ } else {
+ FILE *tmp_patch_f = NULL;
+ const char *err = NULL;
- if (global_config->dl_stats == true)
- printf("\n");
+ if (global_config->dl_stats == true)
+ printf("\n");
- if ((tmp_patch_f = slapt_open_file(patch_filename,"w+b")) == NULL)
- exit (1);
+ if ((tmp_patch_f = slapt_open_file(patch_filename, "w+b")) == NULL)
+ exit(1);
- err = slapt_get_mirror_data_from_source(tmp_patch_f,
- global_config,url,
- SLAPT_PATCHES_LIST_GZ);
- if (!err) {
- FILE *tmp_patch_uncompressed_f = NULL;
+ err = slapt_get_mirror_data_from_source(tmp_patch_f,
+ global_config, url,
+ SLAPT_PATCHES_LIST_GZ);
+ if (!err) {
+ FILE *tmp_patch_uncompressed_f = NULL;
- fclose(tmp_patch_f);
+ fclose(tmp_patch_f);
- if ((tmp_patch_uncompressed_f = tmpfile()) == NULL)
- exit(EXIT_FAILURE);
+ if ((tmp_patch_uncompressed_f = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- slapt_gunzip_file(patch_filename,tmp_patch_uncompressed_f);
+ slapt_gunzip_file(patch_filename, tmp_patch_uncompressed_f);
- patch_pkgs = slapt_parse_packages_txt(tmp_patch_uncompressed_f);
+ patch_pkgs = slapt_parse_packages_txt(tmp_patch_uncompressed_f);
- if (is_interactive)
- printf(gettext("Done\n"));
+ if (is_interactive)
+ printf(gettext("Done\n"));
- if (patch_head != NULL)
- slapt_write_head_cache(patch_head,patch_filename);
+ if (patch_head != NULL)
+ slapt_write_head_cache(patch_head, patch_filename);
- fclose(tmp_patch_uncompressed_f);
- } else {
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- fclose(tmp_patch_f);
- /* we don't care if the patch fails, for example current
+ fclose(tmp_patch_uncompressed_f);
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ fclose(tmp_patch_f);
+ /* we don't care if the patch fails, for example current
doesn't have patches source_dl_failed = 1; */
- slapt_clear_head_cache(patch_filename);
- }
-
- if (global_config->dl_stats == true)
- printf("\n");
+ slapt_clear_head_cache(patch_filename);
+ }
- }
+ if (global_config->dl_stats == true)
+ printf("\n");
+ }
- free(patch_local_head);
- free(patch_filename);
- *compressed = 1;
+ free(patch_local_head);
+ free(patch_filename);
+ *compressed = 1;
- } else {
- char *patch_filename = slapt_gen_filename_from_url(url,SLAPT_PATCHES_LIST);
- char *patch_local_head = slapt_read_head_cache(patch_filename);
- /*
+ } else {
+ char *patch_filename = slapt_gen_filename_from_url(url, SLAPT_PATCHES_LIST);
+ char *patch_local_head = slapt_read_head_cache(patch_filename);
+ /*
we go ahead and run the head request, not caring if it failed.
If the subsequent download fails as well, it will give a nice
error message of why.
*/
- patch_head = slapt_head_mirror_data(url,SLAPT_PATCHES_LIST);
+ patch_head = slapt_head_mirror_data(url, SLAPT_PATCHES_LIST);
- if (patch_head != NULL && patch_local_head != NULL &&
- strcmp(patch_head,patch_local_head) == 0) {
- FILE *tmp_patch_f = NULL;
+ if (patch_head != NULL && patch_local_head != NULL &&
+ strcmp(patch_head, patch_local_head) == 0) {
+ FILE *tmp_patch_f = NULL;
- if ((tmp_patch_f = slapt_open_file(patch_filename,"r")) == NULL)
- exit(EXIT_FAILURE);
+ if ((tmp_patch_f = slapt_open_file(patch_filename, "r")) == NULL)
+ exit(EXIT_FAILURE);
- patch_pkgs = slapt_parse_packages_txt(tmp_patch_f);
+ patch_pkgs = slapt_parse_packages_txt(tmp_patch_f);
- if (is_interactive)
- printf(gettext("Cached\n"));
+ if (is_interactive)
+ printf(gettext("Cached\n"));
- fclose(tmp_patch_f);
- } else {
- FILE *tmp_patch_f = NULL;
- const char *err = NULL;
+ fclose(tmp_patch_f);
+ } else {
+ FILE *tmp_patch_f = NULL;
+ const char *err = NULL;
- if (global_config->dl_stats == true)
- printf("\n");
+ if (global_config->dl_stats == true)
+ printf("\n");
- if ((tmp_patch_f = slapt_open_file(patch_filename,"w+b")) == NULL)
- exit (1);
+ if ((tmp_patch_f = slapt_open_file(patch_filename, "w+b")) == NULL)
+ exit(1);
- err = slapt_get_mirror_data_from_source(tmp_patch_f,
- global_config,url,
- SLAPT_PATCHES_LIST);
- if (!err) {
- rewind(tmp_patch_f); /* make sure we are back at the front of the file */
- patch_pkgs = slapt_parse_packages_txt(tmp_patch_f);
+ err = slapt_get_mirror_data_from_source(tmp_patch_f,
+ global_config, url,
+ SLAPT_PATCHES_LIST);
+ if (!err) {
+ rewind(tmp_patch_f); /* make sure we are back at the front of the file */
+ patch_pkgs = slapt_parse_packages_txt(tmp_patch_f);
- if (is_interactive)
- printf(gettext("Done\n"));
+ if (is_interactive)
+ printf(gettext("Done\n"));
- if (patch_head != NULL)
- slapt_write_head_cache(patch_head,patch_filename);
+ if (patch_head != NULL)
+ slapt_write_head_cache(patch_head, patch_filename);
- } else {
- /* we don't care if the patch fails, for example current
+ } else {
+ /* we don't care if the patch fails, for example current
doesn't have patches source_dl_failed = 1; */
- slapt_clear_head_cache(patch_filename);
+ slapt_clear_head_cache(patch_filename);
- if (is_interactive)
- printf(gettext("Done\n"));
+ if (is_interactive)
+ printf(gettext("Done\n"));
+ }
- }
+ if (global_config->dl_stats == true)
+ printf("\n");
- if (global_config->dl_stats == true)
- printf("\n");
+ fclose(tmp_patch_f);
+ }
- fclose(tmp_patch_f);
+ free(patch_local_head);
+ free(patch_filename);
}
+ if (patch_head != NULL)
+ free(patch_head);
- free(patch_local_head);
- free(patch_filename);
- }
- if (patch_head != NULL)
- free(patch_head);
-
- return patch_pkgs;
+ return patch_pkgs;
}
-FILE *slapt_get_pkg_source_checksums (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed)
+FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed)
{
- FILE *tmp_checksum_f = NULL;
- char *checksum_head = NULL;
- bool is_interactive = slapt_is_interactive(global_config);
- *compressed = 0;
+ FILE *tmp_checksum_f = NULL;
+ char *checksum_head = NULL;
+ bool is_interactive = slapt_is_interactive(global_config);
+ *compressed = 0;
- if ((checksum_head = slapt_head_mirror_data(url,SLAPT_CHECKSUM_FILE_GZ)) != NULL) {
- char *filename = slapt_gen_filename_from_url(url,SLAPT_CHECKSUM_FILE_GZ);
- char *local_head = slapt_read_head_cache(filename);
+ if ((checksum_head = slapt_head_mirror_data(url, SLAPT_CHECKSUM_FILE_GZ)) != NULL) {
+ char *filename = slapt_gen_filename_from_url(url, SLAPT_CHECKSUM_FILE_GZ);
+ char *local_head = slapt_read_head_cache(filename);
- if (local_head != NULL && strcmp(checksum_head,local_head) == 0) {
+ if (local_head != NULL && strcmp(checksum_head, local_head) == 0) {
+ if ((tmp_checksum_f = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- if ((tmp_checksum_f = tmpfile()) == NULL)
- exit(EXIT_FAILURE);
+ slapt_gunzip_file(filename, tmp_checksum_f);
- slapt_gunzip_file(filename,tmp_checksum_f);
+ if (is_interactive)
+ printf(gettext("Cached\n"));
- if (is_interactive)
- printf(gettext("Cached\n"));
+ } else {
+ FILE *working_checksum_f = NULL;
+ const char *err = NULL;
- } else {
- FILE *working_checksum_f = NULL;
- const char *err = NULL;
+ if (global_config->dl_stats == true)
+ printf("\n");
- if (global_config->dl_stats == true)
- printf("\n");
+ if ((working_checksum_f = slapt_open_file(filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
- if ((working_checksum_f = slapt_open_file(filename,"w+b")) == NULL)
- exit(EXIT_FAILURE);
+ err = slapt_get_mirror_data_from_source(working_checksum_f,
+ global_config, url,
+ SLAPT_CHECKSUM_FILE_GZ);
+ if (!err) {
+ if (global_config->dl_stats == true)
+ printf("\n");
+ if (is_interactive)
+ printf(gettext("Done\n"));
- err = slapt_get_mirror_data_from_source(working_checksum_f,
- global_config,url,
- SLAPT_CHECKSUM_FILE_GZ);
- if (!err) {
+ fclose(working_checksum_f);
- if (global_config->dl_stats == true)
- printf("\n");
- if (is_interactive)
- printf(gettext("Done\n"));
+ if ((tmp_checksum_f = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- fclose(working_checksum_f);
+ slapt_gunzip_file(filename, tmp_checksum_f);
- if ((tmp_checksum_f = tmpfile()) == NULL)
- exit(EXIT_FAILURE);
+ /* if all is good, write it */
+ if (checksum_head != NULL)
+ slapt_write_head_cache(checksum_head, filename);
- slapt_gunzip_file(filename,tmp_checksum_f);
-
- /* if all is good, write it */
- if (checksum_head != NULL)
- slapt_write_head_cache(checksum_head,filename);
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ slapt_clear_head_cache(filename);
+ tmp_checksum_f = working_checksum_f;
+ working_checksum_f = NULL;
+ free(filename);
+ free(local_head);
+ fclose(tmp_checksum_f);
+ if (checksum_head != NULL)
+ free(checksum_head);
+ return NULL;
+ }
+ /* make sure we are back at the front of the file */
+ rewind(tmp_checksum_f);
+ }
- } else {
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- slapt_clear_head_cache(filename);
- tmp_checksum_f = working_checksum_f;
- working_checksum_f = NULL;
free(filename);
free(local_head);
- fclose(tmp_checksum_f);
- if (checksum_head != NULL)
- free(checksum_head);
- return NULL;
- }
- /* make sure we are back at the front of the file */
- rewind(tmp_checksum_f);
-
- }
+ *compressed = 1;
- free(filename);
- free(local_head);
- *compressed = 1;
-
- } else {
- char *filename = slapt_gen_filename_from_url(url,SLAPT_CHECKSUM_FILE);
- char *local_head = slapt_read_head_cache(filename);
- /*
+ } else {
+ char *filename = slapt_gen_filename_from_url(url, SLAPT_CHECKSUM_FILE);
+ char *local_head = slapt_read_head_cache(filename);
+ /*
we go ahead and run the head request, not caring if it failed.
If the subsequent download fails as well, it will give a nice
error message of why.
*/
- checksum_head = slapt_head_mirror_data(url,SLAPT_CHECKSUM_FILE);
+ checksum_head = slapt_head_mirror_data(url, SLAPT_CHECKSUM_FILE);
- if (checksum_head != NULL && local_head != NULL &&
- strcmp(checksum_head,local_head) == 0) {
- if ((tmp_checksum_f = slapt_open_file(filename,"r")) == NULL)
- exit(EXIT_FAILURE);
-
- if (is_interactive)
- printf(gettext("Cached\n"));
+ if (checksum_head != NULL && local_head != NULL &&
+ strcmp(checksum_head, local_head) == 0) {
+ if ((tmp_checksum_f = slapt_open_file(filename, "r")) == NULL)
+ exit(EXIT_FAILURE);
- } else {
- const char *err = NULL;
+ if (is_interactive)
+ printf(gettext("Cached\n"));
- if ((tmp_checksum_f = slapt_open_file(filename,"w+b")) == NULL)
- exit(EXIT_FAILURE);
+ } else {
+ const char *err = NULL;
- if (global_config->dl_stats == true)
- printf("\n");
+ if ((tmp_checksum_f = slapt_open_file(filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
- err = slapt_get_mirror_data_from_source(tmp_checksum_f,
- global_config,url,
- SLAPT_CHECKSUM_FILE);
- if (!err) {
+ if (global_config->dl_stats == true)
+ printf("\n");
- if (is_interactive)
- printf(gettext("Done\n"));
+ err = slapt_get_mirror_data_from_source(tmp_checksum_f,
+ global_config, url,
+ SLAPT_CHECKSUM_FILE);
+ if (!err) {
+ if (is_interactive)
+ printf(gettext("Done\n"));
- } else {
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- slapt_clear_head_cache(filename);
- fclose(tmp_checksum_f);
- free(filename);
- free(local_head);
- if (checksum_head != NULL)
- free(checksum_head);
- return NULL;
- }
- /* make sure we are back at the front of the file */
- rewind(tmp_checksum_f);
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ slapt_clear_head_cache(filename);
+ fclose(tmp_checksum_f);
+ free(filename);
+ free(local_head);
+ if (checksum_head != NULL)
+ free(checksum_head);
+ return NULL;
+ }
+ /* make sure we are back at the front of the file */
+ rewind(tmp_checksum_f);
- /* if all is good, write it */
- if (checksum_head != NULL)
- slapt_write_head_cache(checksum_head,filename);
+ /* if all is good, write it */
+ if (checksum_head != NULL)
+ slapt_write_head_cache(checksum_head, filename);
- if (global_config->dl_stats == true)
- printf("\n");
+ if (global_config->dl_stats == true)
+ printf("\n");
+ }
+ free(filename);
+ free(local_head);
}
+ if (checksum_head != NULL)
+ free(checksum_head);
- free(filename);
- free(local_head);
- }
- if (checksum_head != NULL)
- free(checksum_head);
-
- return tmp_checksum_f;
+ return tmp_checksum_f;
}
-int slapt_get_pkg_source_changelog (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed)
+int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed)
{
- char *changelog_head = NULL;
- char *filename = NULL;
- char *local_head = NULL;
- char *location_gz = SLAPT_CHANGELOG_FILE_GZ;
- char *location_uncomp = SLAPT_CHANGELOG_FILE;
- char *location = location_gz;
- int success = 0,failure = -1;
- bool is_interactive = slapt_is_interactive(global_config);
- *compressed = 0;
-
- changelog_head = slapt_head_mirror_data(url,location);
-
- if (changelog_head == NULL) {
- location = location_uncomp;
- changelog_head = slapt_head_mirror_data(url,location);
- } else {
- *compressed = 1;
- }
+ char *changelog_head = NULL;
+ char *filename = NULL;
+ char *local_head = NULL;
+ char *location_gz = SLAPT_CHANGELOG_FILE_GZ;
+ char *location_uncomp = SLAPT_CHANGELOG_FILE;
+ char *location = location_gz;
+ int success = 0, failure = -1;
+ bool is_interactive = slapt_is_interactive(global_config);
+ *compressed = 0;
+
+ changelog_head = slapt_head_mirror_data(url, location);
+
+ if (changelog_head == NULL) {
+ location = location_uncomp;
+ changelog_head = slapt_head_mirror_data(url, location);
+ } else {
+ *compressed = 1;
+ }
- if (changelog_head == NULL) {
- if (is_interactive)
- printf(gettext("Done\n"));
- return success;
- }
+ if (changelog_head == NULL) {
+ if (is_interactive)
+ printf(gettext("Done\n"));
+ return success;
+ }
- filename = slapt_gen_filename_from_url(url,location);
- local_head = slapt_read_head_cache(filename);
+ filename = slapt_gen_filename_from_url(url, location);
+ local_head = slapt_read_head_cache(filename);
- if (local_head != NULL && strcmp(changelog_head,local_head) == 0) {
+ if (local_head != NULL && strcmp(changelog_head, local_head) == 0) {
+ if (is_interactive)
+ printf(gettext("Cached\n"));
- if (is_interactive)
- printf(gettext("Cached\n"));
-
- } else {
- FILE *working_changelog_f = NULL;
- const char *err = NULL;
+ } else {
+ FILE *working_changelog_f = NULL;
+ const char *err = NULL;
- if (global_config->dl_stats == true)
- printf("\n");
+ if (global_config->dl_stats == true)
+ printf("\n");
- if ((working_changelog_f = slapt_open_file(filename,"w+b")) == NULL)
- exit(EXIT_FAILURE);
+ if ((working_changelog_f = slapt_open_file(filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
- err = slapt_get_mirror_data_from_source(working_changelog_f,
- global_config,url,
- location);
- if (!err) {
- if (global_config->dl_stats == true)
- printf("\n");
- if (is_interactive)
- printf(gettext("Done\n"));
+ err = slapt_get_mirror_data_from_source(working_changelog_f,
+ global_config, url,
+ location);
+ if (!err) {
+ if (global_config->dl_stats == true)
+ printf("\n");
+ if (is_interactive)
+ printf(gettext("Done\n"));
- /* if all is good, write it */
- if (changelog_head != NULL)
- slapt_write_head_cache(changelog_head,filename);
+ /* if all is good, write it */
+ if (changelog_head != NULL)
+ slapt_write_head_cache(changelog_head, filename);
- fclose(working_changelog_f);
+ fclose(working_changelog_f);
- if (strcmp(location,location_gz) == 0) {
- char *uncomp_filename = slapt_gen_filename_from_url(url, location_uncomp);
- FILE *uncomp_f = slapt_open_file(uncomp_filename,"w+b");
- free(uncomp_filename);
+ if (strcmp(location, location_gz) == 0) {
+ char *uncomp_filename = slapt_gen_filename_from_url(url, location_uncomp);
+ FILE *uncomp_f = slapt_open_file(uncomp_filename, "w+b");
+ free(uncomp_filename);
- slapt_gunzip_file(filename,uncomp_f);
- fclose(uncomp_f);
- }
+ slapt_gunzip_file(filename, uncomp_f);
+ fclose(uncomp_f);
+ }
- } else {
- fprintf(stderr,gettext("Failed to download: %s\n"),err);
- slapt_clear_head_cache(filename);
- free(filename);
- free(local_head);
- if (changelog_head != NULL)
- free(changelog_head);
- return failure;
+ } else {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ slapt_clear_head_cache(filename);
+ free(filename);
+ free(local_head);
+ if (changelog_head != NULL)
+ free(changelog_head);
+ return failure;
+ }
}
+ free(filename);
+ free(local_head);
- }
- free(filename);
- free(local_head);
-
- if (changelog_head != NULL)
- free(changelog_head);
-
- return success;
+ if (changelog_head != NULL)
+ free(changelog_head);
+ return success;
}
-void slapt_clean_description (char *description, const char *name)
+void slapt_clean_description(char *description, const char *name)
{
- char *p = NULL;
- char *token = NULL;
+ char *p = NULL;
+ char *token = NULL;
- if (description == NULL || name == NULL)
- return;
+ if (description == NULL || name == NULL)
+ return;
- token = calloc(strlen(name) + 3, sizeof *token);
- token = strcat(token,name);
- token = strcat(token,":");
+ token = calloc(strlen(name) + 3, sizeof *token);
+ token = strcat(token, name);
+ token = strcat(token, ":");
- while ( (p = strstr( description, token )) != NULL ) {
- memmove( p, p + strlen(token), strlen(p) - strlen(token) + 1);
- }
+ while ((p = strstr(description, token)) != NULL) {
+ memmove(p, p + strlen(token), strlen(p) - strlen(token) + 1);
+ }
- free(token);
+ free(token);
}
/* retrieve the packages changelog entry, if any. Returns NULL otherwise */
char *slapt_get_pkg_changelog(const slapt_pkg_info_t *pkg)
{
- char *filename = slapt_gen_filename_from_url(pkg->mirror,SLAPT_CHANGELOG_FILE);
- FILE *working_changelog_f = NULL;
- struct stat stat_buf;
- char *pkg_data = NULL, *pkg_name = NULL, *changelog = NULL, *ptr = NULL;
- size_t pls = 1;
- int changelog_len = 0;
-
- if ((working_changelog_f = fopen(filename,"rb")) == NULL)
- return NULL;
-
- /* used with mmap */
- if (stat(filename,&stat_buf) == -1) {
+ char *filename = slapt_gen_filename_from_url(pkg->mirror, SLAPT_CHANGELOG_FILE);
+ FILE *working_changelog_f = NULL;
+ struct stat stat_buf;
+ char *pkg_data = NULL, *pkg_name = NULL, *changelog = NULL, *ptr = NULL;
+ size_t pls = 1;
+ int changelog_len = 0;
- if (errno)
- perror(filename);
+ if ((working_changelog_f = fopen(filename, "rb")) == NULL)
+ return NULL;
- fprintf(stderr,"stat failed: %s\n",filename);
- exit(EXIT_FAILURE);
- }
+ /* used with mmap */
+ if (stat(filename, &stat_buf) == -1) {
+ if (errno)
+ perror(filename);
- /* don't mmap empty files */
- if ((int)stat_buf.st_size < 1) {
- free(filename);
- fclose(working_changelog_f);
- return NULL;
- }
+ fprintf(stderr, "stat failed: %s\n", filename);
+ exit(EXIT_FAILURE);
+ }
- pls = (size_t)stat_buf.st_size;
+ /* don't mmap empty files */
+ if ((int)stat_buf.st_size < 1) {
+ free(filename);
+ fclose(working_changelog_f);
+ return NULL;
+ }
- pkg_data = (char *)mmap(0, pls,
- PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(working_changelog_f), 0);
+ pls = (size_t)stat_buf.st_size;
- if (pkg_data == (void *)-1) {
- if (errno)
- perror(filename);
+ pkg_data = (char *)mmap(0, pls,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE, fileno(working_changelog_f), 0);
- fprintf(stderr,"mmap failed: %s\n",filename);
- exit(EXIT_FAILURE);
- }
+ if (pkg_data == (void *)-1) {
+ if (errno)
+ perror(filename);
- fclose(working_changelog_f);
+ fprintf(stderr, "mmap failed: %s\n", filename);
+ exit(EXIT_FAILURE);
+ }
- /* add \0 for strlen to work */
- pkg_data[pls - 1] = '\0';
+ fclose(working_changelog_f);
- /* search for the entry within the changelog */
- pkg_name = slapt_stringify_pkg(pkg);
+ /* add \0 for strlen to work */
+ pkg_data[pls - 1] = '\0';
- if ((ptr = strstr(pkg_data,pkg_name)) != NULL) {
- int finished_parsing = 0;
+ /* search for the entry within the changelog */
+ pkg_name = slapt_stringify_pkg(pkg);
- ptr += strlen(pkg_name);
- if (ptr[0] == ':')
- ptr++;
+ if ((ptr = strstr(pkg_data, pkg_name)) != NULL) {
+ int finished_parsing = 0;
- while (finished_parsing != 1) {
- char *newline = strchr(ptr,'\n');
- char *start_ptr = ptr, *tmp = NULL;
- int remaining_len = 0;
+ ptr += strlen(pkg_name);
+ if (ptr[0] == ':')
+ ptr++;
- if (ptr[0] != '\n' && isblank(ptr[0]) == 0)
- break;
+ while (finished_parsing != 1) {
+ char *newline = strchr(ptr, '\n');
+ char *start_ptr = ptr, *tmp = NULL;
+ int remaining_len = 0;
- /* figure out how much to copy in */
- if (newline != NULL) {
- remaining_len = strlen(start_ptr) - strlen(newline);
- ptr = newline + 1; /* skip newline */
- } else {
- remaining_len = strlen(start_ptr);
- finished_parsing = 1;
- }
+ if (ptr[0] != '\n' && isblank(ptr[0]) == 0)
+ break;
- tmp = realloc(changelog, sizeof *changelog * (changelog_len + remaining_len + 1));
- if (tmp != NULL) {
- changelog = tmp;
+ /* figure out how much to copy in */
+ if (newline != NULL) {
+ remaining_len = strlen(start_ptr) - strlen(newline);
+ ptr = newline + 1; /* skip newline */
+ } else {
+ remaining_len = strlen(start_ptr);
+ finished_parsing = 1;
+ }
- if (changelog_len == 0)
- changelog[0] = '\0';
+ tmp = realloc(changelog, sizeof *changelog * (changelog_len + remaining_len + 1));
+ if (tmp != NULL) {
+ changelog = tmp;
- changelog = strncat(changelog, start_ptr, remaining_len);
- changelog_len += remaining_len;
- changelog[changelog_len] = '\0';
- }
+ if (changelog_len == 0)
+ changelog[0] = '\0';
+ changelog = strncat(changelog, start_ptr, remaining_len);
+ changelog_len += remaining_len;
+ changelog[changelog_len] = '\0';
+ }
+ }
}
+ free(pkg_name);
- }
- free(pkg_name);
-
- /* munmap now that we are done */
- if (munmap(pkg_data,pls) == -1) {
- if (errno)
- perror(filename);
+ /* munmap now that we are done */
+ if (munmap(pkg_data, pls) == -1) {
+ if (errno)
+ perror(filename);
- fprintf(stderr,"munmap failed: %s\n",filename);
- exit(EXIT_FAILURE);
- }
- free(filename);
+ fprintf(stderr, "munmap failed: %s\n", filename);
+ exit(EXIT_FAILURE);
+ }
+ free(filename);
- return changelog;
+ return changelog;
}
char *slapt_stringify_pkg(const slapt_pkg_info_t *pkg)
{
- char *pkg_str = NULL;
- int pkg_str_len = 0;
+ char *pkg_str = NULL;
+ int pkg_str_len = 0;
- pkg_str_len = strlen(pkg->name) + strlen(pkg->version) + strlen(pkg->file_ext) + 2; /* for the - and \0 */
-
- pkg_str = slapt_malloc(sizeof *pkg_str * pkg_str_len);
+ pkg_str_len = strlen(pkg->name) + strlen(pkg->version) + strlen(pkg->file_ext) + 2; /* for the - and \0 */
- if (snprintf(pkg_str, pkg_str_len, "%s-%s%s",pkg->name,pkg->version,pkg->file_ext) < 1) {
- free(pkg_str);
- return NULL;
- }
+ pkg_str = slapt_malloc(sizeof *pkg_str * pkg_str_len);
+
+ if (snprintf(pkg_str, pkg_str_len, "%s-%s%s", pkg->name, pkg->version, pkg->file_ext) < 1) {
+ free(pkg_str);
+ return NULL;
+ }
- return pkg_str;
+ return pkg_str;
}
slapt_pkg_list_t *
- slapt_get_obsolete_pkgs ( const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs)
+slapt_get_obsolete_pkgs(const slapt_rc_config *global_config,
+ slapt_pkg_list_t *avail_pkgs,
+ slapt_pkg_list_t *installed_pkgs)
{
- unsigned int r;
- slapt_pkg_list_t *obsolete = slapt_init_pkg_list();
- slapt_pkg_list_t *to_install = slapt_init_pkg_list();
- slapt_pkg_list_t *to_remove = slapt_init_pkg_list();
+ unsigned int r;
+ slapt_pkg_list_t *obsolete = slapt_init_pkg_list();
+ slapt_pkg_list_t *to_install = slapt_init_pkg_list();
+ slapt_pkg_list_t *to_remove = slapt_init_pkg_list();
- for (r = 0; r < installed_pkgs->pkg_count; ++r) {
- slapt_pkg_info_t *p = installed_pkgs->pkgs[r];
+ for (r = 0; r < installed_pkgs->pkg_count; ++r) {
+ slapt_pkg_info_t *p = installed_pkgs->pkgs[r];
- /*
+ /*
* if we can't find the installed package in our available pkg list,
* it must be obsolete
*/
- if (slapt_get_newest_pkg(avail_pkgs, p->name) == NULL) {
- slapt_pkg_list_t *deps;
- unsigned int c;
+ if (slapt_get_newest_pkg(avail_pkgs, p->name) == NULL) {
+ slapt_pkg_list_t *deps;
+ unsigned int c;
- /*
+ /*
any packages that require this package we are about to remove
should be scheduled to remove as well
*/
- deps = slapt_is_required_by(global_config,avail_pkgs,installed_pkgs,to_install,to_remove,p);
+ deps = slapt_is_required_by(global_config, avail_pkgs, installed_pkgs, to_install, to_remove, p);
- for (c = 0; c < deps->pkg_count; ++c ) {
- slapt_pkg_info_t *dep = deps->pkgs[c];
- slapt_pkg_info_t *installed_dep = slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version);
+ for (c = 0; c < deps->pkg_count; ++c) {
+ slapt_pkg_info_t *dep = deps->pkgs[c];
+ slapt_pkg_info_t *installed_dep = slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version);
- /* if it is installed, we add it to the list */
- if (installed_dep != NULL) {
- slapt_add_pkg_to_pkg_list(obsolete, installed_dep);
- }
- }
-
- slapt_free_pkg_list(deps);
+ /* if it is installed, we add it to the list */
+ if (installed_dep != NULL) {
+ slapt_add_pkg_to_pkg_list(obsolete, installed_dep);
+ }
+ }
- slapt_add_pkg_to_pkg_list(obsolete, p);
+ slapt_free_pkg_list(deps);
+ slapt_add_pkg_to_pkg_list(obsolete, p);
+ }
}
- }
-
- slapt_free_pkg_list(to_install);
- slapt_free_pkg_list(to_remove);
- return obsolete;
+ slapt_free_pkg_list(to_install);
+ slapt_free_pkg_list(to_remove);
+ return obsolete;
}
-static int pkg_compare (const void *a, const void *b)
+static int pkg_compare(const void *a, const void *b)
{
- int cmp = 0;
-
- slapt_pkg_info_t *pkg_a = *(slapt_pkg_info_t * const *)a;
- slapt_pkg_info_t *pkg_b = *(slapt_pkg_info_t * const *)b;
+ int cmp = 0;
- cmp = strcmp(pkg_a->name, pkg_b->name);
+ slapt_pkg_info_t *pkg_a = *(slapt_pkg_info_t *const *)a;
+ slapt_pkg_info_t *pkg_b = *(slapt_pkg_info_t *const *)b;
- if (cmp == 0) {
+ cmp = strcmp(pkg_a->name, pkg_b->name);
- if ((cmp = strverscmp(pkg_a->version, pkg_b->version)) == 0) {
+ if (cmp == 0) {
+ if ((cmp = strverscmp(pkg_a->version, pkg_b->version)) == 0) {
+ return strcmp(pkg_a->location, pkg_b->location);
- return strcmp(pkg_a->location,pkg_b->location);
+ } else {
+ return cmp;
+ }
} else {
-
- return cmp;
-
+ return cmp;
}
-
- } else {
-
- return cmp;
-
- }
-
}
char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
{
- FILE *pkg_f = NULL;
- char *pkg_log_dirname = NULL;
- char *pkg_f_name = NULL;
- struct stat stat_buf;
- char *pkg_data = NULL;
- char *pkg_name;
- int pkg_name_len;
- char *filelist_p = NULL;
- char *tmp_filelist = NULL;
- size_t tmp_len = 0;
- char *filelist = NULL;
- size_t filelist_len = 0;
- size_t pls = 1;
-
- /* this only handles installed packages at the moment */
- if (pkg->installed != true)
- return filelist;
-
- pkg_log_dirname = slapt_gen_package_log_dir_name();
-
- pkg_name_len = strlen(pkg->name) + strlen(pkg->version) + 2; /* for the - and \0 */
- pkg_name = slapt_malloc(sizeof *pkg_name * pkg_name_len);
- if (snprintf(pkg_name, pkg_name_len, "%s-%s",pkg->name,pkg->version) < 1) {
- free(pkg_name);
- return NULL;
- }
+ FILE *pkg_f = NULL;
+ char *pkg_log_dirname = NULL;
+ char *pkg_f_name = NULL;
+ struct stat stat_buf;
+ char *pkg_data = NULL;
+ char *pkg_name;
+ int pkg_name_len;
+ char *filelist_p = NULL;
+ char *tmp_filelist = NULL;
+ size_t tmp_len = 0;
+ char *filelist = NULL;
+ size_t filelist_len = 0;
+ size_t pls = 1;
+
+ /* this only handles installed packages at the moment */
+ if (pkg->installed != true)
+ return filelist;
+
+ pkg_log_dirname = slapt_gen_package_log_dir_name();
+
+ pkg_name_len = strlen(pkg->name) + strlen(pkg->version) + 2; /* for the - and \0 */
+ pkg_name = slapt_malloc(sizeof *pkg_name * pkg_name_len);
+ if (snprintf(pkg_name, pkg_name_len, "%s-%s", pkg->name, pkg->version) < 1) {
+ free(pkg_name);
+ return NULL;
+ }
- /* build the package filename including the package directory */
- pkg_f_name = slapt_malloc(
- sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(pkg_name) + 2)
- );
- pkg_f_name[0] = '\0';
- strncat(pkg_f_name,pkg_log_dirname,strlen(pkg_log_dirname));
- strncat(pkg_f_name,"/",1);
- strncat(pkg_f_name,pkg_name,strlen(pkg_name));
+ /* build the package filename including the package directory */
+ pkg_f_name = slapt_malloc(
+ sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(pkg_name) + 2));
+ pkg_f_name[0] = '\0';
+ strncat(pkg_f_name, pkg_log_dirname, strlen(pkg_log_dirname));
+ strncat(pkg_f_name, "/", 1);
+ strncat(pkg_f_name, pkg_name, strlen(pkg_name));
- free(pkg_log_dirname);
+ free(pkg_log_dirname);
- /*
+ /*
open the package log file so that we can mmap it and parse out the
file list.
*/
- pkg_f = slapt_open_file(pkg_f_name,"r");
- if (pkg_f == NULL)
- exit(EXIT_FAILURE);
-
- /* used with mmap */
- if (stat(pkg_f_name,&stat_buf) == -1) {
+ pkg_f = slapt_open_file(pkg_f_name, "r");
+ if (pkg_f == NULL)
+ exit(EXIT_FAILURE);
- if (errno)
- perror(pkg_f_name);
+ /* used with mmap */
+ if (stat(pkg_f_name, &stat_buf) == -1) {
+ if (errno)
+ perror(pkg_f_name);
- fprintf(stderr,"stat failed: %s\n",pkg_f_name);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "stat failed: %s\n", pkg_f_name);
+ exit(EXIT_FAILURE);
}
/* don't mmap empty files */
if ((int)stat_buf.st_size < 1) {
- free(pkg_f_name);
- fclose(pkg_f);
- return "";
+ free(pkg_f_name);
+ fclose(pkg_f);
+ return "";
}
pls = (size_t)stat_buf.st_size;
- pkg_data = (char *)mmap(0,pls,
- PROT_READ|PROT_WRITE,MAP_PRIVATE,fileno(pkg_f),0);
+ pkg_data = (char *)mmap(0, pls,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE, fileno(pkg_f), 0);
if (pkg_data == (void *)-1) {
+ if (errno)
+ perror(pkg_f_name);
- if (errno)
- perror(pkg_f_name);
-
- fprintf(stderr,"mmap failed: %s\n",pkg_f_name);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "mmap failed: %s\n", pkg_f_name);
+ exit(EXIT_FAILURE);
}
fclose(pkg_f);
@@ -3562,94 +3419,88 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
/* add \0 for strlen to work */
pkg_data[pls - 1] = '\0';
- filelist_p = strstr(pkg_data,"FILE LIST");
+ filelist_p = strstr(pkg_data, "FILE LIST");
if (filelist_p != NULL) {
- char *nl = strchr(filelist_p,'\n');
- int finished_parsing = 0;
-
- if (nl != NULL)
- filelist_p = ++nl;
-
- while (!finished_parsing) {
-
- if ((nl = strchr(filelist_p,'\n')) != NULL) {
- tmp_len = nl - filelist_p + 1;
- } else {
- tmp_len = strlen(filelist_p);
- finished_parsing = 1;
- }
-
- /* files in install/ are package metadata */
- if (strncmp(filelist_p, "./\n", 3) != 0 &&
- strncmp(filelist_p, "install/", 8) != 0) {
-
- tmp_len += 1; /* prefix '/' */
-
- tmp_filelist = realloc(filelist,
- sizeof *filelist *
- (filelist_len + tmp_len + 1)
- );
-
- if (tmp_filelist != NULL) {
- filelist = tmp_filelist;
- tmp_filelist = filelist + filelist_len;
- tmp_filelist[0] = '/';
- strncpy(tmp_filelist + 1,filelist_p,tmp_len - 1);
- tmp_filelist[tmp_len] = '\0';
- filelist_len += tmp_len;
- }
-
- }
-
- filelist_p = nl + 1;
- }
- }
-
- /* munmap now that we are done */
- if (munmap(pkg_data,pls) == -1) {
- if (errno)
- perror(pkg_f_name);
-
- fprintf(stderr,"munmap failed: %s\n",pkg_f_name);
- exit(EXIT_FAILURE);
- }
- free(pkg_f_name);
- free(pkg_name);
+ char *nl = strchr(filelist_p, '\n');
+ int finished_parsing = 0;
+
+ if (nl != NULL)
+ filelist_p = ++nl;
- return filelist;
+ while (!finished_parsing) {
+ if ((nl = strchr(filelist_p, '\n')) != NULL) {
+ tmp_len = nl - filelist_p + 1;
+ } else {
+ tmp_len = strlen(filelist_p);
+ finished_parsing = 1;
+ }
+
+ /* files in install/ are package metadata */
+ if (strncmp(filelist_p, "./\n", 3) != 0 &&
+ strncmp(filelist_p, "install/", 8) != 0) {
+ tmp_len += 1; /* prefix '/' */
+
+ tmp_filelist = realloc(filelist,
+ sizeof *filelist *
+ (filelist_len + tmp_len + 1));
+
+ if (tmp_filelist != NULL) {
+ filelist = tmp_filelist;
+ tmp_filelist = filelist + filelist_len;
+ tmp_filelist[0] = '/';
+ strncpy(tmp_filelist + 1, filelist_p, tmp_len - 1);
+ tmp_filelist[tmp_len] = '\0';
+ filelist_len += tmp_len;
+ }
+ }
+
+ filelist_p = nl + 1;
+ }
+ }
+
+ /* munmap now that we are done */
+ if (munmap(pkg_data, pls) == -1) {
+ if (errno)
+ perror(pkg_f_name);
+
+ fprintf(stderr, "munmap failed: %s\n", pkg_f_name);
+ exit(EXIT_FAILURE);
+ }
+ free(pkg_f_name);
+ free(pkg_name);
+
+ return filelist;
}
char *slapt_gen_package_log_dir_name(void)
{
- char *root_env_entry = NULL;
- char *pkg_log_dirname = NULL;
- char *path = NULL;
- struct stat stat_buf;
-
- /* Generate package log directory using ROOT env variable if set */
- if (getenv(SLAPT_ROOT_ENV_NAME) && strlen(getenv(SLAPT_ROOT_ENV_NAME)) < SLAPT_ROOT_ENV_LEN) {
- root_env_entry = getenv(SLAPT_ROOT_ENV_NAME);
- }
- pkg_log_dirname = slapt_calloc(
- strlen(SLAPT_PKG_LOG_DIR)+
- (root_env_entry ? strlen(root_env_entry) : 0) + 1 ,
- sizeof *pkg_log_dirname
- );
-
- if (stat(SLAPT_PKG_LOG_DIR, &stat_buf) == 0) {
- path = SLAPT_PKG_LOG_DIR;
- } else if (stat(SLAPT_OLD_PKG_LOG_DIR, &stat_buf) == 0) {
- path = SLAPT_OLD_PKG_LOG_DIR;
- }
+ char *root_env_entry = NULL;
+ char *pkg_log_dirname = NULL;
+ char *path = NULL;
+ struct stat stat_buf;
- *pkg_log_dirname = '\0';
- if (root_env_entry) {
- strncpy(pkg_log_dirname, root_env_entry, strlen(root_env_entry));
- strncat(pkg_log_dirname, path, strlen(path));
- } else {
- strncat(pkg_log_dirname, path, strlen(path));
- }
+ /* Generate package log directory using ROOT env variable if set */
+ if (getenv(SLAPT_ROOT_ENV_NAME) && strlen(getenv(SLAPT_ROOT_ENV_NAME)) < SLAPT_ROOT_ENV_LEN) {
+ root_env_entry = getenv(SLAPT_ROOT_ENV_NAME);
+ }
+ pkg_log_dirname = slapt_calloc(
+ strlen(SLAPT_PKG_LOG_DIR) +
+ (root_env_entry ? strlen(root_env_entry) : 0) + 1,
+ sizeof *pkg_log_dirname);
- return pkg_log_dirname;
-}
+ if (stat(SLAPT_PKG_LOG_DIR, &stat_buf) == 0) {
+ path = SLAPT_PKG_LOG_DIR;
+ } else if (stat(SLAPT_OLD_PKG_LOG_DIR, &stat_buf) == 0) {
+ path = SLAPT_OLD_PKG_LOG_DIR;
+ }
+
+ *pkg_log_dirname = '\0';
+ if (root_env_entry) {
+ strncpy(pkg_log_dirname, root_env_entry, strlen(root_env_entry));
+ strncat(pkg_log_dirname, path, strlen(path));
+ } else {
+ strncat(pkg_log_dirname, path, strlen(path));
+ }
+ return pkg_log_dirname;
+}
diff --git a/src/package.h b/src/package.h
index 663c742..d7b9af5 100644
--- a/src/package.h
+++ b/src/package.h
@@ -53,49 +53,49 @@
#define SLAPT_MAX_ZLIB_BUFFER 1024
typedef struct {
- char md5[SLAPT_MD5_STR_LEN];
- char *name;
- char *version;
- char *mirror;
- char *location;
- char *description;
- char *required;
- char *conflicts;
- char *suggests;
- char *file_ext;
- unsigned int size_c;
- unsigned int size_u;
- unsigned int priority;
- bool installed;
+ char md5[SLAPT_MD5_STR_LEN];
+ char *name;
+ char *version;
+ char *mirror;
+ char *location;
+ char *description;
+ char *required;
+ char *conflicts;
+ char *suggests;
+ char *file_ext;
+ unsigned int size_c;
+ unsigned int size_u;
+ unsigned int priority;
+ bool installed;
} slapt_pkg_info_t;
typedef struct {
- slapt_pkg_info_t **pkgs;
- unsigned int pkg_count;
- bool free_pkgs;
- bool ordered;
+ slapt_pkg_info_t **pkgs;
+ unsigned int pkg_count;
+ bool free_pkgs;
+ bool ordered;
} slapt_pkg_list_t;
typedef struct {
- slapt_pkg_info_t *installed;
- slapt_pkg_info_t *upgrade;
- bool reinstall;
+ slapt_pkg_info_t *installed;
+ slapt_pkg_info_t *upgrade;
+ bool reinstall;
} slapt_pkg_upgrade_t;
typedef struct {
- slapt_pkg_upgrade_t **pkgs;
- unsigned int pkg_count;
- unsigned int reinstall_count;
+ slapt_pkg_upgrade_t **pkgs;
+ unsigned int pkg_count;
+ unsigned int reinstall_count;
} slapt_pkg_upgrade_list_t;
typedef struct {
- char *pkg;
- char *error;
+ char *pkg;
+ char *error;
} slapt_pkg_err_t;
typedef struct {
- slapt_pkg_err_t **errs;
- unsigned int err_count;
+ slapt_pkg_err_t **errs;
+ unsigned int err_count;
} slapt_pkg_err_list_t;
/* returns an empty package structure */
@@ -116,7 +116,7 @@ void slapt_free_pkg_list(slapt_pkg_list_t *);
*/
int slapt_update_pkg_cache(const slapt_rc_config *global_config);
/* write pkg data to disk */
-void slapt_write_pkg_data(const char *source_url,FILE *d_file,
+void slapt_write_pkg_data(const char *source_url, FILE *d_file,
slapt_pkg_list_t *pkgs);
/* parse the PACKAGES.TXT file */
slapt_pkg_list_t *slapt_parse_packages_txt(FILE *);
@@ -130,7 +130,7 @@ slapt_pkg_list_t *slapt_get_available_pkgs(void);
slapt_pkg_list_t *slapt_get_installed_pkgs(void);
/* retrieve the newest package from package list */
-slapt_pkg_info_t *slapt_get_newest_pkg(slapt_pkg_list_t *,const char *);
+slapt_pkg_info_t *slapt_get_newest_pkg(slapt_pkg_list_t *, const char *);
/* get the exact package */
slapt_pkg_info_t *slapt_get_exact_pkg(slapt_pkg_list_t *list,
const char *name,
@@ -142,14 +142,13 @@ slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
const char *location);
/* search package list with pattern */
slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,
- const char *pattern);
-
+ const char *pattern);
/*
install package by calling installpkg
returns 0 on success, -1 on error
*/
-int slapt_install_pkg(const slapt_rc_config *,slapt_pkg_info_t *);
+int slapt_install_pkg(const slapt_rc_config *, slapt_pkg_info_t *);
/*
upgrade package by calling upgradepkg
returns 0 on success, -1 on error
@@ -160,14 +159,13 @@ int slapt_upgrade_pkg(const slapt_rc_config *global_config,
remove package by calling removepkg
returns 0 on success, -1 on error
*/
-int slapt_remove_pkg(const slapt_rc_config *,slapt_pkg_info_t *);
+int slapt_remove_pkg(const slapt_rc_config *, slapt_pkg_info_t *);
/* get a list of obsolete packages */
slapt_pkg_list_t *
- slapt_get_obsolete_pkgs ( const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs);
-
+slapt_get_obsolete_pkgs(const slapt_rc_config *global_config,
+ slapt_pkg_list_t *avail_pkgs,
+ slapt_pkg_list_t *installed_pkgs);
/*
generate a short description, returns (char *) on success or NULL on error
@@ -178,7 +176,7 @@ char *slapt_gen_short_pkg_description(slapt_pkg_info_t *);
generate the filename from the url
caller responsible for freeing the returned data
*/
-char *slapt_gen_filename_from_url(const char *url,const char *file);
+char *slapt_gen_filename_from_url(const char *url, const char *file);
/*
generate the package file name
caller responsible for freeing the returned data
@@ -199,13 +197,13 @@ char *slapt_gen_pkg_url(slapt_pkg_info_t *pkg);
exclude pkg based on pkg name
returns 1 if package is present in the exclude list, 0 if not present
*/
-int slapt_is_excluded(const slapt_rc_config *,slapt_pkg_info_t *);
+int slapt_is_excluded(const slapt_rc_config *, slapt_pkg_info_t *);
/*
package is already downloaded and cached, md5sum if applicable is ok
returns slapt_code_t.
*/
slapt_code_t slapt_verify_downloaded_pkg(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg);
+ slapt_pkg_info_t *pkg);
/*
fill in the md5sum of the package
*/
@@ -232,27 +230,27 @@ int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b);
(usually called with transaction->conflict_err and transaction->missing_err)
*/
int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_info_t *pkg,
- slapt_pkg_list_t *deps,
- slapt_pkg_err_list_t *conflict_err,
- slapt_pkg_err_list_t *missing_err);
+ slapt_pkg_list_t *avail_pkgs,
+ slapt_pkg_list_t *installed_pkgs,
+ slapt_pkg_info_t *pkg,
+ slapt_pkg_list_t *deps,
+ slapt_pkg_err_list_t *conflict_err,
+ slapt_pkg_err_list_t *missing_err);
/*
return list of package conflicts
*/
slapt_pkg_list_t *slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_info_t *pkg);
+ slapt_pkg_list_t *installed_pkgs,
+ slapt_pkg_info_t *pkg);
/*
return list of packages required by
*/
slapt_pkg_list_t *slapt_is_required_by(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_list_t *pkgs_to_install,
- slapt_pkg_list_t *pkgs_to_remove,
- slapt_pkg_info_t *pkg);
+ slapt_pkg_list_t *avail,
+ slapt_pkg_list_t *installed_pkgs,
+ slapt_pkg_list_t *pkgs_to_install,
+ slapt_pkg_list_t *pkgs_to_remove,
+ slapt_pkg_info_t *pkg);
/*
empty packages from cache dir
@@ -269,14 +267,14 @@ void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
/*
make a copy of a package (needs to be freed with free_pkg)
*/
-slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst,slapt_pkg_info_t *src);
+slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst, slapt_pkg_info_t *src);
/*
package error handling api to handle errors within core functions
*/
slapt_pkg_err_list_t *slapt_init_pkg_err_list(void);
void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,
- const char *pkg,const char *err);
+ const char *pkg, const char *err);
int slapt_search_pkg_err_list(slapt_pkg_err_list_t *l,
const char *pkg, const char *err);
void slapt_free_pkg_err_list(slapt_pkg_err_list_t *l);
@@ -285,17 +283,17 @@ void slapt_free_pkg_err_list(slapt_pkg_err_list_t *l);
download the PACKAGES.TXT and CHECKSUMS.md5 files
compressed is set to 1 if the compressed version was downloaded.
*/
-slapt_pkg_list_t *slapt_get_pkg_source_packages (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
-slapt_pkg_list_t *slapt_get_pkg_source_patches (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
-FILE *slapt_get_pkg_source_checksums (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
-int slapt_get_pkg_source_changelog (const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
+slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed);
+slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed);
+FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed);
+int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
+ const char *url, unsigned int *compressed);
/* clean package name from package description */
-void slapt_clean_description (char *description, const char *name);
+void slapt_clean_description(char *description, const char *name);
/*
retrieve the packages changelog entry, if any. Returns NULL otherwise
@@ -318,4 +316,3 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg);
caller responsible for freeing the returned data
*/
char *slapt_gen_package_log_dir_name(void);
-
diff --git a/src/transaction.c b/src/transaction.c
index cce8f1e..73c3d72 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -28,800 +28,744 @@ static void queue_free(slapt_queue_t *t);
static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg);
static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg,
- bool reinstall
-);
+ slapt_pkg_info_t *installed_pkg,
+ slapt_pkg_info_t *slapt_upgrade_pkg,
+ bool reinstall);
slapt_transaction_t *slapt_init_transaction(void)
{
- slapt_transaction_t *tran = slapt_malloc(sizeof *tran);
-
- tran->install_pkgs = slapt_init_pkg_list();
- tran->install_pkgs->free_pkgs = true;
+ slapt_transaction_t *tran = slapt_malloc(sizeof *tran);
- tran->remove_pkgs = slapt_init_pkg_list();
- tran->remove_pkgs->free_pkgs = true;
+ tran->install_pkgs = slapt_init_pkg_list();
+ tran->install_pkgs->free_pkgs = true;
- tran->exclude_pkgs = slapt_init_pkg_list();
- tran->exclude_pkgs->free_pkgs = true;
+ tran->remove_pkgs = slapt_init_pkg_list();
+ tran->remove_pkgs->free_pkgs = true;
- tran->upgrade_pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs);
- tran->upgrade_pkgs->pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs->pkgs);
- tran->upgrade_pkgs->pkg_count = 0;
- tran->upgrade_pkgs->reinstall_count = 0;
+ tran->exclude_pkgs = slapt_init_pkg_list();
+ tran->exclude_pkgs->free_pkgs = true;
+ tran->upgrade_pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs);
+ tran->upgrade_pkgs->pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs->pkgs);
+ tran->upgrade_pkgs->pkg_count = 0;
+ tran->upgrade_pkgs->reinstall_count = 0;
- tran->suggests = slapt_init_list();
+ tran->suggests = slapt_init_list();
- tran->queue = slapt_queue_init();
+ tran->queue = slapt_queue_init();
- tran->conflict_err = slapt_init_pkg_err_list();
- tran->missing_err = slapt_init_pkg_err_list();
+ tran->conflict_err = slapt_init_pkg_err_list();
+ tran->missing_err = slapt_init_pkg_err_list();
- return tran;
+ return tran;
}
-int slapt_handle_transaction (const slapt_rc_config *global_config,
- slapt_transaction_t *tran)
+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);
+ 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 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(" ");
+ /* 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];
+ 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;
- }
+ 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");
}
- printf("\n");
- }
-
- /* show suggested pkgs */
- slapt_generate_suggestions(tran);
- if (tran->suggests->count > 0) {
- unsigned int len = 0;
+ /* show suggested pkgs */
+ slapt_generate_suggestions(tran);
+ if (tran->suggests->count > 0) {
+ unsigned int len = 0;
- printf(gettext("Suggested packages:\n"));
- printf(" ");
+ printf(gettext("Suggested packages:\n"));
+ printf(" ");
- for (i = 0; i < tran->suggests->count; ++i) {
- char *s = tran->suggests->items[i];
+ for (i = 0; i < tran->suggests->count; ++i) {
+ char *s = tran->suggests->items[i];
- /* don't show suggestion for something we already have
+ /* 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;
- }
-
+ 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");
}
- 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(" ");
- /* 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;
- 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;
+ }
- 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;
- existing_file_size = slapt_get_pkg_file_size(global_config,p) / 1024;
+ download_size += p->size_c;
- download_size += p->size_c;
+ if (existing_file_size <= p->size_c)
+ already_download_size += existing_file_size;
- if (existing_file_size <= p->size_c)
- already_download_size += existing_file_size;
-
- uncompressed_size += p->size_u;
+ uncompressed_size += p->size_u;
+ }
+ printf("\n");
}
- 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(" ");
+ /* 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];
+ 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;
- }
+ 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;
+ uncompressed_size -= r->size_u;
+ }
+ printf("\n");
}
- printf("\n");
- }
-
- /* show pkgs to upgrade */
- if (tran->upgrade_pkgs->pkg_count > 0) {
- unsigned int len = 0;
+ /* 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(" ");
- }
+ 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;
+ 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;
+ 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;
+ existing_file_size = slapt_get_pkg_file_size(
+ global_config, u) /
+ 1024;
- download_size += u->size_c;
+ download_size += u->size_c;
- if (existing_file_size <= u->size_c)
- already_download_size += existing_file_size;
+ if (existing_file_size <= u->size_c)
+ already_download_size += existing_file_size;
- uncompressed_size += u->size_u;
- uncompressed_size -= p->size_u;
+ uncompressed_size += u->size_u;
+ uncompressed_size -= p->size_u;
- if (tran->upgrade_pkgs->pkgs[i]->reinstall == true)
- continue;
+ if (tran->upgrade_pkgs->pkgs[i]->reinstall == 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 (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 == 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");
+ }
}
- 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 == false)
- continue;
-
- if (line_len < MAX_LINE_LEN) {
- printf("%s ",u->name);
- len += strlen(u->name) + 1;
+ /* 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("\n %s ",u->name);
- len = strlen(u->name) + 3;
+ printf(gettext("Need to get %.1f%s of archives.\n"),
+ (download_size > 1024) ? download_size / (double)1024 : download_size,
+ (download_size > 1024) ? "MB" : "kB");
}
- }
- 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) == 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 == false) {
- if (slapt_disk_space_check ("/", uncompressed_size) == false) {
- printf(gettext("You don't have enough free space in %s\n"),"/");
- exit(EXIT_FAILURE);
- }
+ /* check we have enough space to download to our working dir */
+ if (slapt_disk_space_check(global_config->working_dir, need_to_download_size) == 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 == false) {
+ if (slapt_disk_space_check("/", uncompressed_size) == 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 == 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 == true) ||
- ((tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
- (tran->install_pkgs->pkg_count > 0 &&
- global_config->dist_upgrade == true)) &&
- (global_config->no_prompt == false &&
- global_config->download_only == false &&
- global_config->simulate == false &&
- global_config->print_uris == false))
- ) {
- if (slapt_ask_yes_no(gettext("Do you want to continue? [y/N] ")) != 1) {
- printf(gettext("Abort.\n"));
- return 1;
+ if (tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
+ tran->install_pkgs->pkg_count > 0) {
+ if (global_config->download_only == 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");
+ }
+ }
}
- }
- if (global_config->print_uris == 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);
+ /* prompt */
+ if ((global_config->prompt == true) ||
+ ((tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
+ (tran->install_pkgs->pkg_count > 0 &&
+ global_config->dist_upgrade == true)) &&
+ (global_config->no_prompt == false &&
+ global_config->download_only == false &&
+ global_config->simulate == false &&
+ global_config->print_uris == false))) {
+ if (slapt_ask_yes_no(gettext("Do you want to continue? [y/N] ")) != 1) {
+ printf(gettext("Abort.\n"));
+ return 1;
+ }
}
- return 0;
- }
-
- /* if simulate is requested, just show what could happen and return */
- if (global_config->simulate == 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);
+ if (global_config->print_uris == 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;
}
- 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
- );
- }
+ /* if simulate is requested, just show what could happen and return */
+ if (global_config->simulate == 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;
- }
+ printf(gettext("Done\n"));
+ return 0;
}
- 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);
- }
+ pkg_dl_count = tran->install_pkgs->pkg_count + tran->upgrade_pkgs->pkg_count;
- printf("\n");
+ /* 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;
+ }
+ }
- /* run transaction, remove, install, and upgrade */
- if (global_config->download_only == false) {
+ if (failed == 1)
+ exit(EXIT_FAILURE);
+ }
- 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->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);
}
- for (i = 0;i < tran->queue->count; ++i) {
+ printf("\n");
- 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);
+ /* run transaction, remove, install, and upgrade */
+ if (global_config->download_only == 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"));
+ printf(gettext("Done\n"));
- return 0;
+ return 0;
}
void slapt_add_install_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_info_t **tmp_list;
-
- /* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran,pkg) == 1)
- return;
-
- tmp_list = realloc(
- tran->install_pkgs->pkgs,
- sizeof *tran->install_pkgs->pkgs * (tran->install_pkgs->pkg_count + 1)
- );
-
- if (tmp_list != NULL) {
- tran->install_pkgs->pkgs = tmp_list;
-
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]
- );
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_copy_pkg(
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count],
- pkg
- );
- queue_add_install(
- tran->queue,
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]
- );
-
- ++tran->install_pkgs->pkg_count;
- }
+ slapt_pkg_info_t **tmp_list;
+
+ /* don't add if already present in the transaction */
+ if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ return;
+
+ tmp_list = realloc(
+ tran->install_pkgs->pkgs,
+ sizeof *tran->install_pkgs->pkgs * (tran->install_pkgs->pkg_count + 1));
+
+ if (tmp_list != NULL) {
+ tran->install_pkgs->pkgs = tmp_list;
+
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_malloc(
+ sizeof *tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]);
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_copy_pkg(
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count],
+ pkg);
+ queue_add_install(
+ tran->queue,
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]);
+ ++tran->install_pkgs->pkg_count;
+ }
}
-void slapt_add_remove_to_transaction(slapt_transaction_t *tran,
+void slapt_add_remove_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_info_t **tmp_list;
-
- /* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran,pkg) == 1)
- return;
-
- tmp_list = realloc(
- tran->remove_pkgs->pkgs,
- sizeof *tran->remove_pkgs->pkgs * (tran->remove_pkgs->pkg_count + 1)
- );
- if (tmp_list != NULL) {
- tran->remove_pkgs->pkgs = tmp_list;
-
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count]
- );
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_copy_pkg(
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count],
- pkg
- );
- ++tran->remove_pkgs->pkg_count;
- }
+ slapt_pkg_info_t **tmp_list;
+
+ /* don't add if already present in the transaction */
+ if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ return;
+
+ tmp_list = realloc(
+ tran->remove_pkgs->pkgs,
+ sizeof *tran->remove_pkgs->pkgs * (tran->remove_pkgs->pkg_count + 1));
+ if (tmp_list != NULL) {
+ tran->remove_pkgs->pkgs = tmp_list;
+ tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_malloc(
+ sizeof *tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count]);
+ tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_copy_pkg(
+ tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count],
+ pkg);
+ ++tran->remove_pkgs->pkg_count;
+ }
}
void slapt_add_exclude_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_info_t **tmp_list;
-
- /* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran,pkg) == 1)
- return;
-
- tmp_list = realloc(
- tran->exclude_pkgs->pkgs,
- sizeof *tran->exclude_pkgs->pkgs * (tran->exclude_pkgs->pkg_count + 1)
- );
- if (tmp_list != NULL) {
- tran->exclude_pkgs->pkgs = tmp_list;
-
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count]
- );
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_copy_pkg(
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count],
- pkg
- );
- ++tran->exclude_pkgs->pkg_count;
- }
+ slapt_pkg_info_t **tmp_list;
+
+ /* don't add if already present in the transaction */
+ if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ return;
+ tmp_list = realloc(
+ tran->exclude_pkgs->pkgs,
+ sizeof *tran->exclude_pkgs->pkgs * (tran->exclude_pkgs->pkg_count + 1));
+ if (tmp_list != NULL) {
+ tran->exclude_pkgs->pkgs = tmp_list;
+
+ tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_malloc(
+ sizeof *tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count]);
+ tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_copy_pkg(
+ tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count],
+ pkg);
+ ++tran->exclude_pkgs->pkg_count;
+ }
}
void slapt_add_reinstall_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg
-)
+ slapt_pkg_info_t *installed_pkg,
+ slapt_pkg_info_t *slapt_upgrade_pkg)
{
- _slapt_add_upgrade_to_transaction(tran, installed_pkg, slapt_upgrade_pkg, true);
+ _slapt_add_upgrade_to_transaction(tran, installed_pkg, slapt_upgrade_pkg, true);
}
void slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg
-)
+ slapt_pkg_info_t *slapt_upgrade_pkg)
{
- _slapt_add_upgrade_to_transaction(tran, installed_pkg, slapt_upgrade_pkg, false);
+ _slapt_add_upgrade_to_transaction(tran, installed_pkg, slapt_upgrade_pkg, false);
}
-
static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg,
- bool reinstall
-)
+ slapt_pkg_info_t *installed_pkg,
+ slapt_pkg_info_t *slapt_upgrade_pkg,
+ bool reinstall)
{
- slapt_pkg_upgrade_t **tmp_list;
+ slapt_pkg_upgrade_t **tmp_list;
- /* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran,slapt_upgrade_pkg) == 1)
- return;
+ /* don't add if already present in the transaction */
+ if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg) == 1)
+ return;
- tmp_list = realloc(
- tran->upgrade_pkgs->pkgs,
- sizeof *tran->upgrade_pkgs->pkgs * (tran->upgrade_pkgs->pkg_count + 1)
- );
+ tmp_list = realloc(
+ tran->upgrade_pkgs->pkgs,
+ sizeof *tran->upgrade_pkgs->pkgs * (tran->upgrade_pkgs->pkg_count + 1));
- if (tmp_list != NULL) {
- tran->upgrade_pkgs->pkgs = tmp_list;
+ if (tmp_list != NULL) {
+ tran->upgrade_pkgs->pkgs = tmp_list;
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]);
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count] = slapt_malloc(
+ sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed =
- slapt_malloc(
- sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed
- );
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed =
+ slapt_malloc(
+ sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade =
- slapt_malloc(
- sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade
- );
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade =
+ slapt_malloc(
+ sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = slapt_copy_pkg(
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed,
- installed_pkg);
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = slapt_copy_pkg(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed,
+ installed_pkg);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = slapt_copy_pkg(
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade,
- slapt_upgrade_pkg);
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = slapt_copy_pkg(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade,
+ slapt_upgrade_pkg);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->reinstall = reinstall;
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->reinstall = reinstall;
- queue_add_upgrade(tran->queue,
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]);
+ queue_add_upgrade(tran->queue,
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]);
- ++tran->upgrade_pkgs->pkg_count;
-
- if (reinstall == true)
- ++tran->upgrade_pkgs->reinstall_count;
-
- }
+ ++tran->upgrade_pkgs->pkg_count;
+ if (reinstall == true)
+ ++tran->upgrade_pkgs->reinstall_count;
+ }
}
-int slapt_search_transaction(slapt_transaction_t *tran,char *pkg_name)
+int slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
{
- unsigned int i,found = 1, not_found = 0;
-
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
-
- if (strcmp(pkg_name,tran->install_pkgs->pkgs[i]->name) == 0)
- return found;
-
- }
-
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
-
- if (strcmp(pkg_name,tran->upgrade_pkgs->pkgs[i]->upgrade->name) == 0)
- return found;
-
- }
-
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
-
- if (strcmp(pkg_name,tran->remove_pkgs->pkgs[i]->name) == 0)
- return found;
+ unsigned int i, found = 1, not_found = 0;
- }
+ for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
+ if (strcmp(pkg_name, tran->install_pkgs->pkgs[i]->name) == 0)
+ return found;
+ }
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
+ for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
+ if (strcmp(pkg_name, tran->upgrade_pkgs->pkgs[i]->upgrade->name) == 0)
+ return found;
+ }
- if (strcmp(pkg_name,tran->exclude_pkgs->pkgs[i]->name) == 0)
- return found;
+ for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
+ if (strcmp(pkg_name, tran->remove_pkgs->pkgs[i]->name) == 0)
+ return found;
+ }
- }
+ for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
+ if (strcmp(pkg_name, tran->exclude_pkgs->pkgs[i]->name) == 0)
+ return found;
+ }
- return not_found;
+ return not_found;
}
int slapt_search_upgrade_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- unsigned int i,
- found = 1,
- not_found = 0;
-
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
-
- if (strcmp(pkg->name,tran->upgrade_pkgs->pkgs[i]->upgrade->name) == 0)
- return found;
+ unsigned int i,
+ found = 1,
+ not_found = 0;
- }
+ for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
+ if (strcmp(pkg->name, tran->upgrade_pkgs->pkgs[i]->upgrade->name) == 0)
+ return found;
+ }
- return not_found;
+ return not_found;
}
void slapt_free_transaction(slapt_transaction_t *tran)
{
- unsigned int i;
+ unsigned int i;
- if (tran->install_pkgs->free_pkgs == true) {
- for (i = 0;i < tran->install_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->install_pkgs->pkgs[i]);
+ if (tran->install_pkgs->free_pkgs == true) {
+ for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
+ slapt_free_pkg(tran->install_pkgs->pkgs[i]);
+ }
}
- }
- free(tran->install_pkgs->pkgs);
- free(tran->install_pkgs);
+ free(tran->install_pkgs->pkgs);
+ free(tran->install_pkgs);
- if (tran->remove_pkgs->free_pkgs == true) {
- for (i = 0;i < tran->remove_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->remove_pkgs->pkgs[i]);
+ if (tran->remove_pkgs->free_pkgs == true) {
+ for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
+ slapt_free_pkg(tran->remove_pkgs->pkgs[i]);
+ }
}
- }
- free(tran->remove_pkgs->pkgs);
- free(tran->remove_pkgs);
-
- for (i = 0;i < tran->upgrade_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->upgrade_pkgs->pkgs[i]->upgrade);
- slapt_free_pkg(tran->upgrade_pkgs->pkgs[i]->installed);
- free(tran->upgrade_pkgs->pkgs[i]);
- }
- free(tran->upgrade_pkgs->pkgs);
- free(tran->upgrade_pkgs);
-
- if (tran->exclude_pkgs->free_pkgs == true) {
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->exclude_pkgs->pkgs[i]);
+ free(tran->remove_pkgs->pkgs);
+ free(tran->remove_pkgs);
+
+ for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
+ slapt_free_pkg(tran->upgrade_pkgs->pkgs[i]->upgrade);
+ slapt_free_pkg(tran->upgrade_pkgs->pkgs[i]->installed);
+ free(tran->upgrade_pkgs->pkgs[i]);
}
- }
- free(tran->exclude_pkgs->pkgs);
- free(tran->exclude_pkgs);
+ free(tran->upgrade_pkgs->pkgs);
+ free(tran->upgrade_pkgs);
- slapt_free_list(tran->suggests);
+ if (tran->exclude_pkgs->free_pkgs == true) {
+ for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
+ slapt_free_pkg(tran->exclude_pkgs->pkgs[i]);
+ }
+ }
+ free(tran->exclude_pkgs->pkgs);
+ free(tran->exclude_pkgs);
- queue_free(tran->queue);
+ slapt_free_list(tran->suggests);
- slapt_free_pkg_err_list(tran->conflict_err);
- slapt_free_pkg_err_list(tran->missing_err);
+ queue_free(tran->queue);
- free(tran);
+ slapt_free_pkg_err_list(tran->conflict_err);
+ slapt_free_pkg_err_list(tran->missing_err);
+
+ free(tran);
}
slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- unsigned int i;
- slapt_transaction_t *new_tran = NULL;
+ unsigned int i;
+ slapt_transaction_t *new_tran = NULL;
- if (slapt_search_transaction_by_pkg(tran,pkg) == 0)
- return tran;
+ if (slapt_search_transaction_by_pkg(tran, pkg) == 0)
+ return tran;
- /* since this is a pointer, slapt_malloc before calling init */
- new_tran = slapt_malloc(sizeof *new_tran);
- new_tran->install_pkgs = slapt_malloc(sizeof *new_tran->install_pkgs);
- new_tran->remove_pkgs = slapt_malloc(sizeof *new_tran->remove_pkgs);
- new_tran->upgrade_pkgs = slapt_malloc(sizeof *new_tran->upgrade_pkgs);
- new_tran->exclude_pkgs = slapt_malloc(sizeof *new_tran->exclude_pkgs);
- new_tran = slapt_init_transaction();
-
- for (i = 0;i < tran->install_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];
-
- if (
- strcmp(pkg->name,p->name) == 0 &&
- strcmp(pkg->version,p->version) == 0 &&
- strcmp(pkg->location,p->location) == 0
- ) {
- continue;
- }
+ /* since this is a pointer, slapt_malloc before calling init */
+ new_tran = slapt_malloc(sizeof *new_tran);
+ new_tran->install_pkgs = slapt_malloc(sizeof *new_tran->install_pkgs);
+ new_tran->remove_pkgs = slapt_malloc(sizeof *new_tran->remove_pkgs);
+ new_tran->upgrade_pkgs = slapt_malloc(sizeof *new_tran->upgrade_pkgs);
+ new_tran->exclude_pkgs = slapt_malloc(sizeof *new_tran->exclude_pkgs);
+ new_tran = slapt_init_transaction();
- slapt_add_install_to_transaction(new_tran,p);
- }
+ for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];
- for (i = 0;i < tran->remove_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->remove_pkgs->pkgs[i];
+ if (
+ strcmp(pkg->name, p->name) == 0 &&
+ strcmp(pkg->version, p->version) == 0 &&
+ strcmp(pkg->location, p->location) == 0) {
+ continue;
+ }
- if (
- strcmp(pkg->name,p->name) == 0 &&
- strcmp(pkg->version,p->version) == 0 &&
- strcmp(pkg->location,p->location) == 0
- ) {
- continue;
+ slapt_add_install_to_transaction(new_tran, p);
}
- slapt_add_remove_to_transaction(new_tran,tran->remove_pkgs->pkgs[i]);
- }
+ for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *p = tran->remove_pkgs->pkgs[i];
- 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;
+ if (
+ strcmp(pkg->name, p->name) == 0 &&
+ strcmp(pkg->version, p->version) == 0 &&
+ strcmp(pkg->location, p->location) == 0) {
+ continue;
+ }
- if (
- strcmp(pkg->name,u->name) == 0 &&
- strcmp(pkg->version,u->version) == 0 &&
- strcmp(pkg->location,u->location) == 0
- ) {
- continue;
+ slapt_add_remove_to_transaction(new_tran, tran->remove_pkgs->pkgs[i]);
}
- slapt_add_upgrade_to_transaction(new_tran, p, u);
- }
+ 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;
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->exclude_pkgs->pkgs[i];
+ if (
+ strcmp(pkg->name, u->name) == 0 &&
+ strcmp(pkg->version, u->version) == 0 &&
+ strcmp(pkg->location, u->location) == 0) {
+ continue;
+ }
- if (
- strcmp(pkg->name,p->name) == 0 &&
- strcmp(pkg->version,p->version) == 0 &&
- strcmp(pkg->location,p->location) == 0
- ) {
- continue;
+ slapt_add_upgrade_to_transaction(new_tran, p, u);
}
- slapt_add_exclude_to_transaction(new_tran,p);
- }
+ for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *p = tran->exclude_pkgs->pkgs[i];
+
+ if (
+ strcmp(pkg->name, p->name) == 0 &&
+ strcmp(pkg->version, p->version) == 0 &&
+ strcmp(pkg->location, p->location) == 0) {
+ continue;
+ }
+
+ slapt_add_exclude_to_transaction(new_tran, p);
+ }
- return new_tran;
+ return new_tran;
}
/* parse the dependencies for a package, and add them to the transaction as */
@@ -832,67 +776,64 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
slapt_pkg_list_t *installed_pkgs,
slapt_pkg_info_t *pkg)
{
- unsigned int c;
- int dep_return = -1;
- slapt_pkg_list_t *deps = NULL;
+ unsigned int c;
+ int dep_return = -1;
+ slapt_pkg_list_t *deps = NULL;
- if (global_config->disable_dep_check == true)
- return 0;
+ if (global_config->disable_dep_check == true)
+ return 0;
- if (pkg == NULL)
- return 0;
+ if (pkg == NULL)
+ return 0;
- deps = slapt_init_pkg_list();
+ deps = slapt_init_pkg_list();
- dep_return = slapt_get_pkg_dependencies(
- global_config,avail_pkgs,installed_pkgs,pkg,
- deps,tran->conflict_err,tran->missing_err
- );
+ dep_return = slapt_get_pkg_dependencies(
+ global_config, avail_pkgs, installed_pkgs, pkg,
+ deps, tran->conflict_err, tran->missing_err);
- /* check to see if there where issues with dep checking */
- /* exclude the package if dep check barfed */
- if ((dep_return == -1) && (global_config->ignore_dep == false) &&
- (slapt_get_exact_pkg(tran->exclude_pkgs,pkg->name,pkg->version) == NULL)
- ) {
- slapt_free_pkg_list(deps);
- return -1;
- }
-
- /* loop through the deps */
- for (c = 0; c < deps->pkg_count; ++c) {
- unsigned int cindex = 0;
- slapt_pkg_info_t *dep = deps->pkgs[c];
- slapt_pkg_info_t *dep_installed = NULL;
- slapt_pkg_list_t *conflicts = NULL;
+ /* check to see if there where issues with dep checking */
+ /* exclude the package if dep check barfed */
+ if ((dep_return == -1) && (global_config->ignore_dep == false) &&
+ (slapt_get_exact_pkg(tran->exclude_pkgs, pkg->name, pkg->version) == NULL)) {
+ slapt_free_pkg_list(deps);
+ return -1;
+ }
+
+ /* loop through the deps */
+ for (c = 0; c < deps->pkg_count; ++c) {
+ unsigned int cindex = 0;
+ slapt_pkg_info_t *dep = deps->pkgs[c];
+ slapt_pkg_info_t *dep_installed = NULL;
+ slapt_pkg_list_t *conflicts = NULL;
- /*
+ /*
* the dep wouldn't get this far if it where excluded,
* so we don't check for that here
*/
- conflicts =
- slapt_is_conflicted(tran,avail_pkgs,installed_pkgs,dep);
+ conflicts =
+ slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, dep);
- for (cindex = 0; cindex < conflicts->pkg_count;cindex++) {
- slapt_add_remove_to_transaction(tran,conflicts->pkgs[cindex]);
- }
+ for (cindex = 0; cindex < conflicts->pkg_count; cindex++) {
+ slapt_add_remove_to_transaction(tran, conflicts->pkgs[cindex]);
+ }
- slapt_free_pkg_list(conflicts);
+ slapt_free_pkg_list(conflicts);
- dep_installed = slapt_get_newest_pkg(installed_pkgs,dep->name);
- if (dep_installed == NULL) {
- slapt_add_install_to_transaction(tran,dep);
- } else {
- /* add only if its a valid upgrade */
- if (slapt_cmp_pkgs(dep_installed,dep) < 0)
- slapt_add_upgrade_to_transaction(tran,dep_installed,dep);
+ dep_installed = slapt_get_newest_pkg(installed_pkgs, dep->name);
+ if (dep_installed == NULL) {
+ slapt_add_install_to_transaction(tran, dep);
+ } else {
+ /* add only if its a valid upgrade */
+ if (slapt_cmp_pkgs(dep_installed, dep) < 0)
+ slapt_add_upgrade_to_transaction(tran, dep_installed, dep);
+ }
}
- }
-
- slapt_free_pkg_list(deps);
+ slapt_free_pkg_list(deps);
- return 0;
+ return 0;
}
/* make sure pkg isn't conflicted with what's already in the transaction */
@@ -901,159 +842,146 @@ slapt_pkg_list_t *slapt_is_conflicted(slapt_transaction_t *tran,
slapt_pkg_list_t *installed_pkgs,
slapt_pkg_info_t *pkg)
{
- unsigned int i;
- slapt_pkg_list_t *conflicts = NULL;
- slapt_pkg_list_t *conflicts_in_transaction = slapt_init_pkg_list();
+ unsigned int i;
+ slapt_pkg_list_t *conflicts = NULL;
+ slapt_pkg_list_t *conflicts_in_transaction = slapt_init_pkg_list();
- /* if conflicts exist, check to see if they are installed
+ /* if conflicts exist, check to see if they are installed
or in the current transaction
*/
- conflicts = slapt_get_pkg_conflicts(avail_pkgs,installed_pkgs,pkg);
- for (i = 0; i < conflicts->pkg_count; ++i) {
- slapt_pkg_info_t *p = conflicts->pkgs[i];
+ conflicts = slapt_get_pkg_conflicts(avail_pkgs, installed_pkgs, pkg);
+ for (i = 0; i < conflicts->pkg_count; ++i) {
+ slapt_pkg_info_t *p = conflicts->pkgs[i];
- if ( slapt_search_upgrade_transaction(tran,p) == 1
- || slapt_get_newest_pkg(tran->install_pkgs,p->name) != NULL
- ) {
- printf(gettext("%s, which is to be installed, conflicts with %s\n"), p->name,pkg->name);
+ if (slapt_search_upgrade_transaction(tran, p) == 1 || slapt_get_newest_pkg(tran->install_pkgs, p->name) != NULL) {
+ printf(gettext("%s, which is to be installed, conflicts with %s\n"), p->name, pkg->name);
- slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
- }
- if (slapt_get_newest_pkg(installed_pkgs,p->name) != NULL) {
- printf(gettext("Installed %s conflicts with %s\n"), p->name,pkg->name);
+ slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
+ }
+ if (slapt_get_newest_pkg(installed_pkgs, p->name) != NULL) {
+ printf(gettext("Installed %s conflicts with %s\n"), p->name, pkg->name);
- slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
+ slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
+ }
}
- }
- slapt_free_pkg_list(conflicts);
+ slapt_free_pkg_list(conflicts);
- return conflicts_in_transaction;
+ return conflicts_in_transaction;
}
static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
- slapt_list_t *suggests = NULL;
- unsigned int i = 0;
-
- if (pkg->suggests == NULL || strlen(pkg->suggests) == 0) {
- return;
- }
-
- suggests = slapt_parse_delimited_list(pkg->suggests, ',');
+ slapt_list_t *suggests = NULL;
+ unsigned int i = 0;
- for (i = 0; i < suggests->count; i++) {
+ if (pkg->suggests == NULL || strlen(pkg->suggests) == 0) {
+ return;
+ }
- /* no need to add it if we already have it */
- if (slapt_search_transaction(tran,suggests->items[i]) == 1)
- continue;
+ suggests = slapt_parse_delimited_list(pkg->suggests, ',');
- slapt_add_list_item(tran->suggests, suggests->items[i]);
+ for (i = 0; i < suggests->count; i++) {
+ /* no need to add it if we already have it */
+ if (slapt_search_transaction(tran, suggests->items[i]) == 1)
+ continue;
- }
+ slapt_add_list_item(tran->suggests, suggests->items[i]);
+ }
- slapt_free_list(suggests);
+ slapt_free_list(suggests);
}
int slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- unsigned int i,found = 1, not_found = 0;
-
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];
+ unsigned int i, found = 1, not_found = 0;
- if ((strcmp(pkg->name,p->name) == 0)
- && (strcmp(pkg->version,p->version) == 0))
- return found;
-
- }
-
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->upgrade_pkgs->pkgs[i]->upgrade;
-
- if ((strcmp(pkg->name,p->name) == 0)
- && (strcmp(pkg->version,p->version) == 0))
- return found;
+ for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];
- }
+ if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
+ return found;
+ }
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->remove_pkgs->pkgs[i];
+ for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *p = tran->upgrade_pkgs->pkgs[i]->upgrade;
- if ((strcmp(pkg->name,p->name) == 0)
- && (strcmp(pkg->version,p->version) == 0))
- return found;
+ if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
+ return found;
+ }
- }
+ for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *p = tran->remove_pkgs->pkgs[i];
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->exclude_pkgs->pkgs[i];
+ if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
+ return found;
+ }
- if ((strcmp(pkg->name,p->name) == 0)
- && (strcmp(pkg->version,p->version) == 0))
- return found;
+ for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
+ slapt_pkg_info_t *p = tran->exclude_pkgs->pkgs[i];
- }
+ if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
+ return found;
+ }
- return not_found;
+ return not_found;
}
static slapt_queue_t *slapt_queue_init(void)
{
- slapt_queue_t *t = NULL;
- t = slapt_malloc(sizeof *t);
- t->pkgs = slapt_malloc(sizeof *t->pkgs);
- t->count = 0;
+ slapt_queue_t *t = NULL;
+ t = slapt_malloc(sizeof *t);
+ t->pkgs = slapt_malloc(sizeof *t->pkgs);
+ t->count = 0;
- return t;
+ return t;
}
static void queue_add_install(slapt_queue_t *t, slapt_pkg_info_t *p)
{
- slapt_queue_i **tmp;
- tmp = realloc(t->pkgs, sizeof *t->pkgs * (t->count + 1));
+ slapt_queue_i **tmp;
+ tmp = realloc(t->pkgs, sizeof *t->pkgs * (t->count + 1));
- if (!tmp)
- return;
+ if (!tmp)
+ return;
- t->pkgs = tmp;
- t->pkgs[t->count] = slapt_malloc(sizeof *t->pkgs[t->count]);
- t->pkgs[t->count]->pkg.i = p;
- t->pkgs[t->count]->type = INSTALL;
- ++t->count;
+ t->pkgs = tmp;
+ t->pkgs[t->count] = slapt_malloc(sizeof *t->pkgs[t->count]);
+ t->pkgs[t->count]->pkg.i = p;
+ t->pkgs[t->count]->type = INSTALL;
+ ++t->count;
}
static void queue_add_upgrade(slapt_queue_t *t, slapt_pkg_upgrade_t *p)
{
- slapt_queue_i **tmp;
- tmp = realloc(t->pkgs, sizeof *t->pkgs * (t->count + 1));
+ slapt_queue_i **tmp;
+ tmp = realloc(t->pkgs, sizeof *t->pkgs * (t->count + 1));
- if (!tmp)
- return;
+ if (!tmp)
+ return;
- t->pkgs = tmp;
- t->pkgs[t->count] = slapt_malloc(sizeof *t->pkgs[t->count]);
- t->pkgs[t->count]->pkg.u = p;
- t->pkgs[t->count]->type = UPGRADE;
- ++t->count;
+ t->pkgs = tmp;
+ t->pkgs[t->count] = slapt_malloc(sizeof *t->pkgs[t->count]);
+ t->pkgs[t->count]->pkg.u = p;
+ t->pkgs[t->count]->type = UPGRADE;
+ ++t->count;
}
static void queue_free(slapt_queue_t *t)
{
- unsigned int i;
- for (i = 0; i < t->count; ++i) {
- free(t->pkgs[i]);
- }
- free(t->pkgs);
- free(t);
+ unsigned int i;
+ for (i = 0; i < t->count; ++i) {
+ free(t->pkgs[i]);
+ }
+ free(t->pkgs);
+ free(t);
}
void slapt_generate_suggestions(slapt_transaction_t *tran)
{
- unsigned int i;
- for (i = 0;i < tran->install_pkgs->pkg_count; ++i) {
- add_suggestion(tran,tran->install_pkgs->pkgs[i]);
- }
+ unsigned int i;
+ for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
+ add_suggestion(tran, tran->install_pkgs->pkgs[i]);
+ }
}
-
diff --git a/src/transaction.h b/src/transaction.h
index d27425b..b2455fa 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -23,24 +23,27 @@
#define MAX_LINE_LEN 80
typedef struct {
- union { slapt_pkg_info_t *i; slapt_pkg_upgrade_t *u; } pkg;
- unsigned int type; /* this is enum slapt_action defined in main.h */
+ union {
+ slapt_pkg_info_t *i;
+ slapt_pkg_upgrade_t *u;
+ } pkg;
+ unsigned int type; /* this is enum slapt_action defined in main.h */
} slapt_queue_i;
typedef struct {
- slapt_queue_i **pkgs;
- unsigned int count;
+ slapt_queue_i **pkgs;
+ unsigned int count;
} slapt_queue_t;
typedef struct {
- slapt_pkg_list_t *install_pkgs;
- slapt_pkg_upgrade_list_t *upgrade_pkgs;
- slapt_pkg_list_t *remove_pkgs;
- slapt_pkg_list_t *exclude_pkgs;
- slapt_list_t *suggests;
- slapt_pkg_err_list_t *conflict_err;
- slapt_pkg_err_list_t *missing_err;
- slapt_queue_t *queue;
+ slapt_pkg_list_t *install_pkgs;
+ slapt_pkg_upgrade_list_t *upgrade_pkgs;
+ slapt_pkg_list_t *remove_pkgs;
+ slapt_pkg_list_t *exclude_pkgs;
+ slapt_list_t *suggests;
+ slapt_pkg_err_list_t *conflict_err;
+ slapt_pkg_err_list_t *missing_err;
+ slapt_queue_t *queue;
} slapt_transaction_t;
/* fill in transaction structure with defaults */
@@ -49,7 +52,7 @@ slapt_transaction_t *slapt_init_transaction(void);
download and install/remove/upgrade packages as defined in the transaction
returns 0 on success
*/
-int slapt_handle_transaction(const slapt_rc_config *,slapt_transaction_t *);
+int slapt_handle_transaction(const slapt_rc_config *, slapt_transaction_t *);
/* add package for installation to transaction */
void slapt_add_install_to_transaction(slapt_transaction_t *,
@@ -63,8 +66,8 @@ void slapt_add_upgrade_to_transaction(slapt_transaction_t *,
slapt_pkg_info_t *upgrade_pkg);
/* add package to reinstall to transaction */
void slapt_add_reinstall_to_transaction(slapt_transaction_t *,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *upgrade_pkg);
+ slapt_pkg_info_t *installed_pkg,
+ slapt_pkg_info_t *upgrade_pkg);
/* add package to exclude to transaction */
void slapt_add_exclude_to_transaction(slapt_transaction_t *,
slapt_pkg_info_t *pkg);
@@ -73,7 +76,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg);
/* search transaction by package name. returns 1 if found, 0 otherwise */
-int slapt_search_transaction(slapt_transaction_t *,char *pkg_name);
+int slapt_search_transaction(slapt_transaction_t *, char *pkg_name);
/*
search transaction by package attributes
returns 1 if found, 0 otherwise
diff --git a/t/common.h b/t/common.h
index 8679349..5ef9a32 100644
--- a/t/common.h
+++ b/t/common.h
@@ -3,7 +3,7 @@
#define TEST_COMMON 1
#ifndef _GNU_SOURCE
- #define _GNU_SOURCE
+#define _GNU_SOURCE
#endif
#include <stdlib.h>
diff --git a/t/test.c b/t/test.c
index 0fa4f07..c889e40 100644
--- a/t/test.c
+++ b/t/test.c
@@ -6,68 +6,65 @@
#include "test_transaction.h"
slapt_pkg_info_t pkg = {
- "8598a2a6d683d098b09cdc938de1e3c7",
- "gslapt",
- "0.3.15-i386-1",
- "http://software.jaos.org/slackpacks/11.0/",
- ".",
- "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
- "",
- "",
- "",
- ".tgz",
- 115,
- 440,
- SLAPT_PRIORITY_DEFAULT,
- true
-};
+ "8598a2a6d683d098b09cdc938de1e3c7",
+ "gslapt",
+ "0.3.15-i386-1",
+ "http://software.jaos.org/slackpacks/11.0/",
+ ".",
+ "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
+ "",
+ "",
+ "",
+ ".tgz",
+ 115,
+ 440,
+ SLAPT_PRIORITY_DEFAULT,
+ true};
int _progress_cb(void *clientp, double dltotal, double dlnow,
- double ultotal, double ulnow)
+ double ultotal, double ulnow)
{
- (void) clientp;
- (void) dltotal;
- (void) dlnow;
- (void) ultotal;
- (void) ulnow;
- return 0;
+ (void)clientp;
+ (void)dltotal;
+ (void)dlnow;
+ (void)ultotal;
+ (void)ulnow;
+ return 0;
}
-
Suite *slapt_test_suite()
{
- Suite *s = suite_create ("Slapt");
-
- /* generic tests */
- TCase *tc_packages = tcase_create ("Core");
- /* tcase_add_checked_fixture (tc_packages, setup, teardown); */
- /* tcase_add_test (tc_packages, test_money_create); */
- suite_add_tcase (s, tc_packages);
+ Suite *s = suite_create("Slapt");
- return s;
+ /* generic tests */
+ TCase *tc_packages = tcase_create("Core");
+ /* tcase_add_checked_fixture (tc_packages, setup, teardown); */
+ /* tcase_add_test (tc_packages, test_money_create); */
+ suite_add_tcase(s, tc_packages);
+ return s;
}
int main(void)
{
- int number_failed;
+ int number_failed;
- Suite *s = slapt_test_suite();
- SRunner *sr = srunner_create (s);
+ Suite *s = slapt_test_suite();
+ SRunner *sr = srunner_create(s);
#ifdef SLAPT_HAS_GPGME
- gpgme_check_version (NULL);
+ gpgme_check_version(NULL);
#endif
- srunner_add_suite(sr, common_test_suite());
- srunner_add_suite(sr, configuration_test_suite());
- srunner_add_suite(sr, curl_test_suite());
- srunner_add_suite(sr, packages_test_suite());
- srunner_add_suite(sr, transaction_test_suite());
+ srunner_add_suite(sr, common_test_suite());
+ srunner_add_suite(sr, configuration_test_suite());
+ srunner_add_suite(sr, curl_test_suite());
+ srunner_add_suite(sr, packages_test_suite());
+ srunner_add_suite(sr, transaction_test_suite());
- srunner_run_all (sr, CK_NORMAL);
- number_failed = srunner_ntests_failed (sr);
+ srunner_run_all(sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed(sr);
- srunner_free (sr);
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+ srunner_free(sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/t/test_common.c b/t/test_common.c
index 9d5181a..8254e19 100644
--- a/t/test_common.c
+++ b/t/test_common.c
@@ -1,96 +1,88 @@
#include "test_common.h"
-
-START_TEST (test_slapt_open_file)
+START_TEST(test_slapt_open_file)
{
- const char *file = "./PACKAGES.TXT";
+ const char *file = "./PACKAGES.TXT";
- FILE *f = slapt_open_file(file,"w");
- fail_if ( fileno(f) == -1, NULL);
+ FILE *f = slapt_open_file(file, "w");
+ fail_if(fileno(f) == -1, NULL);
- fclose(f);
- unlink(file);
+ fclose(f);
+ unlink(file);
}
END_TEST
-
-START_TEST (test_regex)
+START_TEST(test_regex)
{
- slapt_regex_t *regex = slapt_init_regex("^[a-z]+$");
- slapt_regex_t *invalid_regex = slapt_init_regex("^[-");
+ slapt_regex_t *regex = slapt_init_regex("^[a-z]+$");
+ slapt_regex_t *invalid_regex = slapt_init_regex("^[-");
- fail_if ( regex == NULL );
- fail_unless ( invalid_regex == NULL );
+ fail_if(regex == NULL);
+ fail_unless(invalid_regex == NULL);
- slapt_execute_regex(regex, "abc");
- fail_if (regex->reg_return == REG_NOMATCH);
+ slapt_execute_regex(regex, "abc");
+ fail_if(regex->reg_return == REG_NOMATCH);
- slapt_execute_regex(regex, "123");
- fail_unless (regex->reg_return == REG_NOMATCH);
+ slapt_execute_regex(regex, "123");
+ fail_unless(regex->reg_return == REG_NOMATCH);
- slapt_free_regex(regex);
+ slapt_free_regex(regex);
}
END_TEST
-
-START_TEST (test_slapt_create_dir_structure)
+START_TEST(test_slapt_create_dir_structure)
{
- const char *dir_name = "var/cache/slapt-get";
- DIR *d = NULL;
+ const char *dir_name = "var/cache/slapt-get";
+ DIR *d = NULL;
- slapt_create_dir_structure("var/cache/slapt-get");
+ slapt_create_dir_structure("var/cache/slapt-get");
- d = opendir(dir_name);
+ d = opendir(dir_name);
- fail_if (d == NULL);
+ fail_if(d == NULL);
- closedir(d);
+ closedir(d);
- rmdir(dir_name);
- rmdir("var");
+ rmdir(dir_name);
+ rmdir("var");
}
END_TEST
-
-START_TEST (test_slapt_gen_md5_sum_of_file)
+START_TEST(test_slapt_gen_md5_sum_of_file)
{
- const char *file = "data/md5_dummy";
- char result_sum[SLAPT_MD5_STR_LEN];
- FILE *f = fopen(file,"r");
+ const char *file = "data/md5_dummy";
+ char result_sum[SLAPT_MD5_STR_LEN];
+ FILE *f = fopen(file, "r");
- slapt_gen_md5_sum_of_file(f,result_sum);
- fail_unless ( strcmp("96ee23abf2770468e1aac755a0a99809",result_sum) == 0 );
+ slapt_gen_md5_sum_of_file(f, result_sum);
+ fail_unless(strcmp("96ee23abf2770468e1aac755a0a99809", result_sum) == 0);
- fclose(f);
-
+ fclose(f);
}
END_TEST
-
-START_TEST (test_slapt_str_replace_chr)
+START_TEST(test_slapt_str_replace_chr)
{
- const char *s = "/fake/path/to/file";
- char *s_modified = slapt_str_replace_chr(s, '/', '_');
+ const char *s = "/fake/path/to/file";
+ char *s_modified = slapt_str_replace_chr(s, '/', '_');
- fail_unless ( strcmp(s_modified,"_fake_path_to_file") == 0 );
+ fail_unless(strcmp(s_modified, "_fake_path_to_file") == 0);
- free(s_modified);
+ free(s_modified);
}
END_TEST
-
Suite *common_test_suite()
{
- Suite *s = suite_create ("Common");
- TCase *tc = tcase_create ("Common");
+ Suite *s = suite_create("Common");
+ TCase *tc = tcase_create("Common");
- tcase_add_test (tc, test_slapt_open_file);
- tcase_add_test (tc, test_regex);
- tcase_add_test (tc, test_slapt_create_dir_structure);
- tcase_add_test (tc, test_slapt_gen_md5_sum_of_file);
- tcase_add_test (tc, test_slapt_str_replace_chr);
+ tcase_add_test(tc, test_slapt_open_file);
+ tcase_add_test(tc, test_regex);
+ tcase_add_test(tc, test_slapt_create_dir_structure);
+ tcase_add_test(tc, test_slapt_gen_md5_sum_of_file);
+ tcase_add_test(tc, test_slapt_str_replace_chr);
- suite_add_tcase (s, tc);
- return s;
+ suite_add_tcase(s, tc);
+ return s;
}
-
diff --git a/t/test_configuration.c b/t/test_configuration.c
index 8d4f9f0..e7ce5ab 100644
--- a/t/test_configuration.c
+++ b/t/test_configuration.c
@@ -1,116 +1,107 @@
#include "test_configuration.h"
-
-START_TEST (test_struct_config)
+START_TEST(test_struct_config)
{
- slapt_rc_config *rc = NULL;
-
- rc = slapt_init_config();
- fail_if (rc == NULL);
- slapt_free_rc_config(rc);
- rc = NULL;
-
- rc = slapt_read_rc_config("./data/rc1");
- fail_if (rc == NULL);
- {
- slapt_source_list_t *s = rc->sources;
- slapt_list_t *e = rc->exclude_list;
-
- fail_if (s->count < 1);
- fail_if (e->count != 6);
- }
- slapt_free_rc_config(rc);
- rc = NULL;
-
+ slapt_rc_config *rc = NULL;
+
+ rc = slapt_init_config();
+ fail_if(rc == NULL);
+ slapt_free_rc_config(rc);
+ rc = NULL;
+
+ rc = slapt_read_rc_config("./data/rc1");
+ fail_if(rc == NULL);
+ {
+ slapt_source_list_t *s = rc->sources;
+ slapt_list_t *e = rc->exclude_list;
+
+ fail_if(s->count < 1);
+ fail_if(e->count != 6);
+ }
+ slapt_free_rc_config(rc);
+ rc = NULL;
}
END_TEST
-
-START_TEST (test_working_dir)
+START_TEST(test_working_dir)
{
- DIR *d = NULL;
- slapt_rc_config *rc = slapt_read_rc_config("data/rc1");
+ DIR *d = NULL;
+ slapt_rc_config *rc = slapt_read_rc_config("data/rc1");
- /* check that working_dir exists or make it if permissions allow */
- /* void slapt_working_dir_init(const slapt_rc_config *global_config); */
+ /* check that working_dir exists or make it if permissions allow */
+ /* void slapt_working_dir_init(const slapt_rc_config *global_config); */
- slapt_working_dir_init(rc);
-
- d = opendir("data/slapt-get");
- fail_if (d == NULL);
- closedir(d);
- rmdir("data/slapt-get");
+ slapt_working_dir_init(rc);
+ d = opendir("data/slapt-get");
+ fail_if(d == NULL);
+ closedir(d);
+ rmdir("data/slapt-get");
}
END_TEST
-
-START_TEST (test_exclude_list)
+START_TEST(test_exclude_list)
{
- slapt_list_t *e = slapt_init_list();
+ slapt_list_t *e = slapt_init_list();
- fail_if (e == NULL);
- fail_if (e->count != 0);
+ fail_if(e == NULL);
+ fail_if(e->count != 0);
- slapt_add_list_item(e,"^foo$");
- fail_if (e->count != 1);
+ slapt_add_list_item(e, "^foo$");
+ fail_if(e->count != 1);
- slapt_remove_list_item(e,"^foo$");
- fail_if (e->count != 0);
+ slapt_remove_list_item(e, "^foo$");
+ fail_if(e->count != 0);
- slapt_remove_list_item(e,"no_such_exclude");
- fail_if (e->count != 0);
+ slapt_remove_list_item(e, "no_such_exclude");
+ fail_if(e->count != 0);
- slapt_free_list(e);
+ slapt_free_list(e);
}
END_TEST
-
-START_TEST (test_source_list)
+START_TEST(test_source_list)
{
- slapt_source_t *src = slapt_init_source("http://www.test.org/dist");
- slapt_source_list_t *s = slapt_init_source_list();
- fail_if (s == NULL);
- fail_if (s->count != 0);
+ slapt_source_t *src = slapt_init_source("http://www.test.org/dist");
+ slapt_source_list_t *s = slapt_init_source_list();
+ fail_if(s == NULL);
+ fail_if(s->count != 0);
- fail_if (src == NULL);
- slapt_add_source(s, src);
- fail_if (s->count != 1);
+ fail_if(src == NULL);
+ slapt_add_source(s, src);
+ fail_if(s->count != 1);
- slapt_remove_source (s,"http://www.test.org/dist/");
- fail_if (s->count != 0);
+ slapt_remove_source(s, "http://www.test.org/dist/");
+ fail_if(s->count != 0);
- slapt_free_source_list(s);
+ slapt_free_source_list(s);
}
END_TEST
-START_TEST (test_source_trimming)
+START_TEST(test_source_trimming)
{
- slapt_source_t *src1 = slapt_init_source("http://www.test.org/dist ");
- slapt_source_t *src2 = slapt_init_source("http://www.test.org/dist:PREFERRED ");
+ slapt_source_t *src1 = slapt_init_source("http://www.test.org/dist ");
+ slapt_source_t *src2 = slapt_init_source("http://www.test.org/dist:PREFERRED ");
- fail_if ( strcmp (src1->url,"http://www.test.org/dist/") != 0);
- fail_if ( strcmp (src2->url,"http://www.test.org/dist/") != 0);
+ fail_if(strcmp(src1->url, "http://www.test.org/dist/") != 0);
+ fail_if(strcmp(src2->url, "http://www.test.org/dist/") != 0);
- slapt_free_source(src1);
- slapt_free_source(src2);
+ slapt_free_source(src1);
+ slapt_free_source(src2);
}
END_TEST
-
-
Suite *configuration_test_suite()
{
- Suite *s = suite_create ("Configuration");
- TCase *tc = tcase_create ("Configuration");
+ Suite *s = suite_create("Configuration");
+ TCase *tc = tcase_create("Configuration");
- tcase_add_test (tc, test_struct_config);
- tcase_add_test (tc, test_working_dir);
- tcase_add_test (tc, test_exclude_list);
- tcase_add_test (tc, test_source_list);
- tcase_add_test (tc, test_source_trimming);
+ tcase_add_test(tc, test_struct_config);
+ tcase_add_test(tc, test_working_dir);
+ tcase_add_test(tc, test_exclude_list);
+ tcase_add_test(tc, test_source_list);
+ tcase_add_test(tc, test_source_trimming);
- suite_add_tcase (s, tc);
- return s;
+ suite_add_tcase(s, tc);
+ return s;
}
-
diff --git a/t/test_curl.c b/t/test_curl.c
index a7f792e..8e8aff0 100644
--- a/t/test_curl.c
+++ b/t/test_curl.c
@@ -4,110 +4,105 @@ extern slapt_pkg_info_t pkg;
extern int _progress_cb(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow);
-START_TEST (test_slapt_get_mirror_data_from_source)
+START_TEST(test_slapt_get_mirror_data_from_source)
{
- FILE *f = NULL;
- const char *err = NULL;
- slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
- const char *url = rc->sources->src[0]->url;
- char *packages = "PACKAGES.TXT";
- char *packages_gz = "PACKAGES.TXT.gz";
- char *checksums = "CHECKSUMS.md5";
- char *checksums_gz = "CHECKSUMS.md5.gz";
- rc->progress_cb = _progress_cb; /* silence */
-
- f = slapt_open_file("data/PACKAGES.TXT","w+b");
- err = slapt_get_mirror_data_from_source(f, rc, url, packages);
- fail_if (err);
- fclose(f);
-
- f = slapt_open_file("data/PACKAGES.TXT.gz","w+b");
- err = slapt_get_mirror_data_from_source(f, rc, url, packages_gz);
- fail_if (err);
- fclose(f);
-
- f = slapt_open_file("data/CHECKSUMS.md5","w+b");
- err = slapt_get_mirror_data_from_source(f, rc, url, checksums);
- fail_if (err);
- fclose(f);
-
- f = slapt_open_file("data/CHECKSUMS.md5.gz","w+b");
- err = slapt_get_mirror_data_from_source(f, rc, url, checksums_gz);
- fail_if (err);
- fclose(f);
-
- unlink("data/PACKAGES.TXT");
- unlink("data/PACKAGES.TXT.gz");
- unlink("data/CHECKSUMS.md5");
- unlink("data/CHECKSUMS.md5.gz");
-
- slapt_free_rc_config(rc);
+ FILE *f = NULL;
+ const char *err = NULL;
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ const char *url = rc->sources->src[0]->url;
+ char *packages = "PACKAGES.TXT";
+ char *packages_gz = "PACKAGES.TXT.gz";
+ char *checksums = "CHECKSUMS.md5";
+ char *checksums_gz = "CHECKSUMS.md5.gz";
+ rc->progress_cb = _progress_cb; /* silence */
+
+ f = slapt_open_file("data/PACKAGES.TXT", "w+b");
+ err = slapt_get_mirror_data_from_source(f, rc, url, packages);
+ fail_if(err);
+ fclose(f);
+
+ f = slapt_open_file("data/PACKAGES.TXT.gz", "w+b");
+ err = slapt_get_mirror_data_from_source(f, rc, url, packages_gz);
+ fail_if(err);
+ fclose(f);
+
+ f = slapt_open_file("data/CHECKSUMS.md5", "w+b");
+ err = slapt_get_mirror_data_from_source(f, rc, url, checksums);
+ fail_if(err);
+ fclose(f);
+
+ f = slapt_open_file("data/CHECKSUMS.md5.gz", "w+b");
+ err = slapt_get_mirror_data_from_source(f, rc, url, checksums_gz);
+ fail_if(err);
+ fclose(f);
+
+ unlink("data/PACKAGES.TXT");
+ unlink("data/PACKAGES.TXT.gz");
+ unlink("data/CHECKSUMS.md5");
+ unlink("data/CHECKSUMS.md5.gz");
+
+ slapt_free_rc_config(rc);
}
END_TEST
-
-START_TEST (test_slapt_download_pkg)
+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);
+ 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);
+ err = slapt_download_pkg(rc, &pkg, NULL);
+ fail_if(err);
- slapt_free_rc_config(rc);
+ slapt_free_rc_config(rc);
}
END_TEST
-
-START_TEST (test_head)
+START_TEST(test_head)
{
- char *head = slapt_head_request("http://www.google.com/");
- fail_if (head == NULL);
- fail_if ( strstr(head,"Content-Type") == NULL);
+ char *head = slapt_head_request("http://www.google.com/");
+ fail_if(head == NULL);
+ fail_if(strstr(head, "Content-Type") == NULL);
- slapt_write_head_cache(head, "data/head_request");
- free(head);
- head = NULL;
+ slapt_write_head_cache(head, "data/head_request");
+ free(head);
+ head = NULL;
- head = slapt_head_mirror_data("http://www.google.com/","data/head_request");
- fail_unless (head == NULL);
- free(head);
- head = NULL;
+ head = slapt_head_mirror_data("http://www.google.com/", "data/head_request");
+ fail_unless(head == NULL);
+ free(head);
+ head = NULL;
- head = slapt_read_head_cache("data/head_request");
- fail_if (head == NULL);
- free(head);
+ head = slapt_read_head_cache("data/head_request");
+ fail_if(head == NULL);
+ free(head);
- slapt_clear_head_cache("data/head_request");
- unlink("data/head_request.head");
+ slapt_clear_head_cache("data/head_request");
+ unlink("data/head_request.head");
}
END_TEST
-
-START_TEST (test_progress_data)
+START_TEST(test_progress_data)
{
- struct slapt_progress_data *d = slapt_init_progress_data();
- fail_if (d == NULL);
- fail_if (d->bytes != 0);
- fail_if (d->start == 0);
- slapt_free_progress_data(d);
+ struct slapt_progress_data *d = slapt_init_progress_data();
+ fail_if(d == NULL);
+ fail_if(d->bytes != 0);
+ fail_if(d->start == 0);
+ slapt_free_progress_data(d);
}
END_TEST
-
Suite *curl_test_suite()
{
- Suite *s = suite_create ("Curl");
- TCase *tc = tcase_create ("Curl");
+ Suite *s = suite_create("Curl");
+ TCase *tc = tcase_create("Curl");
- tcase_add_test (tc, test_slapt_get_mirror_data_from_source);
- tcase_add_test (tc, test_slapt_download_pkg);
- tcase_add_test (tc, test_head);
- tcase_add_test (tc, test_progress_data);
+ tcase_add_test(tc, test_slapt_get_mirror_data_from_source);
+ tcase_add_test(tc, test_slapt_download_pkg);
+ tcase_add_test(tc, test_head);
+ tcase_add_test(tc, test_progress_data);
- suite_add_tcase (s, tc);
- return s;
+ suite_add_tcase(s, tc);
+ return s;
}
-
diff --git a/t/test_packages.c b/t/test_packages.c
index 18445a5..3b86a65 100644
--- a/t/test_packages.c
+++ b/t/test_packages.c
@@ -4,170 +4,168 @@ extern slapt_pkg_info_t pkg;
extern int _progress_cb(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow);
-START_TEST (test_struct_pkg)
+START_TEST(test_struct_pkg)
{
- slapt_pkg_info_t *cpy = slapt_init_pkg();
- fail_if (cpy == NULL);
+ slapt_pkg_info_t *cpy = slapt_init_pkg();
+ fail_if(cpy == NULL);
- cpy = slapt_copy_pkg(cpy, &pkg);
- fail_if (cpy == NULL);
+ cpy = slapt_copy_pkg(cpy, &pkg);
+ fail_if(cpy == NULL);
- {
- char *pkg_str = slapt_stringify_pkg(&pkg);
- char *cpy_str = slapt_stringify_pkg(cpy);
+ {
+ char *pkg_str = slapt_stringify_pkg(&pkg);
+ char *cpy_str = slapt_stringify_pkg(cpy);
- fail_if (pkg_str == NULL);
- fail_if (cpy_str == NULL);
- fail_unless (strcmp(pkg_str,cpy_str) == 0);
+ fail_if(pkg_str == NULL);
+ fail_if(cpy_str == NULL);
+ fail_unless(strcmp(pkg_str, cpy_str) == 0);
- free(pkg_str);
- free(cpy_str);
- }
+ free(pkg_str);
+ free(cpy_str);
+ }
- slapt_free_pkg(cpy);
+ slapt_free_pkg(cpy);
}
END_TEST
-
-START_TEST (test_pkg_info)
+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);
+ 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_pkg_list)
+START_TEST(test_pkg_list)
{
- slapt_pkg_list_t *list = slapt_init_pkg_list();
- fail_if (list == NULL);
- fail_unless (list->pkg_count == 0);
+ slapt_pkg_list_t *list = slapt_init_pkg_list();
+ fail_if(list == NULL);
+ fail_unless(list->pkg_count == 0);
- slapt_add_pkg_to_pkg_list(list, &pkg);
- fail_unless (list->pkg_count == 1);
+ slapt_add_pkg_to_pkg_list(list, &pkg);
+ fail_unless(list->pkg_count == 1);
- slapt_free_pkg_list(list);
- list = NULL;
+ slapt_free_pkg_list(list);
+ list = NULL;
- list = slapt_get_installed_pkgs();
- fail_if (list == NULL);
- /* fail_unless (list->pkg_count == 0); could be anything */
- slapt_free_pkg_list(list);
- list = NULL;
+ list = slapt_get_installed_pkgs();
+ fail_if(list == NULL);
+ /* fail_unless (list->pkg_count == 0); could be anything */
+ slapt_free_pkg_list(list);
+ list = NULL;
-
- /* parse the PACKAGES.TXT file
+ /* parse the PACKAGES.TXT file
slapt_pkg_list_t *slapt_parse_packages_txt(FILE *);
*/
- /*
+ /*
return a list of available packages must be already chdir'd to
rc_config->working_dir. Otherwise, open a filehandle to the package data
and pass it to slapt_parse_packages_txt();
slapt_pkg_list_t *slapt_get_available_pkgs(void);
*/
- /* get a list of obsolete packages
+ /* get a list of obsolete packages
slapt_pkg_list_t *
slapt_get_obsolete_pkgs ( const slapt_rc_config *global_config,
slapt_pkg_list_t *avail_pkgs,
slapt_pkg_list_t *installed_pkgs);
*/
- /*
+ /*
fill in the md5sum of the package
void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file);
*/
-
}
END_TEST
-
-START_TEST (test_pkg_search)
+START_TEST(test_pkg_search)
{
- slapt_pkg_info_t *p = NULL;
- slapt_pkg_list_t *l = NULL;
- slapt_pkg_list_t *list = slapt_init_pkg_list();
- slapt_add_pkg_to_pkg_list(list, &pkg);
+ slapt_pkg_info_t *p = NULL;
+ slapt_pkg_list_t *l = NULL;
+ slapt_pkg_list_t *list = slapt_init_pkg_list();
+ slapt_add_pkg_to_pkg_list(list, &pkg);
- p = slapt_get_newest_pkg(list, "gslapt");
- fail_if (p == NULL);
+ p = slapt_get_newest_pkg(list, "gslapt");
+ fail_if(p == NULL);
- p = slapt_get_exact_pkg(list, "gslapt", "0.3.15-i386-1");
- fail_if (p == NULL);
+ p = slapt_get_exact_pkg(list, "gslapt", "0.3.15-i386-1");
+ fail_if(p == NULL);
- p = slapt_get_pkg_by_details(list, "gslapt", "0.3.15-i386-1", ".");
- fail_if (p == NULL);
+ p = slapt_get_pkg_by_details(list, "gslapt", "0.3.15-i386-1", ".");
+ fail_if(p == NULL);
- l = slapt_search_pkg_list(list, "^gslapt$");
- fail_if (l == NULL);
- fail_unless (l->pkg_count == 1);
-
- slapt_free_pkg_list(list);
+ l = slapt_search_pkg_list(list, "^gslapt$");
+ fail_if(l == NULL);
+ fail_unless(l->pkg_count == 1);
+ slapt_free_pkg_list(list);
}
END_TEST
-
-START_TEST (test_pkgtool)
+START_TEST(test_pkgtool)
{
- slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
- /* disabled... */
- /*
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ /* disabled... */
+ /*
int r = -1;
r = slapt_install_pkg(rc, &pkg);
r = slapt_upgrade_pkg(rc, &pkg);
r = slapt_remove_pkg(rc, &pkg);
*/
- slapt_free_rc_config(rc);
+ slapt_free_rc_config(rc);
}
END_TEST
@@ -189,255 +187,247 @@ http://software.jaos.org/pipermail/slapt-get-devel/2008-November/000762.html
- If the priorities tie, then the package with the highest version
number wins.
*/
-START_TEST (test_pkg_version)
+START_TEST(test_pkg_version)
{
- slapt_pkg_info_t mirror_pkg1 = {
- "8598a2a6d683d098b09cdc938de1e3c7",
- "gslapt",
- "0.3.15-i386-1",
- "http://software.jaos.org/slackpacks/11.0/",
- ".",
- "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
- "",
- "",
- "",
- ".tgz",
- 115,
- 440,
- SLAPT_PRIORITY_PREFERRED,
- false
- };
- slapt_pkg_info_t mirror_pkg2 = {
- "8598a2a6d683d098b09cdc938de1e3c7",
- "gslapt",
- "0.3.15-i386-2",
- "http://software.jaos.org/slackpacks/11.0/",
- ".",
- "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
- "",
- "",
- "",
- ".tgz",
- 115,
- 440,
- SLAPT_PRIORITY_DEFAULT,
- false
- };
- slapt_pkg_info_t installed_pkg = {
- "8598a2a6d683d098b09cdc938de1e3c7",
- "gslapt",
- "0.3.15-i386-1",
- "http://software.jaos.org/slackpacks/11.0/",
- ".",
- "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
- "",
- "",
- "",
- ".tgz",
- 115,
- 440,
- SLAPT_PRIORITY_DEFAULT,
- true
- };
-
- /* mirror_pkg1 has a higher priority, and should win */
- fail_unless (slapt_cmp_pkgs(&mirror_pkg1,&mirror_pkg2) == 1);
-
- /* both have the same priority, mirror_pkg2 has a higher version and should win */
- mirror_pkg1.priority = SLAPT_PRIORITY_DEFAULT;
- fail_unless (slapt_cmp_pkgs(&mirror_pkg1,&mirror_pkg2) == -1);
-
- /* installed_pkg and mirror_pkg1 have the exact same version and should be
+ slapt_pkg_info_t mirror_pkg1 = {
+ "8598a2a6d683d098b09cdc938de1e3c7",
+ "gslapt",
+ "0.3.15-i386-1",
+ "http://software.jaos.org/slackpacks/11.0/",
+ ".",
+ "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
+ "",
+ "",
+ "",
+ ".tgz",
+ 115,
+ 440,
+ SLAPT_PRIORITY_PREFERRED,
+ false};
+ slapt_pkg_info_t mirror_pkg2 = {
+ "8598a2a6d683d098b09cdc938de1e3c7",
+ "gslapt",
+ "0.3.15-i386-2",
+ "http://software.jaos.org/slackpacks/11.0/",
+ ".",
+ "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
+ "",
+ "",
+ "",
+ ".tgz",
+ 115,
+ 440,
+ SLAPT_PRIORITY_DEFAULT,
+ false};
+ slapt_pkg_info_t installed_pkg = {
+ "8598a2a6d683d098b09cdc938de1e3c7",
+ "gslapt",
+ "0.3.15-i386-1",
+ "http://software.jaos.org/slackpacks/11.0/",
+ ".",
+ "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
+ "",
+ "",
+ "",
+ ".tgz",
+ 115,
+ 440,
+ SLAPT_PRIORITY_DEFAULT,
+ true};
+
+ /* mirror_pkg1 has a higher priority, and should win */
+ fail_unless(slapt_cmp_pkgs(&mirror_pkg1, &mirror_pkg2) == 1);
+
+ /* both have the same priority, mirror_pkg2 has a higher version and should win */
+ mirror_pkg1.priority = SLAPT_PRIORITY_DEFAULT;
+ fail_unless(slapt_cmp_pkgs(&mirror_pkg1, &mirror_pkg2) == -1);
+
+ /* installed_pkg and mirror_pkg1 have the exact same version and should be
equal regardless of priority */
- fail_unless (slapt_cmp_pkgs(&installed_pkg,&mirror_pkg1) == 0);
+ fail_unless(slapt_cmp_pkgs(&installed_pkg, &mirror_pkg1) == 0);
- /* installed_pkg has a higher priority and should win, regardless of the
+ /* installed_pkg has a higher priority and should win, regardless of the
fact that mirror_pkg2 has a higher version */
- installed_pkg.priority = SLAPT_PRIORITY_PREFERRED;
- fail_unless (slapt_cmp_pkgs(&installed_pkg,&mirror_pkg2) == 1);
+ installed_pkg.priority = SLAPT_PRIORITY_PREFERRED;
+ fail_unless(slapt_cmp_pkgs(&installed_pkg, &mirror_pkg2) == 1);
- /* when the priorities are the same, the package with the higher version
+ /* when the priorities are the same, the package with the higher version
always wins */
- installed_pkg.priority = SLAPT_PRIORITY_DEFAULT;
- fail_unless (slapt_cmp_pkgs(&installed_pkg,&mirror_pkg2) == -1);
-
+ installed_pkg.priority = SLAPT_PRIORITY_DEFAULT;
+ fail_unless(slapt_cmp_pkgs(&installed_pkg, &mirror_pkg2) == -1);
}
END_TEST
-START_TEST (test_version)
+START_TEST(test_version)
{
- fail_unless (slapt_cmp_pkg_versions("3","3") == 0);
- fail_unless (slapt_cmp_pkg_versions("4","3") > 0);
- fail_unless (slapt_cmp_pkg_versions("3","4") < 0);
+ fail_unless(slapt_cmp_pkg_versions("3", "3") == 0);
+ fail_unless(slapt_cmp_pkg_versions("4", "3") > 0);
+ fail_unless(slapt_cmp_pkg_versions("3", "4") < 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8.1-i486-1") == 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1jsw","3.8.1-i486-1") == 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i586-1","3.8.1-i486-1") == 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i586-1","3.8.1-i686-1") == 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i486","3.8.1-i486") == 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8.1-i486-1") == 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i486-1", "3.8.1-i486-1") == 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i486-1jsw", "3.8.1-i486-1") == 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i586-1", "3.8.1-i486-1") == 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i586-1", "3.8.1-i686-1") == 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i486", "3.8.1-i486") == 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i486-1", "3.8.1-i486-1") == 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1p1-i486-1","3.8p1-i486-1") > 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8-i486-1") > 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8-i486-3") > 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1p1-i486-1", "3.8p1-i486-1") > 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i486-1", "3.8-i486-1") > 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1-i486-1", "3.8-i486-3") > 0);
- fail_unless (slapt_cmp_pkg_versions("3.8.1_1-i486-1","3.8.1_2-i486-1") < 0);
+ fail_unless(slapt_cmp_pkg_versions("3.8.1_1-i486-1", "3.8.1_2-i486-1") < 0);
- fail_unless (slapt_cmp_pkg_versions("IIIalpha9.8-i486-2","IIIalpha9.7-i486-3") > 0);
- fail_unless (slapt_cmp_pkg_versions("4.13b-i386-2","4.12b-i386-1") > 0);
- fail_unless (slapt_cmp_pkg_versions("4.13b-i386-2","4.13a-i386-2") > 0);
- fail_unless (slapt_cmp_pkg_versions("1.4rc5-i486-2","1.4rc4-i486-2") > 0);
+ fail_unless(slapt_cmp_pkg_versions("IIIalpha9.8-i486-2", "IIIalpha9.7-i486-3") > 0);
+ fail_unless(slapt_cmp_pkg_versions("4.13b-i386-2", "4.12b-i386-1") > 0);
+ fail_unless(slapt_cmp_pkg_versions("4.13b-i386-2", "4.13a-i386-2") > 0);
+ fail_unless(slapt_cmp_pkg_versions("1.4rc5-i486-2", "1.4rc4-i486-2") > 0);
- fail_unless (slapt_cmp_pkg_versions("1.3.35-i486-2_slack10.2","1.3.35-i486-1") > 0);
+ fail_unless(slapt_cmp_pkg_versions("1.3.35-i486-2_slack10.2", "1.3.35-i486-1") > 0);
#if defined(__x86_64__)
- fail_unless (slapt_cmp_pkg_versions("4.1-x86_64-1","4.1-i486-1") > 0);
- fail_unless (slapt_cmp_pkg_versions("4.1-i486-1","4.1-x86_64-1") < 0);
+ fail_unless(slapt_cmp_pkg_versions("4.1-x86_64-1", "4.1-i486-1") > 0);
+ fail_unless(slapt_cmp_pkg_versions("4.1-i486-1", "4.1-x86_64-1") < 0);
#elif defined(__i386__)
- fail_unless (slapt_cmp_pkg_versions("4.1-i486-1","4.1-x86_64-1") > 0);
- fail_unless (slapt_cmp_pkg_versions("4.1-x86_64-1","4.1-486-1") < 0);
+ fail_unless(slapt_cmp_pkg_versions("4.1-i486-1", "4.1-x86_64-1") > 0);
+ fail_unless(slapt_cmp_pkg_versions("4.1-x86_64-1", "4.1-486-1") < 0);
#endif
}
END_TEST
-
-START_TEST (test_dependency)
+START_TEST(test_dependency)
{
- unsigned int i = 0;
- FILE *fh = NULL;
- slapt_pkg_info_t *p = NULL;
- slapt_pkg_list_t *avail = NULL;
- slapt_pkg_list_t *required_by = slapt_init_pkg_list ();
- slapt_pkg_list_t *installed = slapt_init_pkg_list ();
- slapt_pkg_list_t *pkgs_to_install = slapt_init_pkg_list ();
- slapt_pkg_list_t *pkgs_to_remove = slapt_init_pkg_list ();
- slapt_pkg_list_t *conflicts = NULL,
- *deps = slapt_init_pkg_list ();
- slapt_pkg_err_list_t *conflict = slapt_init_pkg_err_list (),
- *missing = slapt_init_pkg_err_list ();
- slapt_rc_config *rc = slapt_read_rc_config ("./data/rc1");
-
- fh = fopen ("data/avail_deps", "r");
- fail_unless (fh != NULL);
- avail = slapt_parse_packages_txt (fh);
- fclose (fh);
-
- fh = fopen ("data/installed_deps", "r");
- fail_unless (fh != NULL);
- installed = slapt_parse_packages_txt (fh);
- fclose (fh);
-
- /*
+ unsigned int i = 0;
+ FILE *fh = NULL;
+ slapt_pkg_info_t *p = NULL;
+ slapt_pkg_list_t *avail = NULL;
+ slapt_pkg_list_t *required_by = slapt_init_pkg_list();
+ slapt_pkg_list_t *installed = slapt_init_pkg_list();
+ slapt_pkg_list_t *pkgs_to_install = slapt_init_pkg_list();
+ slapt_pkg_list_t *pkgs_to_remove = slapt_init_pkg_list();
+ slapt_pkg_list_t *conflicts = NULL,
+ *deps = slapt_init_pkg_list();
+ slapt_pkg_err_list_t *conflict = slapt_init_pkg_err_list(),
+ *missing = slapt_init_pkg_err_list();
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+
+ fh = fopen("data/avail_deps", "r");
+ fail_unless(fh != NULL);
+ avail = slapt_parse_packages_txt(fh);
+ fclose(fh);
+
+ fh = fopen("data/installed_deps", "r");
+ fail_unless(fh != NULL);
+ installed = slapt_parse_packages_txt(fh);
+ fclose(fh);
+
+ /*
dependency tests
*/
- p = slapt_get_newest_pkg(avail, "slapt-src");
- fail_unless (p != NULL);
- i = slapt_get_pkg_dependencies (rc, avail, installed, p, deps, conflict, missing);
- /* we expect 22 deps to return given our current hardcoded data files */
- fail_unless (i != 22);
- /* we should have slapt-get as a dependency for slapt-src */
- fail_unless ( slapt_search_pkg_list(deps, "slapt-get") != NULL);
-
- /*
+ p = slapt_get_newest_pkg(avail, "slapt-src");
+ fail_unless(p != NULL);
+ i = slapt_get_pkg_dependencies(rc, avail, installed, p, deps, conflict, missing);
+ /* we expect 22 deps to return given our current hardcoded data files */
+ fail_unless(i != 22);
+ /* we should have slapt-get as a dependency for slapt-src */
+ fail_unless(slapt_search_pkg_list(deps, "slapt-get") != NULL);
+
+ /*
conflicts tests
*/
- /* scim conflicts with ibus */
- p = slapt_get_newest_pkg(avail, "scim");
- fail_unless (p != NULL);
- conflicts = slapt_get_pkg_conflicts (avail, installed, p);
- fail_unless (conflicts != NULL);
- fail_unless (conflicts->pkg_count == 1);
- fail_unless ( strcmp (conflicts->pkgs[0]->name, "ibus") == 0);
- slapt_free_pkg_list (conflicts);
-
- /*
+ /* scim conflicts with ibus */
+ p = slapt_get_newest_pkg(avail, "scim");
+ fail_unless(p != NULL);
+ conflicts = slapt_get_pkg_conflicts(avail, installed, p);
+ fail_unless(conflicts != NULL);
+ fail_unless(conflicts->pkg_count == 1);
+ fail_unless(strcmp(conflicts->pkgs[0]->name, "ibus") == 0);
+ slapt_free_pkg_list(conflicts);
+
+ /*
required by tests
*/
- /* slapt-get reverse dep test */
- p = slapt_get_newest_pkg(avail, "slapt-get");
- fail_unless (p != NULL);
- required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
- fail_unless (required_by->pkg_count == 5);
- fail_unless ( strcmp (required_by->pkgs[0]->name,"slapt-src") == 0);
- fail_unless ( strcmp (required_by->pkgs[1]->name,"gslapt") == 0);
- fail_unless ( strcmp (required_by->pkgs[2]->name,"foo") == 0);
- fail_unless ( strcmp (required_by->pkgs[3]->name,"boz") == 0);
- fail_unless ( strcmp (required_by->pkgs[4]->name,"bar") == 0);
- slapt_free_pkg_list (required_by);
-
- /* glib reverse dep test */
- p = slapt_get_newest_pkg(avail, "glib");
- fail_unless (p != NULL);
- required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
- fail_unless (required_by->pkg_count == 2);
- fail_unless ( strcmp (required_by->pkgs[0]->name,"xmms") == 0);
- fail_unless ( strcmp (required_by->pkgs[1]->name,"gtk+") == 0);
- slapt_free_pkg_list (required_by);
-
- /* glib2 reverse dep test */
- p = slapt_get_newest_pkg(avail, "glib2");
- fail_unless (p != NULL);
- required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
- fail_unless (required_by->pkg_count == 4);
- fail_unless ( strcmp (required_by->pkgs[0]->name,"ConsoleKit") == 0);
- fail_unless ( strcmp (required_by->pkgs[1]->name,"dbus-glib") == 0);
- fail_unless ( strcmp (required_by->pkgs[2]->name,"gslapt") == 0);
- fail_unless ( strcmp (required_by->pkgs[3]->name,"scim") == 0);
- slapt_free_pkg_list (required_by);
-
- slapt_free_pkg_list (installed);
- slapt_free_pkg_list (pkgs_to_install);
- slapt_free_pkg_list (pkgs_to_remove);
- slapt_free_pkg_list (avail);
- slapt_free_rc_config (rc);
+ /* slapt-get reverse dep test */
+ p = slapt_get_newest_pkg(avail, "slapt-get");
+ fail_unless(p != NULL);
+ required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
+ fail_unless(required_by->pkg_count == 5);
+ fail_unless(strcmp(required_by->pkgs[0]->name, "slapt-src") == 0);
+ fail_unless(strcmp(required_by->pkgs[1]->name, "gslapt") == 0);
+ fail_unless(strcmp(required_by->pkgs[2]->name, "foo") == 0);
+ fail_unless(strcmp(required_by->pkgs[3]->name, "boz") == 0);
+ fail_unless(strcmp(required_by->pkgs[4]->name, "bar") == 0);
+ slapt_free_pkg_list(required_by);
+
+ /* glib reverse dep test */
+ p = slapt_get_newest_pkg(avail, "glib");
+ fail_unless(p != NULL);
+ required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
+ fail_unless(required_by->pkg_count == 2);
+ fail_unless(strcmp(required_by->pkgs[0]->name, "xmms") == 0);
+ fail_unless(strcmp(required_by->pkgs[1]->name, "gtk+") == 0);
+ slapt_free_pkg_list(required_by);
+
+ /* glib2 reverse dep test */
+ p = slapt_get_newest_pkg(avail, "glib2");
+ fail_unless(p != NULL);
+ required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
+ fail_unless(required_by->pkg_count == 4);
+ fail_unless(strcmp(required_by->pkgs[0]->name, "ConsoleKit") == 0);
+ fail_unless(strcmp(required_by->pkgs[1]->name, "dbus-glib") == 0);
+ fail_unless(strcmp(required_by->pkgs[2]->name, "gslapt") == 0);
+ fail_unless(strcmp(required_by->pkgs[3]->name, "scim") == 0);
+ slapt_free_pkg_list(required_by);
+
+ slapt_free_pkg_list(installed);
+ slapt_free_pkg_list(pkgs_to_install);
+ slapt_free_pkg_list(pkgs_to_remove);
+ slapt_free_pkg_list(avail);
+ slapt_free_rc_config(rc);
}
END_TEST
-
-START_TEST (test_cache)
+START_TEST(test_cache)
{
- slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
- slapt_clean_pkg_dir(rc->working_dir);
+ slapt_clean_pkg_dir(rc->working_dir);
- /* not easily testable due to timeout
+ /* not easily testable due to timeout
slapt_pkg_list_t *list = slapt_init_pkg_list();
slapt_purge_old_cached_pkgs(rc, NULL, list);
*/
- slapt_free_rc_config(rc);
+ slapt_free_rc_config(rc);
}
END_TEST
-
-START_TEST (test_error)
+START_TEST(test_error)
{
- slapt_pkg_err_list_t *list = slapt_init_pkg_err_list();
+ slapt_pkg_err_list_t *list = slapt_init_pkg_err_list();
- slapt_add_pkg_err_to_list(list, "gslapt", "Server returned 404");
+ slapt_add_pkg_err_to_list(list, "gslapt", "Server returned 404");
- fail_unless ( slapt_search_pkg_err_list(list, "gslapt", "Server returned 404") == 1);
+ fail_unless(slapt_search_pkg_err_list(list, "gslapt", "Server returned 404") == 1);
- slapt_free_pkg_err_list(list);
+ slapt_free_pkg_err_list(list);
}
END_TEST
-
-START_TEST (test_network)
+START_TEST(test_network)
{
- char *cwd = get_current_dir_name();
- slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
- rc->progress_cb = _progress_cb; /* silence */
+ char *cwd = get_current_dir_name();
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ rc->progress_cb = _progress_cb; /* silence */
- /* must chdir to working dir */
- fail_unless (chdir(rc->working_dir) == 0);
+ /* must chdir to working dir */
+ fail_unless(chdir(rc->working_dir) == 0);
- /* write pkg data to disk
+ /* write pkg data to disk
void slapt_write_pkg_data(const char *source_url,FILE *d_file,
slapt_pkg_list_t *pkgs);
*/
- /* download the PACKAGES.TXT and CHECKSUMS.md5 files
+ /* download the PACKAGES.TXT and CHECKSUMS.md5 files
slapt_pkg_list_t *slapt_get_pkg_source_packages (const slapt_rc_config *global_config,
const char *url);
slapt_pkg_list_t *slapt_get_pkg_source_patches (const slapt_rc_config *global_config,
@@ -448,35 +438,31 @@ START_TEST (test_network)
const char *url);
*/
- fail_unless (slapt_update_pkg_cache(rc) == 0);
+ fail_unless(slapt_update_pkg_cache(rc) == 0);
- fail_unless (chdir(cwd) == 0);
- slapt_free_rc_config(rc);
- free(cwd);
+ fail_unless(chdir(cwd) == 0);
+ slapt_free_rc_config(rc);
+ free(cwd);
}
END_TEST
-
-
Suite *packages_test_suite()
{
- Suite *s = suite_create ("Packages");
- TCase *tc = tcase_create ("Packages");
-
- tcase_add_test (tc, test_struct_pkg);
- tcase_add_test (tc, test_pkg_info);
- tcase_add_test (tc, test_pkg_list);
- tcase_add_test (tc, test_pkg_search);
- tcase_add_test (tc, test_pkgtool);
- tcase_add_test (tc, test_pkg_version);
- tcase_add_test (tc, test_version);
- tcase_add_test (tc, test_dependency);
- tcase_add_test (tc, test_cache);
- tcase_add_test (tc, test_error);
- tcase_add_test (tc, test_network);
-
- suite_add_tcase (s, tc);
- return s;
+ Suite *s = suite_create("Packages");
+ TCase *tc = tcase_create("Packages");
+
+ tcase_add_test(tc, test_struct_pkg);
+ tcase_add_test(tc, test_pkg_info);
+ tcase_add_test(tc, test_pkg_list);
+ tcase_add_test(tc, test_pkg_search);
+ tcase_add_test(tc, test_pkgtool);
+ tcase_add_test(tc, test_pkg_version);
+ tcase_add_test(tc, test_version);
+ tcase_add_test(tc, test_dependency);
+ tcase_add_test(tc, test_cache);
+ tcase_add_test(tc, test_error);
+ tcase_add_test(tc, test_network);
+
+ suite_add_tcase(s, tc);
+ return s;
}
-
-
diff --git a/t/test_transaction.c b/t/test_transaction.c
index 4cfb95c..698f330 100644
--- a/t/test_transaction.c
+++ b/t/test_transaction.c
@@ -1,58 +1,55 @@
#include "test_transaction.h"
extern slapt_pkg_info_t pkg;
-
-START_TEST (test_transaction)
+START_TEST(test_transaction)
{
- slapt_transaction_t *t = slapt_init_transaction();
- fail_if (t == NULL);
+ slapt_transaction_t *t = slapt_init_transaction();
+ fail_if(t == NULL);
- slapt_add_install_to_transaction(t, &pkg);
- fail_unless (t->install_pkgs->pkg_count == 1);
- fail_unless (slapt_search_transaction(t, "gslapt") == 1);
- fail_unless (slapt_search_transaction_by_pkg(t, &pkg) == 1);
- t = slapt_remove_from_transaction(t, &pkg);
+ slapt_add_install_to_transaction(t, &pkg);
+ fail_unless(t->install_pkgs->pkg_count == 1);
+ fail_unless(slapt_search_transaction(t, "gslapt") == 1);
+ fail_unless(slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ t = slapt_remove_from_transaction(t, &pkg);
- slapt_add_remove_to_transaction(t, &pkg);
- fail_unless (t->remove_pkgs->pkg_count == 1);
- fail_unless (slapt_search_transaction(t, "gslapt") == 1);
- fail_unless (slapt_search_transaction_by_pkg(t, &pkg) == 1);
- t = slapt_remove_from_transaction(t, &pkg);
+ slapt_add_remove_to_transaction(t, &pkg);
+ fail_unless(t->remove_pkgs->pkg_count == 1);
+ fail_unless(slapt_search_transaction(t, "gslapt") == 1);
+ fail_unless(slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ t = slapt_remove_from_transaction(t, &pkg);
- slapt_add_exclude_to_transaction(t, &pkg);
- fail_unless (t->exclude_pkgs->pkg_count == 1);
+ slapt_add_exclude_to_transaction(t, &pkg);
+ fail_unless(t->exclude_pkgs->pkg_count == 1);
- slapt_add_upgrade_to_transaction(t, &pkg, &pkg);
- /* fail_unless (slapt_search_upgrade_transaction(t, &pkg) == 1); */
+ slapt_add_upgrade_to_transaction(t, &pkg, &pkg);
+ /* fail_unless (slapt_search_upgrade_transaction(t, &pkg) == 1); */
- slapt_free_transaction(t);
+ slapt_free_transaction(t);
}
END_TEST
-
-START_TEST (test_handle_transaction)
+START_TEST(test_handle_transaction)
{
- slapt_transaction_t *t = slapt_init_transaction();
- slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ slapt_transaction_t *t = slapt_init_transaction();
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
- /*
+ /*
download and install/remove/upgrade packages as defined in the transaction
returns 0 on success
int slapt_handle_transaction(const slapt_rc_config *,slapt_transaction_t *);
*/
- slapt_free_transaction(t);
- slapt_free_rc_config(rc);
+ slapt_free_transaction(t);
+ slapt_free_rc_config(rc);
}
END_TEST
-
-START_TEST (test_transaction_dependencies)
+START_TEST(test_transaction_dependencies)
{
- slapt_transaction_t *t = slapt_init_transaction();
- slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ slapt_transaction_t *t = slapt_init_transaction();
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
- /*
+ /*
add dependencies for package to transaction, returns -1 on error, 0 otherwise
int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
slapt_transaction_t *tran,
@@ -60,7 +57,7 @@ START_TEST (test_transaction_dependencies)
struct slapt_pkg_list *installed_pkgs, slapt_pkg_info_t *pkg);
*/
- /*
+ /*
check to see if a package has a conflict already present in the transaction
returns conflicted package or NULL if none
slapt_pkg_info_t *slapt_is_conflicted(slapt_transaction_t *tran,
@@ -69,29 +66,27 @@ START_TEST (test_transaction_dependencies)
slapt_pkg_info_t *pkg);
*/
- /*
+ /*
generate a list of suggestions based on the current packages
in the transaction
void slapt_generate_suggestions(slapt_transaction_t *tran);
*/
- slapt_generate_suggestions(t);
+ slapt_generate_suggestions(t);
- slapt_free_transaction(t);
- slapt_free_rc_config(rc);
+ slapt_free_transaction(t);
+ slapt_free_rc_config(rc);
}
END_TEST
-
Suite *transaction_test_suite()
{
- Suite *s = suite_create ("Transaction");
- TCase *tc = tcase_create ("Transaction");
+ Suite *s = suite_create("Transaction");
+ TCase *tc = tcase_create("Transaction");
- tcase_add_test (tc, test_transaction);
- tcase_add_test (tc, test_handle_transaction);
- tcase_add_test (tc, test_transaction_dependencies);
+ tcase_add_test(tc, test_transaction);
+ tcase_add_test(tc, test_handle_transaction);
+ tcase_add_test(tc, test_transaction_dependencies);
- suite_add_tcase (s, tc);
- return s;
+ suite_add_tcase(s, tc);
+ return s;
}
-