summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2018-11-10 16:13:46 -0500
committerJason Woodward2018-11-10 16:13:46 -0500
commitc04d01d2f29d77300772eb2aea93def6fe7817a2 (patch)
treeef8b7e8fd28210177e9fae85cae22dcb4657e3ad
parent264edab5be1d7e8aa2fddd59090fe6060c3f2d02 (diff)
parent1bdd660d983601a7a1de5930163f51dfaa09189a (diff)
downloadslapt-get-c04d01d2f29d77300772eb2aea93def6fe7817a2.tar.gz
Merge branch 'refactoring'
-rw-r--r--.clang-format42
-rw-r--r--Makefile1
-rw-r--r--default.slapt-getrc.aarch6420
-rw-r--r--default.slapt-getrc.arm2
-rw-r--r--default.slapt-getrc.i3862
-rw-r--r--default.slapt-getrc.x86_642
-rw-r--r--doc/libslapt.336
-rw-r--r--example.slapt-getrc2
-rw-r--r--example.slapt-getrc.i3862
-rw-r--r--example.slapt-getrc.x86_642
-rw-r--r--src/action.c234
-rw-r--r--src/common.c26
-rw-r--r--src/common.h4
-rw-r--r--src/configuration.c28
-rw-r--r--src/configuration.h5
-rw-r--r--src/curl.c18
-rw-r--r--src/gpgme.c28
-rw-r--r--src/gpgme.h4
-rw-r--r--src/main.c14
-rw-r--r--src/main.h1
-rw-r--r--src/package.c575
-rw-r--r--src/package.h35
-rw-r--r--src/transaction.c372
-rw-r--r--src/transaction.h17
-rw-r--r--t/data/rc12
-rw-r--r--t/test_packages.c4
-rw-r--r--t/test_transaction.c10
27 files changed, 707 insertions, 781 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..6a555de
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,42 @@
+´╗┐Language: Cpp
+IndentWidth: 4
+AllowShortFunctionsOnASingleLine: None
+KeepEmptyLinesAtTheStartOfBlocks: false
+ColumnLimit: 0
+UseTab: Never
+TabWidth: 4
+# BreakBeforeBraces: Linux
+BreakBeforeBraces: Custom
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: false
+ AfterObjCDeclaration: true
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: true
+ BeforeCatch: true
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
+PointerBindsToType: false
+SortIncludes: false
+ForEachMacros: [
+'slapt_list_t_foreach',
+'slapt_source_list_t_foreach',
+'slapt_pkg_list_t_foreach',
+'slapt_pkg_upgrade_list_t_foreach',
+'slapt_pkg_err_list_t_foreach',
+'slapt_queue_t_foreach'
+]
+SpaceBeforeParens: ControlStatements
+SpaceBeforeAssignmentOperators: true
+AlignAfterOpenBracket: true
+AlignConsecutiveAssignments: false
+SpaceBeforeRangeBasedForLoopColon: true
+# SpacesBeforeTrailingComments: true
+SpacesInParentheses: false
diff --git a/Makefile b/Makefile
index 9b86bad..055bb1e 100644
--- a/Makefile
+++ b/Makefile
@@ -157,6 +157,7 @@ dopkg:
$(STRIP) pkg$(LIBDIR)/libslapt.so.$(VERSION)
( cd pkg$(LIBDIR); ln -sf libslapt.so.$(VERSION) libslapt.so )
-( cd pkg; /sbin/makepkg -l y -c n ../$(PACKAGE)-$(VERSION)-$(ARCH)-$(RELEASE).tgz )
+ rmdir -rf pkg
po_file:
-xgettext -o po/slapt-get.pot.new -sC --no-location src/*.c src/*.h
diff --git a/default.slapt-getrc.aarch64 b/default.slapt-getrc.aarch64
new file mode 100644
index 0000000..309742d
--- /dev/null
+++ b/default.slapt-getrc.aarch64
@@ -0,0 +1,20 @@
+# Working directory for local storage/cache.
+WORKINGDIR=/var/cache/slapt-get
+
+# Exclude package names and expressions.
+# To exclude pre and beta packages, add this to the exclude:
+# [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
+EXCLUDE=^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64,i[3456]86,arm
+
+# Base url to directory with a PACKAGES.TXT.
+# This can point to any release, ie: 9.0, 10.0, current, etc.
+SOURCE=http://dl.fail.pp.ua/slackware/slarm64-current/:OFFICIAL
+
+# Source for slapt-get.
+SOURCE=http://software.jaos.org/slackpacks/14.2-arm64/:OFFICIAL
+
+# Packages on a CD/DVD.
+# SOURCE=file:///mnt/cdrom/:OFFICIAL
+
+# Home made packages.
+# SOURCE=file:///var/www/packages/:CUSTOM
diff --git a/default.slapt-getrc.arm b/default.slapt-getrc.arm
index a11413a..e433fa9 100644
--- a/default.slapt-getrc.arm
+++ b/default.slapt-getrc.arm
@@ -4,7 +4,7 @@ WORKINGDIR=/var/cache/slapt-get
# Exclude package names and expressions.
# To exclude pre and beta packages, add this to the exclude:
# [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
-EXCLUDE=^aaa_elflibs,^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64,i[3456]86
+EXCLUDE=^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64,i[3456]86
# Base url to directory with a PACKAGES.TXT.
# This can point to any release, ie: 9.0, 10.0, current, etc.
diff --git a/default.slapt-getrc.i386 b/default.slapt-getrc.i386
index 7ea425f..884bc6d 100644
--- a/default.slapt-getrc.i386
+++ b/default.slapt-getrc.i386
@@ -4,7 +4,7 @@ WORKINGDIR=/var/cache/slapt-get
# Exclude package names and expressions.
# To exclude pre and beta packages, add this to the exclude:
# [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
-EXCLUDE=^aaa_elflibs,^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64
+EXCLUDE=^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64
# Base url to directory with a PACKAGES.TXT.
# This can point to any release, ie: 9.0, 10.0, current, etc.
diff --git a/default.slapt-getrc.x86_64 b/default.slapt-getrc.x86_64
index eac291c..c034ab9 100644
--- a/default.slapt-getrc.x86_64
+++ b/default.slapt-getrc.x86_64
@@ -4,7 +4,7 @@ WORKINGDIR=/var/cache/slapt-get
# Exclude package names and expressions.
# To exclude pre and beta packages, add this to the exclude:
# [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
-EXCLUDE=^aaa_elflibs,^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,i[3456]86
+EXCLUDE=^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,i[3456]86
# Base url to directory with a PACKAGES.TXT.
# This can point to any release, ie: 9.0, 10.0, current, etc.
diff --git a/doc/libslapt.3 b/doc/libslapt.3
index 49a4257..d772698 100644
--- a/doc/libslapt.3
+++ b/doc/libslapt.3
@@ -78,7 +78,7 @@ slapt-get stores the configuration information in a \fIslapt_rc_config\fP object
bool dl_stats;
bool remove_obsolete;
bool no_upgrade;
- unsigned int retry;
+ uint32_t retry;
} slapt_rc_config;
.fi
@@ -122,7 +122,7 @@ The \fIslapt_source_list_t\fP stores the package sources. Sources can be added
.nf
typedef struct {
slapt_source_t **src;
- unsigned int count;
+ uint32_t count;
} slapt_source_list_t;
.sp
.B "slapt_source_list_t *slapt_init_source_list(void);"
@@ -152,9 +152,9 @@ slapt-get stores packages within \fIslapt_pkg_info_t\fP objects.
char *conflicts;
char *suggests;
char *file_ext;
- unsigned int size_c;
- unsigned int size_u;
- unsigned int priority;
+ uint32_t size_c;
+ uint32_t size_u;
+ uint32_t priority;
bool installed;
} slapt_pkg_info_t;
.fi
@@ -175,7 +175,7 @@ Package lists are useful for grouping packages from the existing installed packa
.nf
typedef struct {
slapt_pkg_info_t **pkgs;
- unsigned int pkg_count;
+ uint32_t pkg_count;
bool free_pkgs;
bool ordered;
} slapt_pkg_list_t;
@@ -251,7 +251,7 @@ The following functions deal with determining package dependencies and conflicts
.sp
typedef struct {
slapt_pkg_err_t **errs;
- unsigned int err_count;
+ uint32_t err_count;
} slapt_pkg_err_list_t;
.sp
.B "slapt_pkg_err_list_t *slapt_init_pkg_err_list(void);"
@@ -391,14 +391,14 @@ The following functions download the PACKAGES.TXT, the patches/PACKAGES.TXT, CHE
.nf
.B "slapt_pkg_list_t *"
.B "slapt_get_pkg_source_packages (const slapt_rc_config *global_config,"
-.B " const char *url, unsigned int *compressed);"
+.B " const char *url, bool *compressed);"
.B "slapt_pkg_list_t *"
.B "slapt_get_pkg_source_patches (const slapt_rc_config *global_config,"
-.B " const char *url, unsigned int *compressed);"
+.B " const char *url, bool *compressed);"
.B "FILE *slapt_get_pkg_source_checksums (const slapt_rc_config *global_config,"
-.B " const char *url, unsigned int *compressed);"
+.B " const char *url, bool *compressed);"
.B "int slapt_get_pkg_source_changelog (const slapt_rc_config *global_config,"
-.B " const char *url, unsigned int *compressed);"
+.B " const char *url, bool *compressed);"
.fi
.sp
.TP
@@ -426,12 +426,12 @@ Adding, removing, and upgrading packages can be wrapped in a \fIslapt_transactio
.sp
typedef struct {
union { slapt_pkg_info_t *i; slapt_pkg_upgrade_t *u; } pkg;
- unsigned int type; /* this is enum slapt_action */
+ uint32_t type; /* this is enum slapt_action */
} slapt_queue_i;
.sp
typedef struct {
slapt_queue_i **pkgs;
- unsigned int count;
+ uint32_t count;
} slapt_queue_t;
.sp
typedef struct {
@@ -442,8 +442,8 @@ Adding, removing, and upgrading packages can be wrapped in a \fIslapt_transactio
.sp
typedef struct {
slapt_pkg_upgrade_t **pkgs;
- unsigned int pkg_count;
- unsigned int reinstall_count;
+ uint32_t pkg_count;
+ uint32_t reinstall_count;
} slapt_pkg_upgrade_list_t;
.sp
typedef struct {
@@ -511,7 +511,7 @@ Retrieve the signature file for CHECKSUMS.md5 (or the signature for CHECKSUMS.md
.nf
.B "FILE *slapt_get_pkg_source_checksums_signature (const slapt_rc_config *global_config,"
.B " const char *url,"
-.B " unsigned int *compressed);"
+.B " bool *compressed);"
.fi
.sp
.TP
@@ -519,7 +519,7 @@ Retrieve the GPG-KEY file from the package source, if available. Returns NULL i
.nf
.B "FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,"
.B " const char *url,"
-.B " unsigned int *compressed);"
+.B " bool *compressed);"
.fi
.sp
.TP
@@ -601,7 +601,7 @@ Miscellaneous functionality within libslapt.
.sp
typedef struct {
char **items;
- unsigned int count;
+ uint32_t count;
} slapt_list_t;
.sp
.B /* general list management */
diff --git a/example.slapt-getrc b/example.slapt-getrc
index a3849ab..086de69 100644
--- a/example.slapt-getrc
+++ b/example.slapt-getrc
@@ -3,7 +3,7 @@ WORKINGDIR=/var/cache/slapt-get
# exclude package names and expressions
-EXCLUDE=^kernel-.*,^glibc.*,.*-[0-9]+dl$,^devs$,^udev$,aaa_elflibs,x86_64
+EXCLUDE=^kernel-.*,^glibc.*,.*-[0-9]+dl$,^devs$,^udev$,x86_64
# * to exclude pre and beta packages, add this as an exclude:
# [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
# To exclude architectures such as i686, use the following:
diff --git a/example.slapt-getrc.i386 b/example.slapt-getrc.i386
index 83ead8a..3d6014c 100644
--- a/example.slapt-getrc.i386
+++ b/example.slapt-getrc.i386
@@ -4,7 +4,7 @@ WORKINGDIR=/var/cache/slapt-get
# Exclude package names and expressions.
# To exclude pre and beta packages, add this to the exclude:
# [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
-EXCLUDE=^aaa_elflibs,^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64
+EXCLUDE=^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,x86_64
# Slackware64 mirrors to choose from.
# Please use one of these in preference to ftp.slackware.com
diff --git a/example.slapt-getrc.x86_64 b/example.slapt-getrc.x86_64
index d3bafcb..3255260 100644
--- a/example.slapt-getrc.x86_64
+++ b/example.slapt-getrc.x86_64
@@ -4,7 +4,7 @@ WORKINGDIR=/var/cache/slapt-get
# Exclude package names and expressions.
# To exclude pre and beta packages, add this to the exclude:
# [0-9\_\.\-]{1}pre[0-9\-\.\-]{1}
-EXCLUDE=^aaa_elflibs,^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,i[3456]86
+EXCLUDE=^devs,^glibc-.*,^kernel-.*,^udev,.*-[0-9]+dl$,i[3456]86
# Slackware64 mirrors to choose from.
# Please use one of these in preference to ftp.slackware.com
diff --git a/src/action.c b/src/action.c
index b094e4e..ecfe291 100644
--- a/src/action.c
+++ b/src/action.c
@@ -24,7 +24,6 @@ static int cmp_pkg_arch(const char *a, const char *b);
void slapt_pkg_action_install(const slapt_rc_config *global_config,
const slapt_list_t *action_args)
{
- unsigned int i;
slapt_transaction_t *tran = NULL;
slapt_pkg_list_t *installed_pkgs = NULL;
slapt_pkg_list_t *avail_pkgs = NULL;
@@ -34,7 +33,7 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
installed_pkgs = slapt_get_installed_pkgs();
avail_pkgs = slapt_get_available_pkgs();
- if (avail_pkgs == NULL || avail_pkgs->pkg_count == 0)
+ if (avail_pkgs == NULL || !avail_pkgs->pkg_count)
exit(EXIT_FAILURE);
printf(gettext("Done\n"));
@@ -45,8 +44,7 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
exit(EXIT_FAILURE);
}
- for (i = 0; i < action_args->count; ++i) {
- char *arg = action_args->items[i];
+ slapt_list_t_foreach (arg, action_args) {
slapt_pkg_info_t *pkg = NULL;
slapt_pkg_info_t *installed_pkg = NULL;
@@ -79,34 +77,30 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
installed_pkg = slapt_get_newest_pkg(installed_pkgs, pkg->name);
/* if it is not already installed, install it */
- if (installed_pkg == NULL || global_config->no_upgrade == true) {
+ if (installed_pkg == NULL || global_config->no_upgrade) {
if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
installed_pkgs, pkg) == 0) {
slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, pkg);
- /* this comes first so we can pick up that we are installed the package when
- * checking conflicts */
+ /* this comes first so we can pick up that we are installed the package when checking conflicts */
slapt_add_install_to_transaction(tran, pkg);
/* if there are conflicts, we schedule the conflicts for removal */
- if (conflicts->pkg_count > 0 && global_config->ignore_dep != true) {
- unsigned int cindex = 0;
- for (cindex = 0; cindex < conflicts->pkg_count; cindex++) {
+ if (conflicts->pkg_count && !global_config->ignore_dep) {
+ slapt_pkg_list_t_foreach (conflict, conflicts) {
/* make sure to remove the conflict's dependencies as well */
- unsigned int cdindex = 0;
slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
avail_pkgs, installed_pkgs,
tran->install_pkgs, tran->remove_pkgs,
- conflicts->pkgs[cindex]);
- for (cdindex = 0; cdindex < conflict_deps->pkg_count; ++cdindex) {
- slapt_pkg_info_t *dep = conflict_deps->pkgs[cdindex];
- if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
- slapt_add_remove_to_transaction(tran, dep);
+ conflict);
+ slapt_pkg_list_t_foreach (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);
}
}
slapt_free_pkg_list(conflict_deps);
- slapt_add_remove_to_transaction(tran, conflicts->pkgs[cindex]);
+ slapt_add_remove_to_transaction(tran, conflict);
}
}
slapt_free_pkg_list(conflicts);
@@ -122,29 +116,26 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
/* it is already installed, attempt an upgrade */
if (
((slapt_cmp_pkgs(installed_pkg, pkg)) < 0) ||
- (global_config->re_install == true)) {
+ (global_config->re_install)) {
if (slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
installed_pkgs, pkg) == 0) {
slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs,
installed_pkgs, pkg);
- if (conflicts->pkg_count > 0 && global_config->ignore_dep != true) {
- unsigned int cindex = 0;
- for (cindex = 0; cindex < conflicts->pkg_count; cindex++) {
+ if (conflicts->pkg_count && !global_config->ignore_dep) {
+ slapt_pkg_list_t_foreach (conflict, conflicts) {
/* make sure to remove the conflict's dependencies as well */
- unsigned int cdindex = 0;
slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
avail_pkgs, installed_pkgs,
tran->install_pkgs, tran->remove_pkgs,
- conflicts->pkgs[cindex]);
- for (cdindex = 0; cdindex < conflict_deps->pkg_count; ++cdindex) {
- slapt_pkg_info_t *dep = conflict_deps->pkgs[cdindex];
- if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
- slapt_add_remove_to_transaction(tran, dep);
+ conflict);
+ slapt_pkg_list_t_foreach (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);
}
}
slapt_free_pkg_list(conflict_deps);
- slapt_add_remove_to_transaction(tran, conflicts->pkgs[cindex]);
+ slapt_add_remove_to_transaction(tran, conflict);
}
}
@@ -185,25 +176,24 @@ void slapt_pkg_action_list(const int show)
{
slapt_pkg_list_t *pkgs = NULL;
slapt_pkg_list_t *installed_pkgs = NULL;
- unsigned int i;
pkgs = slapt_get_available_pkgs();
installed_pkgs = slapt_get_installed_pkgs();
if (show == LIST || show == AVAILABLE) {
- for (i = 0; i < pkgs->pkg_count; ++i) {
- unsigned int bool_installed = 0;
- char *short_description = slapt_gen_short_pkg_description(pkgs->pkgs[i]);
+ slapt_pkg_list_t_foreach (pkg, pkgs) {
+ bool installed = false;
+ char *short_description = slapt_gen_short_pkg_description(pkg);
/* is it installed? */
- if (slapt_get_exact_pkg(installed_pkgs, pkgs->pkgs[i]->name,
- pkgs->pkgs[i]->version) != NULL)
- bool_installed = 1;
+ if (slapt_get_exact_pkg(installed_pkgs, pkg->name,
+ pkg->version) != NULL)
+ installed = true;
printf("%s-%s [inst=%s]: %s\n",
- pkgs->pkgs[i]->name,
- pkgs->pkgs[i]->version,
- bool_installed == 1
+ pkg->name,
+ pkg->version,
+ installed
? gettext("yes")
: gettext("no"),
(short_description == NULL) ? "" : short_description);
@@ -211,23 +201,20 @@ void slapt_pkg_action_list(const int show)
}
}
if (show == LIST || show == INSTALLED) {
- for (i = 0; i < installed_pkgs->pkg_count; ++i) {
+ slapt_pkg_list_t_foreach (pkg, installed_pkgs) {
char *short_description = NULL;
if (show == LIST) {
- if (slapt_get_exact_pkg(pkgs,
- installed_pkgs->pkgs[i]->name,
- installed_pkgs->pkgs[i]->version) != NULL) {
+ if (slapt_get_exact_pkg(pkgs, pkg->name, pkg->version) != NULL) {
continue;
}
}
- short_description =
- slapt_gen_short_pkg_description(installed_pkgs->pkgs[i]);
+ short_description = slapt_gen_short_pkg_description(pkg);
printf("%s-%s [inst=%s]: %s\n",
- installed_pkgs->pkgs[i]->name,
- installed_pkgs->pkgs[i]->version,
+ pkg->name,
+ pkg->version,
gettext("yes"),
(short_description == NULL) ? "" : short_description);
free(short_description);
@@ -242,7 +229,6 @@ void slapt_pkg_action_list(const int show)
void slapt_pkg_action_remove(const slapt_rc_config *global_config,
const slapt_list_t *action_args)
{
- unsigned int i;
slapt_pkg_list_t *installed_pkgs = NULL;
slapt_pkg_list_t *avail_pkgs = NULL;
slapt_regex_t *pkg_regex = NULL;
@@ -258,10 +244,8 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
exit(EXIT_FAILURE);
}
- for (i = 0; i < action_args->count; ++i) {
- unsigned int c;
+ slapt_list_t_foreach (arg, action_args) {
slapt_pkg_list_t *deps = NULL;
- char *arg = action_args->items[i];
slapt_pkg_info_t *pkg = NULL;
/* Use regex to see if they specified a particular version */
@@ -295,9 +279,7 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
tran->install_pkgs, tran->remove_pkgs,
pkg);
- for (c = 0; c < deps->pkg_count; ++c) {
- slapt_pkg_info_t *dep = deps->pkgs[c];
-
+ slapt_pkg_list_t_foreach (dep, deps) {
if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
slapt_add_remove_to_transaction(tran, dep);
}
@@ -308,15 +290,14 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
slapt_add_remove_to_transaction(tran, pkg);
}
- if (global_config->remove_obsolete == true) {
- slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(
- global_config, avail_pkgs, installed_pkgs);
+ if (global_config->remove_obsolete) {
+ slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(global_config, avail_pkgs, installed_pkgs);
- for (i = 0; i < obsolete->pkg_count; ++i) {
- if (slapt_is_excluded(global_config, obsolete->pkgs[i]) != 1) {
- slapt_add_remove_to_transaction(tran, obsolete->pkgs[i]);
+ slapt_pkg_list_t_foreach (pkg, obsolete) {
+ if (slapt_is_excluded(global_config, pkg)) {
+ slapt_add_exclude_to_transaction(tran, pkg);
} else {
- slapt_add_exclude_to_transaction(tran, obsolete->pkgs[i]);
+ slapt_add_remove_to_transaction(tran, pkg);
}
}
@@ -337,7 +318,6 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
/* search for a pkg (support extended POSIX regex) */
void slapt_pkg_action_search(const char *pattern)
{
- unsigned int i;
slapt_pkg_list_t *pkgs = NULL;
slapt_pkg_list_t *installed_pkgs = NULL;
slapt_pkg_list_t *matches = NULL, *i_matches = NULL;
@@ -349,34 +329,31 @@ void slapt_pkg_action_search(const char *pattern)
matches = slapt_search_pkg_list(pkgs, pattern);
i_matches = slapt_search_pkg_list(installed_pkgs, pattern);
- for (i = 0; i < matches->pkg_count; ++i) {
- char *short_description =
- slapt_gen_short_pkg_description(matches->pkgs[i]);
+ slapt_pkg_list_t_foreach (pkg, matches) {
+ char *short_description = slapt_gen_short_pkg_description(pkg);
printf("%s-%s [inst=%s]: %s\n",
- matches->pkgs[i]->name,
- matches->pkgs[i]->version,
- (slapt_get_exact_pkg(installed_pkgs,
- matches->pkgs[i]->name, matches->pkgs[i]->version) != NULL)
+ pkg->name,
+ pkg->version,
+ (slapt_get_exact_pkg(installed_pkgs, pkg->name, pkg->version) != NULL)
? gettext("yes")
: gettext("no"),
short_description);
free(short_description);
}
- for (i = 0; i < i_matches->pkg_count; ++i) {
+ slapt_pkg_list_t_foreach (installed_pkg, i_matches) {
char *short_description = NULL;
- if (slapt_get_exact_pkg(matches, i_matches->pkgs[i]->name,
- i_matches->pkgs[i]->version) != NULL) {
+ if (slapt_get_exact_pkg(matches, installed_pkg->name, installed_pkg->version) != NULL) {
continue;
}
- short_description = slapt_gen_short_pkg_description(i_matches->pkgs[i]);
+ short_description = slapt_gen_short_pkg_description(installed_pkg);
printf("%s-%s [inst=%s]: %s\n",
- i_matches->pkgs[i]->name,
- i_matches->pkgs[i]->version,
+ installed_pkg->name,
+ installed_pkg->version,
gettext("yes"),
short_description);
free(short_description);
@@ -394,7 +371,7 @@ void slapt_pkg_action_show(const char *pkg_name)
slapt_pkg_list_t *avail_pkgs = NULL;
slapt_pkg_list_t *installed_pkgs = NULL;
slapt_regex_t *pkg_regex = NULL;
- unsigned int bool_installed = 0;
+ bool installed = false;
slapt_pkg_info_t *pkg = NULL;
avail_pkgs = slapt_get_available_pkgs();
@@ -442,7 +419,7 @@ void slapt_pkg_action_show(const char *pkg_name)
slapt_clean_description(description, pkg->name);
if (slapt_get_exact_pkg(installed_pkgs, pkg->name, pkg->version) != NULL)
- bool_installed = 1;
+ installed = true;
printf(gettext("Package Name: %s\n"), pkg->name);
printf(gettext("Package Mirror: %s\n"), pkg->mirror);
@@ -465,7 +442,7 @@ void slapt_pkg_action_show(const char *pkg_name)
}
printf(gettext("Package Installed: %s\n"),
- bool_installed == 1
+ installed
? gettext("yes")
: gettext("no"));
@@ -483,7 +460,6 @@ void slapt_pkg_action_show(const char *pkg_name)
/* upgrade all installed pkgs with available updates */
void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
{
- unsigned int i;
slapt_pkg_list_t *installed_pkgs = NULL;
slapt_pkg_list_t *avail_pkgs = NULL;
slapt_transaction_t *tran = NULL;
@@ -495,14 +471,14 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
if (avail_pkgs == NULL || installed_pkgs == NULL)
exit(EXIT_FAILURE);
- if (avail_pkgs->pkg_count == 0)
+ if (!avail_pkgs->pkg_count)
exit(EXIT_FAILURE);
printf(gettext("Done\n"));
tran = slapt_init_transaction();
- if (global_config->dist_upgrade == true) {
- char *essential[] = {"pkgtools", "glibc-solibs", "glibc", "aaa_elflibs", "xz", "sed", "tar", "gzip", NULL};
+ if (global_config->dist_upgrade) {
+ 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_pkg_list_t *matches =
@@ -530,37 +506,33 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
}
/* loop through SLAPT_SLACK_BASE_SET_REGEX packages */
- for (i = 0; i < matches->pkg_count; ++i) {
+ slapt_pkg_list_t_foreach (pkg, matches) {
slapt_pkg_info_t *installed_pkg = NULL;
slapt_pkg_info_t *newer_avail_pkg = NULL;
slapt_pkg_info_t *slapt_upgrade_pkg = NULL;
- installed_pkg = slapt_get_newest_pkg(
- installed_pkgs,
- matches->pkgs[i]->name);
- newer_avail_pkg = slapt_get_newest_pkg(
- avail_pkgs,
- matches->pkgs[i]->name);
+ 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 (slapt_cmp_pkgs(matches->pkgs[i], newer_avail_pkg) < 0) {
+ * 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 {
- slapt_upgrade_pkg = matches->pkgs[i];
+ slapt_upgrade_pkg = pkg;
}
/* add to install list if not already installed */
if (installed_pkg == NULL) {
- if (slapt_is_excluded(global_config, slapt_upgrade_pkg) == 1) {
+ if (slapt_is_excluded(global_config, slapt_upgrade_pkg)) {
slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
} else {
slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, slapt_upgrade_pkg);
/* add install if all deps are good and it doesn't have conflicts */
- if (
- (slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, slapt_upgrade_pkg) == 0) && (conflicts->pkg_count == 0 && global_config->ignore_dep != true)) {
+ int rc = slapt_add_deps_to_trans(global_config, tran, avail_pkgs, installed_pkgs, slapt_upgrade_pkg);
+ if (!rc && !conflicts->pkg_count && !global_config->ignore_dep) {
slapt_add_install_to_transaction(tran, slapt_upgrade_pkg);
} else {
/* otherwise exclude */
@@ -577,7 +549,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
} else if (
(slapt_cmp_pkgs(installed_pkg, slapt_upgrade_pkg) <= 0) &&
strcmp(installed_pkg->version, slapt_upgrade_pkg->version) != 0) {
- if (slapt_is_excluded(global_config, installed_pkg) == 1 || slapt_is_excluded(global_config, slapt_upgrade_pkg) == 1) {
+ 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_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs,
@@ -587,7 +559,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
if (
(slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
installed_pkgs, slapt_upgrade_pkg) == 0) &&
- (conflicts->pkg_count == 0 && global_config->ignore_dep != true)) {
+ (!conflicts->pkg_count && !global_config->ignore_dep)) {
slapt_add_upgrade_to_transaction(tran, installed_pkg,
slapt_upgrade_pkg);
} else {
@@ -605,16 +577,14 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
slapt_free_pkg_list(matches);
/* remove obsolete packages if prompted to */
- if (global_config->remove_obsolete == true) {
- unsigned int r;
- slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(
- global_config, avail_pkgs, installed_pkgs);
-
- for (r = 0; r < obsolete->pkg_count; ++r) {
- if (slapt_is_excluded(global_config, obsolete->pkgs[r]) != 1) {
- slapt_add_remove_to_transaction(tran, obsolete->pkgs[r]);
+ if (global_config->remove_obsolete) {
+ slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(global_config, avail_pkgs, installed_pkgs);
+
+ slapt_pkg_list_t_foreach (obsolete_pkg, obsolete) {
+ if (slapt_is_excluded(global_config, obsolete_pkg)) {
+ slapt_add_exclude_to_transaction(tran, obsolete_pkg);
} else {
- slapt_add_exclude_to_transaction(tran, obsolete->pkgs[r]);
+ slapt_add_remove_to_transaction(tran, obsolete_pkg);
}
}
@@ -632,58 +602,54 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
}
}
- for (i = 0; i < installed_pkgs->pkg_count; ++i) {
+ slapt_pkg_list_t_foreach (installed_pkg, installed_pkgs) {
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
- */
+ we need to see if there is another installed
+ package that is newer than this one
+ */
if ((newer_installed_pkg =
- slapt_get_newest_pkg(installed_pkgs,
- installed_pkgs->pkgs[i]->name)) != NULL) {
- if (slapt_cmp_pkgs(installed_pkgs->pkgs[i], newer_installed_pkg) < 0) {
+ slapt_get_newest_pkg(installed_pkgs, installed_pkg->name)) != NULL) {
+ if (slapt_cmp_pkgs(installed_pkg, newer_installed_pkg) < 0) {
continue;
}
}
/* see if we have an available update for the pkg */
- update_pkg = slapt_get_newest_pkg(
- avail_pkgs,
- installed_pkgs->pkgs[i]->name);
+ update_pkg = slapt_get_newest_pkg(avail_pkgs, installed_pkg->name);
if (update_pkg != NULL) {
int cmp_r = 0;
/* if the update has a newer version, attempt to upgrade */
- cmp_r = slapt_cmp_pkgs(installed_pkgs->pkgs[i], update_pkg);
+ cmp_r = slapt_cmp_pkgs(installed_pkg, update_pkg);
if (
/* either it's greater, or we want to reinstall */
- cmp_r < 0 || (global_config->re_install == true) ||
- /*
- * or this is a dist upgrade and the versions are the save
- * except for the arch
- */
+ 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 == true &&
+ global_config->dist_upgrade &&
cmp_r == 0 &&
- cmp_pkg_arch(installed_pkgs->pkgs[i]->version,
+ cmp_pkg_arch(installed_pkg->version,
update_pkg->version) != 0)) {
- if ((slapt_is_excluded(global_config, update_pkg) == 1) || (slapt_is_excluded(global_config, installed_pkgs->pkgs[i]) == 1)) {
+ 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_pkg_list_t *conflicts = slapt_is_conflicted(tran,
- avail_pkgs, installed_pkgs, update_pkg);
+ slapt_pkg_list_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, update_pkg);
/* if all deps are added and there is no conflicts, add on */
if (
(slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
installed_pkgs, update_pkg) == 0) &&
- (global_config->ignore_dep == true || (conflicts->pkg_count == 0))) {
+ (global_config->ignore_dep || !conflicts->pkg_count)) {
if (cmp_r == 0)
- slapt_add_reinstall_to_transaction(tran, installed_pkgs->pkgs[i], update_pkg);
+ slapt_add_reinstall_to_transaction(tran, installed_pkg, update_pkg);
else
- slapt_add_upgrade_to_transaction(tran, installed_pkgs->pkgs[i], update_pkg);
+ slapt_add_upgrade_to_transaction(tran, installed_pkg, update_pkg);
} else {
/* otherwise exclude */
@@ -751,10 +717,10 @@ static int cmp_pkg_arch(const char *a, const char *b)
void slapt_pkg_action_add_keys(const slapt_rc_config *global_config)
{
int rc = 0;
- unsigned int s = 0, compressed = 0;
- for (s = 0; s < global_config->sources->count; s++) {
+ bool compressed = false;
+ slapt_source_list_t_foreach (source, global_config->sources) {
FILE *gpg_key = NULL;
- const char *source_url = global_config->sources->src[s]->url;
+ const char *source_url = source->url;
printf(gettext("Retrieving GPG key [%s]..."), source_url);
gpg_key = slapt_get_pkg_source_gpg_key(global_config, source_url, &compressed);
if (gpg_key != NULL) {
diff --git a/src/common.c b/src/common.c
index a259376..b920f54 100644
--- a/src/common.c
+++ b/src/common.c
@@ -81,7 +81,7 @@ char *slapt_regex_extract_match(const slapt_regex_t *r, const char *src, const i
char *str = NULL;
if (m.rm_so != -1) {
- unsigned int len = m.rm_eo - m.rm_so + 1;
+ uint32_t len = m.rm_eo - m.rm_so + 1;
str = malloc(sizeof *str * len);
str = strncpy(str, src + m.rm_so, len);
@@ -103,7 +103,7 @@ void slapt_gen_md5_sum_of_file(FILE *f, char *result_sum)
EVP_MD_CTX *mdctx = NULL;
const EVP_MD *md;
unsigned char md_value[EVP_MAX_MD_SIZE];
- unsigned int md_len = 0, i;
+ uint32_t md_len = 0;
ssize_t getline_read;
size_t getline_size;
char *result_sum_tmp = NULL;
@@ -135,7 +135,7 @@ void slapt_gen_md5_sum_of_file(FILE *f, char *result_sum)
result_sum[0] = '\0';
- for (i = 0; i < md_len; ++i) {
+ for (uint32_t i = 0; i < md_len; ++i) {
char *p = slapt_malloc(sizeof *p * 3);
if (snprintf(p, 3, "%02x", md_value[i]) > 0) {
@@ -254,12 +254,12 @@ int slapt_ask_yes_no(const char *format, ...)
char *slapt_str_replace_chr(const char *string, const char find,
const char replace)
{
- unsigned int i, len = 0;
+ uint32_t len = 0;
char *clean = slapt_calloc(strlen(string) + 1, sizeof *clean);
;
len = strlen(string);
- for (i = 0; i < len; ++i) {
+ for (uint32_t i = 0; i < len; ++i) {
if (string[i] == find) {
clean[i] = replace;
} else {
@@ -422,7 +422,7 @@ void slapt_add_list_item(slapt_list_t *list, const char *item)
void slapt_remove_list_item(slapt_list_t *list, const char *item)
{
- unsigned int i = 0;
+ uint32_t i = 0;
char *tmp = NULL;
while (i < list->count) {
@@ -453,11 +453,9 @@ void slapt_remove_list_item(slapt_list_t *list, const char *item)
const char *slapt_search_list(slapt_list_t *list, const char *needle)
{
- unsigned int i;
-
- for (i = 0; i < list->count; i++) {
- if (strcmp(list->items[i], needle) == 0)
- return list->items[i];
+ slapt_list_t_foreach (i, list) {
+ if (strcmp(i, needle) == 0)
+ return i;
}
return NULL;
@@ -465,10 +463,8 @@ const char *slapt_search_list(slapt_list_t *list, const char *needle)
void slapt_free_list(slapt_list_t *list)
{
- unsigned int i;
-
- for (i = 0; i < list->count; ++i) {
- free(list->items[i]);
+ slapt_list_t_foreach (i, list) {
+ free(i);
}
free(list->items);
free(list);
diff --git a/src/common.h b/src/common.h
index 49f3b5c..e6fd453 100644
--- a/src/common.h
+++ b/src/common.h
@@ -69,8 +69,10 @@ typedef struct {
typedef struct {
char **items;
- unsigned int count;
+ uint32_t count;
} slapt_list_t;
+#define slapt_list_t_foreach(item, list) char *item; for (uint32_t item##_counter = 0; (item##_counter < list->count) && (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);
diff --git a/src/configuration.c b/src/configuration.c
index 71f936d..094f814 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -126,7 +126,7 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
file_name);
return NULL;
}
- if (global_config->sources->count == 0) {
+ if (!global_config->sources->count) {
fprintf(stderr, gettext("SOURCE directive not set within %s.\n"), file_name);
return NULL;
}
@@ -219,7 +219,7 @@ void slapt_add_source(slapt_source_list_t *list, slapt_source_t *s)
void slapt_remove_source(slapt_source_list_t *list, const char *s)
{
slapt_source_t *src_to_discard = NULL;
- unsigned int i = 0;
+ uint32_t i = 0;
while (i < list->count) {
if (strcmp(s, list->src[i]->url) == 0 && src_to_discard == NULL) {
@@ -251,10 +251,8 @@ void slapt_remove_source(slapt_source_list_t *list, const char *s)
void slapt_free_source_list(slapt_source_list_t *list)
{
- unsigned int i;
-
- for (i = 0; i < list->count; ++i) {
- slapt_free_source(list->src[i]);
+ slapt_source_list_t_foreach (source, list) {
+ slapt_free_source(source);
}
free(list->src);
free(list);
@@ -309,8 +307,8 @@ static void slapt_source_parse_attributes(slapt_source_t *s, const char *string)
slapt_source_t *slapt_init_source(const char *s)
{
slapt_source_t *src;
- unsigned int source_len = 0;
- unsigned int attribute_len = 0;
+ uint32_t source_len = 0;
+ uint32_t attribute_len = 0;
slapt_regex_t *attribute_regex = NULL;
char *source_string = NULL;
char *attribute_string = NULL;
@@ -382,7 +380,7 @@ void slapt_free_source(slapt_source_t *src)
int slapt_write_rc_config(const slapt_rc_config *global_config, const char *location)
{
- unsigned int i;
+ uint32_t i = 0;
FILE *rc;
rc = slapt_open_file(location, "w+");
@@ -392,21 +390,21 @@ int slapt_write_rc_config(const slapt_rc_config *global_config, const char *loca
fprintf(rc, "%s%s\n", SLAPT_WORKINGDIR_TOKEN, global_config->working_dir);
fprintf(rc, "%s", SLAPT_EXCLUDE_TOKEN);
- for (i = 0; i < global_config->exclude_list->count; ++i) {
+ slapt_list_t_foreach (exclude, global_config->exclude_list) {
if (i + 1 == global_config->exclude_list->count) {
- fprintf(rc, "%s", global_config->exclude_list->items[i]);
+ fprintf(rc, "%s", exclude);
} else {
- fprintf(rc, "%s,", global_config->exclude_list->items[i]);
+ fprintf(rc, "%s,", exclude);
}
+ i++;
}
fprintf(rc, "\n");
- for (i = 0; i < global_config->sources->count; ++i) {
- slapt_source_t *src = global_config->sources->src[i];
+ slapt_source_list_t_foreach (src, global_config->sources) {
SLAPT_PRIORITY_T priority = src->priority;
const char *token = SLAPT_SOURCE_TOKEN;
- if (global_config->sources->src[i]->disabled == true)
+ if (src->disabled)
token = SLAPT_DISABLED_SOURCE_TOKEN;
if (priority > SLAPT_PRIORITY_DEFAULT) {
diff --git a/src/configuration.h b/src/configuration.h
index c5fb74f..ceb0aad 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -31,8 +31,9 @@ typedef struct {
typedef struct {
slapt_source_t **src;
- unsigned int count;
+ uint32_t count;
} slapt_source_list_t;
+#define slapt_source_list_t_foreach(item, list) slapt_source_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->count) && (item = list->src[item##_counter]); item##_counter++)
typedef struct {
char working_dir[SLAPT_WORKINGDIR_TOKEN_LEN];
@@ -53,7 +54,7 @@ typedef struct {
bool dl_stats;
bool remove_obsolete;
bool no_upgrade;
- unsigned int retry;
+ uint32_t retry;
bool use_priority;
bool gpgme_allow_unauth;
} slapt_rc_config;
diff --git a/src/curl.c b/src/curl.c
index 042296d..5cad37d 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -61,7 +61,7 @@ int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime,
headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
- if (global_config->dl_stats != true) {
+ if (!global_config->dl_stats) {
if (global_config->progress_cb == NULL) {
curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, slapt_progress_callback);
} else {
@@ -81,14 +81,15 @@ int slapt_download_data(FILE *fh, const char *url, size_t bytes, long *filetime,
return_code = response;
}
+ /* XXX Use CURLINFO_FILETIME_T with 7.59+ */
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); */
@@ -244,7 +245,7 @@ const char *slapt_download_pkg(const slapt_rc_config *global_config,
pkg->mirror, pkg->name, pkg->version,
(dl_total_size > 1024) ? dl_total_size / 1024.0 : dl_total_size,
(dl_total_size > 1024) ? "MB" : "kB");
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
}
@@ -263,10 +264,7 @@ const char *slapt_download_pkg(const slapt_rc_config *global_config,
} else if (dl_return == CURLE_HTTP_RANGE_ERROR ||
dl_return == CURLE_FTP_BAD_DOWNLOAD_RESUME ||
dl_return == CURLE_PARTIAL_FILE) {
- /*
- * this is for errors trying to resume. unlink the file and
- * try again.
- */
+ /* this is for errors trying to resume. unlink the file and try again. */
printf("\r");
fclose(fh);
diff --git a/src/gpgme.c b/src/gpgme.c
index 89c9510..49d46b4 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -51,7 +51,7 @@ static void _slapt_free_gpgme_ctx(gpgme_ctx_t *ctx)
FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_config,
const char *url,
- unsigned int *compressed)
+ bool *compressed)
{
FILE *tmp_checksum_f = NULL;
char *checksum_head = NULL;
@@ -61,14 +61,13 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
char *filename = NULL;
char *local_head = NULL;
char *location;
- int checksums_compressed = *compressed;
- if (checksums_compressed == 1) {
+ if (*compressed) {
location = location_compressed;
- *compressed = 1;
+ *compressed = true;
} else {
location = location_uncompressed;
- *compressed = 0;
+ *compressed = false;
}
filename = slapt_gen_filename_from_url(url, location);
@@ -76,7 +75,7 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
checksum_head = slapt_head_mirror_data(url, location);
if (checksum_head == NULL) {
- if (interactive == true)
+ if (interactive)
printf(gettext("Not Found\n"));
free(filename);
free(local_head);
@@ -96,7 +95,7 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
} else {
const char *err = NULL;
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if ((tmp_checksum_f = slapt_open_file(filename, "w+b")) == NULL)
@@ -106,7 +105,7 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
global_config, url,
location);
if (!err) {
- if (interactive == true)
+ if (interactive)
printf(gettext("Done\n"));
} else {
@@ -138,21 +137,21 @@ FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_con
FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
const char *url,
- unsigned int *compressed)
+ 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 == false
+ bool interactive = global_config->progress_cb == NULL && !global_config->dl_stats
? true
: false;
- *compressed = 0;
+ *compressed = false;
key_head = slapt_head_mirror_data(url, SLAPT_GPG_KEY);
if (key_head == NULL) {
- if (interactive == true)
+ if (interactive)
printf(gettext("Not Found\n"));
free(filename);
free(local_head);
@@ -180,7 +179,7 @@ FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
SLAPT_GPG_KEY);
if (!err) {
- if (interactive == true)
+ if (interactive)
printf(gettext("Done\n"));
} else {
fprintf(stderr, gettext("Failed to download: %s\n"), err);
@@ -302,6 +301,9 @@ slapt_code_t slapt_gpg_verify_checksums(FILE *checksums,
gpgme_verify_result_t verify_result = gpgme_op_verify_result(*ctx);
if (verify_result != NULL) {
gpgme_signature_t sig = verify_result->signatures;
+ if (sig == NULL) {
+ return verified;
+ }
gpgme_sigsum_t sum = sig->summary;
gpgme_error_t status = sig->status;
diff --git a/src/gpgme.h b/src/gpgme.h
index f61872b..38db7f3 100644
--- a/src/gpgme.h
+++ b/src/gpgme.h
@@ -29,11 +29,11 @@
/* retrieve the signature of the CHECKSUMS.md5 file */
FILE *slapt_get_pkg_source_checksums_signature(const slapt_rc_config *global_config,
const char *url,
- unsigned int *compressed);
+ bool *compressed);
/* retrieve the package sources GPG-KEY */
FILE *slapt_get_pkg_source_gpg_key(const slapt_rc_config *global_config,
const char *url,
- unsigned int *compressed);
+ 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 277f51a..a2b1c3a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -278,7 +278,7 @@ int main(int argc, char *argv[])
case INSTALL:
case INSTALL_DISK_SET:
case REMOVE:
- if (global_config->remove_obsolete == true)
+ if (global_config->remove_obsolete)
break;
/* fall through */
@@ -328,12 +328,10 @@ int main(int argc, char *argv[])
slapt_free_list(paa);
break;
case INSTALL_DISK_SET: {
- unsigned int set_i;
slapt_pkg_list_t *set_pkgs = slapt_init_pkg_list();
slapt_pkg_list_t *avail_pkgs = slapt_get_available_pkgs();
while (optind < argc) {
- unsigned int search_i;
slapt_pkg_list_t *matches = NULL;
char *search = slapt_malloc(sizeof *search * (strlen(argv[optind]) + 3));
@@ -341,9 +339,9 @@ int main(int argc, char *argv[])
matches = slapt_search_pkg_list(avail_pkgs, search);
free(search);
- for (search_i = 0; search_i < matches->pkg_count; ++search_i) {
- if (slapt_is_excluded(global_config, matches->pkgs[search_i]) == 0) {
- slapt_add_pkg_to_pkg_list(set_pkgs, matches->pkgs[search_i]);
+ slapt_pkg_list_t_foreach (match, matches) {
+ if (!slapt_is_excluded(global_config, match)) {
+ slapt_add_pkg_to_pkg_list(set_pkgs, match);
}
}
@@ -353,8 +351,8 @@ int main(int argc, char *argv[])
paa = slapt_init_list();
- for (set_i = 0; set_i < set_pkgs->pkg_count; ++set_i) {
- slapt_add_list_item(paa, set_pkgs->pkgs[set_i]->name);
+ slapt_pkg_list_t_foreach (set_pkg, set_pkgs) {
+ slapt_add_list_item(paa, set_pkg->name);
}
slapt_free_pkg_list(set_pkgs);
diff --git a/src/main.h b/src/main.h
index ad77a88..1b0533d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+#include <stdint.h>
#include <unistd.h>
#include <getopt.h>
#include <curl/curl.h>
diff --git a/src/package.c b/src/package.c
index 3618a29..6ffe8bb 100644
--- a/src/package.c
+++ b/src/package.c
@@ -20,7 +20,7 @@
struct slapt_pkg_version_parts {
char **parts;
- unsigned int count;
+ uint32_t count;
};
/* used by qsort */
@@ -69,8 +69,8 @@ slapt_pkg_list_t *slapt_get_available_pkgs(void)
list = slapt_parse_packages_txt(pkg_list_fh);
fclose(pkg_list_fh);
- /* this is pointless to do if we wrote the data sorted, but this
- ensures upgrades from older, presorting slapt-gets still work
+ /* this is pointless to do if we wrote the data sorted, but this
+ ensures upgrades from older, presorting slapt-gets still work
as expected. */
qsort(list->pkgs, list->pkg_count, sizeof(list->pkgs[0]), pkg_compare);
@@ -182,12 +182,11 @@ slapt_pkg_list_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
tmp_pkg->location = slapt_regex_extract_match(location_regex, getline_buffer, 1);
#if SLACKWARE_EXTRA_TESTING_PASTURE_WORKAROUND == 1
- /*
- extra, testing, and pasture support
- they add in extraneous /extra/, /testing/, or /pasture/ in the
- PACKAGES.TXT location. this fixes the downloads and md5 checksum
- matching
- */
+ /* extra, testing, and pasture support
+ they add in extraneous /extra/, /testing/, or /pasture/ in the
+ PACKAGES.TXT location. this fixes the downloads and md5 checksum
+ matching
+ */
if (strstr(tmp_pkg->location, "./testing/") != NULL) {
char *tmp_location = slapt_malloc(
sizeof *tmp_location *
@@ -521,9 +520,9 @@ slapt_pkg_list_t *slapt_get_installed_pkgs(void)
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);
@@ -592,7 +591,6 @@ slapt_pkg_list_t *slapt_get_installed_pkgs(void)
}
/* Ignore the location for installed packages */
-
if (strstr(pkg_data, "PACKAGE DESCRIPTION") != NULL) {
char *desc_p = strstr(pkg_data, "PACKAGE DESCRIPTION");
char *nl = strchr(desc_p, '\n');
@@ -680,19 +678,14 @@ slapt_pkg_list_t *slapt_get_installed_pkgs(void)
slapt_pkg_info_t *slapt_get_newest_pkg(slapt_pkg_list_t *pkg_list,
const char *pkg_name)
{
- unsigned int i;
- slapt_pkg_info_t *pkg = NULL;
-
- for (i = 0; i < pkg_list->pkg_count; ++i) {
- /* if pkg has same name as our requested pkg */
- if ((strcmp(pkg_list->pkgs[i]->name, pkg_name)) == 0) {
- if ((pkg == NULL) || (slapt_cmp_pkgs(pkg, pkg_list->pkgs[i]) < 0)) {
- pkg = pkg_list->pkgs[i];
- }
- }
+ slapt_pkg_info_t *found = NULL;
+ slapt_pkg_list_t_foreach (pkg, pkg_list) {
+ if (strcmp(pkg->name, pkg_name) != 0)
+ continue;
+ if ((found == NULL) || (slapt_cmp_pkgs(found, pkg) < 0))
+ found = pkg;
}
-
- return pkg;
+ return found;
}
slapt_pkg_info_t *slapt_get_exact_pkg(slapt_pkg_list_t *list,
@@ -728,12 +721,9 @@ slapt_pkg_info_t *slapt_get_exact_pkg(slapt_pkg_list_t *list,
}
} else {
- unsigned int i;
-
- for (i = 0; i < list->pkg_count; i++) {
- if ((strcmp(name, list->pkgs[i]->name) == 0) &&
- (strcmp(version, list->pkgs[i]->version) == 0)) {
- return list->pkgs[i];
+ slapt_pkg_list_t_foreach (pkg, list) {
+ if ((strcmp(name, pkg->name) == 0) && (strcmp(version, pkg->version) == 0)) {
+ return pkg;
}
}
}
@@ -859,44 +849,39 @@ void slapt_free_pkg(slapt_pkg_info_t *pkg)
void slapt_free_pkg_list(slapt_pkg_list_t *list)
{
- unsigned int i;
- if (list->free_pkgs == true) {
- for (i = 0; i < list->pkg_count; i++) {
- slapt_free_pkg(list->pkgs[i]);
+ if (list->free_pkgs) {
+ slapt_pkg_list_t_foreach (pkg, list) {
+ slapt_free_pkg(pkg);
}
}
free(list->pkgs);
free(list);
}
-int 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)
{
- unsigned int i, pkg_not_excluded = 0, pkg_slapt_is_excluded = 1;
int name_reg_ret = -1, version_reg_ret = -1, location_reg_ret = -1;
- if (global_config->ignore_excludes == true)
- return pkg_not_excluded;
+ if (global_config->ignore_excludes)
+ return false;
/* maybe EXCLUDE= isn't defined in our rc? */
- if (global_config->exclude_list->count == 0)
- return pkg_not_excluded;
+ if (!global_config->exclude_list->count)
+ return false;
- for (i = 0; i < global_config->exclude_list->count; i++) {
+ slapt_list_t_foreach (exclude, global_config->exclude_list) {
slapt_regex_t *exclude_reg = NULL;
/* return if its an exact match */
- if ((strncmp(global_config->exclude_list->items[i],
- pkg->name, strlen(pkg->name)) == 0))
- return pkg_slapt_is_excluded;
+ 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
- */
- if ((exclude_reg =
- slapt_init_regex(global_config->exclude_list->items[i])) == NULL) {
- fprintf(stderr, "\n\nugh %s\n\n", global_config->exclude_list->items[i]);
+ 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;
}
@@ -912,11 +897,11 @@ int slapt_is_excluded(const slapt_rc_config *global_config,
slapt_free_regex(exclude_reg);
if (name_reg_ret == 0 || version_reg_ret == 0 || location_reg_ret == 0) {
- return pkg_slapt_is_excluded;
+ return true;
}
}
- return pkg_not_excluded;
+ return false;
}
void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file)
@@ -925,7 +910,6 @@ void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file)
ssize_t getline_read;
size_t getline_len = 0;
char *getline_buffer = NULL;
- unsigned int a;
if ((md5sum_regex = slapt_init_regex(SLAPT_MD5SUM_REGEX)) == NULL) {
exit(EXIT_FAILURE);
@@ -958,12 +942,12 @@ void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file)
version = slapt_regex_extract_match(md5sum_regex, getline_buffer, 4);
/* see if we can match up name, version, and location */
- for (a = 0; a < pkgs->pkg_count; a++) {
+ slapt_pkg_list_t_foreach (pkg, pkgs) {
if (
- (strcmp(pkgs->pkgs[a]->name, name) == 0) &&
- (slapt_cmp_pkg_versions(pkgs->pkgs[a]->version, version) == 0) &&
- (strcmp(pkgs->pkgs[a]->location, location) == 0)) {
- memcpy(pkgs->pkgs[a]->md5, sum, SLAPT_MD5_STR_LEN);
+ (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;
}
}
@@ -986,8 +970,7 @@ void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file)
static void slapt_free_pkg_version_parts(struct slapt_pkg_version_parts *parts)
{
- unsigned int i;
- for (i = 0; i < parts->count; i++) {
+ for (uint32_t i = 0; i < parts->count; i++) {
free(parts->parts[i]);
}
free(parts->parts);
@@ -1000,7 +983,7 @@ int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b)
/* if either of the two packages is installed, we look
for the same version to bail out early if possible */
- if (a->installed == true || b->installed == true)
+ if (a->installed || b->installed)
if (strcasecmp(a->version, b->version) == 0)
return equal;
@@ -1015,7 +998,7 @@ int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b)
int slapt_cmp_pkg_versions(const char *a, const char *b)
{
- unsigned int position = 0;
+ uint32_t position = 0;
int greater = 1, lesser = -1, equal = 0;
struct slapt_pkg_version_parts *a_parts;
struct slapt_pkg_version_parts *b_parts;
@@ -1030,10 +1013,10 @@ 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 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) {
@@ -1064,10 +1047,10 @@ int slapt_cmp_pkg_versions(const char *a, const char *b)
}
/*
- * if we got this far, we know that some or all of the version
- * parts are equal in both packages. If pkg-a has 3 version parts
- * and pkg-b has 2, then we assume pkg-a to be greater.
- */
+ if we got this far, we know that some or all of the version
+ parts are equal in both packages. If pkg-a has 3 version parts
+ and pkg-b has 2, then we assume pkg-a to be greater.
+ */
if (a_parts->count != b_parts->count) {
if (a_parts->count > b_parts->count) {
slapt_free_pkg_version_parts(a_parts);
@@ -1084,9 +1067,9 @@ int slapt_cmp_pkg_versions(const char *a, const char *b)
slapt_free_pkg_version_parts(b_parts);
/*
- * Now we check to see that the version follows the standard slackware
- * convention. If it does, we will compare the build portions.
- */
+ Now we check to see that the version follows the standard slackware
+ convention. If it does, we will compare the build portions.
+ */
/* make sure the packages have at least two separators */
if ((index(a, '-') != rindex(a, '-')) && (index(b, '-') != rindex(b, '-'))) {
char *a_build, *b_build;
@@ -1123,9 +1106,9 @@ int slapt_cmp_pkg_versions(const char *a, const char *b)
}
/*
- * If both have the same # of version parts, non-standard version convention,
- * then we fall back on strverscmp.
- */
+ If both have the same # of version parts, non-standard version convention,
+ then we fall back on strverscmp.
+ */
if (strchr(a, '-') == NULL && strchr(b, '-') == NULL)
return strverscmp(a, b);
@@ -1208,41 +1191,38 @@ static struct slapt_pkg_version_parts *break_down_pkg_version(const char *versio
void slapt_write_pkg_data(const char *source_url, FILE *d_file,
slapt_pkg_list_t *pkgs)
{
- unsigned int i;
-
- for (i = 0; i < pkgs->pkg_count; i++) {
- fprintf(d_file, "PACKAGE NAME: %s-%s%s\n",
- pkgs->pkgs[i]->name, pkgs->pkgs[i]->version, pkgs->pkgs[i]->file_ext);
- if (pkgs->pkgs[i]->mirror != NULL && strlen(pkgs->pkgs[i]->mirror) > 0) {
- fprintf(d_file, "PACKAGE MIRROR: %s\n", pkgs->pkgs[i]->mirror);
+ slapt_pkg_list_t_foreach (pkg, pkgs) {
+ fprintf(d_file, "PACKAGE NAME: %s-%s%s\n", pkg->name, pkg->version, pkg->file_ext);
+ if (pkg->mirror != NULL && strlen(pkg->mirror) > 0) {
+ fprintf(d_file, "PACKAGE MIRROR: %s\n", pkg->mirror);
} else {
fprintf(d_file, "PACKAGE MIRROR: %s\n", source_url);
}
- fprintf(d_file, "PACKAGE PRIORITY: %d\n", pkgs->pkgs[i]->priority);
- fprintf(d_file, "PACKAGE LOCATION: %s\n", pkgs->pkgs[i]->location);
- fprintf(d_file, "PACKAGE SIZE (compressed): %d K\n", pkgs->pkgs[i]->size_c);
- fprintf(d_file, "PACKAGE SIZE (uncompressed): %d K\n", pkgs->pkgs[i]->size_u);
- fprintf(d_file, "PACKAGE REQUIRED: %s\n", pkgs->pkgs[i]->required);
- fprintf(d_file, "PACKAGE CONFLICTS: %s\n", pkgs->pkgs[i]->conflicts);
- fprintf(d_file, "PACKAGE SUGGESTS: %s\n", pkgs->pkgs[i]->suggests);
- fprintf(d_file, "PACKAGE MD5SUM: %s\n", pkgs->pkgs[i]->md5);
+ fprintf(d_file, "PACKAGE PRIORITY: %d\n", pkg->priority);
+ fprintf(d_file, "PACKAGE LOCATION: %s\n", pkg->location);
+ fprintf(d_file, "PACKAGE SIZE (compressed): %d K\n", pkg->size_c);
+ fprintf(d_file, "PACKAGE SIZE (uncompressed): %d K\n", pkg->size_u);
+ fprintf(d_file, "PACKAGE REQUIRED: %s\n", pkg->required);
+ fprintf(d_file, "PACKAGE CONFLICTS: %s\n", pkg->conflicts);
+ fprintf(d_file, "PACKAGE SUGGESTS: %s\n", pkg->suggests);
+ fprintf(d_file, "PACKAGE MD5SUM: %s\n", pkg->md5);
fprintf(d_file, "PACKAGE DESCRIPTION:\n");
/* do we have to make up an empty description? */
- if (strlen(pkgs->pkgs[i]->description) < strlen(pkgs->pkgs[i]->name)) {
- fprintf(d_file, "%s: no description\n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n", pkgs->pkgs[i]->name);
- fprintf(d_file, "%s: \n\n", pkgs->pkgs[i]->name);
+ if (strlen(pkg->description) < strlen(pkg->name)) {
+ fprintf(d_file, "%s: no description\n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n", pkg->name);
+ fprintf(d_file, "%s: \n\n", pkg->name);
} else {
- fprintf(d_file, "%s\n", pkgs->pkgs[i]->description);
+ fprintf(d_file, "%s\n", pkg->description);
}
}
}
@@ -1250,7 +1230,6 @@ void slapt_write_pkg_data(const char *source_url, FILE *d_file,
slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,
const char *pattern)
{
- unsigned int i;
int name_r = -1, desc_r = -1, loc_r = -1, version_r = -1;
slapt_regex_t *search_regex = NULL;
slapt_pkg_list_t *matches = NULL;
@@ -1260,31 +1239,31 @@ slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,
if ((search_regex = slapt_init_regex(pattern)) == NULL)
return matches;
- for (i = 0; i < list->pkg_count; i++) {
- if (strcmp(list->pkgs[i]->name, pattern) == 0) {
- slapt_add_pkg_to_pkg_list(matches, list->pkgs[i]);
+ slapt_pkg_list_t_foreach (pkg, list) {
+ if (strcmp(pkg->name, pattern) == 0) {
+ slapt_add_pkg_to_pkg_list(matches, pkg);
continue;
}
- slapt_execute_regex(search_regex, list->pkgs[i]->name);
+ slapt_execute_regex(search_regex, pkg->name);
name_r = search_regex->reg_return;
- slapt_execute_regex(search_regex, list->pkgs[i]->version);
+ slapt_execute_regex(search_regex, pkg->version);
version_r = search_regex->reg_return;
- if (list->pkgs[i]->description != NULL) {
- slapt_execute_regex(search_regex, list->pkgs[i]->description);
+ if (pkg->description != NULL) {
+ slapt_execute_regex(search_regex, pkg->description);
desc_r = search_regex->reg_return;
}
- if (list->pkgs[i]->location != NULL) {
- slapt_execute_regex(search_regex, list->pkgs[i]->location);
+ if (pkg->location != NULL) {
+ slapt_execute_regex(search_regex, pkg->location);
loc_r = search_regex->reg_return;
}
/* search pkg name, pkg description, pkg location */
if (name_r == 0 || version_r == 0 || desc_r == 0 || loc_r == 0) {
- slapt_add_pkg_to_pkg_list(matches, list->pkgs[i]);
+ slapt_add_pkg_to_pkg_list(matches, pkg);
}
}
slapt_free_regex(search_regex);
@@ -1300,14 +1279,10 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
slapt_pkg_err_list_t *conflict_err,
slapt_pkg_err_list_t *missing_err)
{
- unsigned int i = 0;
slapt_list_t *dep_parts = NULL;
- /*
- * don't go any further if the required member is empty
- * or disable_dep_check is set
- */
- if (global_config->disable_dep_check == true ||
+ /* don't go any further if the required member is empty or disable_dep_check is set */
+ if (global_config->disable_dep_check ||
strcmp(pkg->required, "") == 0 ||
strcmp(pkg->required, " ") == 0 ||
strcmp(pkg->required, " ") == 0)
@@ -1324,24 +1299,24 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
/* parse dep line */
dep_parts = slapt_parse_delimited_list(pkg->required, ',');
- for (i = 0; i < dep_parts->count; i++) {
+ slapt_list_t_foreach (part, dep_parts) {
slapt_pkg_info_t *tmp_pkg = NULL;
- if (strchr(dep_parts->items[i], '|') != NULL) {
- tmp_pkg = find_or_requirement(avail_pkgs, installed_pkgs, dep_parts->items[i]);
+ if (strchr(part, '|') != NULL) {
+ tmp_pkg = find_or_requirement(avail_pkgs, installed_pkgs, part);
} else {
- tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, dep_parts->items[i]);
+ tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, part);
}
if (tmp_pkg == NULL) {
/* if we can't find a required dep, return -1 */
- slapt_add_pkg_err_to_list(missing_err, pkg->name, dep_parts->items[i]);
+ slapt_add_pkg_err_to_list(missing_err, pkg->name, part);
slapt_free_list(dep_parts);
return -1;
}
/* if this pkg is excluded */
- if ((slapt_is_excluded(global_config, tmp_pkg) == 1) && (global_config->ignore_dep == false)) {
+ if ((slapt_is_excluded(global_config, tmp_pkg)) && !global_config->ignore_dep) {
if (slapt_get_exact_pkg(installed_pkgs, tmp_pkg->name, tmp_pkg->version) == NULL) {
slapt_add_pkg_err_to_list(conflict_err, pkg->name, tmp_pkg->name);
slapt_free_list(dep_parts);
@@ -1361,29 +1336,29 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
global_config, avail_pkgs, installed_pkgs, tmp_pkg,
deps, conflict_err, missing_err);
- if (dep_check_return == -1 && global_config->ignore_dep == false) {
+ if (dep_check_return == -1 && !global_config->ignore_dep) {
slapt_free_list(dep_parts);
return -1;
} else {
/* now move the package to the end after it's dependencies */
slapt_pkg_info_t *tmp = NULL;
+ uint32_t dep_idx = 0;
- i = 0;
- while (i < deps->pkg_count) {
- if (strcmp(deps->pkgs[i]->name, tmp_pkg->name) == 0 && tmp == NULL)
- tmp = deps->pkgs[i];
+ while (dep_idx < deps->pkg_count) {
+ if (strcmp(deps->pkgs[dep_idx]->name, tmp_pkg->name) == 0 && tmp == NULL)
+ tmp = deps->pkgs[dep_idx];
/* move all subsequent packages up */
- if (tmp != NULL && (i + 1 < deps->pkg_count))
- deps->pkgs[i] = deps->pkgs[i + 1];
+ if (tmp != NULL && (dep_idx + 1 < deps->pkg_count))
+ deps->pkgs[dep_idx] = deps->pkgs[dep_idx + 1];
- ++i;
+ ++dep_idx;
}
/*
- * now put the pkg we found at the end...
- * note no resizing is necessary, we just moved the location
- */
+ now put the pkg we found at the end...
+ note no resizing is necessary, we just moved the location
+ */
if (tmp != NULL)
deps->pkgs[deps->pkg_count - 1] = tmp;
}
@@ -1407,9 +1382,7 @@ slapt_pkg_list_t *slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
conflicts = slapt_init_pkg_list();
- /*
- * don't go any further if the required member is empty
- */
+ /* don't go any further if the required member is empty */
if (strcmp(pkg->conflicts, "") == 0 ||
strcmp(pkg->conflicts, " ") == 0 ||
strcmp(pkg->conflicts, " ") == 0)
@@ -1461,7 +1434,6 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
slapt_pkg_list_t *installed_pkgs,
char *dep_entry)
{
- unsigned int i;
slapt_regex_t *parse_dep_regex = NULL;
char *tmp_pkg_name = NULL, *tmp_pkg_ver = NULL;
char tmp_pkg_cond[3];
@@ -1510,17 +1482,19 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
return NULL;
}
- strcpy(tmp_pkg_cond, dep_entry + parse_dep_regex->pmatch[2].rm_so);
- tmp_pkg_cond[tmp_cond_len] = '\0';
+ 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';
+ }
tmp_pkg_ver = slapt_regex_extract_match(parse_dep_regex, dep_entry, 3);
slapt_free_regex(parse_dep_regex);
/*
- * check the newest version of tmp_pkg_name (in newest_installed_pkg)
- * before we try looping through installed_pkgs
- */
+ check the newest version of tmp_pkg_name (in newest_installed_pkg)
+ before we try looping through installed_pkgs
+ */
if (newest_installed_pkg != NULL) {
/* if condition is "=",">=", or "=<" and versions are the same */
if ((strchr(tmp_pkg_cond, '=') != NULL) &&
@@ -1549,43 +1523,41 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
}
}
- for (i = 0; i < installed_pkgs->pkg_count; i++) {
- if (strcmp(tmp_pkg_name, installed_pkgs->pkgs[i]->name) != 0)
+ slapt_pkg_list_t_foreach (installed_pkg, installed_pkgs) {
+ if (strcmp(tmp_pkg_name, installed_pkg->name) != 0)
continue;
/* if condition is "=",">=", or "=<" and versions are the same */
if ((strchr(tmp_pkg_cond, '=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver, installed_pkgs->pkgs[i]->version) == 0)) {
+ (slapt_cmp_pkg_versions(tmp_pkg_ver, installed_pkg->version) == 0)) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
+ return installed_pkg;
}
/* if "<" */
if (strchr(tmp_pkg_cond, '<') != NULL) {
- if (slapt_cmp_pkg_versions(installed_pkgs->pkgs[i]->version,
- tmp_pkg_ver) < 0) {
+ if (slapt_cmp_pkg_versions(installed_pkg->version, tmp_pkg_ver) < 0) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
+ return installed_pkg;
}
}
/* if ">" */
if (strchr(tmp_pkg_cond, '>') != NULL) {
- if (slapt_cmp_pkg_versions(installed_pkgs->pkgs[i]->version,
- tmp_pkg_ver) > 0) {
+ if (slapt_cmp_pkg_versions(installed_pkg->version, tmp_pkg_ver) > 0) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
+ return installed_pkg;
}
}
}
/*
- * 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) &&
@@ -1615,33 +1587,33 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
}
/* loop through avail_pkgs */
- for (i = 0; i < avail_pkgs->pkg_count; i++) {
- if (strcmp(tmp_pkg_name, avail_pkgs->pkgs[i]->name) != 0)
+ slapt_pkg_list_t_foreach (avail_pkg, avail_pkgs) {
+ if (strcmp(tmp_pkg_name, avail_pkg->name) != 0)
continue;
/* if condition is "=",">=", or "=<" and versions are the same */
if ((strchr(tmp_pkg_cond, '=') != NULL) &&
- (slapt_cmp_pkg_versions(tmp_pkg_ver, avail_pkgs->pkgs[i]->version) == 0)) {
+ (slapt_cmp_pkg_versions(tmp_pkg_ver, avail_pkg->version) == 0)) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
+ return avail_pkg;
}
/* if "<" */
if (strchr(tmp_pkg_cond, '<') != NULL) {
- if (slapt_cmp_pkg_versions(avail_pkgs->pkgs[i]->version, tmp_pkg_ver) < 0) {
+ if (slapt_cmp_pkg_versions(avail_pkg->version, tmp_pkg_ver) < 0) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
+ return avail_pkg;
}
}
/* if ">" */
if (strchr(tmp_pkg_cond, '>') != NULL) {
- if (slapt_cmp_pkg_versions(avail_pkgs->pkgs[i]->version, tmp_pkg_ver) > 0) {
+ if (slapt_cmp_pkg_versions(avail_pkg->version, tmp_pkg_ver) > 0) {
free(tmp_pkg_name);
free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
+ return avail_pkg;
}
}
}
@@ -1661,10 +1633,8 @@ slapt_pkg_list_t *slapt_is_required_by(const slapt_rc_config *global_config,
{
slapt_pkg_list_t *required_by_list = slapt_init_pkg_list();
- /*
- * don't go any further if disable_dep_check is set
- */
- if (global_config->disable_dep_check == true)
+ /* don't go any further if disable_dep_check is set */
+ if (global_config->disable_dep_check)
return required_by_list;
required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, pkg, required_by_list);
@@ -1674,7 +1644,7 @@ slapt_pkg_list_t *slapt_is_required_by(const slapt_rc_config *global_config,
static char *escape_package_name(slapt_pkg_info_t *pkg)
{
- unsigned int name_len = 0, escape_count = 0, i;
+ uint32_t name_len = 0, escape_count = 0, i;
char *escaped_name = NULL, *escaped_ptr;
char p;
@@ -1708,7 +1678,6 @@ static void required_by(slapt_pkg_list_t *avail,
slapt_pkg_info_t *pkg,
slapt_pkg_list_t *required_by_list)
{
- unsigned int i;
slapt_regex_t *required_by_reg = NULL;
char *pkg_name = escape_package_name(pkg);
int reg_str_len = strlen(pkg_name) + 31;
@@ -1729,50 +1698,47 @@ static void required_by(slapt_pkg_list_t *avail,
free(pkg_name);
free(reg);
- for (i = 0; i < avail->pkg_count; i++) {
- slapt_pkg_info_t *pkg_ptr = avail->pkgs[i];
+ slapt_pkg_list_t_foreach (avail_pkg, avail) {
slapt_list_t *dep_list = NULL;
- unsigned int d = 0;
- if (strcmp(pkg_ptr->required, "") == 0)
+ if (strcmp(avail_pkg->required, "") == 0)
continue;
- if (strcmp(pkg_ptr->required, " ") == 0)
+ if (strcmp(avail_pkg->required, " ") == 0)
continue;
- if (strcmp(pkg_ptr->required, " ") == 0)
+ if (strcmp(avail_pkg->required, " ") == 0)
continue;
- if (strstr(pkg_ptr->required, pkg->name) == NULL)
+ if (strstr(avail_pkg->required, pkg->name) == NULL)
continue;
- slapt_execute_regex(required_by_reg, pkg_ptr->required);
+ slapt_execute_regex(required_by_reg, avail_pkg->required);
if (required_by_reg->reg_return != 0)
continue;
/* check for the offending dependency entry and see if we have an alternative */
- dep_list = slapt_parse_delimited_list(pkg_ptr->required, ',');
- for (d = 0; d < dep_list->count; d++) {
+ dep_list = slapt_parse_delimited_list(avail_pkg->required, ',');
+ slapt_list_t_foreach (part, dep_list) {
slapt_list_t *satisfies = NULL;
- unsigned int s = 0;
bool has_alternative = false, found = false;
/* found our package in the list of dependencies */
- if (strstr(dep_list->items[d], pkg->name) == NULL)
+ if (strstr(part, pkg->name) == NULL)
continue;
/* not an |or, just add it */
- if (strchr(dep_list->items[d], '|') == NULL) {
- if (strcmp(dep_list->items[d], pkg->name) != 0)
+ if (strchr(part, '|') == NULL) {
+ if (strcmp(part, pkg->name) != 0)
continue;
- if (slapt_get_exact_pkg(required_by_list, pkg_ptr->name, pkg_ptr->version) == NULL) {
- slapt_add_pkg_to_pkg_list(required_by_list, pkg_ptr);
- required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, pkg_ptr, required_by_list);
+ if (slapt_get_exact_pkg(required_by_list, avail_pkg->name, avail_pkg->version) == NULL) {
+ slapt_add_pkg_to_pkg_list(required_by_list, avail_pkg);
+ required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, avail_pkg, required_by_list);
}
break;
}
/* we need to find out if we have something else that satisfies the dependency */
- satisfies = slapt_parse_delimited_list(dep_list->items[d], '|');
- for (s = 0; s < satisfies->count; s++) {
- slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail, installed_pkgs, satisfies->items[s]);
+ satisfies = slapt_parse_delimited_list(part, '|');
+ slapt_list_t_foreach (satisfies_part, satisfies) {
+ slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail, installed_pkgs, satisfies_part);
if (tmp_pkg == NULL)
continue;
@@ -1794,10 +1760,10 @@ static void required_by(slapt_pkg_list_t *avail,
slapt_free_list(satisfies);
/* we couldn't find an installed pkg that satisfies the |or */
- if (has_alternative == false && found == true) {
- if (slapt_get_exact_pkg(required_by_list, pkg_ptr->name, pkg_ptr->version) == NULL) {
- slapt_add_pkg_to_pkg_list(required_by_list, pkg_ptr);
- required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, pkg_ptr, required_by_list);
+ if (!has_alternative && found) {
+ if (slapt_get_exact_pkg(required_by_list, avail_pkg->name, avail_pkg->version) == NULL) {
+ slapt_add_pkg_to_pkg_list(required_by_list, avail_pkg);
+ required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, avail_pkg, required_by_list);
}
}
}
@@ -1851,18 +1817,16 @@ slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
}
} else {
- unsigned int i;
-
- for (i = 0; i < list->pkg_count; i++) {
- if (strcmp(list->pkgs[i]->name, name) == 0) {
+ slapt_pkg_list_t_foreach (pkg, list) {
+ if (strcmp(pkg->name, name) == 0) {
if (version != NULL) {
- if (strcmp(list->pkgs[i]->version, version) == 0) {
+ if (strcmp(pkg->version, version) == 0) {
if (location != NULL) {
- if (strcmp(list->pkgs[i]->location, location) == 0) {
- return list->pkgs[i];
+ if (strcmp(pkg->location, location) == 0) {
+ return pkg;
}
} else {
- return list->pkgs[i];
+ return pkg;
}
}
}
@@ -1876,13 +1840,13 @@ slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
/* update package data from mirror url */
int slapt_update_pkg_cache(const slapt_rc_config *global_config)
{
- unsigned int i, source_dl_failed = 0;
+ bool source_dl_failed = false;
slapt_pkg_list_t *new_pkgs = slapt_init_pkg_list();
new_pkgs->free_pkgs = true;
/* go through each package source and download the meta data */
- for (i = 0; i < global_config->sources->count; i++) {
- unsigned int compressed = 0;
+ slapt_source_list_t_foreach (source, global_config->sources) {
+ bool compressed = false;
slapt_pkg_list_t *available_pkgs = NULL;
slapt_pkg_list_t *patch_pkgs = NULL;
FILE *tmp_checksum_f = NULL;
@@ -1890,10 +1854,10 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
FILE *tmp_signature_f = NULL;
FILE *tmp_checksum_to_verify_f = NULL;
#endif
- const char *source_url = global_config->sources->src[i]->url;
- SLAPT_PRIORITY_T source_priority = global_config->sources->src[i]->priority;
+ const char *source_url = source->url;
+ SLAPT_PRIORITY_T source_priority = source->priority;
- if (global_config->sources->src[i]->disabled == true)
+ if (source->disabled)
continue;
/* download our SLAPT_PKG_LIST */
@@ -1901,7 +1865,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
available_pkgs = slapt_get_pkg_source_packages(global_config, source_url, &compressed);
if (available_pkgs == NULL) {
- source_dl_failed = 1;
+ source_dl_failed = true;
continue;
}
@@ -1919,7 +1883,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
tmp_signature_f = slapt_get_pkg_source_checksums_signature(global_config, source_url, &compressed);
/* if we downloaded the compressed checksums, open it raw (w/o gunzipping) */
- if (compressed == 1) {
+ if (compressed) {
char *filename = slapt_gen_filename_from_url(source_url, SLAPT_CHECKSUM_FILE_GZ);
tmp_checksum_to_verify_f = slapt_open_file(filename, "r");
free(filename);
@@ -1935,11 +1899,11 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
printf("%s\n", gettext("Verified"));
} else if (verified == SLAPT_CHECKSUMS_MISSING_KEY) {
printf("%s\n", gettext("No key for verification"));
- } else if ((global_config->gpgme_allow_unauth == true) && (slapt_pkg_sign_is_unauthenticated(verified) == true)) {
+ } else if ((global_config->gpgme_allow_unauth) && (slapt_pkg_sign_is_unauthenticated(verified))) {
printf("%s%s\n", slapt_strerror(verified), gettext(", but accepted as an exception"));
} else {
printf("%s\n", gettext(slapt_strerror(verified)));
- source_dl_failed = 1;
+ source_dl_failed = true;
fclose(tmp_checksum_f);
tmp_checksum_f = NULL;
}
@@ -1949,7 +1913,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
fclose(tmp_signature_f);
/* if we opened the raw gzipped checksums, close it here */
- if (compressed == 1) {
+ if (compressed) {
fclose(tmp_checksum_to_verify_f);
} else {
if (tmp_checksum_f)
@@ -1957,21 +1921,18 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
}
#endif
- if (source_dl_failed != 1) {
+ if (!source_dl_failed) {
printf(gettext("Retrieving ChangeLog.txt [%s]..."), source_url);
slapt_get_pkg_source_changelog(global_config, source_url, &compressed);
}
if (tmp_checksum_f != NULL) {
- unsigned int pkg_i;
-
/* now map md5 checksums to packages */
printf(gettext("Reading Package Lists..."));
slapt_get_md5sums(available_pkgs, tmp_checksum_f);
- for (pkg_i = 0; pkg_i < available_pkgs->pkg_count; ++pkg_i) {
- slapt_pkg_info_t *p = available_pkgs->pkgs[pkg_i];
+ slapt_pkg_list_t_foreach (p, available_pkgs) {
int mirror_len = -1;
/* honor the mirror if it was set in the PACKAGES.TXT */
@@ -1991,25 +1952,24 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
if (patch_pkgs) {
slapt_get_md5sums(patch_pkgs, tmp_checksum_f);
- for (pkg_i = 0; pkg_i < patch_pkgs->pkg_count; ++pkg_i) {
- slapt_pkg_info_t *p = patch_pkgs->pkgs[pkg_i];
+ slapt_pkg_list_t_foreach (patch_pkg, patch_pkgs) {
int mirror_len = -1;
/* honor the mirror if it was set in the PACKAGES.TXT */
- if (p->mirror == NULL || (mirror_len = strlen(p->mirror)) == 0) {
+ if (patch_pkg->mirror == NULL || (mirror_len = strlen(patch_pkg->mirror)) == 0) {
if (mirror_len == 0)
- free(p->mirror);
+ free(patch_pkg->mirror);
- p->mirror = strdup(source_url);
+ patch_pkg->mirror = strdup(source_url);
}
/* set the priority of the package based on the source, plus 1 for the patch priority */
- if (global_config->use_priority == true)
- p->priority = source_priority + 1;
+ if (global_config->use_priority)
+ patch_pkg->priority = source_priority + 1;
else
- p->priority = source_priority;
+ patch_pkg->priority = source_priority;
- slapt_add_pkg_to_pkg_list(new_pkgs, p);
+ slapt_add_pkg_to_pkg_list(new_pkgs, patch_pkg);
}
patch_pkgs->free_pkgs = false;
}
@@ -2018,7 +1978,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
fclose(tmp_checksum_f);
} else {
- source_dl_failed = 1;
+ source_dl_failed = true;
}
if (available_pkgs)
@@ -2030,7 +1990,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
} /* end for loop */
/* if all our downloads where a success, write to SLAPT_PKG_LIST_L */
- if (source_dl_failed != 1) {
+ if (!source_dl_failed) {
FILE *pkg_list_fh;
if ((pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L, "w+")) == NULL)
@@ -2213,7 +2173,7 @@ slapt_code_t slapt_verify_downloaded_pkg(const slapt_rc_config *global_config,
char md5sum_f[SLAPT_MD5_STR_LEN];
/*
- size_t file_size = 0;
+ size_t file_size = 0;
check the file size first so we don't run an md5 checksum
on an incomplete file
@@ -2223,14 +2183,14 @@ slapt_code_t slapt_verify_downloaded_pkg(const slapt_rc_config *global_config,
the PACKAGES.TXT... we do not really lose a lot by not checking
since we are validating the checksum anyway.
- file_size = slapt_get_pkg_file_size(global_config,pkg);
- if ((unsigned int)(file_size/1024) != pkg->size_c) {
- return SLAPT_DOWNLOAD_INCOMPLETE;
- }
- */
+ file_size = slapt_get_pkg_file_size(global_config,pkg);
+ if ((uint32_t)(file_size/1024) != pkg->size_c) {
+ return SLAPT_DOWNLOAD_INCOMPLETE;
+ }
+ */
/* if not checking the md5 checksum and the sizes match, assume its good */
- if (global_config->no_md5_check == true)
+ if (global_config->no_md5_check)
return SLAPT_OK;
/* check to see that we actually have an md5 checksum */
@@ -2350,7 +2310,7 @@ void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
free(tmp_pkg_version);
if (tmp_pkg == NULL) {
- if (global_config->no_prompt == true) {
+ if (global_config->no_prompt) {
unlink(file->d_name);
} else {
if (slapt_ask_yes_no(gettext("Delete %s ? [y/N]"), file->d_name) == 1)
@@ -2428,11 +2388,10 @@ static slapt_pkg_info_t *find_or_requirement(slapt_pkg_list_t *avail_pkgs,
char *required_str)
{
slapt_pkg_info_t *pkg = NULL;
- unsigned int i = 0;
slapt_list_t *alternates = slapt_parse_delimited_list(required_str, '|');
- for (i = 0; i < alternates->count; i++) {
- slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, alternates->items[i]);
+ slapt_list_t_foreach (alternate, alternates) {
+ slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, alternate);
if (tmp_pkg != NULL) {
/* installed packages are preferred */
@@ -2500,7 +2459,7 @@ void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,
{
slapt_pkg_err_t **tmp;
- if (slapt_search_pkg_err_list(l, pkg, err) == 1)
+ if (slapt_search_pkg_err_list(l, pkg, err))
return;
tmp = realloc(l->errs, sizeof *l->errs * (l->err_count + 1));
@@ -2516,27 +2475,24 @@ void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,
++l->err_count;
}
-int slapt_search_pkg_err_list(slapt_pkg_err_list_t *l,
- const char *pkg, const char *err)
+bool slapt_search_pkg_err_list(slapt_pkg_err_list_t *l,
+ const char *pkg, const char *err)
{
- unsigned int i, found = 1, not_found = 0;
- for (i = 0; i < l->err_count; ++i) {
- if (strcmp(l->errs[i]->pkg, pkg) == 0 &&
- strcmp(l->errs[i]->error, err) == 0) {
- return found;
+ slapt_pkg_err_list_t_foreach (error, l) {
+ if (strcmp(error->pkg, pkg) == 0 &&
+ strcmp(error->error, err) == 0) {
+ return true;
}
}
- return not_found;
+ return false;
}
void slapt_free_pkg_err_list(slapt_pkg_err_list_t *l)
{
- unsigned int i;
-
- for (i = 0; i < l->err_count; ++i) {
- free(l->errs[i]->pkg);
- free(l->errs[i]->error);
- free(l->errs[i]);
+ slapt_pkg_err_list_t_foreach (error, l) {
+ free(error->pkg);
+ free(error->error);
+ free(error);
}
free(l->errs);
free(l);
@@ -2565,7 +2521,7 @@ static FILE *slapt_gunzip_file(const char *file_name, FILE *dest_file)
}
slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed)
+ const char *url, bool *compressed)
{
slapt_pkg_list_t *available_pkgs = NULL;
char *pkg_head = NULL;
@@ -2610,7 +2566,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
FILE *tmp_pkg_f = NULL;
const char *err = NULL;
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if ((tmp_pkg_f = slapt_open_file(pkg_filename, "w+b")) == NULL)
@@ -2673,11 +2629,10 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
} else { /* fall back to uncompressed package list */
char *pkg_filename = slapt_gen_filename_from_url(url, SLAPT_PKG_LIST);
char *pkg_local_head = slapt_read_head_cache(pkg_filename);
- /*
- we go ahead and run the head request, not caring if it failed.
- If the subsequent download fails as well, it will give a nice
- error message of why.
- */
+ /* we go ahead and run the head request, not caring if it failed.
+ If the subsequent download fails as well, it will give a nice
+ error message of why.
+ */
pkg_head = slapt_head_mirror_data(url, SLAPT_PKG_LIST);
/* is it cached ? */
@@ -2697,7 +2652,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
FILE *tmp_pkg_f = NULL;
const char *err = NULL;
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if ((tmp_pkg_f = slapt_open_file(pkg_filename, "w+b")) == NULL)
@@ -2758,7 +2713,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
}
slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed)
+ const char *url, bool *compressed)
{
slapt_pkg_list_t *patch_pkgs = NULL;
char *patch_head = NULL;
@@ -2787,7 +2742,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
FILE *tmp_patch_f = NULL;
const char *err = NULL;
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if ((tmp_patch_f = slapt_open_file(patch_filename, "w+b")) == NULL)
@@ -2819,11 +2774,11 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
fprintf(stderr, gettext("Failed to download: %s\n"), err);
fclose(tmp_patch_f);
/* we don't care if the patch fails, for example current
- doesn't have patches source_dl_failed = 1; */
+ doesn't have patches source_dl_failed = true; */
slapt_clear_head_cache(patch_filename);
}
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
}
@@ -2835,10 +2790,10 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
char *patch_filename = slapt_gen_filename_from_url(url, SLAPT_PATCHES_LIST);
char *patch_local_head = slapt_read_head_cache(patch_filename);
/*
- we go ahead and run the head request, not caring if it failed.
- If the subsequent download fails as well, it will give a nice
- error message of why.
- */
+ we go ahead and run the head request, not caring if it failed.
+ If the subsequent download fails as well, it will give a nice
+ error message of why.
+ */
patch_head = slapt_head_mirror_data(url, SLAPT_PATCHES_LIST);
if (patch_head != NULL && patch_local_head != NULL &&
@@ -2858,7 +2813,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
FILE *tmp_patch_f = NULL;
const char *err = NULL;
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if ((tmp_patch_f = slapt_open_file(patch_filename, "w+b")) == NULL)
@@ -2879,14 +2834,14 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
} else {
/* we don't care if the patch fails, for example current
- doesn't have patches source_dl_failed = 1; */
+ doesn't have patches source_dl_failed = true; */
slapt_clear_head_cache(patch_filename);
if (is_interactive)
printf(gettext("Done\n"));
}
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
fclose(tmp_patch_f);
@@ -2902,7 +2857,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
}
FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed)
+ const char *url, bool *compressed)
{
FILE *tmp_checksum_f = NULL;
char *checksum_head = NULL;
@@ -2926,7 +2881,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
FILE *working_checksum_f = NULL;
const char *err = NULL;
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if ((working_checksum_f = slapt_open_file(filename, "w+b")) == NULL)
@@ -2936,7 +2891,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
global_config, url,
SLAPT_CHECKSUM_FILE_GZ);
if (!err) {
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if (is_interactive)
printf(gettext("Done\n"));
@@ -2976,10 +2931,10 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
char *filename = slapt_gen_filename_from_url(url, SLAPT_CHECKSUM_FILE);
char *local_head = slapt_read_head_cache(filename);
/*
- we go ahead and run the head request, not caring if it failed.
- If the subsequent download fails as well, it will give a nice
- error message of why.
- */
+ we go ahead and run the head request, not caring if it failed.
+ If the subsequent download fails as well, it will give a nice
+ error message of why.
+ */
checksum_head = slapt_head_mirror_data(url, SLAPT_CHECKSUM_FILE);
if (checksum_head != NULL && local_head != NULL &&
@@ -2996,7 +2951,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
if ((tmp_checksum_f = slapt_open_file(filename, "w+b")) == NULL)
exit(EXIT_FAILURE);
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
err = slapt_get_mirror_data_from_source(tmp_checksum_f,
@@ -3023,7 +2978,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
if (checksum_head != NULL)
slapt_write_head_cache(checksum_head, filename);
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
}
@@ -3036,8 +2991,8 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
return tmp_checksum_f;
}
-int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
- const char *url, unsigned int *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;
@@ -3045,7 +3000,6 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
char *location_gz = SLAPT_CHANGELOG_FILE_GZ;
char *location_uncomp = SLAPT_CHANGELOG_FILE;
char *location = location_gz;
- int success = 0, failure = -1;
bool is_interactive = slapt_is_interactive(global_config);
*compressed = 0;
@@ -3061,7 +3015,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
if (changelog_head == NULL) {
if (is_interactive)
printf(gettext("Done\n"));
- return success;
+ return true;
}
filename = slapt_gen_filename_from_url(url, location);
@@ -3075,7 +3029,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
FILE *working_changelog_f = NULL;
const char *err = NULL;
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if ((working_changelog_f = slapt_open_file(filename, "w+b")) == NULL)
@@ -3085,7 +3039,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
global_config, url,
location);
if (!err) {
- if (global_config->dl_stats == true)
+ if (global_config->dl_stats)
printf("\n");
if (is_interactive)
printf(gettext("Done\n"));
@@ -3112,7 +3066,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
free(local_head);
if (changelog_head != NULL)
free(changelog_head);
- return failure;
+ return false;
}
}
free(filename);
@@ -3121,7 +3075,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
if (changelog_head != NULL)
free(changelog_head);
- return success;
+ return true;
}
void slapt_clean_description(char *description, const char *name)
@@ -3267,30 +3221,25 @@ slapt_get_obsolete_pkgs(const slapt_rc_config *global_config,
slapt_pkg_list_t *avail_pkgs,
slapt_pkg_list_t *installed_pkgs)
{
- unsigned int r;
slapt_pkg_list_t *obsolete = slapt_init_pkg_list();
slapt_pkg_list_t *to_install = slapt_init_pkg_list();
slapt_pkg_list_t *to_remove = slapt_init_pkg_list();
- for (r = 0; r < installed_pkgs->pkg_count; ++r) {
- slapt_pkg_info_t *p = installed_pkgs->pkgs[r];
-
+ slapt_pkg_list_t_foreach (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) {
slapt_pkg_list_t *deps;
- unsigned int c;
/*
- any packages that require this package we are about to remove
- should be scheduled to remove as well
- */
+ any packages that require this package we are about to remove
+ should be scheduled to remove as well
+ */
deps = slapt_is_required_by(global_config, avail_pkgs, installed_pkgs, to_install, to_remove, p);
- for (c = 0; c < deps->pkg_count; ++c) {
- slapt_pkg_info_t *dep = deps->pkgs[c];
+ slapt_pkg_list_t_foreach (dep, deps) {
slapt_pkg_info_t *installed_dep = slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version);
/* if it is installed, we add it to the list */
@@ -3349,7 +3298,7 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
size_t pls = 1;
/* this only handles installed packages at the moment */
- if (pkg->installed != true)
+ if (!pkg->installed)
return filelist;
pkg_log_dirname = slapt_gen_package_log_dir_name();
@@ -3374,7 +3323,7 @@ char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg)
/*
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);
diff --git a/src/package.h b/src/package.h
index a1280f4..96e27f9 100644
--- a/src/package.h
+++ b/src/package.h
@@ -63,18 +63,19 @@ typedef struct {
char *conflicts;
char *suggests;
char *file_ext;
- unsigned int size_c;
- unsigned int size_u;
- unsigned int priority;
+ uint32_t size_c;
+ uint32_t size_u;
+ uint32_t priority;
bool installed;
} slapt_pkg_info_t;
typedef struct {
slapt_pkg_info_t **pkgs;
- unsigned int pkg_count;
+ uint32_t pkg_count;
bool free_pkgs;
bool ordered;
} slapt_pkg_list_t;
+#define slapt_pkg_list_t_foreach(item, list) slapt_pkg_info_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->pkg_count) && (item = list->pkgs[item##_counter]); item##_counter++)
typedef struct {
slapt_pkg_info_t *installed;
@@ -84,9 +85,10 @@ typedef struct {
typedef struct {
slapt_pkg_upgrade_t **pkgs;
- unsigned int pkg_count;
- unsigned int reinstall_count;
+ uint32_t pkg_count;
+ uint32_t reinstall_count;
} slapt_pkg_upgrade_list_t;
+#define slapt_pkg_upgrade_list_t_foreach(item, list) slapt_pkg_upgrade_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->pkg_count) && (item = list->pkgs[item##_counter]); item##_counter++)
typedef struct {
char *pkg;
@@ -95,8 +97,9 @@ typedef struct {
typedef struct {
slapt_pkg_err_t **errs;
- unsigned int err_count;
+ uint32_t err_count;
} slapt_pkg_err_list_t;
+#define slapt_pkg_err_list_t_foreach(item, list) slapt_pkg_err_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->err_count) && (item = list->errs[item##_counter]); item##_counter++)
/* returns an empty package structure */
slapt_pkg_info_t *slapt_init_pkg(void);
@@ -197,7 +200,7 @@ char *slapt_gen_pkg_url(slapt_pkg_info_t *pkg);
exclude pkg based on pkg name
returns 1 if package is present in the exclude list, 0 if not present
*/
-int slapt_is_excluded(const slapt_rc_config *, slapt_pkg_info_t *);
+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.
@@ -275,22 +278,22 @@ slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst, slapt_pkg_info_t *src);
slapt_pkg_err_list_t *slapt_init_pkg_err_list(void);
void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,
const char *pkg, const char *err);
-int slapt_search_pkg_err_list(slapt_pkg_err_list_t *l,
+bool slapt_search_pkg_err_list(slapt_pkg_err_list_t *l,
const char *pkg, const char *err);
void slapt_free_pkg_err_list(slapt_pkg_err_list_t *l);
/*
download the PACKAGES.TXT and CHECKSUMS.md5 files
- compressed is set to 1 if the compressed version was downloaded.
+ compressed is set if the compressed version was downloaded.
*/
slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
+ const char *url, bool *compressed);
slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
+ const char *url, bool *compressed);
FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
-int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
- const char *url, unsigned int *compressed);
+ 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);
@@ -311,7 +314,7 @@ char *slapt_stringify_pkg(const slapt_pkg_info_t *pkg);
char *slapt_get_pkg_filelist(const slapt_pkg_info_t *pkg);
/*
- generate the directory name for the package log directory,
+ generate the directory name for the package log directory,
considering the ROOT environment variable if set
caller responsible for freeing the returned data
*/
diff --git a/src/transaction.c b/src/transaction.c
index 38be3ef..7882506 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -63,7 +63,7 @@ slapt_transaction_t *slapt_init_transaction(void)
int slapt_handle_transaction(const slapt_rc_config *global_config,
slapt_transaction_t *tran)
{
- unsigned int i, pkg_dl_count = 0, dl_counter = 0, len = 0;
+ uint32_t pkg_dl_count = 0, dl_counter = 0, len = 0;
double download_size = 0;
double already_download_size = 0;
double uncompressed_size = 0;
@@ -72,17 +72,16 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* show unmet dependencies */
if (tran->missing_err->err_count > 0) {
fprintf(stderr, gettext("The following packages have unmet dependencies:\n"));
- for (i = 0; i < tran->missing_err->err_count; ++i) {
- fprintf(stderr, gettext(" %s: Depends: %s\n"),
- tran->missing_err->errs[i]->pkg, tran->missing_err->errs[i]->error);
+ slapt_pkg_err_list_t_foreach (error, tran->missing_err) {
+ fprintf(stderr, gettext(" %s: Depends: %s\n"), error->pkg, error->error);
}
}
/* show conflicts */
if (tran->conflict_err->err_count > 0) {
- for (i = 0; i < tran->conflict_err->err_count; ++i) {
+ slapt_pkg_err_list_t_foreach (conflict_error, tran->conflict_err) {
fprintf(stderr, gettext("%s, which is required by %s, is excluded\n"),
- tran->conflict_err->errs[i]->error, tran->conflict_err->errs[i]->pkg);
+ conflict_error->error, conflict_error->pkg);
}
}
@@ -92,9 +91,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
printf(" ");
len = 0;
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- const slapt_pkg_info_t *e = tran->exclude_pkgs->pkgs[i];
-
+ slapt_pkg_list_t_foreach (e, tran->exclude_pkgs) {
if (len + strlen(e->name) + 1 < MAX_LINE_LEN) {
printf("%s ", e->name);
len += strlen(e->name) + 1;
@@ -110,17 +107,13 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* show suggested pkgs */
slapt_generate_suggestions(tran);
if (tran->suggests->count > 0) {
-
printf(gettext("Suggested packages:\n"));
printf(" ");
len = 0;
- for (i = 0; i < tran->suggests->count; ++i) {
- char *s = tran->suggests->items[i];
-
- /* don't show suggestion for something we already have
- in the transaction */
- if (slapt_search_transaction(tran, s) == 1)
+ slapt_list_t_foreach (s, tran->suggests) {
+ /* don't show suggestion for something we already have in the transaction */
+ if (slapt_search_transaction(tran, s))
continue;
if (len + strlen(s) + 1 < MAX_LINE_LEN) {
@@ -140,8 +133,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
printf(" ");
len = 0;
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];
+ slapt_pkg_list_t_foreach (p, tran->install_pkgs) {
size_t existing_file_size = 0;
if (len + strlen(p->name) + 1 < MAX_LINE_LEN) {
@@ -170,9 +162,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
printf(" ");
len = 0;
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- const slapt_pkg_info_t *r = tran->remove_pkgs->pkgs[i];
-
+ slapt_pkg_list_t_foreach (r, tran->remove_pkgs) {
if (len + strlen(r->name) + 1 < MAX_LINE_LEN) {
printf("%s ", r->name);
len += strlen(r->name) + 1;
@@ -189,16 +179,15 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* show pkgs to upgrade */
if (tran->upgrade_pkgs->pkg_count > 0) {
-
if ((tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count) > 0) {
printf(gettext("The following packages will be upgraded:\n"));
printf(" ");
}
len = 0;
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *u = tran->upgrade_pkgs->pkgs[i]->upgrade;
- slapt_pkg_info_t *p = tran->upgrade_pkgs->pkgs[i]->installed;
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_pkg_info_t *u = upgrade->upgrade;
+ slapt_pkg_info_t *p = upgrade->installed;
size_t existing_file_size = 0;
int line_len = len + strlen(u->name) + 1;
@@ -215,7 +204,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
uncompressed_size += u->size_u;
uncompressed_size -= p->size_u;
- if (tran->upgrade_pkgs->pkgs[i]->reinstall == true)
+ if (upgrade->reinstall)
continue;
if (line_len < MAX_LINE_LEN) {
@@ -235,11 +224,11 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
printf(" ");
len = 0;
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *u = tran->upgrade_pkgs->pkgs[i]->upgrade;
+ slapt_pkg_upgrade_list_t_foreach (reinstall_upgrade, tran->upgrade_pkgs) {
+ slapt_pkg_info_t *u = reinstall_upgrade->upgrade;
int line_len = len + strlen(u->name) + 1;
- if (tran->upgrade_pkgs->pkgs[i]->reinstall == false)
+ if (!reinstall_upgrade->reinstall)
continue;
if (line_len < MAX_LINE_LEN) {
@@ -294,15 +283,15 @@ 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) == false) {
+ 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);
exit(EXIT_FAILURE);
}
/* check that we have enough space in the root filesystem */
- if (global_config->download_only == false) {
- if (slapt_disk_space_check("/", uncompressed_size) == false) {
+ if (!global_config->download_only) {
+ if (!slapt_disk_space_check("/", uncompressed_size)) {
printf(gettext("You don't have enough free space in %s\n"), "/");
exit(EXIT_FAILURE);
}
@@ -329,10 +318,10 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
}
/* prompt */
- if ((global_config->prompt == true) ||
+ if ((global_config->prompt) ||
((tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
(tran->install_pkgs->pkg_count > 0 &&
- global_config->dist_upgrade == true)) &&
+ global_config->dist_upgrade)) &&
(global_config->no_prompt == false &&
global_config->download_only == false &&
global_config->simulate == false &&
@@ -343,41 +332,39 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
}
}
- if (global_config->print_uris == true) {
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- const slapt_pkg_info_t *info = tran->install_pkgs->pkgs[i];
+ if (global_config->print_uris) {
+ slapt_pkg_list_t_foreach (info, tran->install_pkgs) {
const char *location = info->location + strspn(info->location, "./");
printf("%s%s/%s-%s%s\n",
info->mirror, location, info->name,
info->version, info->file_ext);
}
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- const slapt_pkg_info_t *info = tran->upgrade_pkgs->pkgs[i]->upgrade;
- const char *location = info->location + strspn(info->location, "./");
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ const slapt_pkg_info_t *upgrade_info = upgrade->upgrade;
+ const char *location = upgrade_info->location + strspn(upgrade_info->location, "./");
printf("%s%s/%s-%s%s\n",
- info->mirror, location, info->name,
- info->version, info->file_ext);
+ upgrade_info->mirror, location, upgrade_info->name,
+ upgrade_info->version, upgrade_info->file_ext);
}
return 0;
}
/* if simulate is requested, just show what could happen and return */
- if (global_config->simulate == true) {
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- const slapt_pkg_info_t *r = tran->remove_pkgs->pkgs[i];
+ if (global_config->simulate) {
+ slapt_pkg_list_t_foreach (r, tran->remove_pkgs) {
printf(gettext("%s-%s is to be removed\n"), r->name, r->version);
}
- for (i = 0; i < tran->queue->count; ++i) {
- if (tran->queue->pkgs[i]->type == INSTALL) {
+ slapt_queue_t_foreach (q, tran->queue) {
+ if (q->type == INSTALL) {
printf(gettext("%s-%s is to be installed\n"),
- tran->queue->pkgs[i]->pkg.i->name,
- tran->queue->pkgs[i]->pkg.i->version);
- } else if (tran->queue->pkgs[i]->type == UPGRADE) {
+ q->pkg.i->name,
+ q->pkg.i->version);
+ } else if (q->type == UPGRADE) {
printf(gettext("%s-%s is to be upgraded to version %s\n"),
- tran->queue->pkgs[i]->pkg.u->upgrade->name,
- tran->queue->pkgs[i]->pkg.u->installed->version,
- tran->queue->pkgs[i]->pkg.u->upgrade->version);
+ q->pkg.u->upgrade->name,
+ q->pkg.u->installed->version,
+ q->pkg.u->upgrade->version);
}
}
@@ -388,44 +375,44 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
pkg_dl_count = tran->install_pkgs->pkg_count + tran->upgrade_pkgs->pkg_count;
/* download pkgs */
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- unsigned int retry_count, failed = 1;
+ slapt_pkg_list_t_foreach (pkg, tran->install_pkgs) {
+ bool failed = true;
++dl_counter;
snprintf(dl_note, SLAPT_PKG_DL_NOTE_LEN, "%d/%d", dl_counter, pkg_dl_count);
- for (retry_count = 0; retry_count < global_config->retry; ++retry_count) {
- const char *err = slapt_download_pkg(global_config, tran->install_pkgs->pkgs[i], dl_note);
+ for (uint32_t retry_count = 0; retry_count < global_config->retry; ++retry_count) {
+ const char *err = slapt_download_pkg(global_config, pkg, dl_note);
if (err) {
fprintf(stderr, gettext("Failed to download: %s\n"), err);
- failed = 1;
+ failed = true;
} else {
- failed = 0;
+ failed = false;
break;
}
}
- if (failed == 1)
+ if (failed)
exit(EXIT_FAILURE);
}
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- unsigned int retry_count, failed = 1;
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ bool failed = true;
++dl_counter;
snprintf(dl_note, SLAPT_PKG_DL_NOTE_LEN, "%d/%d", dl_counter, pkg_dl_count);
- for (retry_count = 0; retry_count < global_config->retry; ++retry_count) {
- const char *err = slapt_download_pkg(global_config, tran->upgrade_pkgs->pkgs[i]->upgrade, dl_note);
+ for (uint32_t retry_count = 0; retry_count < global_config->retry; ++retry_count) {
+ const char *err = slapt_download_pkg(global_config, upgrade->upgrade, dl_note);
if (err) {
fprintf(stderr, gettext("Failed to download: %s\n"), err);
- failed = 1;
+ failed = true;
} else {
- failed = 0;
+ failed = false;
break;
}
}
- if (failed == 1)
+ if (failed)
exit(EXIT_FAILURE);
}
@@ -433,29 +420,29 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* run transaction, remove, install, and upgrade */
if (global_config->download_only == false) {
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- if (slapt_remove_pkg(global_config, tran->remove_pkgs->pkgs[i]) == -1) {
+ slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ if (slapt_remove_pkg(global_config, remove_pkg) == -1) {
exit(EXIT_FAILURE);
}
}
- for (i = 0; i < tran->queue->count; ++i) {
- if (tran->queue->pkgs[i]->type == INSTALL) {
+ slapt_queue_t_foreach (q, tran->queue) {
+ if (q->type == INSTALL) {
printf(gettext("Preparing to install %s-%s\n"),
- tran->queue->pkgs[i]->pkg.i->name,
- tran->queue->pkgs[i]->pkg.i->version);
+ q->pkg.i->name,
+ q->pkg.i->version);
if (slapt_install_pkg(global_config,
- tran->queue->pkgs[i]->pkg.i) == -1) {
+ q->pkg.i) == -1) {
exit(EXIT_FAILURE);
}
- } else if (tran->queue->pkgs[i]->type == UPGRADE) {
+ } else if (q->type == UPGRADE) {
printf(gettext("Preparing to replace %s-%s with %s-%s\n"),
- tran->queue->pkgs[i]->pkg.u->upgrade->name,
- tran->queue->pkgs[i]->pkg.u->installed->version,
- tran->queue->pkgs[i]->pkg.u->upgrade->name,
- tran->queue->pkgs[i]->pkg.u->upgrade->version);
+ q->pkg.u->upgrade->name,
+ q->pkg.u->installed->version,
+ q->pkg.u->upgrade->name,
+ q->pkg.u->upgrade->version);
if (slapt_upgrade_pkg(global_config,
- tran->queue->pkgs[i]->pkg.u->upgrade) == -1) {
+ q->pkg.u->upgrade) == -1) {
exit(EXIT_FAILURE);
}
}
@@ -473,7 +460,7 @@ void slapt_add_install_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, pkg))
return;
tmp_list = realloc(
@@ -502,7 +489,7 @@ void slapt_add_remove_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, pkg))
return;
tmp_list = realloc(
@@ -526,7 +513,7 @@ void slapt_add_exclude_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, pkg))
return;
tmp_list = realloc(
@@ -566,7 +553,7 @@ static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
slapt_pkg_upgrade_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg))
return;
tmp_list = realloc(
@@ -602,84 +589,76 @@ static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
++tran->upgrade_pkgs->pkg_count;
- if (reinstall == true)
+ if (reinstall)
++tran->upgrade_pkgs->reinstall_count;
}
}
-int slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
+bool slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
{
- unsigned int i, found = 1, not_found = 0;
-
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- if (strcmp(pkg_name, tran->install_pkgs->pkgs[i]->name) == 0)
- return found;
+ slapt_pkg_list_t_foreach (pkg, tran->install_pkgs) {
+ if (strcmp(pkg_name, pkg->name) == 0)
+ return true;
}
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- if (strcmp(pkg_name, tran->upgrade_pkgs->pkgs[i]->upgrade->name) == 0)
- return found;
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ if (strcmp(pkg_name, upgrade->upgrade->name) == 0)
+ return true;
}
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- if (strcmp(pkg_name, tran->remove_pkgs->pkgs[i]->name) == 0)
- return found;
+ slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ if (strcmp(pkg_name, remove_pkg->name) == 0)
+ return true;
}
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- if (strcmp(pkg_name, tran->exclude_pkgs->pkgs[i]->name) == 0)
- return found;
+ slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
+ if (strcmp(pkg_name, exclude_pkg->name) == 0)
+ return true;
}
- return not_found;
+ return false;
}
-int 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)
{
- unsigned int i,
- found = 1,
- not_found = 0;
-
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- if (strcmp(pkg->name, tran->upgrade_pkgs->pkgs[i]->upgrade->name) == 0)
- return found;
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ if (strcmp(pkg->name, upgrade->upgrade->name) == 0)
+ return true;
}
- return not_found;
+ return false;
}
void slapt_free_transaction(slapt_transaction_t *tran)
{
- unsigned int i;
-
- if (tran->install_pkgs->free_pkgs == true) {
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->install_pkgs->pkgs[i]);
+ if (tran->install_pkgs->free_pkgs) {
+ slapt_pkg_list_t_foreach (pkg, tran->install_pkgs) {
+ slapt_free_pkg(pkg);
}
}
free(tran->install_pkgs->pkgs);
free(tran->install_pkgs);
- if (tran->remove_pkgs->free_pkgs == true) {
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->remove_pkgs->pkgs[i]);
+ if (tran->remove_pkgs->free_pkgs) {
+ slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ slapt_free_pkg(remove_pkg);
}
}
free(tran->remove_pkgs->pkgs);
free(tran->remove_pkgs);
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->upgrade_pkgs->pkgs[i]->upgrade);
- slapt_free_pkg(tran->upgrade_pkgs->pkgs[i]->installed);
- free(tran->upgrade_pkgs->pkgs[i]);
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_free_pkg(upgrade->upgrade);
+ slapt_free_pkg(upgrade->installed);
+ free(upgrade);
}
free(tran->upgrade_pkgs->pkgs);
free(tran->upgrade_pkgs);
- if (tran->exclude_pkgs->free_pkgs == true) {
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- slapt_free_pkg(tran->exclude_pkgs->pkgs[i]);
+ if (tran->exclude_pkgs->free_pkgs) {
+ slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
+ slapt_free_pkg(exclude_pkg);
}
}
free(tran->exclude_pkgs->pkgs);
@@ -698,10 +677,9 @@ void slapt_free_transaction(slapt_transaction_t *tran)
slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- unsigned int i;
slapt_transaction_t *new_tran = NULL;
- if (slapt_search_transaction_by_pkg(tran, pkg) == 0)
+ if (!slapt_search_transaction_by_pkg(tran, pkg))
return tran;
/* since this is a pointer, slapt_malloc before calling init */
@@ -712,35 +690,31 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
new_tran->exclude_pkgs = slapt_malloc(sizeof *new_tran->exclude_pkgs);
new_tran = slapt_init_transaction();
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];
-
+ slapt_pkg_list_t_foreach (installed_pkg, tran->install_pkgs) {
if (
- strcmp(pkg->name, p->name) == 0 &&
- strcmp(pkg->version, p->version) == 0 &&
- strcmp(pkg->location, p->location) == 0) {
+ strcmp(pkg->name, installed_pkg->name) == 0 &&
+ strcmp(pkg->version, installed_pkg->version) == 0 &&
+ strcmp(pkg->location, installed_pkg->location) == 0) {
continue;
}
- slapt_add_install_to_transaction(new_tran, p);
+ slapt_add_install_to_transaction(new_tran, installed_pkg);
}
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->remove_pkgs->pkgs[i];
-
+ slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
if (
- strcmp(pkg->name, p->name) == 0 &&
- strcmp(pkg->version, p->version) == 0 &&
- strcmp(pkg->location, p->location) == 0) {
+ strcmp(pkg->name, remove_pkg->name) == 0 &&
+ strcmp(pkg->version, remove_pkg->version) == 0 &&
+ strcmp(pkg->location, remove_pkg->location) == 0) {
continue;
}
- slapt_add_remove_to_transaction(new_tran, tran->remove_pkgs->pkgs[i]);
+ slapt_add_remove_to_transaction(new_tran, remove_pkg);
}
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *u = tran->upgrade_pkgs->pkgs[i]->upgrade;
- slapt_pkg_info_t *p = tran->upgrade_pkgs->pkgs[i]->installed;
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_pkg_info_t *u = upgrade->upgrade;
+ slapt_pkg_info_t *p = upgrade->installed;
if (
strcmp(pkg->name, u->name) == 0 &&
@@ -752,17 +726,15 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_add_upgrade_to_transaction(new_tran, p, u);
}
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->exclude_pkgs->pkgs[i];
-
+ slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
if (
- strcmp(pkg->name, p->name) == 0 &&
- strcmp(pkg->version, p->version) == 0 &&
- strcmp(pkg->location, p->location) == 0) {
+ strcmp(pkg->name, exclude_pkg->name) == 0 &&
+ strcmp(pkg->version, exclude_pkg->version) == 0 &&
+ strcmp(pkg->location, exclude_pkg->location) == 0) {
continue;
}
- slapt_add_exclude_to_transaction(new_tran, p);
+ slapt_add_exclude_to_transaction(new_tran, exclude_pkg);
}
return new_tran;
@@ -776,11 +748,10 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
slapt_pkg_list_t *installed_pkgs,
slapt_pkg_info_t *pkg)
{
- unsigned int c;
int dep_return = -1;
slapt_pkg_list_t *deps = NULL;
- if (global_config->disable_dep_check == true)
+ if (global_config->disable_dep_check)
return 0;
if (pkg == NULL)
@@ -801,22 +772,15 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
}
/* loop through the deps */
- for (c = 0; c < deps->pkg_count; ++c) {
- unsigned int cindex = 0;
- slapt_pkg_info_t *dep = deps->pkgs[c];
+ slapt_pkg_list_t_foreach (dep, deps) {
slapt_pkg_info_t *dep_installed = NULL;
slapt_pkg_list_t *conflicts = NULL;
- /*
- * the dep wouldn't get this far if it where excluded,
- * so we don't check for that here
- */
-
- conflicts =
- slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, dep);
+ /* the dep wouldn't get this far if it where excluded, so we don't check for that here */
+ conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, dep);
- for (cindex = 0; cindex < conflicts->pkg_count; cindex++) {
- slapt_add_remove_to_transaction(tran, conflicts->pkgs[cindex]);
+ slapt_pkg_list_t_foreach (conflict, conflicts) {
+ slapt_add_remove_to_transaction(tran, conflict);
}
slapt_free_pkg_list(conflicts);
@@ -842,26 +806,21 @@ slapt_pkg_list_t *slapt_is_conflicted(slapt_transaction_t *tran,
slapt_pkg_list_t *installed_pkgs,
slapt_pkg_info_t *pkg)
{
- unsigned int i;
slapt_pkg_list_t *conflicts = NULL;
slapt_pkg_list_t *conflicts_in_transaction = slapt_init_pkg_list();
- /* if conflicts exist, check to see if they are installed
- or in the current transaction
- */
+ /* if conflicts exist, check to see if they are installed or in the current transaction */
conflicts = slapt_get_pkg_conflicts(avail_pkgs, installed_pkgs, pkg);
- for (i = 0; i < conflicts->pkg_count; ++i) {
- slapt_pkg_info_t *p = conflicts->pkgs[i];
+ slapt_pkg_list_t_foreach (conflict, conflicts) {
+ if (slapt_search_upgrade_transaction(tran, conflict) == 1 || slapt_get_newest_pkg(tran->install_pkgs, conflict->name) != NULL) {
+ printf(gettext("%s, which is to be installed, conflicts with %s\n"), conflict->name, pkg->name);
- if (slapt_search_upgrade_transaction(tran, p) == 1 || slapt_get_newest_pkg(tran->install_pkgs, p->name) != NULL) {
- printf(gettext("%s, which is to be installed, conflicts with %s\n"), p->name, pkg->name);
-
- slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
+ slapt_add_pkg_to_pkg_list(conflicts_in_transaction, conflict);
}
- if (slapt_get_newest_pkg(installed_pkgs, p->name) != NULL) {
- printf(gettext("Installed %s conflicts with %s\n"), p->name, pkg->name);
+ if (slapt_get_newest_pkg(installed_pkgs, conflict->name) != NULL) {
+ printf(gettext("Installed %s conflicts with %s\n"), conflict->name, pkg->name);
- slapt_add_pkg_to_pkg_list(conflicts_in_transaction, p);
+ slapt_add_pkg_to_pkg_list(conflicts_in_transaction, conflict);
}
}
@@ -873,7 +832,6 @@ slapt_pkg_list_t *slapt_is_conflicted(slapt_transaction_t *tran,
static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
slapt_list_t *suggests = NULL;
- unsigned int i = 0;
if (pkg->suggests == NULL || strlen(pkg->suggests) == 0) {
return;
@@ -881,51 +839,43 @@ static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
suggests = slapt_parse_delimited_list(pkg->suggests, ',');
- for (i = 0; i < suggests->count; i++) {
+ slapt_list_t_foreach (s, suggests) {
/* no need to add it if we already have it */
- if (slapt_search_transaction(tran, suggests->items[i]) == 1)
+ if (slapt_search_transaction(tran, s))
continue;
- slapt_add_list_item(tran->suggests, suggests->items[i]);
+ slapt_add_list_item(tran->suggests, s);
}
slapt_free_list(suggests);
}
-int 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)
{
- unsigned int i, found = 1, not_found = 0;
-
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->install_pkgs->pkgs[i];
-
- if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
- return found;
+ slapt_pkg_list_t_foreach (install_pkg, tran->install_pkgs) {
+ if ((strcmp(pkg->name, install_pkg->name) == 0) && (strcmp(pkg->version, install_pkg->version) == 0))
+ return true;
}
- for (i = 0; i < tran->upgrade_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->upgrade_pkgs->pkgs[i]->upgrade;
+ slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_pkg_info_t *p = upgrade->upgrade;
if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
- return found;
+ return true;
}
- for (i = 0; i < tran->remove_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->remove_pkgs->pkgs[i];
-
- if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
- return found;
+ slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ if ((strcmp(pkg->name, remove_pkg->name) == 0) && (strcmp(pkg->version, remove_pkg->version) == 0))
+ return true;
}
- for (i = 0; i < tran->exclude_pkgs->pkg_count; ++i) {
- slapt_pkg_info_t *p = tran->exclude_pkgs->pkgs[i];
-
- if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
- return found;
+ slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
+ if ((strcmp(pkg->name, exclude_pkg->name) == 0) && (strcmp(pkg->version, exclude_pkg->version) == 0))
+ return true;
}
- return not_found;
+ return false;
}
static slapt_queue_t *slapt_queue_init(void)
@@ -970,9 +920,8 @@ static void queue_add_upgrade(slapt_queue_t *t, slapt_pkg_upgrade_t *p)
static void queue_free(slapt_queue_t *t)
{
- unsigned int i;
- for (i = 0; i < t->count; ++i) {
- free(t->pkgs[i]);
+ slapt_queue_t_foreach (i, t) {
+ free(i);
}
free(t->pkgs);
free(t);
@@ -980,8 +929,7 @@ static void queue_free(slapt_queue_t *t)
void slapt_generate_suggestions(slapt_transaction_t *tran)
{
- unsigned int i;
- for (i = 0; i < tran->install_pkgs->pkg_count; ++i) {
- add_suggestion(tran, tran->install_pkgs->pkgs[i]);
+ slapt_pkg_list_t_foreach (pkg, tran->install_pkgs) {
+ add_suggestion(tran, pkg);
}
}
diff --git a/src/transaction.h b/src/transaction.h
index b2455fa..1723cbd 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -27,13 +27,14 @@ typedef struct {
slapt_pkg_info_t *i;
slapt_pkg_upgrade_t *u;
} pkg;
- unsigned int type; /* this is enum slapt_action defined in main.h */
+ uint32_t type; /* this is enum slapt_action defined in main.h */
} slapt_queue_i;
typedef struct {
slapt_queue_i **pkgs;
- unsigned int count;
+ uint32_t count;
} slapt_queue_t;
+#define slapt_queue_t_foreach(item, list) slapt_queue_i *item; for (uint32_t item##_counter = 0; (item##_counter < list->count) && (item = list->pkgs[item##_counter]); item##_counter++)
typedef struct {
slapt_pkg_list_t *install_pkgs;
@@ -75,19 +76,19 @@ void slapt_add_exclude_to_transaction(slapt_transaction_t *,
slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg);
-/* search transaction by package name. returns 1 if found, 0 otherwise */
-int slapt_search_transaction(slapt_transaction_t *, char *pkg_name);
+/* 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 1 if found, 0 otherwise
+ returns true if found, false otherwise
*/
-int slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
+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 1 if found, 0 if not found
+ returns true if found, false if not found
*/
-int slapt_search_upgrade_transaction(slapt_transaction_t *tran,
+bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg);
/*
diff --git a/t/data/rc1 b/t/data/rc1
index df0a18c..d8a829b 100644
--- a/t/data/rc1
+++ b/t/data/rc1
@@ -1,3 +1,3 @@
WORKINGDIR=data/slapt-get
-EXCLUDE=^kernel-.*,^alsa-.*,.*-[0-9]+dl$,^devs$,^udev$,aaa_elflibs
+EXCLUDE=^kernel-.*,^alsa-.*,.*-[0-9]+dl$,^devs$,^udev$
SOURCE=http://software.jaos.org/slackpacks/13.37/
diff --git a/t/test_packages.c b/t/test_packages.c
index 3b86a65..087cf8e 100644
--- a/t/test_packages.c
+++ b/t/test_packages.c
@@ -59,7 +59,7 @@ START_TEST(test_pkg_info)
string = NULL;
slapt_add_list_item(rc->exclude_list, "^gslapt$");
- fail_if(slapt_is_excluded(rc, &pkg) == 0);
+ fail_if(!slapt_is_excluded(rc, &pkg));
slapt_remove_list_item(rc->exclude_list, "^gslapt$");
fail_unless(slapt_download_pkg(rc, &pkg, NULL) == 0);
@@ -296,7 +296,7 @@ END_TEST
START_TEST(test_dependency)
{
- unsigned int i = 0;
+ uint32_t i = 0;
FILE *fh = NULL;
slapt_pkg_info_t *p = NULL;
slapt_pkg_list_t *avail = NULL;
diff --git a/t/test_transaction.c b/t/test_transaction.c
index 698f330..1e0adaa 100644
--- a/t/test_transaction.c
+++ b/t/test_transaction.c
@@ -8,21 +8,21 @@ START_TEST(test_transaction)
slapt_add_install_to_transaction(t, &pkg);
fail_unless(t->install_pkgs->pkg_count == 1);
- fail_unless(slapt_search_transaction(t, "gslapt") == 1);
- fail_unless(slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ fail_unless(slapt_search_transaction(t, "gslapt"));
+ fail_unless(slapt_search_transaction_by_pkg(t, &pkg));
t = slapt_remove_from_transaction(t, &pkg);
slapt_add_remove_to_transaction(t, &pkg);
fail_unless(t->remove_pkgs->pkg_count == 1);
- fail_unless(slapt_search_transaction(t, "gslapt") == 1);
- fail_unless(slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ fail_unless(slapt_search_transaction(t, "gslapt"));
+ fail_unless(slapt_search_transaction_by_pkg(t, &pkg));
t = slapt_remove_from_transaction(t, &pkg);
slapt_add_exclude_to_transaction(t, &pkg);
fail_unless(t->exclude_pkgs->pkg_count == 1);
slapt_add_upgrade_to_transaction(t, &pkg, &pkg);
- /* fail_unless (slapt_search_upgrade_transaction(t, &pkg) == 1); */
+ /* fail_unless (slapt_search_upgrade_transaction(t, &pkg)); */
slapt_free_transaction(t);
}