summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2019-07-10 19:49:44 -0400
committerJason Woodward2019-07-14 19:59:59 -0400
commitc8d79ef43f04b7bbb898f981766803d3f89bde84 (patch)
tree33b2b89e9495105288c931a404ffa9f70a841fc6
parentcbdcf595c3530b231be56e4b10d6f582db3fe0fe (diff)
downloadslapt-get-c8d79ef43f04b7bbb898f981766803d3f89bde84.tar.gz
clang-format
-rw-r--r--src/action.c104
-rw-r--r--src/action.h6
-rw-r--r--src/common.c57
-rw-r--r--src/common.h11
-rw-r--r--src/configuration.c25
-rw-r--r--src/curl.c33
-rw-r--r--src/curl.h54
-rw-r--r--src/gpgme.c29
-rw-r--r--src/gpgme.h8
-rw-r--r--src/main.c3
-rw-r--r--src/package.c353
-rw-r--r--src/package.h144
-rw-r--r--src/transaction.c84
-rw-r--r--src/transaction.h61
14 files changed, 287 insertions, 685 deletions
diff --git a/src/action.c b/src/action.c
index 46704a3..4786227 100644
--- a/src/action.c
+++ b/src/action.c
@@ -21,8 +21,7 @@
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_vector_t *action_args)
+void slapt_pkg_action_install(const slapt_rc_config *global_config, const slapt_vector_t *action_args)
{
slapt_transaction_t *tran = NULL;
slapt_vector_t *installed_pkgs = NULL;
@@ -78,8 +77,7 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
/* if it is not already installed, install it */
if (installed_pkg == NULL || global_config->no_upgrade) {
- if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
- installed_pkgs, pkg) == 0) {
+ if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, pkg) == 0) {
slapt_vector_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 checking conflicts */
@@ -89,10 +87,7 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
if (conflicts->size && !global_config->ignore_dep) {
slapt_vector_t_foreach (slapt_pkg_info_t *, conflict, conflicts) {
/* make sure to remove the conflict's dependencies as well */
- slapt_vector_t *conflict_deps = slapt_is_required_by(global_config,
- avail_pkgs, installed_pkgs,
- tran->install_pkgs, tran->remove_pkgs,
- conflict);
+ slapt_vector_t *conflict_deps = slapt_is_required_by(global_config, avail_pkgs, installed_pkgs, tran->install_pkgs, tran->remove_pkgs, conflict);
slapt_vector_t_foreach (slapt_pkg_info_t *, conflict_dep, conflict_deps) {
if (slapt_get_exact_pkg(installed_pkgs, conflict_dep->name, conflict_dep->version) != NULL) {
slapt_add_remove_to_transaction(tran, conflict_dep);
@@ -106,28 +101,20 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
slapt_vector_t_free(conflicts);
} else {
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- pkg->name);
+ 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)) {
- if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
- installed_pkgs, pkg) == 0) {
- slapt_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs,
- installed_pkgs, pkg);
+ if (((slapt_cmp_pkgs(installed_pkg, pkg)) < 0) || (global_config->re_install)) {
+ if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, pkg) == 0) {
+ slapt_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, pkg);
if (conflicts->size && !global_config->ignore_dep) {
slapt_vector_t_foreach (slapt_pkg_info_t *, conflict, conflicts) {
/* make sure to remove the conflict's dependencies as well */
- slapt_vector_t *conflict_deps = slapt_is_required_by(global_config,
- avail_pkgs, installed_pkgs,
- tran->install_pkgs, tran->remove_pkgs,
- conflict);
+ slapt_vector_t *conflict_deps = slapt_is_required_by(global_config, avail_pkgs, installed_pkgs, tran->install_pkgs, tran->remove_pkgs, conflict);
slapt_vector_t_foreach (slapt_pkg_info_t *, conflict_dep, conflict_deps) {
if (slapt_get_exact_pkg(installed_pkgs, conflict_dep->name, conflict_dep->version) != NULL) {
slapt_add_remove_to_transaction(tran, conflict_dep);
@@ -147,8 +134,7 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
slapt_vector_t_free(conflicts);
} else {
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- pkg->name);
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"), pkg->name);
slapt_add_exclude_to_transaction(tran, pkg);
}
@@ -186,8 +172,7 @@ void slapt_pkg_action_list(const int show)
char *short_description = slapt_gen_short_pkg_description(pkg);
/* is it installed? */
- if (slapt_get_exact_pkg(installed_pkgs, pkg->name,
- pkg->version) != NULL)
+ if (slapt_get_exact_pkg(installed_pkgs, pkg->name, pkg->version) != NULL)
installed = true;
printf("%s-%s [inst=%s]: %s\n",
@@ -226,8 +211,7 @@ void slapt_pkg_action_list(const int show)
}
/* remove/uninstall pkg */
-void slapt_pkg_action_remove(const slapt_rc_config *global_config,
- const slapt_vector_t *action_args)
+void slapt_pkg_action_remove(const slapt_rc_config *global_config, const slapt_vector_t *action_args)
{
slapt_vector_t *installed_pkgs = NULL;
slapt_vector_t *avail_pkgs = NULL;
@@ -274,10 +258,7 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
}
}
- 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);
slapt_vector_t_foreach (slapt_pkg_info_t *, dep, deps) {
if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
@@ -441,10 +422,7 @@ void slapt_pkg_action_show(const char *pkg_name)
free(changelog);
}
- printf(gettext("Package Installed: %s\n"),
- installed
- ? gettext("yes")
- : gettext("no"));
+ printf(gettext("Package Installed: %s\n"), installed ? gettext("yes") : gettext("no"));
free(description);
} else {
@@ -481,8 +459,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
char *essential[] = {"aaa_base", "pkgtools", "glibc-solibs", "glibc", "aaa_elflibs", "xz", "sed", "tar", "gzip", NULL};
int epi = 0;
slapt_pkg_info_t *newest_slaptget = NULL;
- slapt_vector_t *matches =
- slapt_search_pkg_list(avail_pkgs, SLAPT_SLACK_BASE_SET_REGEX);
+ slapt_vector_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) {
@@ -513,10 +490,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
installed_pkg = slapt_get_newest_pkg(installed_pkgs, pkg->name);
newer_avail_pkg = slapt_get_newest_pkg(avail_pkgs, pkg->name);
- /*
- * if there is a newer available version (such as from patches/)
- * use it instead
- */
+ /* if there is a newer available version (such as from patches/) use it instead */
if (slapt_cmp_pkgs(pkg, newer_avail_pkg) < 0) {
slapt_upgrade_pkg = newer_avail_pkg;
} else {
@@ -536,8 +510,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
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);
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"), slapt_upgrade_pkg->name);
slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
}
@@ -546,26 +519,18 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
/* 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) {
+ } 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) || slapt_is_excluded(global_config, slapt_upgrade_pkg)) {
slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
} else {
- slapt_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs,
- slapt_upgrade_pkg);
+ slapt_vector_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->size && !global_config->ignore_dep)) {
- slapt_add_upgrade_to_transaction(tran, installed_pkg,
- slapt_upgrade_pkg);
+ if ((slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, slapt_upgrade_pkg) == 0) && (!conflicts->size && !global_config->ignore_dep)) {
+ 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);
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"), slapt_upgrade_pkg->name);
slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
}
@@ -606,12 +571,8 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
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_pkg->name)) != 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_pkg->name)) != NULL) {
if (slapt_cmp_pkgs(installed_pkg, newer_installed_pkg) < 0) {
continue;
}
@@ -627,25 +588,15 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
if (
/* either it's greater, or we want to reinstall */
cmp_r < 0 || (global_config->re_install) ||
- /*
- * or this is a dist upgrade and the versions are the save
- * except for the arch
- */
- (
- global_config->dist_upgrade &&
- cmp_r == 0 &&
- cmp_pkg_arch(installed_pkg->version,
- update_pkg->version) != 0)) {
+ /* or this is a dist upgrade and the versions are the save except for the arch */
+ (global_config->dist_upgrade && cmp_r == 0 && cmp_pkg_arch(installed_pkg->version, update_pkg->version) != 0)) {
if ((slapt_is_excluded(global_config, update_pkg)) || (slapt_is_excluded(global_config, installed_pkg))) {
slapt_add_exclude_to_transaction(tran, update_pkg);
} else {
slapt_vector_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 || !conflicts->size)) {
+ if ((slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, update_pkg) == 0) && (global_config->ignore_dep || !conflicts->size)) {
if (cmp_r == 0)
slapt_add_reinstall_to_transaction(tran, installed_pkg, update_pkg);
else
@@ -653,8 +604,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
} else {
/* otherwise exclude */
- printf(gettext("Excluding %s, use --ignore-dep to override\n"),
- update_pkg->name);
+ printf(gettext("Excluding %s, use --ignore-dep to override\n"), update_pkg->name);
slapt_add_exclude_to_transaction(tran, update_pkg);
}
diff --git a/src/action.h b/src/action.h
index 5033c6e..9e24e49 100644
--- a/src/action.h
+++ b/src/action.h
@@ -16,11 +16,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-void slapt_pkg_action_install(const slapt_rc_config *global_config,
- const slapt_vector_t *action_args);
+void slapt_pkg_action_install(const slapt_rc_config *global_config, const slapt_vector_t *action_args);
void slapt_pkg_action_list(const int show);
-void slapt_pkg_action_remove(const slapt_rc_config *global_config,
- const slapt_vector_t *action_args);
+void slapt_pkg_action_remove(const slapt_rc_config *global_config, const slapt_vector_t *action_args);
void slapt_pkg_action_search(const char *pattern);
void slapt_pkg_action_show(const char *pkg_name);
void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config);
diff --git a/src/common.c b/src/common.c
index 1040556..ceb5c17 100644
--- a/src/common.c
+++ b/src/common.c
@@ -46,16 +46,14 @@ slapt_regex_t *slapt_init_regex(const char *regex_string)
r->reg_return = -1;
/* compile our regex */
- r->reg_return = regcomp(&r->regex, regex_string,
- REG_EXTENDED | REG_NEWLINE | REG_ICASE);
+ 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) {
+ if ((regerror_size = regerror(r->reg_return, &r->regex, errbuf, errbuf_size)) != 0) {
printf(gettext("Regex Error: %s\n"), errbuf);
}
free(r);
@@ -65,14 +63,10 @@ slapt_regex_t *slapt_init_regex(const char *regex_string)
return r;
}
-/*
- execute the regular expression and set the return code
- in the passed in structure
- */
+/* 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)
{
- 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)
@@ -166,9 +160,7 @@ void slapt_create_dir_structure(const char *dir_name)
/* 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));
+ dir_name_buffer = strndup(dir_name + position, strlen(dir_name + position));
if (strcmp(dir_name_buffer, ".") != 0) {
if ((mkdir(dir_name_buffer, 0755)) == -1) {
@@ -192,9 +184,7 @@ void slapt_create_dir_structure(const char *dir_name)
} 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));
+ 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) {
@@ -236,9 +226,7 @@ int slapt_ask_yes_no(const char *format, ...)
if (answer == '\n')
break;
- if (((tolower(answer) == 'y') ||
- (tolower(answer) == 'n')) &&
- parsed_answer == 0)
+ if (((tolower(answer) == 'y') || (tolower(answer) == 'n')) && parsed_answer == 0)
parsed_answer = tolower(answer);
}
@@ -251,8 +239,7 @@ int slapt_ask_yes_no(const char *format, ...)
return -1;
}
-char *slapt_str_replace_chr(const char *string, const char find,
- const char replace)
+char *slapt_str_replace_chr(const char *string, const char find, const char replace)
{
uint32_t len = 0;
char *clean = slapt_calloc(strlen(string) + 1, sizeof *clean);
@@ -440,8 +427,8 @@ char *slapt_strip_whitespace(const char *s)
return strndup(s, len);
}
-
-slapt_vector_t *slapt_vector_t_init(slapt_vector_t_free_function f) {
+slapt_vector_t *slapt_vector_t_init(slapt_vector_t_free_function f)
+{
slapt_vector_t *v = NULL;
v = slapt_malloc(sizeof *v);
v->size = 0;
@@ -452,9 +439,10 @@ slapt_vector_t *slapt_vector_t_init(slapt_vector_t_free_function f) {
return v;
}
-void slapt_vector_t_free(slapt_vector_t *v) {
+void slapt_vector_t_free(slapt_vector_t *v)
+{
if (v->free_function) {
- for (uint32_t i = 0; i < v->size; i++ ) {
+ for (uint32_t i = 0; i < v->size; i++) {
v->free_function(v->items[i]);
}
}
@@ -462,9 +450,10 @@ void slapt_vector_t_free(slapt_vector_t *v) {
free(v);
}
-void slapt_vector_t_add(slapt_vector_t *v, void *a) {
+void slapt_vector_t_add(slapt_vector_t *v, void *a)
+{
if (v->capacity == v->size) {
- uint32_t new_capacity = (v->capacity+1) * 2;
+ uint32_t new_capacity = (v->capacity + 1) * 2;
v->items = realloc(v->items, sizeof *v->items * new_capacity);
if (v->items == NULL) {
exit(EXIT_FAILURE);
@@ -475,7 +464,8 @@ void slapt_vector_t_add(slapt_vector_t *v, void *a) {
v->sorted = false;
}
-void slapt_vector_t_remove(slapt_vector_t *v, void *j) {
+void slapt_vector_t_remove(slapt_vector_t *v, void *j)
+{
bool found = false;
for (uint32_t i = 0; i < v->size; i++) {
if (j == v->items[i]) {
@@ -484,7 +474,7 @@ void slapt_vector_t_remove(slapt_vector_t *v, void *j) {
}
found = true;
}
- if (found && ((i+1) < v->size)) {
+ if (found && ((i + 1) < v->size)) {
v->items[i] = v->items[i + 1];
}
}
@@ -493,14 +483,16 @@ void slapt_vector_t_remove(slapt_vector_t *v, void *j) {
}
}
-void slapt_vector_t_sort(slapt_vector_t *v, slapt_vector_t_qsort_cmp cmp) {
+void slapt_vector_t_sort(slapt_vector_t *v, slapt_vector_t_qsort_cmp cmp)
+{
if (v->size > 0) {
qsort(v->items, v->size, sizeof(v->items[0]), cmp);
v->sorted = true;
}
}
-int slapt_vector_t_index_of(slapt_vector_t *v, slapt_vector_t_cmp cmp, void *opt) {
+int slapt_vector_t_index_of(slapt_vector_t *v, slapt_vector_t_cmp cmp, void *opt)
+{
if (v->sorted) {
int min = 0, max = v->size - 1;
@@ -526,7 +518,8 @@ int slapt_vector_t_index_of(slapt_vector_t *v, slapt_vector_t_cmp cmp, void *opt
return -1;
}
-slapt_vector_t *slapt_vector_t_search(slapt_vector_t *v, slapt_vector_t_cmp cmp, void *opt) {
+slapt_vector_t *slapt_vector_t_search(slapt_vector_t *v, slapt_vector_t_cmp cmp, void *opt)
+{
slapt_vector_t *matches = slapt_vector_t_init(NULL);
if (v->sorted) {
diff --git a/src/common.h b/src/common.h
index c119181..5080346 100644
--- a/src/common.h
+++ b/src/common.h
@@ -67,10 +67,9 @@ typedef struct {
int reg_return;
} slapt_regex_t;
-
typedef int (*slapt_vector_t_cmp)(const void *, const void *);
typedef int (*slapt_vector_t_qsort_cmp)(const void *, const void *);
-typedef void (*slapt_vector_t_free_function)(void*);
+typedef void (*slapt_vector_t_free_function)(void *);
typedef struct slapt_vector_t {
uint32_t size;
uint32_t capacity;
@@ -85,8 +84,9 @@ void slapt_vector_t_remove(slapt_vector_t *v, void *);
void slapt_vector_t_sort(slapt_vector_t *, slapt_vector_t_qsort_cmp);
int slapt_vector_t_index_of(slapt_vector_t *, slapt_vector_t_cmp, void *);
slapt_vector_t *slapt_vector_t_search(slapt_vector_t *, slapt_vector_t_cmp, void *);
-#define slapt_vector_t_foreach(type, item, list) type item; for (uint32_t item##_counter = 0; (item##_counter < list->size) && (item = list->items[item##_counter]); item##_counter++)
-
+#define slapt_vector_t_foreach(type, item, list) \
+ type item; \
+ for (uint32_t item##_counter = 0; (item##_counter < list->size) && (item = list->items[item##_counter]); item##_counter++)
FILE *slapt_open_file(const char *file_name, const char *mode);
slapt_regex_t *slapt_init_regex(const char *regex_string);
@@ -102,8 +102,7 @@ void slapt_gen_md5_sum_of_file(FILE *f, char *result_sum);
* 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,
- const char replace);
+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);
diff --git a/src/configuration.c b/src/configuration.c
index 99e632d..738ed61 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -102,10 +102,7 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
/* 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)));
+ 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';
}
@@ -122,8 +119,7 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
free(getline_buffer);
if (strcmp(global_config->working_dir, "") == 0) {
- fprintf(stderr, gettext("WORKINGDIR directive not set within %s.\n"),
- file_name);
+ fprintf(stderr, gettext("WORKINGDIR directive not set within %s.\n"), file_name);
return NULL;
}
if (!global_config->sources->size) {
@@ -149,8 +145,7 @@ void slapt_working_dir_init(const slapt_rc_config *global_config)
r = chdir(cwd);
free(cwd);
} else {
- printf(gettext("Failed to build working directory [%s]\n"),
- global_config->working_dir);
+ printf(gettext("Failed to build working directory [%s]\n"), global_config->working_dir);
exit(EXIT_FAILURE);
}
}
@@ -165,9 +160,7 @@ void slapt_working_dir_init(const slapt_rc_config *global_config)
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);
+ fprintf(stderr, gettext("Please update permissions on %s or run with appropriate privileges\n"), global_config->working_dir);
exit(EXIT_FAILURE);
}
@@ -191,10 +184,7 @@ static slapt_vector_t *parse_exclude(char *line)
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;
}
@@ -273,10 +263,7 @@ slapt_source_t *slapt_init_source(const char *s)
src->url = slapt_malloc(sizeof *src->url * (source_len + 2));
src->url[0] = '\0';
- src->url = strncat(
- src->url,
- source_string,
- source_len);
+ src->url = strncat(src->url, source_string, source_len);
if (isblank(src->url[source_len - 1]) == 0) {
src->url = strcat(src->url, "/");
diff --git a/src/curl.c b/src/curl.c
index 544ce23..bbbec0e 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -17,16 +17,14 @@
*/
#include "main.h"
-static size_t write_header_callback(void *buffer,
- size_t size, size_t nmemb, void *userp);
+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;
};
-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;
@@ -65,8 +63,7 @@ int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime,
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_PROGRESSFUNCTION, global_config->progress_cb);
}
curl_easy_setopt(ch, CURLOPT_PROGRESSDATA, cb_data);
}
@@ -85,11 +82,7 @@ int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *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.
- */
+ /* 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); */
@@ -99,8 +92,7 @@ int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime,
return return_code;
}
-static size_t write_header_callback(void *buffer, size_t size,
- size_t nmemb, void *userp)
+static size_t write_header_callback(void *buffer, size_t size, size_t nmemb, void *userp)
{
char *tmp;
register int a_size = size * nmemb;
@@ -164,10 +156,7 @@ char *slapt_head_request(const char *url)
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 char *slapt_get_mirror_data_from_source(FILE *fh, const slapt_rc_config *global_config, const char *base_url, const char *filename)
{
int return_code = 0;
char *url = NULL;
@@ -184,13 +173,10 @@ const char *slapt_get_mirror_data_from_source(FILE *fh,
/* make sure we are back at the front of the file */
/* DISABLED */
/* rewind(fh); */
- return return_code != 0
- ? curl_easy_strerror(return_code)
- : NULL;
+ 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)
+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;
@@ -336,8 +322,7 @@ const char *slapt_download_pkg(const slapt_rc_config *global_config,
}
}
-int slapt_progress_callback(void *clientp, double dltotal, double dlnow,
- double ultotal, double ulnow)
+int slapt_progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
size_t percent = 0;
struct slapt_progress_data *cb_data = (struct slapt_progress_data *)clientp;
diff --git a/src/curl.h b/src/curl.h
index 70c44f1..605424e 100644
--- a/src/curl.h
+++ b/src/curl.h
@@ -18,56 +18,28 @@
#define SLAPT_NO_SSL_VERIFYPEER "SLAPT_NO_SSL_VERIFYPEER"
-/*
- download data to file, resuming from bytes and preserving filetime.
- returns curl code
-*/
-int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime,
- const slapt_rc_config *global_config);
+/* download data to file, resuming from bytes and preserving filetime. returns curl code */
+int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime, const slapt_rc_config *global_config);
-/*
- retrieves the head data for the url, returns (char *) or NULL on error
-*/
+/* retrieves the head data for the url, returns (char *) or NULL on error */
char *slapt_head_request(const char *url);
-/*
- this fills FILE with data from url, used for PACKAGES.TXT and CHECKSUMS
- Returns error on failure.
-*/
-const char *slapt_get_mirror_data_from_source(FILE *fh,
- const slapt_rc_config *global_config,
- const char *base_url,
- const char *filename);
+/* this fills FILE with data from url, used for PACKAGES.TXT and CHECKSUMS Returns error on failure. */
+const char *slapt_get_mirror_data_from_source(FILE *fh, const slapt_rc_config *global_config, const char *base_url, const char *filename);
-/*
- download pkg, calls download_data. returns error on failure.
-*/
-const char *slapt_download_pkg(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg, const char *note);
+/* download pkg, calls download_data. returns error on failure. */
+const char *slapt_download_pkg(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg, const char *note);
-/*
- 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);
+/* 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);
-/*
- do a head request on the mirror data to find out if it's new
- returns (char *) or NULL
-*/
+/* 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);
-/*
- clear head cache storage file
-*/
+/* clear head cache storage file */
void slapt_clear_head_cache(const char *cache_filename);
-/*
- cache the head request
-*/
+/* cache the head request */
void slapt_write_head_cache(const char *cache, const char *cache_filename);
-/*
- read the cached head request
- returns (char *) or NULL
-*/
+/* read the cached head request, returns (char *) or NULL */
char *slapt_read_head_cache(const char *cache_filename);
struct slapt_progress_data {
diff --git a/src/gpgme.c b/src/gpgme.c
index caf5303..5907ce9 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -49,9 +49,7 @@ static void _slapt_free_gpgme_ctx(gpgme_ctx_t *ctx)
free(ctx);
}
-FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_config,
- const char *url,
- bool *compressed)
+FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_config, const char *url, bool *compressed)
{
FILE *tmp_checksum_f = NULL;
char *checksum_head = NULL;
@@ -84,8 +82,7 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
return NULL;
}
- if (checksum_head != NULL && local_head != NULL &&
- strcmp(checksum_head, local_head) == 0) {
+ 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);
@@ -101,9 +98,7 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
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);
+ err = slapt_get_mirror_data_from_source(tmp_checksum_f, global_config, url, location);
if (!err) {
if (interactive)
printf(gettext("Done\n"));
@@ -135,17 +130,13 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
return tmp_checksum_f;
}
-FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
- const char *url,
- bool *compressed)
+FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config, const char *url, bool *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
- ? true
- : false;
+ bool interactive = global_config->progress_cb == NULL && !global_config->dl_stats ? true : false;
*compressed = false;
key_head = slapt_head_mirror_data(url, SLAPT_GPG_KEY);
@@ -160,8 +151,7 @@ FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
return NULL;
}
- if (key_head != NULL && local_head != NULL &&
- strcmp(key_head, local_head) == 0) {
+ 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);
@@ -174,9 +164,7 @@ FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
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);
+ err = slapt_get_mirror_data_from_source(tmp_key_f, global_config, url, SLAPT_GPG_KEY);
if (!err) {
if (interactive)
@@ -271,8 +259,7 @@ static slapt_code_t _slapt_gpg_get_gpgme_error(gpgme_sigsum_t sum)
return SLAPT_CHECKSUMS_NOT_VERIFIED;
}
-slapt_code_t slapt_gpg_verify_checksums(FILE *checksums,
- FILE *signature)
+slapt_code_t slapt_gpg_verify_checksums(FILE *checksums, FILE *signature)
{
gpgme_error_t e;
gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
diff --git a/src/gpgme.h b/src/gpgme.h
index 3099ff4..072f25b 100644
--- a/src/gpgme.h
+++ b/src/gpgme.h
@@ -27,13 +27,9 @@
#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,
- bool *compressed);
+FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_config, const char *url, bool *compressed);
/* retrieve the package sources GPG-KEY */
-FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
- const char *url,
- bool *compressed);
+FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config, const char *url, bool *compressed);
/* Add the GPG-KEY to the local keyring */
slapt_code_t slapt_add_pkg_source_gpg_key(FILE *key);
/* Verify the signature is valid for the checksum file */
diff --git a/src/main.c b/src/main.c
index cdee429..901c885 100644
--- a/src/main.c
+++ b/src/main.c
@@ -107,8 +107,7 @@ int main(int argc, char *argv[])
curl_global_init(CURL_GLOBAL_ALL);
- while ((c = getopt_long_only(argc, argv, "", long_options,
- &option_index)) != -1) {
+ while ((c = getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
switch (c) {
case SLAPT_UPDATE_OPT: /* update */
do_action = UPDATE;
diff --git a/src/package.c b/src/package.c
index a136b73..d374dbf 100644
--- a/src/package.c
+++ b/src/package.c
@@ -26,9 +26,7 @@ struct slapt_pkg_version_parts {
/* analyze the pkg version hunk by hunk */
static struct slapt_pkg_version_parts *break_down_pkg_version(const char *version);
/* parse the meta lines */
-static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- char *dep_entry);
+static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs, char *dep_entry);
/* called by slapt_is_required_by */
static void required_by(slapt_vector_t *avail,
slapt_vector_t *installed_pkgs,
@@ -40,9 +38,7 @@ static char *escape_package_name(slapt_pkg_info_t *pkg);
/* free pkg_version_parts struct */
static void slapt_free_pkg_version_parts(struct slapt_pkg_version_parts *parts);
/* find dependency from "or" requirement */
-static slapt_pkg_info_t *find_or_requirement(slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- char *required_str);
+static slapt_pkg_info_t *find_or_requirement(slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs, char *required_str);
/* uncompress compressed package data */
static FILE *slapt_gunzip_file(const char *file_name, FILE *dest_file);
@@ -114,8 +110,7 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
exit(EXIT_FAILURE);
}
- while ((bytes_read = getline(&getline_buffer, &getline_len,
- pkg_list_fh)) != EOF) {
+ while ((bytes_read = getline(&getline_buffer, &getline_len, pkg_list_fh)) != EOF) {
slapt_pkg_info_t *tmp_pkg;
getline_buffer[bytes_read - 1] = '\0';
@@ -186,42 +181,24 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
matching
*/
if (strstr(tmp_pkg->location, "./testing/") != NULL) {
- char *tmp_location = slapt_malloc(
- sizeof *tmp_location *
- (strlen(tmp_pkg->location) - 7) /* ./testing - 2 */
- );
+ 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 */
- );
+ strncat(tmp_location, &tmp_pkg->location[0] + 9, 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 */
- );
+ 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 */
- );
+ strncat(tmp_location, &tmp_pkg->location[0] + 7, 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 */
- );
+ 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 */
- );
+ strncat(tmp_location, &tmp_pkg->location[0] + 9, strlen(tmp_pkg->location) - 9); /* ./pasture */
free(tmp_pkg->location);
tmp_pkg->location = tmp_location;
}
@@ -282,16 +259,12 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
/* 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)) {
+ 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));
+ 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;
strcpy(tmp_pkg->required, char_pointer + req_len);
@@ -304,16 +277,12 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
/* 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)) {
+ 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));
+ 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;
strcpy(tmp_pkg->conflicts, char_pointer + req_len);
@@ -326,16 +295,12 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
/* 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)) {
+ 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));
+ 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;
strcpy(tmp_pkg->suggests, char_pointer + req_len);
@@ -348,10 +313,7 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
/* 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)) {
+ 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;
@@ -373,14 +335,11 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
}
/* description */
- if (
- (getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF) &&
- (strstr(getline_buffer, "PACKAGE DESCRIPTION") != NULL)) {
+ 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) {
+ if ((bytes_read = getline(&getline_buffer, &getline_len, pkg_list_fh)) == EOF) {
break;
}
@@ -388,9 +347,7 @@ slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
break;
}
- tmp_desc = realloc(tmp_pkg->description,
- sizeof *tmp_pkg->description *
- (strlen(tmp_pkg->description) + bytes_read + 1));
+ tmp_desc = realloc(tmp_pkg->description, sizeof *tmp_pkg->description * (strlen(tmp_pkg->description) + bytes_read + 1));
if (tmp_desc == NULL) {
break;
}
@@ -440,17 +397,14 @@ char *slapt_gen_short_pkg_description(slapt_pkg_info_t *pkg)
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'));
+ 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;
- 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;
}
@@ -516,10 +470,7 @@ slapt_vector_t *slapt_get_installed_pkgs(void)
strcat(pkg_f_name, "/");
strcat(pkg_f_name, file->d_name);
- /*
- open the package log file so that we can mmap it and parse out the
- package attributes.
- */
+ /* 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);
@@ -546,8 +497,7 @@ slapt_vector_t *slapt_get_installed_pkgs(void)
pls = SLAPT_MAX_MMAP_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);
@@ -601,9 +551,7 @@ slapt_vector_t *slapt_get_installed_pkgs(void)
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));
+ 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);
@@ -614,9 +562,7 @@ slapt_vector_t *slapt_get_installed_pkgs(void)
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));
+ 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;
strcpy(tmp_pkg->description, desc_p);
@@ -674,7 +620,8 @@ static int by_name(const void *pkg, const void *name){
return strcmp(p->name, cname);
}
*/
-static int by_details(const void *a, const void *b) {
+static int by_details(const void *a, const void *b)
+{
return slapt_pkg_info_t_qsort_cmp(&a, &b);
}
@@ -682,7 +629,7 @@ static int by_details(const void *a, const void *b) {
slapt_pkg_info_t *slapt_get_newest_pkg(slapt_vector_t *pkg_list, const char *pkg_name)
{
slapt_pkg_info_t *found = NULL;
- slapt_vector_t *matches = slapt_vector_t_search(pkg_list, by_details, &(slapt_pkg_info_t){.name=(char *)pkg_name});
+ slapt_vector_t *matches = slapt_vector_t_search(pkg_list, by_details, &(slapt_pkg_info_t){.name = (char *)pkg_name});
if (!matches) {
return found;
}
@@ -696,19 +643,16 @@ slapt_pkg_info_t *slapt_get_newest_pkg(slapt_vector_t *pkg_list, const char *pkg
return found;
}
-slapt_pkg_info_t *slapt_get_exact_pkg(slapt_vector_t *list,
- const char *name,
- const char *version)
+slapt_pkg_info_t *slapt_get_exact_pkg(slapt_vector_t *list, const char *name, const char *version)
{
- int idx = slapt_vector_t_index_of(list, by_details, &(slapt_pkg_info_t){.name=(char *)name, .version=(char *)version});
+ int idx = slapt_vector_t_index_of(list, by_details, &(slapt_pkg_info_t){.name = (char *)name, .version = (char *)version});
if (idx > -1) {
return list->items[idx];
}
return NULL;
}
-int slapt_install_pkg(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg)
+int slapt_install_pkg(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg)
{
char *pkg_file_name = NULL;
char *command = NULL;
@@ -718,8 +662,7 @@ int slapt_install_pkg(const slapt_rc_config *global_config,
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 = slapt_calloc(strlen(SLAPT_INSTALL_CMD) + strlen(pkg_file_name) + 1, sizeof *command);
command[0] = '\0';
command = strcat(command, SLAPT_INSTALL_CMD);
command = strcat(command, pkg_file_name);
@@ -736,8 +679,7 @@ int slapt_install_pkg(const slapt_rc_config *global_config,
return cmd_return;
}
-int slapt_upgrade_pkg(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg)
+int slapt_upgrade_pkg(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg)
{
char *pkg_file_name = NULL;
char *command = NULL;
@@ -747,8 +689,7 @@ int slapt_upgrade_pkg(const slapt_rc_config *global_config,
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 = slapt_calloc(strlen(SLAPT_UPGRADE_CMD) + strlen(pkg_file_name) + 1, sizeof *command);
command[0] = '\0';
command = strcat(command, SLAPT_UPGRADE_CMD);
command = strcat(command, pkg_file_name);
@@ -773,9 +714,7 @@ int slapt_remove_pkg(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg
(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 = slapt_calloc(strlen(SLAPT_REMOVE_CMD) + strlen(pkg->name) + strlen(pkg->version) + 2, sizeof *command);
command[0] = '\0';
command = strcat(command, SLAPT_REMOVE_CMD);
command = strcat(command, pkg->name);
@@ -823,8 +762,7 @@ void slapt_free_pkg(slapt_pkg_info_t *pkg)
free(pkg);
}
-bool slapt_is_excluded(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg)
+bool slapt_is_excluded(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg)
{
int name_reg_ret = -1, version_reg_ret = -1, location_reg_ret = -1;
@@ -842,10 +780,7 @@ bool slapt_is_excluded(const slapt_rc_config *global_config,
if ((strncmp(exclude, pkg->name, strlen(pkg->name)) == 0))
return true;
- /*
- this regex has to be init'd and free'd within the loop b/c the regex is pulled
- from the exclude list
- */
+ /* 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(exclude)) == NULL) {
continue;
}
@@ -880,8 +815,7 @@ void slapt_get_md5sums(slapt_vector_t *pkgs, FILE *checksum_file)
exit(EXIT_FAILURE);
}
- while ((getline_read = getline(&getline_buffer, &getline_len,
- checksum_file)) != EOF) {
+ while ((getline_read = getline(&getline_buffer, &getline_len, checksum_file)) != EOF) {
if (
(strstr(getline_buffer, ".tgz") == NULL) &&
(strstr(getline_buffer, ".tlz") == NULL) &&
@@ -908,10 +842,7 @@ void slapt_get_md5sums(slapt_vector_t *pkgs, FILE *checksum_file)
/* see if we can match up name, version, and location */
slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, pkgs) {
- if (
- (strcmp(pkg->name, name) == 0) &&
- (slapt_cmp_pkg_versions(pkg->version, version) == 0) &&
- (strcmp(pkg->location, location) == 0)) {
+ if ((strcmp(pkg->name, name) == 0) && (slapt_cmp_pkg_versions(pkg->version, version) == 0) && (strcmp(pkg->location, location) == 0)) {
memcpy(pkg->md5, sum, SLAPT_MD5_STR_LEN);
break;
}
@@ -946,8 +877,7 @@ int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b)
{
int greater = 1, lesser = -1, equal = 0;
- /* if either of the two packages is installed, we look
- for the same version to bail out early if possible */
+ /* if either of the two packages is installed, we look for the same version to bail out early if possible */
if (a->installed || b->installed)
if (strcasecmp(a->version, b->version) == 0)
return equal;
@@ -977,13 +907,8 @@ int slapt_cmp_pkg_versions(const char *a, const char *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 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);
@@ -1117,8 +1042,7 @@ static struct slapt_pkg_version_parts *break_down_pkg_version(const char *versio
/* 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);
+ 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';
@@ -1128,8 +1052,7 @@ static struct slapt_pkg_version_parts *break_down_pkg_version(const char *versio
/* 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);
+ 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';
@@ -1139,8 +1062,7 @@ static struct slapt_pkg_version_parts *break_down_pkg_version(const char *versio
/* 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);
+ 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';
@@ -1153,8 +1075,7 @@ static struct slapt_pkg_version_parts *break_down_pkg_version(const char *versio
return pvp;
}
-void slapt_write_pkg_data(const char *source_url, FILE *d_file,
- slapt_vector_t *pkgs)
+void slapt_write_pkg_data(const char *source_url, FILE *d_file, slapt_vector_t *pkgs)
{
slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, pkgs) {
fprintf(d_file, "PACKAGE NAME: %s-%s%s\n", pkg->name, pkg->version, pkg->file_ext);
@@ -1192,8 +1113,7 @@ void slapt_write_pkg_data(const char *source_url, FILE *d_file,
}
}
-slapt_vector_t *slapt_search_pkg_list(slapt_vector_t *list,
- const char *pattern)
+slapt_vector_t *slapt_search_pkg_list(slapt_vector_t *list, const char *pattern)
{
int name_r = -1, desc_r = -1, loc_r = -1, version_r = -1;
slapt_regex_t *search_regex = NULL;
@@ -1299,9 +1219,7 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
slapt_vector_t_add(deps, tmp_pkg);
/* 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);
+ dep_check_return = slapt_get_pkg_dependencies(global_config, avail_pkgs, installed_pkgs, tmp_pkg, deps, conflict_err, missing_err);
if (dep_check_return == -1 && !global_config->ignore_dep) {
slapt_vector_t_free(dep_parts);
@@ -1320,9 +1238,7 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
}
/* lookup conflicts for package */
-slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- slapt_pkg_info_t *pkg)
+slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs, slapt_pkg_info_t *pkg)
{
slapt_vector_t *conflicts = NULL;
int position = 0, len = 0;
@@ -1359,9 +1275,7 @@ slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs,
/* build the buffer to contain the conflict entry */
pointer = strchr(pkg->conflicts + position, ',');
- buffer = strndup(
- pkg->conflicts + position,
- strlen(pkg->conflicts + position) - strlen(pointer));
+ 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);
@@ -1379,9 +1293,7 @@ slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs,
return conflicts;
}
-static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- char *dep_entry)
+static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs, char *dep_entry)
{
slapt_regex_t *parse_dep_regex = NULL;
char *tmp_pkg_name = NULL, *tmp_pkg_ver = NULL;
@@ -1432,8 +1344,8 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
}
if (tmp_cond_len != 0) {
- strcpy(tmp_pkg_cond, dep_entry + parse_dep_regex->pmatch[2].rm_so);
- tmp_pkg_cond[tmp_cond_len] = '\0';
+ strcpy(tmp_pkg_cond, dep_entry + parse_dep_regex->pmatch[2].rm_so);
+ tmp_pkg_cond[tmp_cond_len] = '\0';
}
tmp_pkg_ver = slapt_regex_extract_match(parse_dep_regex, dep_entry, 3);
@@ -1446,8 +1358,7 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_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)) {
+ 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;
@@ -1477,8 +1388,7 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
continue;
/* if condition is "=",">=", or "=<" and versions are the same */
- if ((strchr(tmp_pkg_cond, '=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver, installed_pkg->version) == 0)) {
+ if ((strchr(tmp_pkg_cond, '=') != NULL) && (slapt_cmp_pkg_versions(tmp_pkg_ver, installed_pkg->version) == 0)) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
return installed_pkg;
@@ -1503,14 +1413,10 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
}
}
- /*
- check the newest version of tmp_pkg_name (in newest_avail_pkg)
- before we try looping through avail_pkgs
- */
+ /* 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)) {
+ 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;
@@ -1541,8 +1447,7 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
continue;
/* if condition is "=",">=", or "=<" and versions are the same */
- if ((strchr(tmp_pkg_cond, '=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver, avail_pkg->version) == 0)) {
+ if ((strchr(tmp_pkg_cond, '=') != NULL) && (slapt_cmp_pkg_versions(tmp_pkg_ver, avail_pkg->version) == 0)) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
return avail_pkg;
@@ -1574,11 +1479,11 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
}
slapt_vector_t *slapt_is_required_by(const slapt_rc_config *global_config,
- slapt_vector_t *avail,
- slapt_vector_t *installed_pkgs,
- slapt_vector_t *pkgs_to_install,
- slapt_vector_t *pkgs_to_remove,
- slapt_pkg_info_t *pkg)
+ slapt_vector_t *avail,
+ slapt_vector_t *installed_pkgs,
+ slapt_vector_t *pkgs_to_install,
+ slapt_vector_t *pkgs_to_remove,
+ slapt_pkg_info_t *pkg)
{
slapt_vector_t *required_by_list = slapt_vector_t_init(NULL);
@@ -1722,12 +1627,9 @@ static void required_by(slapt_vector_t *avail,
slapt_free_regex(required_by_reg);
}
-slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_vector_t *list,
- const char *name,
- const char *version,
- const char *location)
+slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_vector_t *list, const char *name, const char *version, const char *location)
{
- int idx = slapt_vector_t_index_of(list, by_details, &(slapt_pkg_info_t){.name=(char *)name, .version=(char *)version, .location=(char *)location});
+ int idx = slapt_vector_t_index_of(list, by_details, &(slapt_pkg_info_t){.name = (char *)name, .version = (char *)version, .location = (char *)location});
if (idx > -1) {
return list->items[idx];
}
@@ -1963,16 +1865,12 @@ slapt_pkg_info_t *slapt_init_pkg(void)
}
/* generate the package file name */
-char *slapt_gen_pkg_file_name(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg)
+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 = 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 = strcpy(file_name, global_config->working_dir);
file_name[strlen(global_config->working_dir)] = '\0';
file_name = strcat(file_name, "/");
@@ -1996,9 +1894,7 @@ char *slapt_gen_pkg_url(slapt_pkg_info_t *pkg)
file_name = slapt_stringify_pkg(pkg);
/* build the url */
- url = slapt_calloc(strlen(pkg->mirror) + strlen(pkg->location) +
- strlen(file_name) + 2,
- sizeof *url);
+ url = slapt_calloc(strlen(pkg->mirror) + strlen(pkg->location) + strlen(file_name) + 2, sizeof *url);
url = memcpy(url, pkg->mirror, strlen(pkg->mirror));
url[strlen(pkg->mirror)] = '\0';
@@ -2011,8 +1907,7 @@ char *slapt_gen_pkg_url(slapt_pkg_info_t *pkg)
}
/* 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)
+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;
@@ -2030,8 +1925,7 @@ size_t slapt_get_pkg_file_size(const slapt_rc_config *global_config,
}
/* 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_code_t slapt_verify_downloaded_pkg(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg)
{
char *file_name = NULL;
FILE *fh_test = NULL;
@@ -2100,9 +1994,7 @@ char *slapt_gen_filename_from_url(const char *url, const char *file)
return cleaned;
}
-void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
- const char *dir_name,
- slapt_vector_t *avail_pkgs)
+void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config, const char *dir_name, slapt_vector_t *avail_pkgs)
{
DIR *dir;
struct dirent *file;
@@ -2248,9 +2140,7 @@ void slapt_clean_pkg_dir(const char *dir_name)
}
/* find dependency from "or" requirement */
-static slapt_pkg_info_t *find_or_requirement(slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- char *required_str)
+static slapt_pkg_info_t *find_or_requirement(slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs, char *required_str)
{
slapt_pkg_info_t *pkg = NULL;
slapt_vector_t *alternates = slapt_parse_delimited_list(required_str, '|');
@@ -2313,7 +2203,8 @@ slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst, slapt_pkg_info_t *src)
return dst;
}
-slapt_pkg_err_t *slapt_pkg_err_t_init(char *pkg, char *err) {
+slapt_pkg_err_t *slapt_pkg_err_t_init(char *pkg, char *err)
+{
slapt_pkg_err_t *e = NULL;
e = slapt_malloc(sizeof *e);
e->pkg = pkg;
@@ -2321,7 +2212,8 @@ slapt_pkg_err_t *slapt_pkg_err_t_init(char *pkg, char *err) {
return e;
}
-void slapt_pkg_err_t_free(slapt_pkg_err_t *e) {
+void slapt_pkg_err_t_free(slapt_pkg_err_t *e)
+{
free(e->pkg);
free(e->error);
free(e);
@@ -2349,8 +2241,7 @@ static FILE *slapt_gunzip_file(const char *file_name, FILE *dest_file)
return dest_file;
}
-slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
- const char *url, bool *compressed)
+slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config, const char *url, bool *compressed)
{
slapt_vector_t *available_pkgs = NULL;
char *pkg_head = NULL;
@@ -2377,8 +2268,7 @@ slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_conf
if (available_pkgs == NULL || available_pkgs->size < 1) {
slapt_clear_head_cache(pkg_filename);
- fprintf(stderr, gettext("Failed to parse package data from %s\n"),
- pkg_filename);
+ fprintf(stderr, gettext("Failed to parse package data from %s\n"), pkg_filename);
if (available_pkgs)
slapt_vector_t_free(available_pkgs);
@@ -2402,9 +2292,7 @@ slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_conf
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);
+ 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;
@@ -2465,8 +2353,7 @@ slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_conf
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) {
+ 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);
@@ -2488,9 +2375,7 @@ slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_conf
exit(EXIT_FAILURE);
/* retrieve the uncompressed package data */
- err = slapt_get_mirror_data_from_source(tmp_pkg_f,
- global_config, url,
- SLAPT_PKG_LIST);
+ 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 */
@@ -2540,8 +2425,7 @@ slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_conf
return available_pkgs;
}
-slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
- const char *url, bool *compressed)
+slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config, const char *url, bool *compressed)
{
slapt_vector_t *patch_pkgs = NULL;
char *patch_head = NULL;
@@ -2576,9 +2460,7 @@ slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_confi
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);
+ 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;
@@ -2624,8 +2506,7 @@ slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_confi
*/
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) {
+ 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)
@@ -2647,9 +2528,7 @@ slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_confi
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);
+ 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);
@@ -2684,8 +2563,7 @@ slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_confi
return patch_pkgs;
}
-FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
- const char *url, bool *compressed)
+FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config, const char *url, bool *compressed)
{
FILE *tmp_checksum_f = NULL;
char *checksum_head = NULL;
@@ -2715,9 +2593,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
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);
+ err = slapt_get_mirror_data_from_source(working_checksum_f, global_config, url, SLAPT_CHECKSUM_FILE_GZ);
if (!err) {
if (global_config->dl_stats)
printf("\n");
@@ -2765,8 +2641,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
*/
checksum_head = slapt_head_mirror_data(url, SLAPT_CHECKSUM_FILE);
- if (checksum_head != NULL && local_head != NULL &&
- strcmp(checksum_head, local_head) == 0) {
+ 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);
@@ -2782,9 +2657,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
if (global_config->dl_stats)
printf("\n");
- err = slapt_get_mirror_data_from_source(tmp_checksum_f,
- global_config, url,
- SLAPT_CHECKSUM_FILE);
+ 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"));
@@ -2819,8 +2692,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
return tmp_checksum_f;
}
-bool slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
- const char *url, bool *compressed)
+bool slapt_get_pkg_source_changelog(const slapt_rc_config *global_config, const char *url, bool *compressed)
{
char *changelog_head = NULL;
char *filename = NULL;
@@ -2863,9 +2735,7 @@ bool slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
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);
+ err = slapt_get_mirror_data_from_source(working_changelog_f, global_config, url, location);
if (!err) {
if (global_config->dl_stats)
printf("\n");
@@ -2956,8 +2826,7 @@ char *slapt_get_pkg_changelog(const slapt_pkg_info_t *pkg)
pls = (size_t)stat_buf.st_size;
- pkg_data = (char *)mmap(0, pls,
- PROT_READ | PROT_WRITE, MAP_PRIVATE, fileno(working_changelog_f), 0);
+ pkg_data = (char *)mmap(0, pls, PROT_READ | PROT_WRITE, MAP_PRIVATE, fileno(working_changelog_f), 0);
if (pkg_data == (void *)-1) {
if (errno)
@@ -3045,24 +2914,16 @@ char *slapt_stringify_pkg(const slapt_pkg_info_t *pkg)
}
slapt_vector_t *
-slapt_get_obsolete_pkgs(const slapt_rc_config *global_config,
- slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs)
+slapt_get_obsolete_pkgs(const slapt_rc_config *global_config, slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs)
{
slapt_vector_t *obsolete = slapt_vector_t_init(NULL);
slapt_vector_t *to_install = slapt_vector_t_init(NULL);
slapt_vector_t *to_remove = slapt_vector_t_init(NULL);
slapt_vector_t_foreach (slapt_pkg_info_t *, p, installed_pkgs) {
- /*
- if we can't find the installed package in our available pkg list,
- it must be obsolete
- */
+ /* 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) {
- /*
- any packages that require this package we are about to remove
- should be scheduled to remove as well
- */
+ /* any packages that require this package we are about to remove should be scheduled to remove as well */
slapt_vector_t *deps = slapt_is_required_by(global_config, avail_pkgs, installed_pkgs, to_install, to_remove, p);
slapt_vector_t_foreach (slapt_pkg_info_t *, dep, deps) {
@@ -3142,8 +3003,7 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
}
/* 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 = slapt_malloc(sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(pkg_name) + 2));
pkg_f_name[0] = '\0';
strcat(pkg_f_name, pkg_log_dirname);
strcat(pkg_f_name, "/");
@@ -3151,10 +3011,7 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
free(pkg_log_dirname);
- /*
- open the package log file so that we can mmap it and parse out the
- file list.
- */
+ /* 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);
@@ -3177,8 +3034,7 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
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);
@@ -3209,13 +3065,10 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
}
/* files in install/ are package metadata */
- if (strncmp(filelist_p, "./\n", 3) != 0 &&
- strncmp(filelist_p, "install/", 8) != 0) {
+ 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));
+ tmp_filelist = realloc(filelist, sizeof *filelist * (filelist_len + tmp_len + 1));
if (tmp_filelist != NULL) {
filelist = tmp_filelist;
@@ -3279,7 +3132,8 @@ char *slapt_gen_package_log_dir_name(void)
return pkg_log_dirname;
}
-slapt_pkg_upgrade_t *slapt_pkg_upgrade_t_init(slapt_pkg_info_t *i, slapt_pkg_info_t *u) {
+slapt_pkg_upgrade_t *slapt_pkg_upgrade_t_init(slapt_pkg_info_t *i, slapt_pkg_info_t *u)
+{
slapt_pkg_upgrade_t *upgrade = NULL;
upgrade = slapt_malloc(sizeof *upgrade);
upgrade->installed = i;
@@ -3287,7 +3141,8 @@ slapt_pkg_upgrade_t *slapt_pkg_upgrade_t_init(slapt_pkg_info_t *i, slapt_pkg_inf
return upgrade;
}
-void slapt_pkg_upgrade_t_free(slapt_pkg_upgrade_t *upgrade) {
+void slapt_pkg_upgrade_t_free(slapt_pkg_upgrade_t *upgrade)
+{
slapt_free_pkg(upgrade->installed);
slapt_free_pkg(upgrade->upgrade);
free(upgrade);
diff --git a/src/package.h b/src/package.h
index 16797c0..951ec00 100644
--- a/src/package.h
+++ b/src/package.h
@@ -95,8 +95,7 @@ void slapt_free_pkg(slapt_pkg_info_t *pkg);
*/
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,
- slapt_vector_t *pkgs);
+void slapt_write_pkg_data(const char *source_url, FILE *d_file, slapt_vector_t *pkgs);
/* parse the PACKAGES.TXT file */
slapt_vector_t *slapt_parse_packages_txt(FILE *);
/*
@@ -111,90 +110,42 @@ slapt_vector_t *slapt_get_installed_pkgs(void);
/* retrieve the newest package from package list */
slapt_pkg_info_t *slapt_get_newest_pkg(slapt_vector_t *, const char *);
/* get the exact package */
-slapt_pkg_info_t *slapt_get_exact_pkg(slapt_vector_t *list,
- const char *name,
- const char *version);
+slapt_pkg_info_t *slapt_get_exact_pkg(slapt_vector_t *list, const char *name, const char *version);
/* lookup package by details */
-slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_vector_t *list,
- const char *name,
- const char *version,
- const char *location);
+slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_vector_t *list, const char *name, const char *version, const char *location);
/* search package list with pattern */
-slapt_vector_t *slapt_search_pkg_list(slapt_vector_t *list,
- const char *pattern);
+slapt_vector_t *slapt_search_pkg_list(slapt_vector_t *list, const char *pattern);
-/*
- install package by calling installpkg
- returns 0 on success, -1 on error
-*/
+/* install package by calling installpkg, returns 0 on success, -1 on error */
int slapt_install_pkg(const slapt_rc_config *, slapt_pkg_info_t *);
-/*
- upgrade package by calling upgradepkg
- returns 0 on success, -1 on error
-*/
-int slapt_upgrade_pkg(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg);
-/*
- remove package by calling removepkg
- returns 0 on success, -1 on error
-*/
+/* upgrade package by calling upgradepkg, returns 0 on success, -1 on error */
+int slapt_upgrade_pkg(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg);
+/* remove package by calling removepkg, returns 0 on success, -1 on error */
int slapt_remove_pkg(const slapt_rc_config *, slapt_pkg_info_t *);
/* get a list of obsolete packages */
-slapt_vector_t *
-slapt_get_obsolete_pkgs(const slapt_rc_config *global_config,
- slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs);
+slapt_vector_t *slapt_get_obsolete_pkgs(const slapt_rc_config *global_config, slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs);
-/*
- generate a short description, returns (char *) on success or NULL on error
- caller responsible for freeing the returned data
-*/
+/* generate a short description, returns (char *) on success or NULL on error, caller responsible for freeing the returned data */
char *slapt_gen_short_pkg_description(slapt_pkg_info_t *);
-/*
- generate the filename from the url
- caller responsible for freeing the returned data
-*/
+/* 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);
-/*
- generate the package file name
- caller responsible for freeing the returned data
-*/
-char *slapt_gen_pkg_file_name(const slapt_rc_config *global_config,
- slapt_pkg_info_t *pkg);
-/*
- generate the head cache filename
- caller responsible for freeing the returned data
-*/
+/* generate the package file name, caller responsible for freeing the returned data */
+char *slapt_gen_pkg_file_name(const slapt_rc_config *global_config, slapt_pkg_info_t *pkg);
+/* generate the head cache filename, caller responsible for freeing the returned data */
char *slapt_gen_head_cache_filename(const char *filename_from_url);
-/*
- generate the download url for a package
- caller responsible for freeing the returned data
-*/
+/* generate the download url for a package, caller responsible for freeing the returned data */
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
-*/
+/* exclude pkg based on pkg name, returns 1 if package is present in the exclude list, 0 if not present */
bool 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);
-/*
- fill in the md5sum of the package
-*/
+/* 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);
+/* fill in the md5sum of the package */
void slapt_get_md5sums(slapt_vector_t *pkgs, FILE *checksum_file);
-/*
- 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);
+/* 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);
-/*
- compare package versions
+/* compare package versions,
returns just like strcmp,
> 0 if a is greater than b
< 0 if a is less than b
@@ -215,59 +166,40 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
slapt_vector_t *deps,
slapt_vector_t *conflict_err,
slapt_vector_t *missing_err);
-/*
- return list of package conflicts
-*/
-slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- slapt_pkg_info_t *pkg);
-/*
- return list of packages required by
-*/
+/* return list of package conflicts */
+slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs, slapt_vector_t *installed_pkgs, slapt_pkg_info_t *pkg);
+/* return list of packages required by */
slapt_vector_t *slapt_is_required_by(const slapt_rc_config *global_config,
- slapt_vector_t *avail,
- slapt_vector_t *installed_pkgs,
- slapt_vector_t *pkgs_to_install,
- slapt_vector_t *pkgs_to_remove,
- slapt_pkg_info_t *pkg);
+ slapt_vector_t *avail,
+ slapt_vector_t *installed_pkgs,
+ slapt_vector_t *pkgs_to_install,
+ slapt_vector_t *pkgs_to_remove,
+ slapt_pkg_info_t *pkg);
-/*
- empty packages from cache dir
-*/
+/* empty packages from cache dir */
void slapt_clean_pkg_dir(const char *dir_name);
/*
clean out old outdated packages in the cache that are no longer available
in the current source lists (ie are not downloadable)
*/
-void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
- const char *dir_name,
- slapt_vector_t *avail_pkgs);
+void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config, const char *dir_name, slapt_vector_t *avail_pkgs);
-/*
- make a copy of a package (needs to be freed with free_pkg)
-*/
+/* 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);
/*
download the PACKAGES.TXT and CHECKSUMS.md5 files
compressed is set if the compressed version was downloaded.
*/
-slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
- const char *url, bool *compressed);
-slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
- const char *url, bool *compressed);
-FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
- const char *url, bool *compressed);
-bool slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
- const char *url, bool *compressed);
+slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config, const char *url, bool *compressed);
+slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config, const char *url, bool *compressed);
+FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config, const char *url, bool *compressed);
+bool slapt_get_pkg_source_changelog(const slapt_rc_config *global_config, const char *url, bool *compressed);
/* clean package name from package description */
void slapt_clean_description(char *description, const char *name);
-/*
- retrieve the packages changelog entry, if any. Returns NULL otherwise
- Must be chdir'd to working_dir.
-*/
+/* retrieve the packages changelog entry, if any. Returns NULL otherwise, Must be chdir'd to working_dir. */
char *slapt_get_pkg_changelog(const slapt_pkg_info_t *pkg);
/* returns a string representation of the package */
diff --git a/src/transaction.c b/src/transaction.c
index f5801a1..a937523 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -45,10 +45,11 @@ slapt_transaction_t *slapt_init_transaction(void)
return tran;
}
-slapt_queue_i *slapt_queue_i_init(slapt_pkg_info_t *i, slapt_pkg_upgrade_t *u) {
+slapt_queue_i *slapt_queue_i_init(slapt_pkg_info_t *i, slapt_pkg_upgrade_t *u)
+{
slapt_queue_i *qi = NULL;
qi = slapt_malloc(sizeof *qi);
- if ((i && u ) || (!i && !u)){
+ if ((i && u) || (!i && !u)) {
exit(EXIT_FAILURE);
}
if (i) {
@@ -61,12 +62,12 @@ slapt_queue_i *slapt_queue_i_init(slapt_pkg_info_t *i, slapt_pkg_upgrade_t *u) {
return qi;
}
-void slapt_queue_i_free(slapt_queue_i *qi) {
+void slapt_queue_i_free(slapt_queue_i *qi)
+{
free(qi);
}
-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)
{
uint32_t pkg_dl_count = 0, dl_counter = 0, len = 0;
double download_size = 0;
@@ -85,8 +86,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* show conflicts */
if (tran->conflict_err->size > 0) {
slapt_vector_t_foreach (slapt_pkg_err_t *, conflict_error, tran->conflict_err) {
- fprintf(stderr, gettext("%s, which is required by %s, is excluded\n"),
- conflict_error->error, conflict_error->pkg);
+ fprintf(stderr, gettext("%s, which is required by %s, is excluded\n"), conflict_error->error, conflict_error->pkg);
}
}
@@ -270,9 +270,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* check we have enough space to download to our working dir */
if (!slapt_disk_space_check(global_config->working_dir, need_to_download_size)) {
- printf(
- gettext("You don't have enough free space in %s\n"),
- global_config->working_dir);
+ 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 */
@@ -284,8 +282,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
}
}
- if (tran->upgrade_pkgs->size > 0 || tran->remove_pkgs->size > 0 ||
- tran->install_pkgs->size > 0 || tran->reinstall_pkgs->size > 0) {
+ if (tran->upgrade_pkgs->size > 0 || tran->remove_pkgs->size > 0 || tran->install_pkgs->size > 0 || tran->reinstall_pkgs->size > 0) {
if (global_config->download_only == false) {
if ((int)uncompressed_size < 0) {
uncompressed_size *= -1;
@@ -443,11 +440,8 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
slapt_vector_t_foreach (slapt_queue_i *, q, tran->queue) {
if (q->type == INSTALL) {
- printf(gettext("Preparing to install %s-%s\n"),
- q->pkg.i->name,
- q->pkg.i->version);
- if (slapt_install_pkg(global_config,
- q->pkg.i) == -1) {
+ printf(gettext("Preparing to install %s-%s\n"), q->pkg.i->name, q->pkg.i->version);
+ if (slapt_install_pkg(global_config, q->pkg.i) == -1) {
exit(EXIT_FAILURE);
}
} else if (q->type == UPGRADE) {
@@ -456,8 +450,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
q->pkg.u->installed->version,
q->pkg.u->upgrade->name,
q->pkg.u->upgrade->version);
- if (slapt_upgrade_pkg(global_config,
- q->pkg.u->upgrade) == -1) {
+ if (slapt_upgrade_pkg(global_config, q->pkg.u->upgrade) == -1) {
exit(EXIT_FAILURE);
}
}
@@ -469,8 +462,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
return 0;
}
-void slapt_add_install_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg)
+void slapt_add_install_to_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, pkg))
@@ -481,8 +473,7 @@ void slapt_add_install_to_transaction(slapt_transaction_t *tran,
slapt_vector_t_add(tran->queue, slapt_queue_i_init(tran->install_pkgs->items[tran->install_pkgs->size - 1], NULL));
}
-void slapt_add_remove_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg)
+void slapt_add_remove_to_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, pkg))
@@ -492,8 +483,7 @@ void slapt_add_remove_to_transaction(slapt_transaction_t *tran,
slapt_vector_t_add(tran->remove_pkgs, r);
}
-void slapt_add_exclude_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg)
+void slapt_add_exclude_to_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, pkg))
@@ -503,9 +493,7 @@ void slapt_add_exclude_to_transaction(slapt_transaction_t *tran,
slapt_vector_t_add(tran->exclude_pkgs, e);
}
-void slapt_add_reinstall_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg)
+void slapt_add_reinstall_to_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *installed_pkg, slapt_pkg_info_t *slapt_upgrade_pkg)
{
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg))
@@ -515,12 +503,10 @@ void slapt_add_reinstall_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *u = slapt_copy_pkg(NULL, slapt_upgrade_pkg);
slapt_vector_t_add(tran->reinstall_pkgs, slapt_pkg_upgrade_t_init(i, u));
- slapt_vector_t_add(tran->queue, slapt_queue_i_init(NULL, tran->reinstall_pkgs->items[tran->reinstall_pkgs->size -1]));
+ slapt_vector_t_add(tran->queue, slapt_queue_i_init(NULL, tran->reinstall_pkgs->items[tran->reinstall_pkgs->size - 1]));
}
-void slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg)
+void slapt_add_upgrade_to_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *installed_pkg, slapt_pkg_info_t *slapt_upgrade_pkg)
{
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg))
@@ -563,8 +549,7 @@ bool slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
return false;
}
-bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg)
+bool slapt_search_upgrade_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
slapt_vector_t_foreach (slapt_pkg_upgrade_t *, upgrade, tran->upgrade_pkgs) {
if (strcmp(pkg->name, upgrade->upgrade->name) == 0)
@@ -589,8 +574,7 @@ void slapt_free_transaction(slapt_transaction_t *tran)
free(tran);
}
-slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg)
+slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
slapt_transaction_t *new_tran = NULL;
@@ -606,8 +590,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
new_tran = slapt_init_transaction();
slapt_vector_t_foreach (slapt_pkg_info_t *, installed_pkg, tran->install_pkgs) {
- if (
- strcmp(pkg->name, installed_pkg->name) == 0 &&
+ if (strcmp(pkg->name, installed_pkg->name) == 0 &&
strcmp(pkg->version, installed_pkg->version) == 0 &&
strcmp(pkg->location, installed_pkg->location) == 0) {
continue;
@@ -617,8 +600,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
}
slapt_vector_t_foreach (slapt_pkg_info_t *, remove_pkg, tran->remove_pkgs) {
- if (
- strcmp(pkg->name, remove_pkg->name) == 0 &&
+ if (strcmp(pkg->name, remove_pkg->name) == 0 &&
strcmp(pkg->version, remove_pkg->version) == 0 &&
strcmp(pkg->location, remove_pkg->location) == 0) {
continue;
@@ -631,8 +613,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *u = upgrade->upgrade;
slapt_pkg_info_t *p = upgrade->installed;
- if (
- strcmp(pkg->name, u->name) == 0 &&
+ if (strcmp(pkg->name, u->name) == 0 &&
strcmp(pkg->version, u->version) == 0 &&
strcmp(pkg->location, u->location) == 0) {
continue;
@@ -642,8 +623,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
}
slapt_vector_t_foreach (slapt_pkg_info_t *, exclude_pkg, tran->exclude_pkgs) {
- if (
- strcmp(pkg->name, exclude_pkg->name) == 0 &&
+ if (strcmp(pkg->name, exclude_pkg->name) == 0 &&
strcmp(pkg->version, exclude_pkg->version) == 0 &&
strcmp(pkg->location, exclude_pkg->location) == 0) {
continue;
@@ -673,14 +653,11 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
slapt_vector_t *deps = slapt_vector_t_init(NULL);
- 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)) {
+ if ((dep_return == -1) && (global_config->ignore_dep == false) && (slapt_get_exact_pkg(tran->exclude_pkgs, pkg->name, pkg->version) == NULL)) {
slapt_vector_t_free(deps);
return -1;
}
@@ -715,9 +692,9 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
/* make sure pkg isn't conflicted with what's already in the transaction */
slapt_vector_t *slapt_is_conflicted(slapt_transaction_t *tran,
- slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- slapt_pkg_info_t *pkg)
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
+ slapt_pkg_info_t *pkg)
{
slapt_vector_t *conflicts = NULL;
slapt_vector_t *conflicts_in_transaction = slapt_vector_t_init(NULL);
@@ -763,8 +740,7 @@ static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
slapt_vector_t_free(suggests);
}
-bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg)
+bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
slapt_vector_t_foreach (slapt_pkg_info_t *, install_pkg, tran->install_pkgs) {
if ((strcmp(pkg->name, install_pkg->name) == 0) && (strcmp(pkg->version, install_pkg->version) == 0))
diff --git a/src/transaction.h b/src/transaction.h
index 62032ca..bf81deb 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -46,69 +46,42 @@ typedef struct {
/* fill in transaction structure with defaults */
slapt_transaction_t *slapt_init_transaction(void);
-/*
- download and install/remove/upgrade packages as defined in the transaction
- returns 0 on success
-*/
+/* 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 *);
/* add package for installation to transaction */
-void slapt_add_install_to_transaction(slapt_transaction_t *,
- slapt_pkg_info_t *pkg);
+void slapt_add_install_to_transaction(slapt_transaction_t *, slapt_pkg_info_t *pkg);
/* add package for removal to transaction */
-void slapt_add_remove_to_transaction(slapt_transaction_t *,
- slapt_pkg_info_t *pkg);
+void slapt_add_remove_to_transaction(slapt_transaction_t *, slapt_pkg_info_t *pkg);
/* add package to upgrade to transaction */
-void slapt_add_upgrade_to_transaction(slapt_transaction_t *,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *upgrade_pkg);
+void slapt_add_upgrade_to_transaction(slapt_transaction_t *, slapt_pkg_info_t *installed_pkg, 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);
+void slapt_add_reinstall_to_transaction(slapt_transaction_t *, 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);
+void slapt_add_exclude_to_transaction(slapt_transaction_t *, slapt_pkg_info_t *pkg);
/* remove package from transaction, returns modified transaction */
-slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg);
+slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *pkg);
/* search transaction by package name. returns true if found, false otherwise */
bool slapt_search_transaction(slapt_transaction_t *, char *pkg_name);
-/*
- search transaction by package attributes
- returns true if found, false otherwise
-*/
-bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg);
-/*
- searches the upgrade list of the transaction for the present of the package
- returns true if found, false if not found
-*/
-bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *pkg);
+/* search transaction by package attributes, returns true if found, false otherwise */
+bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran, slapt_pkg_info_t *pkg);
+/* searches the upgrade list of the transaction for the present of the package, returns true if found, false if not found */
+bool slapt_search_upgrade_transaction(slapt_transaction_t *tran, slapt_pkg_info_t *pkg);
-/*
- add dependencies for package to transaction, returns -1 on error, 0 otherwise
-*/
+/* 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,
slapt_vector_t *avail_pkgs,
slapt_vector_t *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
-*/
+/* check to see if a package has a conflict already present in the transaction, returns conflicted package or NULL if none */
slapt_vector_t *slapt_is_conflicted(slapt_transaction_t *tran,
- slapt_vector_t *avail_pkgs,
- slapt_vector_t *installed_pkgs,
- slapt_pkg_info_t *pkg);
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
+ slapt_pkg_info_t *pkg);
-/*
- generate a list of suggestions based on the current packages
- in the transaction
-*/
+/* generate a list of suggestions based on the current packages in the transaction */
void slapt_generate_suggestions(slapt_transaction_t *tran);
/* free the transaction structure and it's members */