summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format7
-rw-r--r--doc/libslapt.3174
-rw-r--r--src/action.c152
-rw-r--r--src/action.h4
-rw-r--r--src/common.c82
-rw-r--r--src/common.h16
-rw-r--r--src/configuration.c95
-rw-r--r--src/configuration.h19
-rw-r--r--src/main.c40
-rw-r--r--src/package.c535
-rw-r--r--src/package.h96
-rw-r--r--src/transaction.c515
-rw-r--r--src/transaction.h35
-rw-r--r--t/test_configuration.c48
-rw-r--r--t/test_curl.c3
-rw-r--r--t/test_packages.c148
-rw-r--r--t/test_transaction.c32
17 files changed, 673 insertions, 1328 deletions
diff --git a/.clang-format b/.clang-format
index 6a555de..7952c63 100644
--- a/.clang-format
+++ b/.clang-format
@@ -26,12 +26,7 @@ BraceWrapping:
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'
+'slapt_vector_t_foreach',
]
SpaceBeforeParens: ControlStatements
SpaceBeforeAssignmentOperators: true
diff --git a/doc/libslapt.3 b/doc/libslapt.3
index d772698..27a0667 100644
--- a/doc/libslapt.3
+++ b/doc/libslapt.3
@@ -11,13 +11,13 @@ slapt_rc_config *slapt_init_config(void);
/* parse config file for sources, excludes, and working_dir*/
slapt_rc_config *config = slapt_read_rc_config("/etc/slapt-get/slapt-getrc");
/* get a list of installed packages */
-slapt_pkg_list_t *installed = slapt_get_installed_pkgs();
+slapt_vector_t *installed = slapt_get_installed_pkgs();
/* parse the package data, normally using config->working_dir */
FILE *data_f = fopen("/var/cache/slapt-get/package_data","r");
-slapt_pkg_list_t *available = slapt_parse_packages_txt(data_f);
+slapt_vector_t *available = slapt_parse_packages_txt(data_f);
/* search for a package in a list via regex */
-slapt_pkg_list_t *results = slapt_search_pkg_list(installed,"[0-9]frg");
+slapt_vector_t *results = slapt_search_pkg_list(installed,"[0-9]frg");
slapt_free_pkg_list(results);
/* look for a specific package */
@@ -62,8 +62,8 @@ slapt-get stores the configuration information in a \fIslapt_rc_config\fP object
.nf
typedef struct {
char working_dir[WORKINGDIR_TOKEN_LEN];
- slapt_source_list_t *sources;
- slapt_list_t *exclude_list;
+ slapt_vector_t *sources;
+ slapt_vector_t *exclude_list;
int (*progress_cb) (void *,double,double,double,double);
bool download_only;
bool dist_upgrade;
@@ -117,21 +117,6 @@ Package sources are represented by the \fIslapt_source_t\fP type. They are crea
.fi
.sp
.TP
-The \fIslapt_source_list_t\fP stores the package sources. Sources can be added and removed with \fIslapt_add_source\fP() and \fIslapt_remove_source\fP(). Typically, \fIslapt_rc_config->sources\fP is passed as the first argument, but it could be any pointer to a \fIslapt_source_list_t\fP that is created by \fIslapt_init_source_list\fP().
-.sp
-.nf
- typedef struct {
- slapt_source_t **src;
- uint32_t count;
- } slapt_source_list_t;
-.sp
-.B "slapt_source_list_t *slapt_init_source_list(void);"
-.B "void slapt_add_source(slapt_source_list_t *list, slapt_source_t *s);"
-.B "void slapt_remove_source (slapt_source_list_t *list, const char *s);"
-.B "void slapt_free_source_list(slapt_source_list_t *list);"
-.fi
-.sp
-.TP
In order to initialize the slapt_rc_config->working_dir directory, \fIslapt_working_dir_init\fP() must be called. It is a fatal error to call \fIslapt_working_dir_init\fP() with a directory that the current process does not have privileges to read, write, and execute.
.sp
.B "void slapt_working_dir_init(const slapt_rc_config *global_config);"
@@ -170,55 +155,31 @@ The \fIslapt_pkg_info_t\fP object is created and freed with \fIslapt_init_pkg\fP
.fi
.sp
.TP
-Package lists are useful for grouping packages from the existing installed packages, packages available from external sources, a list of dependencies, and more. Package lists are stored within a \fIslapt_pkg_list_t\fP.
-.sp
-.nf
- typedef struct {
- slapt_pkg_info_t **pkgs;
- uint32_t pkg_count;
- bool free_pkgs;
- bool ordered;
- } slapt_pkg_list_t;
-.fi
-.sp
-.TP
-If \fIfree_pkgs\fP is set to TRUE, \fIslapt_free_pkg_list\fP will call \fIslapt_free_pkg\fP() for each \fIslapt_pkg_info_t\fP within the list. Leave this to the default of FALSE if the list is populated with pointers to \fIslapt_pkg_info_t\fP objects that are freed elsewhere.
-.sp
-.TP
-If \fIordered\fP is is set to TRUE, the list has been sorted by \fIqsort\fP().
-.sp
-.TP
-\fIslapt_pkg_info_t\fP objects are created by \fIslapt_init_pkg_list\fP() and freed by \fIslapt_free_pkg_list\fP(). \fIslapt_add_pkg_to_pkg_list\fP() is used to add a package to a list.
-.sp
-.nf
-.B "slapt_pkg_list_t *slapt_init_pkg_list(void);"
-.B "void slapt_free_pkg_list(slapt_pkg_list_t *);"
-.B "void slapt_add_pkg_to_pkg_list(slapt_pkg_list_t *list, slapt_pkg_info_t *pkg);"
-.fi
+Package lists are useful for grouping packages from the existing installed packages, packages available from external sources, a list of dependencies, and more. Package lists are stored within a \fIslapt_vector_t\fP.
.sp
.TP
Package lists can be parsed from PACKAGES.TXT or similar formated files (such as the working_dir/package_data file used by slapt-get) with \fIslapt_parse_packages_txt\fP(). A package list of the currently installed packages is returned by \fIslapt_get_installed_pkgs\fP(). \fIslapt_get_available_pkgs\fP() is a frontend to \fIslapt_parse_packages_txt\fP() looking for a package_data file in the current directory. All three of the following set \fIfree_pkgs\fP to TRUE.
.sp
.nf
-.B "slapt_pkg_list_t *slapt_parse_packages_txt(FILE *);"
-.B "slapt_pkg_list_t *slapt_get_available_pkgs(void);"
-.B "slapt_pkg_list_t *slapt_get_installed_pkgs(void);"
+.B "slapt_vector_t *slapt_parse_packages_txt(FILE *);"
+.B "slapt_vector_t *slapt_get_available_pkgs(void);"
+.B "slapt_vector_t *slapt_get_installed_pkgs(void);"
.fi
.sp
.TP
-Finding a specific package in a package list is done through one of the following functions. All return \fIslapt_pkg_info_t\fP, or NULL on error, except for \fIslapt_search_pkg_list\fP() which returns a list of packages as \fIslapt_pkg_list_t\fP.
+Finding a specific package in a package list is done through one of the following functions. All return \fIslapt_pkg_info_t\fP, or NULL on error, except for \fIslapt_search_pkg_list\fP() which returns a list of packages as \fIslapt_vector_t\fP.
.sp
.nf
-.B "slapt_pkg_info_t *slapt_get_newest_pkg(slapt_pkg_list_t *,"
+.B "slapt_pkg_info_t *slapt_get_newest_pkg(slapt_vector_t *,"
.B " const char *);"
-.B "slapt_pkg_info_t *slapt_get_exact_pkg(slapt_pkg_list_t *list,"
+.B "slapt_pkg_info_t *slapt_get_exact_pkg(slapt_vector_t *list,"
.B " const char *name,"
.B " const char *version);"
-.B "slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,"
+.B "slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_vector_t *list,"
.B " const char *name,"
.B " const char *version,"
.B " const char *location);"
-.B "slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,"
+.B "slapt_vector_t *slapt_search_pkg_list(slapt_vector_t *list,"
.B " const char *pattern);"
.fi
.sp
@@ -241,7 +202,7 @@ Comparing package versions is done with the \fIslapt_cmp_pkgs\fP functions. It
.fi
.sp
.TP
-The following functions deal with determining package dependencies and conflicts and returning them within a package list. Some require the use of a \fIslapt_pkg_err_list_t\fP of \fIslapt_pkg_err_t\fP objects for reporting errors on which packages failed or were missing. \fIslapt_search_pkg_err_list\fP() returns 0 if the package and error string combination does not already exist in the \fIslapt_pkg_err_list_t\fP, or 1 if found.
+The following functions deal with determining package dependencies and conflicts and returning them within a package list. Some require the use of a \fIslapt_vector_t\fP of \fIslapt_pkg_err_t\fP objects for reporting errors on which packages failed or were missing. \fIslapt_search_pkg_err_list\fP() returns 0 if the package and error string combination does not already exist in the \fIslapt_vector_t\fP, or 1 if found.
.sp
.nf
typedef struct {
@@ -249,63 +210,51 @@ The following functions deal with determining package dependencies and conflicts
char *error;
} slapt_pkg_err_t;
.sp
- typedef struct {
- slapt_pkg_err_t **errs;
- uint32_t err_count;
- } slapt_pkg_err_list_t;
-.sp
-.B "slapt_pkg_err_list_t *slapt_init_pkg_err_list(void);"
-.B "void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,"
-.B " const char *pkg,const char *err);"
-.B "int slapt_search_pkg_err_list(slapt_pkg_err_list_t *l, const char *pkg,"
-.B " const char *err);"
-.B "void slapt_free_pkg_err_list(slapt_pkg_err_list_t *l);"
-.sp
.fi
.TP
-\fIslapt_get_pkg_dependencies\fP() fills a \fIslapt_pkg_list_t\fP of dependencies for the specified package. These dependencies are pulled from the available package list and the installed package lists. Missing and conflict errors are placed in \fIslapt_pkg_err_list_t\fP. \fIdeps\fP, \fIconflict_err\fP, and \fImissing_err\fP are initialized if NULL. \fIslapt_get_pkg_dependencies\fP() returns 0 on success, or -1 on error.
+\fIslapt_get_pkg_dependencies\fP() fills a \fIslapt_vector_t\fP of dependencies for the specified package. These dependencies are pulled from the available package list and the installed package lists. Missing and conflict errors are placed in \fIslapt_vector_t\fP. \fIdeps\fP, \fIconflict_err\fP, and \fImissing_err\fP are initialized if NULL. \fIslapt_get_pkg_dependencies\fP() returns 0 on success, or -1 on error.
.sp
.nf
.B "int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
-.B " slapt_pkg_list_t *avail_pkgs,
-.B " slapt_pkg_list_t *installed_pkgs,
+.B " slapt_vector_t *avail_pkgs,
+.B " slapt_vector_t *installed_pkgs,
.B " slapt_pkg_info_t *pkg,
-.B " slapt_pkg_list_t *deps,
-.B " slapt_pkg_err_list_t *conflict_err,
-.B " slapt_pkg_err_list_t *missing_err);"
+.B " slapt_vector_t *deps,
+.B " slapt_vector_t *conflict_err,
+.B " slapt_vector_t *missing_err);"
.sp
.fi
.TP
-\fIslapt_get_pkg_conflicts\fP() returns a \fIslapt_pkg_list_t\fP of packages that conflict with the specified package.
+\fIslapt_get_pkg_conflicts\fP() returns a \fIslapt_vector_t\fP of packages that conflict with the specified package.
.sp
.nf
-.B "slapt_pkg_list_t *"
-.B "slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
-.B " slapt_pkg_list_t *installed_pkgs,
+.B "slapt_vector_t *"
+.B "slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs,
+.B " slapt_vector_t *installed_pkgs,
.B " slapt_pkg_info_t *pkg);"
.sp
.fi
.TP
-\fIslapt_is_required_by\fP() returns a \fIslapt_pkg_list_t\fP of packages that require the package specified.
+\fIslapt_is_required_by\fP() returns a \fIslapt_vector_t\fP of packages that require the package specified.
.sp
.nf
-.B "slapt_pkg_list_t *"
+.B "slapt_vector_t *"
.B "slapt_is_required_by(const slapt_rc_config *global_config,
-.B " slapt_pkg_list_t *avail,
-.B " slapt_pkg_list_t *installed_pkgs,
-.B " slapt_pkg_list_t *pkgs_to_install,
-.B " slapt_pkg_list_t *pkgs_to_remove,
+.B " slapt_vector_t *avail,
+.B " slapt_vector_t *installed_pkgs,
+.B " slapt_vector_t *pkgs_to_install,
+.B " slapt_vector_t *pkgs_to_remove,
.B " slapt_pkg_info_t *pkg);"
.sp
.fi
.TP
-\fIslapt_get_obsolete_pkgs\fP() returns a \fIslapt_pkg_list_t\fP of packages that are no longer available from the current package sources.
+\fIslapt_get_obsolete_pkgs\fP() returns a \fIslapt_vector_t\fP of packages that are no longer available from the current package sources.
.sp
.nf
-.B "slapt_pkg_list_t *"
+.B "slapt_vector_t *"
.B " slapt_get_obsolete_pkgs ( const slapt_rc_config *global_config,"
-.B " slapt_pkg_list_t *avail_pkgs,"
-.B " slapt_pkg_list_t *installed_pkgs);"
+.B " slapt_vector_t *avail_pkgs,"
+.B " slapt_vector_t *installed_pkgs);"
.B "
.sp
.fi
@@ -351,7 +300,7 @@ The \fIworking_dir\fP, defined within the \fIslapt_rc_config\fP object, caches t
.B "void slapt_clean_pkg_dir(const char *dir_name);"
.B "void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,"
.B " const char *dir_name,"
-.B " slapt_pkg_list_t *avail_pkgs);"
+.B " slapt_vector_t *avail_pkgs);"
.fi
.sp
.TP
@@ -389,10 +338,10 @@ Downloading packages and the package data from various sources is handled with t
The following functions download the PACKAGES.TXT, the patches/PACKAGES.TXT, CHECKSUMS.md5, and ChangeLog.txt. Each sets the compressed option if a compressed version was available and retrieved.
.sp
.nf
-.B "slapt_pkg_list_t *"
+.B "slapt_vector_t *"
.B "slapt_get_pkg_source_packages (const slapt_rc_config *global_config,"
.B " const char *url, bool *compressed);"
-.B "slapt_pkg_list_t *"
+.B "slapt_vector_t *"
.B "slapt_get_pkg_source_patches (const slapt_rc_config *global_config,"
.B " const char *url, bool *compressed);"
.B "FILE *slapt_get_pkg_source_checksums (const slapt_rc_config *global_config,"
@@ -430,31 +379,20 @@ Adding, removing, and upgrading packages can be wrapped in a \fIslapt_transactio
} slapt_queue_i;
.sp
typedef struct {
- slapt_queue_i **pkgs;
- uint32_t count;
- } slapt_queue_t;
-.sp
- typedef struct {
slapt_pkg_info_t *installed;
slapt_pkg_info_t *upgrade;
bool reinstall;
} slapt_pkg_upgrade_t;
.sp
typedef struct {
- slapt_pkg_upgrade_t **pkgs;
- uint32_t pkg_count;
- uint32_t reinstall_count;
- } slapt_pkg_upgrade_list_t;
-.sp
- typedef struct {
- slapt_pkg_list_t *install_pkgs;
- slapt_pkg_upgrade_list_t *upgrade_pkgs;
- slapt_pkg_list_t *remove_pkgs;
- slapt_pkg_list_t *exclude_pkgs;
- slapt_list_t *suggests;
- slapt_pkg_err_list_t *conflict_err;
- slapt_pkg_err_list_t *missing_err;
- slapt_queue_t *queue;
+ slapt_vector_t *install_pkgs;
+ slapt_vector_t *upgrade_pkgs;
+ slapt_vector_t *remove_pkgs;
+ slapt_vector_t *exclude_pkgs;
+ slapt_vector_t *suggests;
+ slapt_vector_t *conflict_err;
+ slapt_vector_t *missing_err;
+ slapt_vector_t *queue;
} slapt_transaction_t;
.sp
.B "slapt_transaction_t *slapt_init_transaction(void);"
@@ -490,13 +428,13 @@ Adding, removing, and upgrading packages can be wrapped in a \fIslapt_transactio
.sp
.B "int slapt_add_deps_to_trans(const slapt_rc_config *global_config,"
.B " slapt_transaction_t *tran,"
-.B " slapt_pkg_list_t *avail_pkgs,"
-.B " slapt_pkg_list_t *installed_pkgs,"
+.B " slapt_vector_t *avail_pkgs,"
+.B " slapt_vector_t *installed_pkgs,"
.B " slapt_pkg_info_t *pkg);"
.sp
.B "slapt_pkg_info_t *slapt_is_conflicted(slapt_transaction_t *tran,"
-.B " slapt_pkg_list_t *avail_pkgs,"
-.B " slapt_pkg_list_t *installed_pkgs,"
+.B " slapt_vector_t *avail_pkgs,"
+.B " slapt_vector_t *installed_pkgs,"
.B " slapt_pkg_info_t *pkg);"
.sp
.B "void slapt_generate_suggestions(slapt_transaction_t *tran);"
@@ -599,18 +537,6 @@ Miscellaneous functionality within libslapt.
.sp
.B bool slapt_disk_space_check (const char *path,double space_needed);
.sp
- typedef struct {
- char **items;
- uint32_t count;
- } slapt_list_t;
-.sp
-.B /* general list management */
-.B slapt_list_t *slapt_parse_delimited_list(char *line, char delim);
-.B slapt_list_t *slapt_init_list(void);
-.B void slapt_add_list_item(slapt_list_t *list,const char *item);
-.B void slapt_remove_list_item(slapt_list_t *list,const char *item);
-.B const char *slapt_search_list(slapt_list_t *list, const char *needle);
-.B void slapt_free_list(slapt_list_t *list);
.fi
.sp
.SH LINKING WITH LIBSLAPT
diff --git a/src/action.c b/src/action.c
index 780a5bf..46704a3 100644
--- a/src/action.c
+++ b/src/action.c
@@ -22,18 +22,18 @@ static int cmp_pkg_arch(const char *a, const char *b);
/* install pkg */
void slapt_pkg_action_install(const slapt_rc_config *global_config,
- const slapt_list_t *action_args)
+ const slapt_vector_t *action_args)
{
slapt_transaction_t *tran = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *avail_pkgs = NULL;
+ slapt_vector_t *installed_pkgs = NULL;
+ slapt_vector_t *avail_pkgs = NULL;
slapt_regex_t *pkg_regex = NULL;
printf(gettext("Reading Package Lists..."));
installed_pkgs = slapt_get_installed_pkgs();
avail_pkgs = slapt_get_available_pkgs();
- if (avail_pkgs == NULL || !avail_pkgs->pkg_count)
+ if (avail_pkgs == NULL || !avail_pkgs->size)
exit(EXIT_FAILURE);
printf(gettext("Done\n"));
@@ -44,7 +44,7 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
exit(EXIT_FAILURE);
}
- slapt_list_t_foreach (arg, action_args) {
+ slapt_vector_t_foreach (char *, arg, action_args) {
slapt_pkg_info_t *pkg = NULL;
slapt_pkg_info_t *installed_pkg = NULL;
@@ -80,30 +80,30 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
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);
+ slapt_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, pkg);
/* this comes first so we can pick up that we are installed the package when checking conflicts */
slapt_add_install_to_transaction(tran, pkg);
/* if there are conflicts, we schedule the conflicts for removal */
- if (conflicts->pkg_count && !global_config->ignore_dep) {
- slapt_pkg_list_t_foreach (conflict, conflicts) {
+ if (conflicts->size && !global_config->ignore_dep) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, conflict, conflicts) {
/* make sure to remove the conflict's dependencies as well */
- slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
+ slapt_vector_t *conflict_deps = slapt_is_required_by(global_config,
avail_pkgs, installed_pkgs,
tran->install_pkgs, tran->remove_pkgs,
conflict);
- slapt_pkg_list_t_foreach (conflict_dep, conflict_deps) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, conflict_dep, conflict_deps) {
if (slapt_get_exact_pkg(installed_pkgs, conflict_dep->name, conflict_dep->version) != NULL) {
slapt_add_remove_to_transaction(tran, conflict_dep);
}
}
- slapt_free_pkg_list(conflict_deps);
+ slapt_vector_t_free(conflict_deps);
slapt_add_remove_to_transaction(tran, conflict);
}
}
- slapt_free_pkg_list(conflicts);
+ slapt_vector_t_free(conflicts);
} else {
printf(gettext("Excluding %s, use --ignore-dep to override\n"),
@@ -119,21 +119,21 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
(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,
+ slapt_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs,
installed_pkgs, pkg);
- if (conflicts->pkg_count && !global_config->ignore_dep) {
- slapt_pkg_list_t_foreach (conflict, conflicts) {
+ if (conflicts->size && !global_config->ignore_dep) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, conflict, conflicts) {
/* make sure to remove the conflict's dependencies as well */
- slapt_pkg_list_t *conflict_deps = slapt_is_required_by(global_config,
+ slapt_vector_t *conflict_deps = slapt_is_required_by(global_config,
avail_pkgs, installed_pkgs,
tran->install_pkgs, tran->remove_pkgs,
conflict);
- slapt_pkg_list_t_foreach (conflict_dep, conflict_deps) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, conflict_dep, conflict_deps) {
if (slapt_get_exact_pkg(installed_pkgs, conflict_dep->name, conflict_dep->version) != NULL) {
slapt_add_remove_to_transaction(tran, conflict_dep);
}
}
- slapt_free_pkg_list(conflict_deps);
+ slapt_vector_t_free(conflict_deps);
slapt_add_remove_to_transaction(tran, conflict);
}
@@ -144,7 +144,7 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
else
slapt_add_upgrade_to_transaction(tran, installed_pkg, pkg);
- slapt_free_pkg_list(conflicts);
+ slapt_vector_t_free(conflicts);
} else {
printf(gettext("Excluding %s, use --ignore-dep to override\n"),
@@ -158,8 +158,8 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
}
}
- slapt_free_pkg_list(installed_pkgs);
- slapt_free_pkg_list(avail_pkgs);
+ slapt_vector_t_free(installed_pkgs);
+ slapt_vector_t_free(avail_pkgs);
slapt_free_regex(pkg_regex);
@@ -174,14 +174,14 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
/* list pkgs */
void slapt_pkg_action_list(const int show)
{
- slapt_pkg_list_t *pkgs = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_vector_t *pkgs = NULL;
+ slapt_vector_t *installed_pkgs = NULL;
pkgs = slapt_get_available_pkgs();
installed_pkgs = slapt_get_installed_pkgs();
if (show == LIST || show == AVAILABLE) {
- slapt_pkg_list_t_foreach (pkg, pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, pkgs) {
bool installed = false;
char *short_description = slapt_gen_short_pkg_description(pkg);
@@ -201,7 +201,7 @@ void slapt_pkg_action_list(const int show)
}
}
if (show == LIST || show == INSTALLED) {
- slapt_pkg_list_t_foreach (pkg, installed_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, installed_pkgs) {
char *short_description = NULL;
if (show == LIST) {
@@ -221,16 +221,16 @@ void slapt_pkg_action_list(const int show)
}
}
- slapt_free_pkg_list(pkgs);
- slapt_free_pkg_list(installed_pkgs);
+ slapt_vector_t_free(pkgs);
+ slapt_vector_t_free(installed_pkgs);
}
/* remove/uninstall pkg */
void slapt_pkg_action_remove(const slapt_rc_config *global_config,
- const slapt_list_t *action_args)
+ const slapt_vector_t *action_args)
{
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *avail_pkgs = NULL;
+ slapt_vector_t *installed_pkgs = NULL;
+ slapt_vector_t *avail_pkgs = NULL;
slapt_regex_t *pkg_regex = NULL;
slapt_transaction_t *tran = NULL;
@@ -244,8 +244,8 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
exit(EXIT_FAILURE);
}
- slapt_list_t_foreach (arg, action_args) {
- slapt_pkg_list_t *deps = NULL;
+ slapt_vector_t_foreach (char *, arg, action_args) {
+ slapt_vector_t *deps = NULL;
slapt_pkg_info_t *pkg = NULL;
/* Use regex to see if they specified a particular version */
@@ -279,21 +279,21 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
tran->install_pkgs, tran->remove_pkgs,
pkg);
- slapt_pkg_list_t_foreach (dep, deps) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, dep, deps) {
if (slapt_get_exact_pkg(installed_pkgs, dep->name, dep->version) != NULL) {
slapt_add_remove_to_transaction(tran, dep);
}
}
- slapt_free_pkg_list(deps);
+ slapt_vector_t_free(deps);
slapt_add_remove_to_transaction(tran, pkg);
}
if (global_config->remove_obsolete) {
- slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(global_config, avail_pkgs, installed_pkgs);
+ slapt_vector_t *obsolete = slapt_get_obsolete_pkgs(global_config, avail_pkgs, installed_pkgs);
- slapt_pkg_list_t_foreach (pkg, obsolete) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, obsolete) {
if (slapt_is_excluded(global_config, pkg)) {
slapt_add_exclude_to_transaction(tran, pkg);
} else {
@@ -301,11 +301,11 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
}
}
- slapt_free_pkg_list(obsolete);
+ slapt_vector_t_free(obsolete);
}
- slapt_free_pkg_list(installed_pkgs);
- slapt_free_pkg_list(avail_pkgs);
+ slapt_vector_t_free(installed_pkgs);
+ slapt_vector_t_free(avail_pkgs);
slapt_free_regex(pkg_regex);
if (slapt_handle_transaction(global_config, tran) != 0) {
@@ -318,9 +318,9 @@ 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)
{
- slapt_pkg_list_t *pkgs = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *matches = NULL, *i_matches = NULL;
+ slapt_vector_t *pkgs = NULL;
+ slapt_vector_t *installed_pkgs = NULL;
+ slapt_vector_t *matches = NULL, *i_matches = NULL;
/* read in pkg data */
pkgs = slapt_get_available_pkgs();
@@ -329,7 +329,7 @@ void slapt_pkg_action_search(const char *pattern)
matches = slapt_search_pkg_list(pkgs, pattern);
i_matches = slapt_search_pkg_list(installed_pkgs, pattern);
- slapt_pkg_list_t_foreach (pkg, matches) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, matches) {
char *short_description = slapt_gen_short_pkg_description(pkg);
printf("%s-%s [inst=%s]: %s\n",
@@ -342,7 +342,7 @@ void slapt_pkg_action_search(const char *pattern)
free(short_description);
}
- slapt_pkg_list_t_foreach (installed_pkg, i_matches) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, installed_pkg, i_matches) {
char *short_description = NULL;
if (slapt_get_exact_pkg(matches, installed_pkg->name, installed_pkg->version) != NULL) {
@@ -359,17 +359,17 @@ void slapt_pkg_action_search(const char *pattern)
free(short_description);
}
- slapt_free_pkg_list(matches);
- slapt_free_pkg_list(i_matches);
- slapt_free_pkg_list(pkgs);
- slapt_free_pkg_list(installed_pkgs);
+ slapt_vector_t_free(matches);
+ slapt_vector_t_free(i_matches);
+ slapt_vector_t_free(pkgs);
+ slapt_vector_t_free(installed_pkgs);
}
/* show the details for a specific package */
void slapt_pkg_action_show(const char *pkg_name)
{
- slapt_pkg_list_t *avail_pkgs = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_vector_t *avail_pkgs = NULL;
+ slapt_vector_t *installed_pkgs = NULL;
slapt_regex_t *pkg_regex = NULL;
bool installed = false;
slapt_pkg_info_t *pkg = NULL;
@@ -452,16 +452,16 @@ void slapt_pkg_action_show(const char *pkg_name)
exit(EXIT_FAILURE);
}
- slapt_free_pkg_list(avail_pkgs);
- slapt_free_pkg_list(installed_pkgs);
+ slapt_vector_t_free(avail_pkgs);
+ slapt_vector_t_free(installed_pkgs);
slapt_free_regex(pkg_regex);
}
/* upgrade all installed pkgs with available updates */
void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
{
- slapt_pkg_list_t *installed_pkgs = NULL;
- slapt_pkg_list_t *avail_pkgs = NULL;
+ slapt_vector_t *installed_pkgs = NULL;
+ slapt_vector_t *avail_pkgs = NULL;
slapt_transaction_t *tran = NULL;
printf(gettext("Reading Package Lists..."));
@@ -471,7 +471,7 @@ 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)
+ if (!avail_pkgs->size)
exit(EXIT_FAILURE);
printf(gettext("Done\n"));
@@ -481,7 +481,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
char *essential[] = {"aaa_base", "pkgtools", "glibc-solibs", "glibc", "aaa_elflibs", "xz", "sed", "tar", "gzip", NULL};
int epi = 0;
slapt_pkg_info_t *newest_slaptget = NULL;
- slapt_pkg_list_t *matches =
+ slapt_vector_t *matches =
slapt_search_pkg_list(avail_pkgs, SLAPT_SLACK_BASE_SET_REGEX);
/* make sure the essential packages are installed/upgraded first */
@@ -506,7 +506,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
}
/* loop through SLAPT_SLACK_BASE_SET_REGEX packages */
- slapt_pkg_list_t_foreach (pkg, matches) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, 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;
@@ -528,11 +528,11 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
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);
+ slapt_vector_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 */
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) {
+ if (!rc && !conflicts->size && !global_config->ignore_dep) {
slapt_add_install_to_transaction(tran, slapt_upgrade_pkg);
} else {
/* otherwise exclude */
@@ -541,7 +541,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
}
- slapt_free_pkg_list(conflicts);
+ slapt_vector_t_free(conflicts);
}
/* even if it's installed, check to see that the packages are different */
/* simply running a version comparison won't do it since sometimes the */
@@ -552,14 +552,14 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
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,
+ slapt_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs,
slapt_upgrade_pkg);
/* if all deps are added and there is no conflicts, add on */
if (
(slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
installed_pkgs, slapt_upgrade_pkg) == 0) &&
- (!conflicts->pkg_count && !global_config->ignore_dep)) {
+ (!conflicts->size && !global_config->ignore_dep)) {
slapt_add_upgrade_to_transaction(tran, installed_pkg,
slapt_upgrade_pkg);
} else {
@@ -569,18 +569,18 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
slapt_add_exclude_to_transaction(tran, slapt_upgrade_pkg);
}
- slapt_free_pkg_list(conflicts);
+ slapt_vector_t_free(conflicts);
}
}
}
- slapt_free_pkg_list(matches);
+ slapt_vector_t_free(matches);
/* remove obsolete packages if prompted to */
if (global_config->remove_obsolete) {
- slapt_pkg_list_t *obsolete = slapt_get_obsolete_pkgs(global_config, avail_pkgs, installed_pkgs);
+ slapt_vector_t *obsolete = slapt_get_obsolete_pkgs(global_config, avail_pkgs, installed_pkgs);
- slapt_pkg_list_t_foreach (obsolete_pkg, obsolete) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, obsolete_pkg, obsolete) {
if (slapt_is_excluded(global_config, obsolete_pkg)) {
slapt_add_exclude_to_transaction(tran, obsolete_pkg);
} else {
@@ -588,7 +588,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
}
}
- slapt_free_pkg_list(obsolete);
+ slapt_vector_t_free(obsolete);
} /* end if remove_obsolete */
@@ -602,7 +602,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
}
}
- slapt_pkg_list_t_foreach (installed_pkg, installed_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, installed_pkg, installed_pkgs) {
slapt_pkg_info_t *update_pkg = NULL;
slapt_pkg_info_t *newer_installed_pkg = NULL;
@@ -639,13 +639,13 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
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_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, update_pkg);
/* if all deps are added and there is no conflicts, add on */
if (
(slapt_add_deps_to_trans(global_config, tran, avail_pkgs,
installed_pkgs, update_pkg) == 0) &&
- (global_config->ignore_dep || !conflicts->pkg_count)) {
+ (global_config->ignore_dep || !conflicts->size)) {
if (cmp_r == 0)
slapt_add_reinstall_to_transaction(tran, installed_pkg, update_pkg);
else
@@ -658,7 +658,7 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
slapt_add_exclude_to_transaction(tran, update_pkg);
}
- slapt_free_pkg_list(conflicts);
+ slapt_vector_t_free(conflicts);
}
}
@@ -666,8 +666,8 @@ void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config)
} /* end for */
- slapt_free_pkg_list(installed_pkgs);
- slapt_free_pkg_list(avail_pkgs);
+ slapt_vector_t_free(installed_pkgs);
+ slapt_vector_t_free(avail_pkgs);
if (slapt_handle_transaction(global_config, tran) != 0) {
exit(EXIT_FAILURE);
@@ -718,7 +718,7 @@ void slapt_pkg_action_add_keys(const slapt_rc_config *global_config)
{
int rc = 0;
bool compressed = false;
- slapt_source_list_t_foreach (source, global_config->sources) {
+ slapt_vector_t_foreach (slapt_source_t *, source, global_config->sources) {
FILE *gpg_key = NULL;
const char *source_url = source->url;
printf(gettext("Retrieving GPG key [%s]..."), source_url);
@@ -747,7 +747,7 @@ void slapt_pkg_action_add_keys(const slapt_rc_config *global_config)
void slapt_pkg_action_filelist(const char *pkg_name)
{
slapt_regex_t *pkg_regex = NULL;
- slapt_pkg_list_t *installed_pkgs = NULL;
+ slapt_vector_t *installed_pkgs = NULL;
slapt_pkg_info_t *pkg = NULL;
char *filelist = NULL;
@@ -788,5 +788,5 @@ void slapt_pkg_action_filelist(const char *pkg_name)
free(filelist);
slapt_free_regex(pkg_regex);
- slapt_free_pkg_list(installed_pkgs);
+ slapt_vector_t_free(installed_pkgs);
}
diff --git a/src/action.h b/src/action.h
index 90f81fb..5033c6e 100644
--- a/src/action.h
+++ b/src/action.h
@@ -17,10 +17,10 @@
*/
void slapt_pkg_action_install(const slapt_rc_config *global_config,
- const slapt_list_t *action_args);
+ const slapt_vector_t *action_args);
void slapt_pkg_action_list(const int show);
void slapt_pkg_action_remove(const slapt_rc_config *global_config,
- const slapt_list_t *action_args);
+ const slapt_vector_t *action_args);
void slapt_pkg_action_search(const char *pattern);
void slapt_pkg_action_show(const char *pkg_name);
void slapt_pkg_action_upgrade_all(const slapt_rc_config *global_config);
diff --git a/src/common.c b/src/common.c
index b2b3d6b..1040556 100644
--- a/src/common.c
+++ b/src/common.c
@@ -395,84 +395,9 @@ bool slapt_disk_space_check(const char *path, double space_needed)
return true;
}
-slapt_list_t *slapt_init_list(void)
+slapt_vector_t *slapt_parse_delimited_list(char *line, char delim)
{
- slapt_list_t *list = slapt_malloc(sizeof *list);
- list->items = slapt_malloc(sizeof *list->items);
- list->count = 0;
-
- return list;
-}
-
-void slapt_add_list_item(slapt_list_t *list, const char *item)
-{
- char **realloc_tmp;
-
- realloc_tmp =
- realloc(list->items, sizeof *list->items * (list->count + 1));
-
- if (realloc_tmp == NULL)
- return;
-
- list->items = realloc_tmp;
- list->items[list->count] = strndup(item, strlen(item));
- list->items[list->count][strlen(item)] = '\0';
- ++list->count;
-}
-
-void slapt_remove_list_item(slapt_list_t *list, const char *item)
-{
- uint32_t i = 0;
- char *tmp = NULL;
-
- while (i < list->count) {
- if (strcmp(item, list->items[i]) == 0 && tmp == NULL) {
- tmp = list->items[i];
- }
- if (tmp != NULL && (i + 1 < list->count)) {
- list->items[i] = list->items[i + 1];
- }
- ++i;
- }
- if (tmp != NULL) {
- char **realloc_tmp;
- int count = list->count - 1;
- if (count < 1)
- count = 1;
-
- free(tmp);
-
- realloc_tmp = realloc(list->items, sizeof *list->items * count);
- if (realloc_tmp != NULL) {
- list->items = realloc_tmp;
- if (list->count > 0)
- --list->count;
- }
- }
-}
-
-const char *slapt_search_list(slapt_list_t *list, const char *needle)
-{
- slapt_list_t_foreach (i, list) {
- if (strcmp(i, needle) == 0)
- return i;
- }
-
- return NULL;
-}
-
-void slapt_free_list(slapt_list_t *list)
-{
- slapt_list_t_foreach (i, list) {
- free(i);
- }
- free(list->items);
- free(list);
-}
-
-slapt_list_t *slapt_parse_delimited_list(char *line, char delim)
-{
- slapt_list_t *list = slapt_init_list();
+ slapt_vector_t *list = slapt_vector_t_init(free);
int count = 0, position = 0, len = strlen(line);
while (isspace(line[position]) != 0)
@@ -496,8 +421,7 @@ slapt_list_t *slapt_parse_delimited_list(char *line, char delim)
ptr = strndup(start, start_len - end_len);
- slapt_add_list_item(list, ptr);
- free(ptr);
+ slapt_vector_t_add(list, ptr);
++count;
position += start_len - end_len;
diff --git a/src/common.h b/src/common.h
index eb3eb75..c119181 100644
--- a/src/common.h
+++ b/src/common.h
@@ -67,12 +67,6 @@ typedef struct {
int reg_return;
} slapt_regex_t;
-typedef struct {
- char **items;
- 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++)
-
typedef int (*slapt_vector_t_cmp)(const void *, const void *);
typedef int (*slapt_vector_t_qsort_cmp)(const void *, const void *);
@@ -119,12 +113,6 @@ const char *slapt_strerror(slapt_code_t code);
const char *slapt_priority_to_str(SLAPT_PRIORITY_T priority);
bool slapt_disk_space_check(const char *path, double space_needed);
-/* general list management */
-slapt_list_t *slapt_parse_delimited_list(char *line, char delim);
-slapt_list_t *slapt_init_list(void);
-void slapt_add_list_item(slapt_list_t *list, const char *item);
-void slapt_remove_list_item(slapt_list_t *list, const char *item);
-const char *slapt_search_list(slapt_list_t *list, const char *needle);
-void slapt_free_list(slapt_list_t *list);
-
+/* utils */
+slapt_vector_t *slapt_parse_delimited_list(char *line, char delim);
char *slapt_strip_whitespace(const char *s);
diff --git a/src/configuration.c b/src/configuration.c
index 0498791..99e632d 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -18,7 +18,7 @@
#include "main.h"
/* parse the exclude list */
-static slapt_list_t *parse_exclude(char *line);
+static slapt_vector_t *parse_exclude(char *line);
slapt_rc_config *slapt_init_config(void)
{
@@ -43,8 +43,8 @@ slapt_rc_config *slapt_init_config(void)
global_config->progress_cb = NULL;
global_config->gpgme_allow_unauth = false; /* even without GPGME */
- global_config->sources = slapt_init_source_list();
- global_config->exclude_list = slapt_init_list();
+ global_config->sources = slapt_vector_t_init((slapt_vector_t_free_function)slapt_free_source);
+ global_config->exclude_list = slapt_vector_t_init(free);
global_config->retry = 1;
@@ -80,7 +80,7 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
if (strlen(token_ptr) > strlen(SLAPT_SOURCE_TOKEN)) {
slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_SOURCE_TOKEN));
if (s != NULL) {
- slapt_add_source(global_config->sources, s);
+ slapt_vector_t_add(global_config->sources, s);
if (s->priority != SLAPT_PRIORITY_DEFAULT) {
global_config->use_priority = true;
}
@@ -94,7 +94,7 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
slapt_source_t *s = slapt_init_source(token_ptr + strlen(SLAPT_DISABLED_SOURCE_TOKEN));
if (s != NULL) {
s->disabled = true;
- slapt_add_source(global_config->sources, s);
+ slapt_vector_t_add(global_config->sources, s);
}
}
@@ -111,7 +111,7 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
} else if ((token_ptr = strstr(getline_buffer, SLAPT_EXCLUDE_TOKEN)) != NULL) {
/* exclude list */
- slapt_free_list(global_config->exclude_list);
+ slapt_vector_t_free(global_config->exclude_list);
global_config->exclude_list = parse_exclude(token_ptr);
}
}
@@ -126,7 +126,7 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
file_name);
return NULL;
}
- if (!global_config->sources->count) {
+ if (!global_config->sources->size) {
fprintf(stderr, gettext("SOURCE directive not set within %s.\n"), file_name);
return NULL;
}
@@ -176,12 +176,12 @@ void slapt_working_dir_init(const slapt_rc_config *global_config)
void slapt_free_rc_config(slapt_rc_config *global_config)
{
- slapt_free_list(global_config->exclude_list);
- slapt_free_source_list(global_config->sources);
+ slapt_vector_t_free(global_config->exclude_list);
+ slapt_vector_t_free(global_config->sources);
free(global_config);
}
-static slapt_list_t *parse_exclude(char *line)
+static slapt_vector_t *parse_exclude(char *line)
{
/* skip ahead past the = */
line = strchr(line, '=') + 1;
@@ -189,75 +189,6 @@ static slapt_list_t *parse_exclude(char *line)
return slapt_parse_delimited_list(line, ',');
}
-slapt_source_list_t *slapt_init_source_list(void)
-{
- slapt_source_list_t *list = slapt_malloc(sizeof *list);
- list->src = slapt_malloc(sizeof *list->src);
- list->count = 0;
-
- return list;
-}
-
-void slapt_add_source(slapt_source_list_t *list, slapt_source_t *s)
-{
- slapt_source_t **realloc_tmp;
-
- if (s == NULL)
- return;
-
- realloc_tmp = realloc(list->src, sizeof *list->src * (list->count + 1));
-
- if (realloc_tmp == NULL)
- return;
-
- list->src = realloc_tmp;
-
- list->src[list->count] = s;
- ++list->count;
-}
-
-void slapt_remove_source(slapt_source_list_t *list, const char *s)
-{
- slapt_source_t *src_to_discard = NULL;
- uint32_t i = 0;
-
- while (i < list->count) {
- if (strcmp(s, list->src[i]->url) == 0 && src_to_discard == NULL) {
- src_to_discard = list->src[i];
- }
- if (src_to_discard != NULL && (i + 1 < list->count)) {
- list->src[i] = list->src[i + 1];
- }
- ++i;
- }
-
- if (src_to_discard != NULL) {
- slapt_source_t **realloc_tmp;
- int count = list->count - 1;
-
- if (count < 1)
- count = 1;
-
- slapt_free_source(src_to_discard);
-
- realloc_tmp = realloc(list->src, sizeof *list->src * count);
- if (realloc_tmp != NULL) {
- list->src = realloc_tmp;
- if (list->count > 0)
- --list->count;
- }
- }
-}
-
-void slapt_free_source_list(slapt_source_list_t *list)
-{
- slapt_source_list_t_foreach (source, list) {
- slapt_free_source(source);
- }
- free(list->src);
- free(list);
-}
-
bool slapt_is_interactive(const slapt_rc_config *global_config)
{
bool interactive = global_config->progress_cb == NULL
@@ -390,8 +321,8 @@ 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);
- slapt_list_t_foreach (exclude, global_config->exclude_list) {
- if (i + 1 == global_config->exclude_list->count) {
+ slapt_vector_t_foreach (char *, exclude, global_config->exclude_list) {
+ if (i + 1 == global_config->exclude_list->size) {
fprintf(rc, "%s", exclude);
} else {
fprintf(rc, "%s,", exclude);
@@ -400,7 +331,7 @@ int slapt_write_rc_config(const slapt_rc_config *global_config, const char *loca
}
fprintf(rc, "\n");
- slapt_source_list_t_foreach (src, global_config->sources) {
+ slapt_vector_t_foreach (slapt_source_t *, src, global_config->sources) {
SLAPT_PRIORITY_T priority = src->priority;
const char *token = SLAPT_SOURCE_TOKEN;
diff --git a/src/configuration.h b/src/configuration.h
index 3809e16..b8d4477 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -30,15 +30,9 @@ typedef struct {
} slapt_source_t;
typedef struct {
- slapt_source_t **src;
- 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];
- slapt_source_list_t *sources;
- slapt_list_t *exclude_list;
+ slapt_vector_t *sources;
+ slapt_vector_t *exclude_list;
int (*progress_cb)(void *, double, double, double, double);
bool download_only;
bool dist_upgrade;
@@ -73,15 +67,6 @@ void slapt_working_dir_init(const slapt_rc_config *global_config);
slapt_source_t *slapt_init_source(const char *s);
void slapt_free_source(slapt_source_t *src);
-/*
- add or remove a package source url to the source list.
- commonly called with global_config->source_list
-*/
-slapt_source_list_t *slapt_init_source_list(void);
-void slapt_add_source(slapt_source_list_t *list, slapt_source_t *s);
-void slapt_remove_source(slapt_source_list_t *list, const char *s);
-void slapt_free_source_list(slapt_source_list_t *list);
-
bool slapt_is_interactive(const slapt_rc_config *);
int slapt_write_rc_config(const slapt_rc_config *global_config, const char *location);
diff --git a/src/main.c b/src/main.c
index 08c9107..cdee429 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,7 +26,7 @@ extern int optind, opterr, optopt;
int main(int argc, char *argv[])
{
slapt_rc_config *global_config, *initial_config; /* our config struct */
- slapt_list_t *paa;
+ slapt_vector_t *paa = NULL;
int c = 0;
enum slapt_action do_action = 0;
@@ -319,57 +319,47 @@ int main(int argc, char *argv[])
}
break;
case INSTALL:
- paa = slapt_init_list();
+ paa = slapt_vector_t_init(free);
while (optind < argc) {
- slapt_add_list_item(paa, argv[optind]);
+ slapt_vector_t_add(paa, strdup(argv[optind]));
++optind;
}
slapt_pkg_action_install(global_config, paa);
- slapt_free_list(paa);
+ slapt_vector_t_free(paa);
break;
case INSTALL_DISK_SET: {
- slapt_pkg_list_t *set_pkgs = slapt_init_pkg_list();
- slapt_pkg_list_t *avail_pkgs = slapt_get_available_pkgs();
+ paa = slapt_vector_t_init(NULL);
+ slapt_vector_t *avail_pkgs = slapt_get_available_pkgs();
while (optind < argc) {
- slapt_pkg_list_t *matches = NULL;
char *search = slapt_malloc(sizeof *search * (strlen(argv[optind]) + 3));
-
snprintf(search, strlen(argv[optind]) + 3, "/%s$", argv[optind]);
- matches = slapt_search_pkg_list(avail_pkgs, search);
+ slapt_vector_t *matches = slapt_search_pkg_list(avail_pkgs, search);
free(search);
- slapt_pkg_list_t_foreach (match, matches) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, match, matches) {
if (!slapt_is_excluded(global_config, match)) {
- slapt_add_pkg_to_pkg_list(set_pkgs, match);
+ slapt_vector_t_add(paa, match->name);
}
}
- slapt_free_pkg_list(matches);
+ slapt_vector_t_free(matches);
++optind;
}
- paa = slapt_init_list();
-
- slapt_pkg_list_t_foreach (set_pkg, set_pkgs) {
- slapt_add_list_item(paa, set_pkg->name);
- }
-
- slapt_free_pkg_list(set_pkgs);
- slapt_free_pkg_list(avail_pkgs);
-
slapt_pkg_action_install(global_config, paa);
- slapt_free_list(paa);
+ slapt_vector_t_free(paa);
+ slapt_vector_t_free(avail_pkgs);
} break;
case REMOVE:
- paa = slapt_init_list();
+ paa = slapt_vector_t_init(free);
while (optind < argc) {
- slapt_add_list_item(paa, argv[optind]);
+ slapt_vector_t_add(paa, strdup(argv[optind]));
++optind;
}
slapt_pkg_action_remove(global_config, paa);
- slapt_free_list(paa);
+ slapt_vector_t_free(paa);
break;
case SHOW:
while (optind < argc) {
diff --git a/src/package.c b/src/package.c
index 5d2c1be..a136b73 100644
--- a/src/package.c
+++ b/src/package.c
@@ -26,22 +26,22 @@ struct slapt_pkg_version_parts {
/* analyze the pkg version hunk by hunk */
static struct slapt_pkg_version_parts *break_down_pkg_version(const char *version);
/* parse the meta lines */
-static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
char *dep_entry);
/* called by slapt_is_required_by */
-static void required_by(slapt_pkg_list_t *avail,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_list_t *pkgs_to_install,
- slapt_pkg_list_t *pkgs_to_remove,
+static void required_by(slapt_vector_t *avail,
+ slapt_vector_t *installed_pkgs,
+ slapt_vector_t *pkgs_to_install,
+ slapt_vector_t *pkgs_to_remove,
slapt_pkg_info_t *pkg,
- slapt_pkg_list_t *required_by_list);
+ slapt_vector_t *required_by_list);
static char *escape_package_name(slapt_pkg_info_t *pkg);
/* free pkg_version_parts struct */
static void slapt_free_pkg_version_parts(struct slapt_pkg_version_parts *parts);
/* find dependency from "or" requirement */
-static slapt_pkg_info_t *find_or_requirement(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+static slapt_pkg_info_t *find_or_requirement(slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
char *required_str);
/* uncompress compressed package data */
static FILE *slapt_gunzip_file(const char *file_name, FILE *dest_file);
@@ -52,16 +52,16 @@ bool slapt_pkg_sign_is_unauthenticated(slapt_code_t code);
#endif
/* parse the PACKAGES.TXT file */
-slapt_pkg_list_t *slapt_get_available_pkgs(void)
+slapt_vector_t *slapt_get_available_pkgs(void)
{
FILE *pkg_list_fh;
- slapt_pkg_list_t *list = NULL;
+ slapt_vector_t *list = NULL;
/* open pkg list */
pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L, "r");
if (pkg_list_fh == NULL) {
fprintf(stderr, gettext("Perhaps you want to run --update?\n"));
- list = slapt_init_pkg_list();
+ list = slapt_vector_t_init(NULL);
return list; /* return an empty list */
}
list = slapt_parse_packages_txt(pkg_list_fh);
@@ -70,14 +70,14 @@ slapt_pkg_list_t *slapt_get_available_pkgs(void)
/* 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]), slapt_pkg_info_t_qsort_cmp);
+ qsort(list->items, list->size, sizeof(list->items[0]), slapt_pkg_info_t_qsort_cmp);
- list->ordered = true;
+ list->sorted = true;
return list;
}
-slapt_pkg_list_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
+slapt_vector_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
{
slapt_regex_t *name_regex = NULL,
*mirror_regex = NULL,
@@ -86,13 +86,13 @@ slapt_pkg_list_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
*size_c_regex = NULL,
*size_u_regex = NULL;
ssize_t bytes_read;
- slapt_pkg_list_t *list = NULL;
+ slapt_vector_t *list = NULL;
long f_pos = 0;
size_t getline_len = 0;
char *getline_buffer = NULL;
char *char_pointer = NULL;
- list = slapt_init_pkg_list();
+ list = slapt_vector_t_init((slapt_vector_t_free_function)slapt_free_pkg);
/* compile our regexen */
if ((name_regex = slapt_init_regex(SLAPT_PKG_NAME_PATTERN)) == NULL) {
@@ -417,7 +417,7 @@ slapt_pkg_list_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
tmp_pkg->mirror[0] = '\0';
}
- slapt_add_pkg_to_pkg_list(list, tmp_pkg);
+ slapt_vector_t_add(list, tmp_pkg);
tmp_pkg = NULL;
}
@@ -431,7 +431,6 @@ slapt_pkg_list_t *slapt_parse_packages_txt(FILE *pkg_list_fh)
slapt_free_regex(size_c_regex);
slapt_free_regex(size_u_regex);
- list->free_pkgs = true;
return list;
}
@@ -456,7 +455,7 @@ char *slapt_gen_short_pkg_description(slapt_pkg_info_t *pkg)
return short_description;
}
-slapt_pkg_list_t *slapt_get_installed_pkgs(void)
+slapt_vector_t *slapt_get_installed_pkgs(void)
{
DIR *pkg_log_dir;
char *pkg_log_dirname = NULL;
@@ -464,10 +463,10 @@ slapt_pkg_list_t *slapt_get_installed_pkgs(void)
slapt_regex_t *ip_regex = NULL,
*compressed_size_reg = NULL,
*uncompressed_size_reg = NULL;
- slapt_pkg_list_t *list = NULL;
+ slapt_vector_t *list = NULL;
size_t pls = 1;
- list = slapt_init_pkg_list();
+ list = slapt_vector_t_init((slapt_vector_t_free_function)slapt_free_pkg);
if ((ip_regex = slapt_init_regex(SLAPT_PKG_LOG_PATTERN)) == NULL) {
exit(EXIT_FAILURE);
@@ -653,7 +652,7 @@ slapt_pkg_list_t *slapt_get_installed_pkgs(void)
/* mark as installed */
tmp_pkg->installed = true;
- slapt_add_pkg_to_pkg_list(list, tmp_pkg);
+ slapt_vector_t_add(list, tmp_pkg);
tmp_pkg = NULL;
} /* end while */
@@ -663,69 +662,48 @@ slapt_pkg_list_t *slapt_get_installed_pkgs(void)
slapt_free_regex(compressed_size_reg);
slapt_free_regex(uncompressed_size_reg);
- list->free_pkgs = true;
-
- qsort(list->pkgs, list->pkg_count, sizeof(list->pkgs[0]), slapt_pkg_info_t_qsort_cmp);
-
- list->ordered = true;
+ qsort(list->items, list->size, sizeof(list->items[0]), slapt_pkg_info_t_qsort_cmp);
return list;
}
+/*
+static int by_name(const void *pkg, const void *name){
+ slapt_pkg_info_t *p = *(slapt_pkg_info_t **)pkg;
+ char *cname = *(char **)name;
+ return strcmp(p->name, cname);
+}
+*/
+static int by_details(const void *a, const void *b) {
+ return slapt_pkg_info_t_qsort_cmp(&a, &b);
+}
+
/* lookup newest package from pkg_list */
-slapt_pkg_info_t *slapt_get_newest_pkg(slapt_pkg_list_t *pkg_list,
- const char *pkg_name)
+slapt_pkg_info_t *slapt_get_newest_pkg(slapt_vector_t *pkg_list, const char *pkg_name)
{
slapt_pkg_info_t *found = NULL;
- slapt_pkg_list_t_foreach (pkg, pkg_list) {
+ slapt_vector_t *matches = slapt_vector_t_search(pkg_list, by_details, &(slapt_pkg_info_t){.name=(char *)pkg_name});
+ if (!matches) {
+ return found;
+ }
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, matches) {
if (strcmp(pkg->name, pkg_name) != 0)
continue;
if ((found == NULL) || (slapt_cmp_pkgs(found, pkg) < 0))
found = pkg;
}
+ slapt_vector_t_free(matches);
return found;
}
-slapt_pkg_info_t *slapt_get_exact_pkg(slapt_pkg_list_t *list,
+slapt_pkg_info_t *slapt_get_exact_pkg(slapt_vector_t *list,
const char *name,
const char *version)
{
- if (list->ordered) {
- int min = 0, max = list->pkg_count - 1;
-
- while (max >= min) {
- int pivot = (min + max) / 2;
- int name_cmp = strcmp(list->pkgs[pivot]->name, name);
-
- if (name_cmp == 0) {
- int version_cmp = strverscmp(list->pkgs[pivot]->version, version);
-
- if (version_cmp == 0) {
- return list->pkgs[pivot];
-
- } else {
- if (version_cmp < 0)
- min = pivot + 1;
- else
- max = pivot - 1;
- }
-
- } else {
- if (name_cmp < 0)
- min = pivot + 1;
- else
- max = pivot - 1;
- }
- }
-
- } else {
- slapt_pkg_list_t_foreach (pkg, list) {
- if ((strcmp(name, pkg->name) == 0) && (strcmp(version, pkg->version) == 0)) {
- return pkg;
- }
- }
+ int idx = slapt_vector_t_index_of(list, by_details, &(slapt_pkg_info_t){.name=(char *)name, .version=(char *)version});
+ if (idx > -1) {
+ return list->items[idx];
}
-
return NULL;
}
@@ -845,17 +823,6 @@ void slapt_free_pkg(slapt_pkg_info_t *pkg)
free(pkg);
}
-void slapt_free_pkg_list(slapt_pkg_list_t *list)
-{
- if (list->free_pkgs) {
- slapt_pkg_list_t_foreach (pkg, list) {
- slapt_free_pkg(pkg);
- }
- }
- free(list->pkgs);
- free(list);
-}
-
bool slapt_is_excluded(const slapt_rc_config *global_config,
slapt_pkg_info_t *pkg)
{
@@ -865,10 +832,10 @@ bool slapt_is_excluded(const slapt_rc_config *global_config,
return false;
/* maybe EXCLUDE= isn't defined in our rc? */
- if (!global_config->exclude_list->count)
+ if (!global_config->exclude_list->size)
return false;
- slapt_list_t_foreach (exclude, global_config->exclude_list) {
+ slapt_vector_t_foreach (char *, exclude, global_config->exclude_list) {
slapt_regex_t *exclude_reg = NULL;
/* return if its an exact match */
@@ -902,7 +869,7 @@ bool slapt_is_excluded(const slapt_rc_config *global_config,
return false;
}
-void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file)
+void slapt_get_md5sums(slapt_vector_t *pkgs, FILE *checksum_file)
{
slapt_regex_t *md5sum_regex = NULL;
ssize_t getline_read;
@@ -940,7 +907,7 @@ 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 */
- slapt_pkg_list_t_foreach (pkg, pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, pkgs) {
if (
(strcmp(pkg->name, name) == 0) &&
(slapt_cmp_pkg_versions(pkg->version, version) == 0) &&
@@ -1187,9 +1154,9 @@ 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)
+ slapt_vector_t *pkgs)
{
- slapt_pkg_list_t_foreach (pkg, pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, pkgs) {
fprintf(d_file, "PACKAGE NAME: %s-%s%s\n", pkg->name, pkg->version, pkg->file_ext);
if (pkg->mirror != NULL && strlen(pkg->mirror) > 0) {
fprintf(d_file, "PACKAGE MIRROR: %s\n", pkg->mirror);
@@ -1225,21 +1192,21 @@ 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,
+slapt_vector_t *slapt_search_pkg_list(slapt_vector_t *list,
const char *pattern)
{
int name_r = -1, desc_r = -1, loc_r = -1, version_r = -1;
slapt_regex_t *search_regex = NULL;
- slapt_pkg_list_t *matches = NULL;
+ slapt_vector_t *matches = NULL;
- matches = slapt_init_pkg_list();
+ matches = slapt_vector_t_init(NULL);
if ((search_regex = slapt_init_regex(pattern)) == NULL)
return matches;
- slapt_pkg_list_t_foreach (pkg, list) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, list) {
if (strcmp(pkg->name, pattern) == 0) {
- slapt_add_pkg_to_pkg_list(matches, pkg);
+ slapt_vector_t_add(matches, pkg);
continue;
}
@@ -1261,7 +1228,7 @@ slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,
/* 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, pkg);
+ slapt_vector_t_add(matches, pkg);
}
}
slapt_free_regex(search_regex);
@@ -1271,13 +1238,13 @@ slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,
/* lookup dependencies for pkg */
int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs, slapt_pkg_info_t *pkg,
- slapt_pkg_list_t *deps,
- slapt_pkg_err_list_t *conflict_err,
- slapt_pkg_err_list_t *missing_err)
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs, slapt_pkg_info_t *pkg,
+ slapt_vector_t *deps,
+ slapt_vector_t *conflict_err,
+ slapt_vector_t *missing_err)
{
- slapt_list_t *dep_parts = NULL;
+ slapt_vector_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 ||
@@ -1287,17 +1254,17 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
return 0;
if (deps == NULL)
- deps = slapt_init_pkg_list();
+ deps = slapt_vector_t_init(NULL);
if (conflict_err == NULL)
- conflict_err = slapt_init_pkg_err_list();
+ conflict_err = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_err_t_free);
if (missing_err == NULL)
- missing_err = slapt_init_pkg_err_list();
+ missing_err = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_err_t_free);
/* parse dep line */
dep_parts = slapt_parse_delimited_list(pkg->required, ',');
- slapt_list_t_foreach (part, dep_parts) {
+ slapt_vector_t_foreach (char *, part, dep_parts) {
slapt_pkg_info_t *tmp_pkg = NULL;
if (strchr(part, '|') != NULL) {
@@ -1308,16 +1275,18 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
if (tmp_pkg == NULL) {
/* if we can't find a required dep, return -1 */
- slapt_add_pkg_err_to_list(missing_err, pkg->name, part);
- slapt_free_list(dep_parts);
+ slapt_pkg_err_t *err = slapt_pkg_err_t_init(strdup(pkg->name), strdup(part));
+ slapt_vector_t_add(missing_err, err);
+ slapt_vector_t_free(dep_parts);
return -1;
}
/* if this pkg is excluded */
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);
+ slapt_pkg_err_t *err = slapt_pkg_err_t_init(strdup(pkg->name), strdup(tmp_pkg->name));
+ slapt_vector_t_add(conflict_err, err);
+ slapt_vector_t_free(dep_parts);
return -1;
}
}
@@ -1327,7 +1296,7 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
int dep_check_return;
/* add tmp_pkg to deps so that we don't needlessly recurse */
- slapt_add_pkg_to_pkg_list(deps, tmp_pkg);
+ slapt_vector_t_add(deps, tmp_pkg);
/* now check to see if tmp_pkg has dependencies */
dep_check_return = slapt_get_pkg_dependencies(
@@ -1335,50 +1304,32 @@ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
deps, conflict_err, missing_err);
if (dep_check_return == -1 && !global_config->ignore_dep) {
- slapt_free_list(dep_parts);
+ slapt_vector_t_free(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;
-
- 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 && (dep_idx + 1 < deps->pkg_count))
- deps->pkgs[dep_idx] = deps->pkgs[dep_idx + 1];
-
- ++dep_idx;
- }
-
- /*
- 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;
+ slapt_vector_t_remove(deps, tmp_pkg);
+ slapt_vector_t_add(deps, tmp_pkg);
}
} /* end already exists in dep check */
}
- slapt_free_list(dep_parts);
+ slapt_vector_t_free(dep_parts);
return 0;
}
/* lookup conflicts for package */
-slapt_pkg_list_t *slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_list_t *conflicts = NULL;
+ slapt_vector_t *conflicts = NULL;
int position = 0, len = 0;
char *pointer = NULL;
char *buffer = NULL;
- conflicts = slapt_init_pkg_list();
+ conflicts = slapt_vector_t_init(NULL);
/* don't go any further if the required member is empty */
if (strcmp(pkg->conflicts, "") == 0 ||
@@ -1420,7 +1371,7 @@ slapt_pkg_list_t *slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
}
if (tmp_pkg != NULL) {
- slapt_add_pkg_to_pkg_list(conflicts, tmp_pkg);
+ slapt_vector_t_add(conflicts, tmp_pkg);
}
} /* end while */
@@ -1428,8 +1379,8 @@ slapt_pkg_list_t *slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
return conflicts;
}
-static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+static slapt_pkg_info_t *parse_meta_entry(slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
char *dep_entry)
{
slapt_regex_t *parse_dep_regex = NULL;
@@ -1521,7 +1472,7 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
}
}
- slapt_pkg_list_t_foreach (installed_pkg, installed_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, installed_pkg, installed_pkgs) {
if (strcmp(tmp_pkg_name, installed_pkg->name) != 0)
continue;
@@ -1585,7 +1536,7 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
}
/* loop through avail_pkgs */
- slapt_pkg_list_t_foreach (avail_pkg, avail_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, avail_pkg, avail_pkgs) {
if (strcmp(tmp_pkg_name, avail_pkg->name) != 0)
continue;
@@ -1622,14 +1573,14 @@ static slapt_pkg_info_t *parse_meta_entry(slapt_pkg_list_t *avail_pkgs,
return NULL;
}
-slapt_pkg_list_t *slapt_is_required_by(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_list_t *pkgs_to_install,
- slapt_pkg_list_t *pkgs_to_remove,
+slapt_vector_t *slapt_is_required_by(const slapt_rc_config *global_config,
+ slapt_vector_t *avail,
+ slapt_vector_t *installed_pkgs,
+ slapt_vector_t *pkgs_to_install,
+ slapt_vector_t *pkgs_to_remove,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_list_t *required_by_list = slapt_init_pkg_list();
+ slapt_vector_t *required_by_list = slapt_vector_t_init(NULL);
/* don't go any further if disable_dep_check is set */
if (global_config->disable_dep_check)
@@ -1669,12 +1620,12 @@ static char *escape_package_name(slapt_pkg_info_t *pkg)
return escaped_name;
}
-static void required_by(slapt_pkg_list_t *avail,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_list_t *pkgs_to_install,
- slapt_pkg_list_t *pkgs_to_remove,
+static void required_by(slapt_vector_t *avail,
+ slapt_vector_t *installed_pkgs,
+ slapt_vector_t *pkgs_to_install,
+ slapt_vector_t *pkgs_to_remove,
slapt_pkg_info_t *pkg,
- slapt_pkg_list_t *required_by_list)
+ slapt_vector_t *required_by_list)
{
slapt_regex_t *required_by_reg = NULL;
char *pkg_name = escape_package_name(pkg);
@@ -1696,8 +1647,8 @@ static void required_by(slapt_pkg_list_t *avail,
free(pkg_name);
free(reg);
- slapt_pkg_list_t_foreach (avail_pkg, avail) {
- slapt_list_t *dep_list = NULL;
+ slapt_vector_t_foreach (slapt_pkg_info_t *, avail_pkg, avail) {
+ slapt_vector_t *dep_list = NULL;
if (strcmp(avail_pkg->required, "") == 0)
continue;
@@ -1714,8 +1665,8 @@ static void required_by(slapt_pkg_list_t *avail,
/* check for the offending dependency entry and see if we have an alternative */
dep_list = slapt_parse_delimited_list(avail_pkg->required, ',');
- slapt_list_t_foreach (part, dep_list) {
- slapt_list_t *satisfies = NULL;
+ slapt_vector_t_foreach (char *, part, dep_list) {
+ slapt_vector_t *satisfies = NULL;
bool has_alternative = false, found = false;
/* found our package in the list of dependencies */
@@ -1727,7 +1678,7 @@ static void required_by(slapt_pkg_list_t *avail,
if (strcmp(part, pkg->name) != 0)
continue;
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);
+ slapt_vector_t_add(required_by_list, avail_pkg);
required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, avail_pkg, required_by_list);
}
break;
@@ -1735,7 +1686,7 @@ static void required_by(slapt_pkg_list_t *avail,
/* we need to find out if we have something else that satisfies the dependency */
satisfies = slapt_parse_delimited_list(part, '|');
- slapt_list_t_foreach (satisfies_part, satisfies) {
+ slapt_vector_t_foreach (char *, satisfies_part, satisfies) {
slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail, installed_pkgs, satisfies_part);
if (tmp_pkg == NULL)
continue;
@@ -1755,83 +1706,31 @@ static void required_by(slapt_pkg_list_t *avail,
break;
}
}
- slapt_free_list(satisfies);
+ slapt_vector_t_free(satisfies);
/* we couldn't find an installed pkg that satisfies the |or */
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);
+ slapt_vector_t_add(required_by_list, avail_pkg);
required_by(avail, installed_pkgs, pkgs_to_install, pkgs_to_remove, avail_pkg, required_by_list);
}
}
}
- slapt_free_list(dep_list);
+ slapt_vector_t_free(dep_list);
}
slapt_free_regex(required_by_reg);
}
-slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
+slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_vector_t *list,
const char *name,
const char *version,
const char *location)
{
- if (list->ordered) {
- int min = 0, max = list->pkg_count - 1;
-
- while (max >= min) {
- int pivot = (min + max) / 2;
- int name_cmp = strcmp(list->pkgs[pivot]->name, name);
-
- if (name_cmp == 0) {
- int version_cmp = strverscmp(list->pkgs[pivot]->version, version);
-
- if (version_cmp == 0) {
- int location_cmp = strcmp(list->pkgs[pivot]->location, location);
-
- if (location_cmp == 0) {
- return list->pkgs[pivot];
-
- } else {
- if (location_cmp < 0)
- min = pivot + 1;
- else
- max = pivot - 1;
- }
-
- } else {
- if (version_cmp < 0)
- min = pivot + 1;
- else
- max = pivot - 1;
- }
-
- } else {
- if (name_cmp < 0)
- min = pivot + 1;
- else
- max = pivot - 1;
- }
- }
-
- } else {
- slapt_pkg_list_t_foreach (pkg, list) {
- if (strcmp(pkg->name, name) == 0) {
- if (version != NULL) {
- if (strcmp(pkg->version, version) == 0) {
- if (location != NULL) {
- if (strcmp(pkg->location, location) == 0) {
- return pkg;
- }
- } else {
- return pkg;
- }
- }
- }
- }
- }
+ int idx = slapt_vector_t_index_of(list, by_details, &(slapt_pkg_info_t){.name=(char *)name, .version=(char *)version, .location=(char *)location});
+ if (idx > -1) {
+ return list->items[idx];
}
-
return NULL;
}
@@ -1839,14 +1738,13 @@ slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
int slapt_update_pkg_cache(const slapt_rc_config *global_config)
{
bool source_dl_failed = false;
- slapt_pkg_list_t *new_pkgs = slapt_init_pkg_list();
- new_pkgs->free_pkgs = true;
+ slapt_vector_t *new_pkgs = slapt_vector_t_init((slapt_vector_t_free_function)slapt_free_pkg);
/* go through each package source and download the meta data */
- slapt_source_list_t_foreach (source, global_config->sources) {
+ slapt_vector_t_foreach (slapt_source_t *, source, global_config->sources) {
bool compressed = false;
- slapt_pkg_list_t *available_pkgs = NULL;
- slapt_pkg_list_t *patch_pkgs = NULL;
+ slapt_vector_t *available_pkgs = NULL;
+ slapt_vector_t *patch_pkgs = NULL;
FILE *tmp_checksum_f = NULL;
#ifdef SLAPT_HAS_GPGME
FILE *tmp_signature_f = NULL;
@@ -1930,7 +1828,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
slapt_get_md5sums(available_pkgs, tmp_checksum_f);
- slapt_pkg_list_t_foreach (p, available_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, p, available_pkgs) {
int mirror_len = -1;
/* honor the mirror if it was set in the PACKAGES.TXT */
@@ -1944,13 +1842,13 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
/* set the priority of the package based on the source */
p->priority = source_priority;
- slapt_add_pkg_to_pkg_list(new_pkgs, p);
+ slapt_vector_t_add(new_pkgs, p);
}
- available_pkgs->free_pkgs = false;
+ available_pkgs->free_function = NULL;
if (patch_pkgs) {
slapt_get_md5sums(patch_pkgs, tmp_checksum_f);
- slapt_pkg_list_t_foreach (patch_pkg, patch_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, patch_pkg, patch_pkgs) {
int mirror_len = -1;
/* honor the mirror if it was set in the PACKAGES.TXT */
@@ -1967,9 +1865,9 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
else
patch_pkg->priority = source_priority;
- slapt_add_pkg_to_pkg_list(new_pkgs, patch_pkg);
+ slapt_vector_t_add(new_pkgs, patch_pkg);
}
- patch_pkgs->free_pkgs = false;
+ patch_pkgs->free_function = NULL;
}
printf(gettext("Done\n"));
@@ -1980,10 +1878,10 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
}
if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ slapt_vector_t_free(available_pkgs);
if (patch_pkgs)
- slapt_free_pkg_list(patch_pkgs);
+ slapt_vector_t_free(patch_pkgs);
} /* end for loop */
@@ -1994,7 +1892,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
if ((pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L, "w+")) == NULL)
exit(EXIT_FAILURE);
- qsort(new_pkgs->pkgs, new_pkgs->pkg_count, sizeof(new_pkgs->pkgs[0]), slapt_pkg_info_t_qsort_cmp);
+ qsort(new_pkgs->items, new_pkgs->size, sizeof(new_pkgs->items[0]), slapt_pkg_info_t_qsort_cmp);
slapt_write_pkg_data(NULL, pkg_list_fh, new_pkgs);
@@ -2004,7 +1902,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
printf(gettext("Sources failed to download, correct sources and rerun --update\n"));
}
- slapt_free_pkg_list(new_pkgs);
+ slapt_vector_t_free(new_pkgs);
return source_dl_failed;
}
@@ -2028,37 +1926,6 @@ bool slapt_pkg_sign_is_unauthenticated(slapt_code_t code)
}
#endif
-slapt_pkg_list_t *slapt_init_pkg_list(void)
-{
- slapt_pkg_list_t *list = NULL;
-
- list = slapt_malloc(sizeof *list);
- list->pkgs = slapt_malloc(sizeof *list->pkgs);
- list->pkg_count = 0;
- list->free_pkgs = false;
- list->ordered = false;
-
- return list;
-}
-
-void slapt_add_pkg_to_pkg_list(slapt_pkg_list_t *list,
- slapt_pkg_info_t *pkg)
-{
- slapt_pkg_info_t **realloc_tmp;
-
- /* grow our struct array */
- realloc_tmp = realloc(list->pkgs,
- sizeof *list->pkgs * (list->pkg_count + 1));
- if (realloc_tmp == NULL) {
- fprintf(stderr, gettext("Failed to realloc %s\n"), "pkgs");
- exit(EXIT_FAILURE);
- }
-
- list->pkgs = realloc_tmp;
- list->pkgs[list->pkg_count] = pkg;
- ++list->pkg_count;
-}
-
slapt_pkg_info_t *slapt_init_pkg(void)
{
slapt_pkg_info_t *pkg;
@@ -2235,7 +2102,7 @@ char *slapt_gen_filename_from_url(const char *url, const char *file)
void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
const char *dir_name,
- slapt_pkg_list_t *avail_pkgs)
+ slapt_vector_t *avail_pkgs)
{
DIR *dir;
struct dirent *file;
@@ -2323,7 +2190,7 @@ void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
slapt_free_regex(cached_pkgs_regex);
if (local_pkg_list == 1) {
- slapt_free_pkg_list(avail_pkgs);
+ slapt_vector_t_free(avail_pkgs);
}
}
@@ -2381,14 +2248,14 @@ void slapt_clean_pkg_dir(const char *dir_name)
}
/* find dependency from "or" requirement */
-static slapt_pkg_info_t *find_or_requirement(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+static slapt_pkg_info_t *find_or_requirement(slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
char *required_str)
{
slapt_pkg_info_t *pkg = NULL;
- slapt_list_t *alternates = slapt_parse_delimited_list(required_str, '|');
+ slapt_vector_t *alternates = slapt_parse_delimited_list(required_str, '|');
- slapt_list_t_foreach (alternate, alternates) {
+ slapt_vector_t_foreach (char *, alternate, alternates) {
slapt_pkg_info_t *tmp_pkg = parse_meta_entry(avail_pkgs, installed_pkgs, alternate);
if (tmp_pkg != NULL) {
@@ -2405,12 +2272,15 @@ static slapt_pkg_info_t *find_or_requirement(slapt_pkg_list_t *avail_pkgs,
}
}
- slapt_free_list(alternates);
+ slapt_vector_t_free(alternates);
return pkg;
}
slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst, slapt_pkg_info_t *src)
{
+ if (dst == NULL) {
+ dst = slapt_malloc(sizeof *dst);
+ }
dst = memcpy(dst, src, sizeof *src);
if (src->name != NULL)
@@ -2443,57 +2313,18 @@ slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst, slapt_pkg_info_t *src)
return dst;
}
-slapt_pkg_err_list_t *slapt_init_pkg_err_list(void)
-{
- slapt_pkg_err_list_t *l = slapt_malloc(sizeof *l);
- l->errs = slapt_malloc(sizeof *l->errs);
- l->err_count = 0;
-
- return l;
-}
-
-void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,
- const char *pkg, const char *err)
-{
- slapt_pkg_err_t **tmp;
-
- if (slapt_search_pkg_err_list(l, pkg, err))
- return;
-
- tmp = realloc(l->errs, sizeof *l->errs * (l->err_count + 1));
- if (tmp == NULL)
- return;
-
- l->errs = tmp;
-
- l->errs[l->err_count] = slapt_malloc(sizeof *l->errs[l->err_count]);
- l->errs[l->err_count]->pkg = strdup(pkg);
- l->errs[l->err_count]->error = strdup(err);
-
- ++l->err_count;
-}
-
-bool slapt_search_pkg_err_list(slapt_pkg_err_list_t *l,
- const char *pkg, const char *err)
-{
- slapt_pkg_err_list_t_foreach (error, l) {
- if (strcmp(error->pkg, pkg) == 0 &&
- strcmp(error->error, err) == 0) {
- return true;
- }
- }
- return false;
+slapt_pkg_err_t *slapt_pkg_err_t_init(char *pkg, char *err) {
+ slapt_pkg_err_t *e = NULL;
+ e = slapt_malloc(sizeof *e);
+ e->pkg = pkg;
+ e->error = err;
+ return e;
}
-void slapt_free_pkg_err_list(slapt_pkg_err_list_t *l)
-{
- slapt_pkg_err_list_t_foreach (error, l) {
- free(error->pkg);
- free(error->error);
- free(error);
- }
- free(l->errs);
- free(l);
+void slapt_pkg_err_t_free(slapt_pkg_err_t *e) {
+ free(e->pkg);
+ free(e->error);
+ free(e);
}
/* FIXME this sucks... it needs to check file headers and more */
@@ -2518,10 +2349,10 @@ static FILE *slapt_gunzip_file(const char *file_name, FILE *dest_file)
return dest_file;
}
-slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
+slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
const char *url, bool *compressed)
{
- slapt_pkg_list_t *available_pkgs = NULL;
+ slapt_vector_t *available_pkgs = NULL;
char *pkg_head = NULL;
bool is_interactive = slapt_is_interactive(global_config);
@@ -2544,13 +2375,13 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
fclose(tmp_pkg_f);
- if (available_pkgs == NULL || available_pkgs->pkg_count < 1) {
+ if (available_pkgs == NULL || available_pkgs->size < 1) {
slapt_clear_head_cache(pkg_filename);
fprintf(stderr, gettext("Failed to parse package data from %s\n"),
pkg_filename);
if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ slapt_vector_t_free(available_pkgs);
free(pkg_filename);
free(pkg_local_head);
@@ -2590,13 +2421,13 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
fclose(tmp_pkg_uncompressed_f);
/* if we can't parse any packages out of this */
- if (available_pkgs == NULL || available_pkgs->pkg_count < 1) {
+ if (available_pkgs == NULL || available_pkgs->size < 1) {
slapt_clear_head_cache(pkg_filename);
fprintf(stderr, gettext("Failed to parse package data from %s\n"), url);
if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ slapt_vector_t_free(available_pkgs);
free(pkg_filename);
free(pkg_local_head);
@@ -2667,18 +2498,17 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
available_pkgs = slapt_parse_packages_txt(tmp_pkg_f);
/* if we can't parse any packages out of this */
- if (available_pkgs == NULL || available_pkgs->pkg_count < 1) {
+ if (available_pkgs == NULL || available_pkgs->size < 1) {
slapt_clear_head_cache(pkg_filename);
fprintf(stderr, gettext("Failed to parse package data from %s\n"), url);
if (available_pkgs)
- slapt_free_pkg_list(available_pkgs);
+ slapt_vector_t_free(available_pkgs);
fclose(tmp_pkg_f);
free(pkg_filename);
free(pkg_local_head);
- slapt_clear_head_cache(pkg_filename);
return NULL;
}
@@ -2710,10 +2540,10 @@ slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_co
return available_pkgs;
}
-slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
+slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
const char *url, bool *compressed)
{
- slapt_pkg_list_t *patch_pkgs = NULL;
+ slapt_vector_t *patch_pkgs = NULL;
char *patch_head = NULL;
bool is_interactive = slapt_is_interactive(global_config);
*compressed = 0;
@@ -3214,46 +3044,44 @@ char *slapt_stringify_pkg(const slapt_pkg_info_t *pkg)
return pkg_str;
}
-slapt_pkg_list_t *
+slapt_vector_t *
slapt_get_obsolete_pkgs(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs)
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs)
{
- 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();
+ slapt_vector_t *obsolete = slapt_vector_t_init(NULL);
+ slapt_vector_t *to_install = slapt_vector_t_init(NULL);
+ slapt_vector_t *to_remove = slapt_vector_t_init(NULL);
- slapt_pkg_list_t_foreach (p, installed_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, p, installed_pkgs) {
/*
if we can't find the installed package in our available pkg list,
it must be obsolete
*/
if (slapt_get_newest_pkg(avail_pkgs, p->name) == NULL) {
- slapt_pkg_list_t *deps;
-
/*
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);
+ slapt_vector_t *deps = slapt_is_required_by(global_config, avail_pkgs, installed_pkgs, to_install, to_remove, p);
- slapt_pkg_list_t_foreach (dep, deps) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, 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 */
if (installed_dep != NULL) {
- slapt_add_pkg_to_pkg_list(obsolete, installed_dep);
+ slapt_vector_t_add(obsolete, installed_dep);
}
}
- slapt_free_pkg_list(deps);
+ slapt_vector_t_free(deps);
- slapt_add_pkg_to_pkg_list(obsolete, p);
+ slapt_vector_t_add(obsolete, p);
}
}
- slapt_free_pkg_list(to_install);
- slapt_free_pkg_list(to_remove);
+ slapt_vector_t_free(to_install);
+ slapt_vector_t_free(to_remove);
return obsolete;
}
@@ -3264,11 +3092,18 @@ int slapt_pkg_info_t_qsort_cmp(const void *a, const void *b)
slapt_pkg_info_t *pkg_a = *(slapt_pkg_info_t *const *)a;
slapt_pkg_info_t *pkg_b = *(slapt_pkg_info_t *const *)b;
+ if (!pkg_a->name || !pkg_b->name)
+ return cmp;
+
cmp = strcmp(pkg_a->name, pkg_b->name);
if (cmp == 0) {
- if ((cmp = strverscmp(pkg_a->version, pkg_b->version)) == 0) {
- return strcmp(pkg_a->location, pkg_b->location);
+ if ((pkg_a->version && pkg_b->version) && (cmp = strverscmp(pkg_a->version, pkg_b->version)) == 0) {
+ if (pkg_a->location && pkg_b->location) {
+ return strcmp(pkg_a->location, pkg_b->location);
+ } else {
+ return cmp;
+ }
} else {
return cmp;
}
@@ -3443,3 +3278,17 @@ char *slapt_gen_package_log_dir_name(void)
return pkg_log_dirname;
}
+
+slapt_pkg_upgrade_t *slapt_pkg_upgrade_t_init(slapt_pkg_info_t *i, slapt_pkg_info_t *u) {
+ slapt_pkg_upgrade_t *upgrade = NULL;
+ upgrade = slapt_malloc(sizeof *upgrade);
+ upgrade->installed = i;
+ upgrade->upgrade = u;
+ return upgrade;
+}
+
+void slapt_pkg_upgrade_t_free(slapt_pkg_upgrade_t *upgrade) {
+ slapt_free_pkg(upgrade->installed);
+ slapt_free_pkg(upgrade->upgrade);
+ free(upgrade);
+}
diff --git a/src/package.h b/src/package.h
index 685dbe3..16797c0 100644
--- a/src/package.h
+++ b/src/package.h
@@ -70,81 +70,57 @@ typedef struct {
} slapt_pkg_info_t;
typedef struct {
- slapt_pkg_info_t **pkgs;
- 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;
slapt_pkg_info_t *upgrade;
- bool reinstall;
} slapt_pkg_upgrade_t;
-typedef struct {
- slapt_pkg_upgrade_t **pkgs;
- 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++)
+slapt_pkg_upgrade_t *slapt_pkg_upgrade_t_init(slapt_pkg_info_t *, slapt_pkg_info_t *);
+void slapt_pkg_upgrade_t_free(slapt_pkg_upgrade_t *);
typedef struct {
char *pkg;
char *error;
} slapt_pkg_err_t;
-typedef struct {
- slapt_pkg_err_t **errs;
- 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++)
+slapt_pkg_err_t *slapt_pkg_err_t_init(char *, char *);
+void slapt_pkg_err_t_free(slapt_pkg_err_t *);
/* returns an empty package structure */
slapt_pkg_info_t *slapt_init_pkg(void);
/* frees the package structure */
void slapt_free_pkg(slapt_pkg_info_t *pkg);
-/* create an empty package list */
-slapt_pkg_list_t *slapt_init_pkg_list(void);
-/* add a package to a package list */
-void slapt_add_pkg_to_pkg_list(slapt_pkg_list_t *list,
- slapt_pkg_info_t *pkg);
-/* free package list */
-void slapt_free_pkg_list(slapt_pkg_list_t *);
-
/*
update the local package cache. Must be chdir'd to working_dir.
*/
int slapt_update_pkg_cache(const slapt_rc_config *global_config);
/* write pkg data to disk */
void slapt_write_pkg_data(const char *source_url, FILE *d_file,
- slapt_pkg_list_t *pkgs);
+ slapt_vector_t *pkgs);
/* parse the PACKAGES.TXT file */
-slapt_pkg_list_t *slapt_parse_packages_txt(FILE *);
+slapt_vector_t *slapt_parse_packages_txt(FILE *);
/*
return a list of available packages. Must be chdir'd to
rc_config->working_dir. Otherwise, open a filehandle to the package data
and pass it to slapt_parse_packages_txt();
*/
-slapt_pkg_list_t *slapt_get_available_pkgs(void);
+slapt_vector_t *slapt_get_available_pkgs(void);
/* retrieve list of installed pkgs */
-slapt_pkg_list_t *slapt_get_installed_pkgs(void);
+slapt_vector_t *slapt_get_installed_pkgs(void);
/* retrieve the newest package from package list */
-slapt_pkg_info_t *slapt_get_newest_pkg(slapt_pkg_list_t *, const char *);
+slapt_pkg_info_t *slapt_get_newest_pkg(slapt_vector_t *, const char *);
/* get the exact package */
-slapt_pkg_info_t *slapt_get_exact_pkg(slapt_pkg_list_t *list,
+slapt_pkg_info_t *slapt_get_exact_pkg(slapt_vector_t *list,
const char *name,
const char *version);
/* lookup package by details */
-slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
+slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_vector_t *list,
const char *name,
const char *version,
const char *location);
/* search package list with pattern */
-slapt_pkg_list_t *slapt_search_pkg_list(slapt_pkg_list_t *list,
+slapt_vector_t *slapt_search_pkg_list(slapt_vector_t *list,
const char *pattern);
/*
@@ -165,10 +141,10 @@ int slapt_upgrade_pkg(const slapt_rc_config *global_config,
int slapt_remove_pkg(const slapt_rc_config *, slapt_pkg_info_t *);
/* get a list of obsolete packages */
-slapt_pkg_list_t *
+slapt_vector_t *
slapt_get_obsolete_pkgs(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs);
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs);
/*
generate a short description, returns (char *) on success or NULL on error
@@ -210,7 +186,7 @@ slapt_code_t slapt_verify_downloaded_pkg(const slapt_rc_config *global_config,
/*
fill in the md5sum of the package
*/
-void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file);
+void slapt_get_md5sums(slapt_vector_t *pkgs, FILE *checksum_file);
/*
find out the pkg file size (post download)
*/
@@ -233,26 +209,26 @@ int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b);
(usually called with transaction->conflict_err and transaction->missing_err)
*/
int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
slapt_pkg_info_t *pkg,
- slapt_pkg_list_t *deps,
- slapt_pkg_err_list_t *conflict_err,
- slapt_pkg_err_list_t *missing_err);
+ slapt_vector_t *deps,
+ slapt_vector_t *conflict_err,
+ slapt_vector_t *missing_err);
/*
return list of package conflicts
*/
-slapt_pkg_list_t *slapt_get_pkg_conflicts(slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+slapt_vector_t *slapt_get_pkg_conflicts(slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
slapt_pkg_info_t *pkg);
/*
return list of packages required by
*/
-slapt_pkg_list_t *slapt_is_required_by(const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail,
- slapt_pkg_list_t *installed_pkgs,
- slapt_pkg_list_t *pkgs_to_install,
- slapt_pkg_list_t *pkgs_to_remove,
+slapt_vector_t *slapt_is_required_by(const slapt_rc_config *global_config,
+ slapt_vector_t *avail,
+ slapt_vector_t *installed_pkgs,
+ slapt_vector_t *pkgs_to_install,
+ slapt_vector_t *pkgs_to_remove,
slapt_pkg_info_t *pkg);
/*
@@ -265,7 +241,7 @@ void slapt_clean_pkg_dir(const char *dir_name);
*/
void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
const char *dir_name,
- slapt_pkg_list_t *avail_pkgs);
+ slapt_vector_t *avail_pkgs);
/*
make a copy of a package (needs to be freed with free_pkg)
@@ -273,22 +249,12 @@ void slapt_purge_old_cached_pkgs(const slapt_rc_config *global_config,
slapt_pkg_info_t *slapt_copy_pkg(slapt_pkg_info_t *dst, slapt_pkg_info_t *src);
/*
- package error handling api to handle errors within core functions
-*/
-slapt_pkg_err_list_t *slapt_init_pkg_err_list(void);
-void slapt_add_pkg_err_to_list(slapt_pkg_err_list_t *l,
- const char *pkg, const char *err);
-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 if the compressed version was downloaded.
*/
-slapt_pkg_list_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
+slapt_vector_t *slapt_get_pkg_source_packages(const slapt_rc_config *global_config,
const char *url, bool *compressed);
-slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
+slapt_vector_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_config,
const char *url, bool *compressed);
FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
const char *url, bool *compressed);
diff --git a/src/transaction.c b/src/transaction.c
index 5527a20..f5801a1 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -20,46 +20,51 @@
#define SLAPT_PKG_DL_NOTE_LEN 16
-static slapt_queue_t *slapt_queue_init(void);
-static void queue_add_install(slapt_queue_t *t, slapt_pkg_info_t *p);
-static void queue_add_upgrade(slapt_queue_t *t, slapt_pkg_upgrade_t *p);
-static void queue_free(slapt_queue_t *t);
-
static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg);
-static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg,
- bool reinstall);
-
slapt_transaction_t *slapt_init_transaction(void)
{
slapt_transaction_t *tran = slapt_malloc(sizeof *tran);
- tran->install_pkgs = slapt_init_pkg_list();
- tran->install_pkgs->free_pkgs = true;
+ tran->install_pkgs = slapt_vector_t_init((slapt_vector_t_free_function)slapt_free_pkg);
- tran->remove_pkgs = slapt_init_pkg_list();
- tran->remove_pkgs->free_pkgs = true;
+ tran->remove_pkgs = slapt_vector_t_init((slapt_vector_t_free_function)slapt_free_pkg);
- tran->exclude_pkgs = slapt_init_pkg_list();
- tran->exclude_pkgs->free_pkgs = true;
+ tran->exclude_pkgs = slapt_vector_t_init((slapt_vector_t_free_function)slapt_free_pkg);
- tran->upgrade_pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs);
- tran->upgrade_pkgs->pkgs = slapt_malloc(sizeof *tran->upgrade_pkgs->pkgs);
- tran->upgrade_pkgs->pkg_count = 0;
- tran->upgrade_pkgs->reinstall_count = 0;
+ tran->upgrade_pkgs = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_upgrade_t_free);
+ tran->reinstall_pkgs = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_upgrade_t_free);
- tran->suggests = slapt_init_list();
+ tran->suggests = slapt_vector_t_init(NULL);
- tran->queue = slapt_queue_init();
+ tran->queue = slapt_vector_t_init((slapt_vector_t_free_function)slapt_queue_i_free);
- tran->conflict_err = slapt_init_pkg_err_list();
- tran->missing_err = slapt_init_pkg_err_list();
+ tran->conflict_err = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_err_t_free);
+ tran->missing_err = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_err_t_free);
return tran;
}
+slapt_queue_i *slapt_queue_i_init(slapt_pkg_info_t *i, slapt_pkg_upgrade_t *u) {
+ slapt_queue_i *qi = NULL;
+ qi = slapt_malloc(sizeof *qi);
+ if ((i && u ) || (!i && !u)){
+ exit(EXIT_FAILURE);
+ }
+ if (i) {
+ qi->pkg.i = i;
+ qi->type = INSTALL;
+ } else if (u) {
+ qi->pkg.u = u;
+ qi->type = UPGRADE;
+ }
+ return qi;
+}
+
+void slapt_queue_i_free(slapt_queue_i *qi) {
+ free(qi);
+}
+
int slapt_handle_transaction(const slapt_rc_config *global_config,
slapt_transaction_t *tran)
{
@@ -70,28 +75,28 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
char dl_note[SLAPT_PKG_DL_NOTE_LEN];
/* show unmet dependencies */
- if (tran->missing_err->err_count > 0) {
+ if (tran->missing_err->size > 0) {
fprintf(stderr, gettext("The following packages have unmet dependencies:\n"));
- slapt_pkg_err_list_t_foreach (error, tran->missing_err) {
+ slapt_vector_t_foreach (slapt_pkg_err_t *, error, tran->missing_err) {
fprintf(stderr, gettext(" %s: Depends: %s\n"), error->pkg, error->error);
}
}
/* show conflicts */
- if (tran->conflict_err->err_count > 0) {
- slapt_pkg_err_list_t_foreach (conflict_error, tran->conflict_err) {
+ if (tran->conflict_err->size > 0) {
+ slapt_vector_t_foreach (slapt_pkg_err_t *, conflict_error, tran->conflict_err) {
fprintf(stderr, gettext("%s, which is required by %s, is excluded\n"),
conflict_error->error, conflict_error->pkg);
}
}
/* show pkgs to exclude */
- if (tran->exclude_pkgs->pkg_count > 0) {
+ if (tran->exclude_pkgs->size > 0) {
printf(gettext("The following packages have been EXCLUDED:\n"));
printf(" ");
len = 0;
- slapt_pkg_list_t_foreach (e, tran->exclude_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, e, tran->exclude_pkgs) {
if (len + strlen(e->name) + 1 < MAX_LINE_LEN) {
printf("%s ", e->name);
len += strlen(e->name) + 1;
@@ -106,12 +111,12 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* show suggested pkgs */
slapt_generate_suggestions(tran);
- if (tran->suggests->count > 0) {
+ if (tran->suggests->size > 0) {
printf(gettext("Suggested packages:\n"));
printf(" ");
len = 0;
- slapt_list_t_foreach (s, tran->suggests) {
+ slapt_vector_t_foreach (char *, s, tran->suggests) {
/* don't show suggestion for something we already have in the transaction */
if (slapt_search_transaction(tran, s))
continue;
@@ -128,12 +133,12 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
}
/* show pkgs to install */
- if (tran->install_pkgs->pkg_count > 0) {
+ if (tran->install_pkgs->size > 0) {
printf(gettext("The following NEW packages will be installed:\n"));
printf(" ");
len = 0;
- slapt_pkg_list_t_foreach (p, tran->install_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, p, tran->install_pkgs) {
size_t existing_file_size = 0;
if (len + strlen(p->name) + 1 < MAX_LINE_LEN) {
@@ -157,12 +162,12 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
}
/* show pkgs to remove */
- if (tran->remove_pkgs->pkg_count > 0) {
+ if (tran->remove_pkgs->size > 0) {
printf(gettext("The following packages will be REMOVED:\n"));
printf(" ");
len = 0;
- slapt_pkg_list_t_foreach (r, tran->remove_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, r, tran->remove_pkgs) {
if (len + strlen(r->name) + 1 < MAX_LINE_LEN) {
printf("%s ", r->name);
len += strlen(r->name) + 1;
@@ -178,35 +183,23 @@ 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(" ");
- }
+ if (tran->upgrade_pkgs->size > 0) {
+ printf(gettext("The following packages will be upgraded:\n"));
+ printf(" ");
len = 0;
- slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, 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;
-
- existing_file_size = slapt_get_pkg_file_size(
- global_config, u) /
- 1024;
-
+ size_t existing_file_size = slapt_get_pkg_file_size(global_config, u) / 1024;
download_size += u->size_c;
-
if (existing_file_size <= u->size_c)
already_download_size += existing_file_size;
-
uncompressed_size += u->size_u;
uncompressed_size -= p->size_u;
- if (upgrade->reinstall)
- continue;
-
if (line_len < MAX_LINE_LEN) {
printf("%s ", u->name);
len += strlen(u->name) + 1;
@@ -215,53 +208,46 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
len = strlen(u->name) + 3;
}
}
+ printf("\n");
+ }
- if ((tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count) > 0)
- printf("\n");
-
- if (tran->upgrade_pkgs->reinstall_count > 0) {
- printf(gettext("The following packages will be reinstalled:\n"));
- printf(" ");
+ if (tran->reinstall_pkgs->size > 0) {
+ printf(gettext("The following packages will be reinstalled:\n"));
+ printf(" ");
- len = 0;
- 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;
+ len = 0;
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, reinstall_upgrade, tran->reinstall_pkgs) {
+ slapt_pkg_info_t *u = reinstall_upgrade->upgrade;
+ slapt_pkg_info_t *p = reinstall_upgrade->installed;
- if (!reinstall_upgrade->reinstall)
- continue;
+ int line_len = len + strlen(u->name) + 1;
+ size_t existing_file_size = slapt_get_pkg_file_size(global_config, u) / 1024;
+ download_size += u->size_c;
+ if (existing_file_size <= u->size_c)
+ already_download_size += existing_file_size;
+ uncompressed_size += u->size_u;
+ uncompressed_size -= p->size_u;
- if (line_len < MAX_LINE_LEN) {
- printf("%s ", u->name);
- len += strlen(u->name) + 1;
- } else {
- printf("\n %s ", u->name);
- len = strlen(u->name) + 3;
- }
+ if (line_len < MAX_LINE_LEN) {
+ printf("%s ", u->name);
+ len += strlen(u->name) + 1;
+ } else {
+ printf("\n %s ", u->name);
+ len = strlen(u->name) + 3;
}
- printf("\n");
}
+ printf("\n");
}
/* print the summary */
- printf(ngettext("%d upgraded, ", "%d upgraded, ",
- tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count),
- tran->upgrade_pkgs->pkg_count - tran->upgrade_pkgs->reinstall_count);
- printf(ngettext("%d reinstalled, ", "%d reinstalled, ",
- tran->upgrade_pkgs->reinstall_count),
- tran->upgrade_pkgs->reinstall_count);
- printf(ngettext("%d newly installed, ", "%d newly installed, ",
- tran->install_pkgs->pkg_count),
- tran->install_pkgs->pkg_count);
- printf(ngettext("%d to remove, ", "%d to remove, ",
- tran->remove_pkgs->pkg_count),
- tran->remove_pkgs->pkg_count);
- printf(ngettext("%d not upgraded.\n", "%d not upgraded.\n",
- tran->exclude_pkgs->pkg_count),
- tran->exclude_pkgs->pkg_count);
+ printf(ngettext("%d upgraded, ", "%d upgraded, ", tran->upgrade_pkgs->size), tran->upgrade_pkgs->size);
+ printf(ngettext("%d reinstalled, ", "%d reinstalled, ", tran->reinstall_pkgs->size), tran->reinstall_pkgs->size);
+ printf(ngettext("%d newly installed, ", "%d newly installed, ", tran->install_pkgs->size), tran->install_pkgs->size);
+ printf(ngettext("%d to remove, ", "%d to remove, ", tran->remove_pkgs->size), tran->remove_pkgs->size);
+ printf(ngettext("%d not upgraded.\n", "%d not upgraded.\n", tran->exclude_pkgs->size), tran->exclude_pkgs->size);
/* only show this if we are going to do download something */
- if (tran->upgrade_pkgs->pkg_count > 0 || tran->install_pkgs->pkg_count > 0) {
+ if (tran->upgrade_pkgs->size > 0 || tran->install_pkgs->size > 0 || tran->reinstall_pkgs->size > 0) {
/* how much we need to download */
double need_to_download_size = download_size - already_download_size;
@@ -298,8 +284,8 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
}
}
- if (tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
- tran->install_pkgs->pkg_count > 0) {
+ if (tran->upgrade_pkgs->size > 0 || tran->remove_pkgs->size > 0 ||
+ tran->install_pkgs->size > 0 || tran->reinstall_pkgs->size > 0) {
if (global_config->download_only == false) {
if ((int)uncompressed_size < 0) {
uncompressed_size *= -1;
@@ -319,8 +305,8 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* prompt */
if ((global_config->prompt) ||
- ((tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
- (tran->install_pkgs->pkg_count > 0 &&
+ ((tran->upgrade_pkgs->size > 0 || tran->remove_pkgs->size > 0 || tran->reinstall_pkgs->size > 0 ||
+ (tran->install_pkgs->size > 0 &&
global_config->dist_upgrade)) &&
(global_config->no_prompt == false &&
global_config->download_only == false &&
@@ -333,29 +319,36 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
}
if (global_config->print_uris) {
- slapt_pkg_list_t_foreach (info, tran->install_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, 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);
}
- slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, 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",
upgrade_info->mirror, location, upgrade_info->name,
upgrade_info->version, upgrade_info->file_ext);
}
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, reinstall, tran->reinstall_pkgs) {
+ const slapt_pkg_info_t *upgrade_info = reinstall->upgrade;
+ const char *location = upgrade_info->location + strspn(upgrade_info->location, "./");
+ printf("%s%s/%s-%s%s\n",
+ 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) {
- slapt_pkg_list_t_foreach (r, tran->remove_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, r, tran->remove_pkgs) {
printf(gettext("%s-%s is to be removed\n"), r->name, r->version);
}
- slapt_queue_t_foreach (q, tran->queue) {
+ slapt_vector_t_foreach (slapt_queue_i *, q, tran->queue) {
if (q->type == INSTALL) {
printf(gettext("%s-%s is to be installed\n"),
q->pkg.i->name,
@@ -365,6 +358,8 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
q->pkg.u->upgrade->name,
q->pkg.u->installed->version,
q->pkg.u->upgrade->version);
+ } else {
+ exit(EXIT_FAILURE);
}
}
@@ -372,10 +367,10 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
return 0;
}
- pkg_dl_count = tran->install_pkgs->pkg_count + tran->upgrade_pkgs->pkg_count;
+ pkg_dl_count = tran->install_pkgs->size + tran->upgrade_pkgs->size + tran->reinstall_pkgs->size;
/* download pkgs */
- slapt_pkg_list_t_foreach (pkg, tran->install_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, tran->install_pkgs) {
bool failed = true;
++dl_counter;
@@ -396,7 +391,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
exit(EXIT_FAILURE);
}
- slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, upgrade, tran->upgrade_pkgs) {
bool failed = true;
++dl_counter;
@@ -416,17 +411,37 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
exit(EXIT_FAILURE);
}
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, reinstall, tran->reinstall_pkgs) {
+ bool failed = true;
+
+ ++dl_counter;
+ snprintf(dl_note, SLAPT_PKG_DL_NOTE_LEN, "%d/%d", dl_counter, pkg_dl_count);
+
+ for (uint32_t retry_count = 0; retry_count < global_config->retry; ++retry_count) {
+ const char *err = slapt_download_pkg(global_config, reinstall->upgrade, dl_note);
+ if (err) {
+ fprintf(stderr, gettext("Failed to download: %s\n"), err);
+ failed = true;
+ } else {
+ failed = false;
+ break;
+ }
+ }
+ if (failed)
+ exit(EXIT_FAILURE);
+ }
+
printf("\n");
/* run transaction, remove, install, and upgrade */
if (global_config->download_only == false) {
- slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, remove_pkg, tran->remove_pkgs) {
if (slapt_remove_pkg(global_config, remove_pkg) == -1) {
exit(EXIT_FAILURE);
}
}
- slapt_queue_t_foreach (q, tran->queue) {
+ slapt_vector_t_foreach (slapt_queue_i *, q, tran->queue) {
if (q->type == INSTALL) {
printf(gettext("Preparing to install %s-%s\n"),
q->pkg.i->name,
@@ -457,161 +472,90 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
void slapt_add_install_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_info_t **tmp_list;
-
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, pkg))
return;
- tmp_list = realloc(
- tran->install_pkgs->pkgs,
- sizeof *tran->install_pkgs->pkgs * (tran->install_pkgs->pkg_count + 1));
-
- if (tmp_list != NULL) {
- tran->install_pkgs->pkgs = tmp_list;
-
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]);
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_copy_pkg(
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count],
- pkg);
- queue_add_install(
- tran->queue,
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]);
-
- ++tran->install_pkgs->pkg_count;
- }
+ slapt_pkg_info_t *i = slapt_copy_pkg(NULL, pkg);
+ slapt_vector_t_add(tran->install_pkgs, i);
+ slapt_vector_t_add(tran->queue, slapt_queue_i_init(tran->install_pkgs->items[tran->install_pkgs->size - 1], NULL));
}
void slapt_add_remove_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_info_t **tmp_list;
-
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, pkg))
return;
- tmp_list = realloc(
- tran->remove_pkgs->pkgs,
- sizeof *tran->remove_pkgs->pkgs * (tran->remove_pkgs->pkg_count + 1));
- if (tmp_list != NULL) {
- tran->remove_pkgs->pkgs = tmp_list;
-
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count]);
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_copy_pkg(
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count],
- pkg);
- ++tran->remove_pkgs->pkg_count;
- }
+ slapt_pkg_info_t *r = slapt_copy_pkg(NULL, pkg);
+ slapt_vector_t_add(tran->remove_pkgs, r);
}
void slapt_add_exclude_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_info_t **tmp_list;
-
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, pkg))
return;
- tmp_list = realloc(
- tran->exclude_pkgs->pkgs,
- sizeof *tran->exclude_pkgs->pkgs * (tran->exclude_pkgs->pkg_count + 1));
- if (tmp_list != NULL) {
- tran->exclude_pkgs->pkgs = tmp_list;
-
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count]);
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_copy_pkg(
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count],
- pkg);
- ++tran->exclude_pkgs->pkg_count;
- }
+ slapt_pkg_info_t *e = slapt_copy_pkg(NULL, pkg);
+ slapt_vector_t_add(tran->exclude_pkgs, e);
}
void slapt_add_reinstall_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *installed_pkg,
slapt_pkg_info_t *slapt_upgrade_pkg)
{
- _slapt_add_upgrade_to_transaction(tran, installed_pkg, slapt_upgrade_pkg, true);
+ /* don't add if already present in the transaction */
+ if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg))
+ return;
+
+ slapt_pkg_info_t *i = slapt_copy_pkg(NULL, installed_pkg);
+ slapt_pkg_info_t *u = slapt_copy_pkg(NULL, slapt_upgrade_pkg);
+
+ slapt_vector_t_add(tran->reinstall_pkgs, slapt_pkg_upgrade_t_init(i, u));
+ slapt_vector_t_add(tran->queue, slapt_queue_i_init(NULL, tran->reinstall_pkgs->items[tran->reinstall_pkgs->size -1]));
}
void slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *installed_pkg,
slapt_pkg_info_t *slapt_upgrade_pkg)
{
- _slapt_add_upgrade_to_transaction(tran, installed_pkg, slapt_upgrade_pkg, false);
-}
-
-static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
- slapt_pkg_info_t *installed_pkg,
- slapt_pkg_info_t *slapt_upgrade_pkg,
- bool reinstall)
-{
- slapt_pkg_upgrade_t **tmp_list;
-
/* don't add if already present in the transaction */
if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg))
return;
- tmp_list = realloc(
- tran->upgrade_pkgs->pkgs,
- sizeof *tran->upgrade_pkgs->pkgs * (tran->upgrade_pkgs->pkg_count + 1));
-
- if (tmp_list != NULL) {
- tran->upgrade_pkgs->pkgs = tmp_list;
+ slapt_pkg_info_t *i = slapt_copy_pkg(NULL, installed_pkg);
+ slapt_pkg_info_t *u = slapt_copy_pkg(NULL, slapt_upgrade_pkg);
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count] = slapt_malloc(
- sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]);
-
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed =
- slapt_malloc(
- sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed);
-
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade =
- slapt_malloc(
- sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade);
-
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = slapt_copy_pkg(
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed,
- installed_pkg);
-
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = slapt_copy_pkg(
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade,
- slapt_upgrade_pkg);
-
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->reinstall = reinstall;
-
- queue_add_upgrade(tran->queue,
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]);
-
- ++tran->upgrade_pkgs->pkg_count;
-
- if (reinstall)
- ++tran->upgrade_pkgs->reinstall_count;
- }
+ slapt_vector_t_add(tran->upgrade_pkgs, slapt_pkg_upgrade_t_init(i, u));
+ slapt_vector_t_add(tran->queue, slapt_queue_i_init(NULL, tran->upgrade_pkgs->items[tran->upgrade_pkgs->size - 1]));
}
bool slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
{
- slapt_pkg_list_t_foreach (pkg, tran->install_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, tran->install_pkgs) {
if (strcmp(pkg_name, pkg->name) == 0)
return true;
}
- slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, upgrade, tran->upgrade_pkgs) {
if (strcmp(pkg_name, upgrade->upgrade->name) == 0)
return true;
}
- slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, reinstall, tran->reinstall_pkgs) {
+ if (strcmp(pkg_name, reinstall->upgrade->name) == 0)
+ return true;
+ }
+
+ slapt_vector_t_foreach (slapt_pkg_info_t *, remove_pkg, tran->remove_pkgs) {
if (strcmp(pkg_name, remove_pkg->name) == 0)
return true;
}
- slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, exclude_pkg, tran->exclude_pkgs) {
if (strcmp(pkg_name, exclude_pkg->name) == 0)
return true;
}
@@ -622,7 +566,7 @@ bool slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, upgrade, tran->upgrade_pkgs) {
if (strcmp(pkg->name, upgrade->upgrade->name) == 0)
return true;
}
@@ -632,44 +576,15 @@ bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
void slapt_free_transaction(slapt_transaction_t *tran)
{
- 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) {
- slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
- slapt_free_pkg(remove_pkg);
- }
- }
- free(tran->remove_pkgs->pkgs);
- free(tran->remove_pkgs);
-
- 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) {
- slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
- slapt_free_pkg(exclude_pkg);
- }
- }
- free(tran->exclude_pkgs->pkgs);
- free(tran->exclude_pkgs);
-
- slapt_free_list(tran->suggests);
-
- queue_free(tran->queue);
-
- slapt_free_pkg_err_list(tran->conflict_err);
- slapt_free_pkg_err_list(tran->missing_err);
+ slapt_vector_t_free(tran->install_pkgs);
+ slapt_vector_t_free(tran->remove_pkgs);
+ slapt_vector_t_free(tran->upgrade_pkgs);
+ slapt_vector_t_free(tran->reinstall_pkgs);
+ slapt_vector_t_free(tran->exclude_pkgs);
+ slapt_vector_t_free(tran->suggests);
+ slapt_vector_t_free(tran->queue);
+ slapt_vector_t_free(tran->conflict_err);
+ slapt_vector_t_free(tran->missing_err);
free(tran);
}
@@ -690,7 +605,7 @@ 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();
- slapt_pkg_list_t_foreach (installed_pkg, tran->install_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, installed_pkg, tran->install_pkgs) {
if (
strcmp(pkg->name, installed_pkg->name) == 0 &&
strcmp(pkg->version, installed_pkg->version) == 0 &&
@@ -701,7 +616,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_add_install_to_transaction(new_tran, installed_pkg);
}
- slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, remove_pkg, tran->remove_pkgs) {
if (
strcmp(pkg->name, remove_pkg->name) == 0 &&
strcmp(pkg->version, remove_pkg->version) == 0 &&
@@ -712,7 +627,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_add_remove_to_transaction(new_tran, remove_pkg);
}
- slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, upgrade, tran->upgrade_pkgs) {
slapt_pkg_info_t *u = upgrade->upgrade;
slapt_pkg_info_t *p = upgrade->installed;
@@ -726,7 +641,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_add_upgrade_to_transaction(new_tran, p, u);
}
- slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, exclude_pkg, tran->exclude_pkgs) {
if (
strcmp(pkg->name, exclude_pkg->name) == 0 &&
strcmp(pkg->version, exclude_pkg->version) == 0 &&
@@ -744,12 +659,11 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
/* needed check to see if a package is conflicted */
int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
slapt_transaction_t *tran,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
slapt_pkg_info_t *pkg)
{
int dep_return = -1;
- slapt_pkg_list_t *deps = NULL;
if (global_config->disable_dep_check)
return 0;
@@ -757,7 +671,7 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
if (pkg == NULL)
return 0;
- deps = slapt_init_pkg_list();
+ slapt_vector_t *deps = slapt_vector_t_init(NULL);
dep_return = slapt_get_pkg_dependencies(
global_config, avail_pkgs, installed_pkgs, pkg,
@@ -767,23 +681,22 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
/* exclude the package if dep check barfed */
if ((dep_return == -1) && (global_config->ignore_dep == false) &&
(slapt_get_exact_pkg(tran->exclude_pkgs, pkg->name, pkg->version) == NULL)) {
- slapt_free_pkg_list(deps);
+ slapt_vector_t_free(deps);
return -1;
}
/* loop through the deps */
- slapt_pkg_list_t_foreach (dep, deps) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, 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);
+ slapt_vector_t *conflicts = slapt_is_conflicted(tran, avail_pkgs, installed_pkgs, dep);
- slapt_pkg_list_t_foreach (conflict, conflicts) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, conflict, conflicts) {
slapt_add_remove_to_transaction(tran, conflict);
}
- slapt_free_pkg_list(conflicts);
+ slapt_vector_t_free(conflicts);
dep_installed = slapt_get_newest_pkg(installed_pkgs, dep->name);
if (dep_installed == NULL) {
@@ -795,43 +708,43 @@ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
}
}
- slapt_free_pkg_list(deps);
+ slapt_vector_t_free(deps);
return 0;
}
/* make sure pkg isn't conflicted with what's already in the transaction */
-slapt_pkg_list_t *slapt_is_conflicted(slapt_transaction_t *tran,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+slapt_vector_t *slapt_is_conflicted(slapt_transaction_t *tran,
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_list_t *conflicts = NULL;
- slapt_pkg_list_t *conflicts_in_transaction = slapt_init_pkg_list();
+ slapt_vector_t *conflicts = NULL;
+ slapt_vector_t *conflicts_in_transaction = slapt_vector_t_init(NULL);
/* 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);
- slapt_pkg_list_t_foreach (conflict, conflicts) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, 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);
- slapt_add_pkg_to_pkg_list(conflicts_in_transaction, conflict);
+ slapt_vector_t_add(conflicts_in_transaction, conflict);
}
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, conflict);
+ slapt_vector_t_add(conflicts_in_transaction, conflict);
}
}
- slapt_free_pkg_list(conflicts);
+ slapt_vector_t_free(conflicts);
return conflicts_in_transaction;
}
static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
{
- slapt_list_t *suggests = NULL;
+ slapt_vector_t *suggests = NULL;
if (pkg->suggests == NULL || strlen(pkg->suggests) == 0) {
return;
@@ -839,38 +752,43 @@ static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
suggests = slapt_parse_delimited_list(pkg->suggests, ',');
- slapt_list_t_foreach (s, suggests) {
+ slapt_vector_t_foreach (char *, s, suggests) {
/* no need to add it if we already have it */
if (slapt_search_transaction(tran, s))
continue;
- slapt_add_list_item(tran->suggests, s);
+ slapt_vector_t_add(tran->suggests, strdup(s));
}
- slapt_free_list(suggests);
+ slapt_vector_t_free(suggests);
}
bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- slapt_pkg_list_t_foreach (install_pkg, tran->install_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, install_pkg, tran->install_pkgs) {
if ((strcmp(pkg->name, install_pkg->name) == 0) && (strcmp(pkg->version, install_pkg->version) == 0))
return true;
}
- slapt_pkg_upgrade_list_t_foreach (upgrade, tran->upgrade_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, 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 true;
+ }
+ slapt_vector_t_foreach (slapt_pkg_upgrade_t *, reinstall, tran->reinstall_pkgs) {
+ slapt_pkg_info_t *p = reinstall->upgrade;
if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
return true;
}
- slapt_pkg_list_t_foreach (remove_pkg, tran->remove_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, remove_pkg, tran->remove_pkgs) {
if ((strcmp(pkg->name, remove_pkg->name) == 0) && (strcmp(pkg->version, remove_pkg->version) == 0))
return true;
}
- slapt_pkg_list_t_foreach (exclude_pkg, tran->exclude_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, exclude_pkg, tran->exclude_pkgs) {
if ((strcmp(pkg->name, exclude_pkg->name) == 0) && (strcmp(pkg->version, exclude_pkg->version) == 0))
return true;
}
@@ -878,58 +796,9 @@ bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
return false;
}
-static slapt_queue_t *slapt_queue_init(void)
-{
- slapt_queue_t *t = NULL;
- t = slapt_malloc(sizeof *t);
- t->pkgs = slapt_malloc(sizeof *t->pkgs);
- t->count = 0;
-
- return t;
-}
-
-static void queue_add_install(slapt_queue_t *t, slapt_pkg_info_t *p)
-{
- slapt_queue_i **tmp;
- tmp = realloc(t->pkgs, sizeof *t->pkgs * (t->count + 1));
-
- if (!tmp)
- return;
-
- t->pkgs = tmp;
- t->pkgs[t->count] = slapt_malloc(sizeof *t->pkgs[t->count]);
- t->pkgs[t->count]->pkg.i = p;
- t->pkgs[t->count]->type = INSTALL;
- ++t->count;
-}
-
-static void queue_add_upgrade(slapt_queue_t *t, slapt_pkg_upgrade_t *p)
-{
- slapt_queue_i **tmp;
- tmp = realloc(t->pkgs, sizeof *t->pkgs * (t->count + 1));
-
- if (!tmp)
- return;
-
- t->pkgs = tmp;
- t->pkgs[t->count] = slapt_malloc(sizeof *t->pkgs[t->count]);
- t->pkgs[t->count]->pkg.u = p;
- t->pkgs[t->count]->type = UPGRADE;
- ++t->count;
-}
-
-static void queue_free(slapt_queue_t *t)
-{
- slapt_queue_t_foreach (i, t) {
- free(i);
- }
- free(t->pkgs);
- free(t);
-}
-
void slapt_generate_suggestions(slapt_transaction_t *tran)
{
- slapt_pkg_list_t_foreach (pkg, tran->install_pkgs) {
+ slapt_vector_t_foreach (slapt_pkg_info_t *, pkg, tran->install_pkgs) {
add_suggestion(tran, pkg);
}
}
diff --git a/src/transaction.h b/src/transaction.h
index 74de317..62032ca 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -29,22 +29,19 @@ typedef struct {
} pkg;
uint32_t type; /* this is enum slapt_action defined in main.h */
} slapt_queue_i;
+slapt_queue_i *slapt_queue_i_init(slapt_pkg_info_t *, slapt_pkg_upgrade_t *);
+void slapt_queue_i_free(slapt_queue_i *);
typedef struct {
- slapt_queue_i **pkgs;
- 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;
- slapt_pkg_upgrade_list_t *upgrade_pkgs;
- slapt_pkg_list_t *remove_pkgs;
- slapt_pkg_list_t *exclude_pkgs;
- slapt_list_t *suggests;
- slapt_pkg_err_list_t *conflict_err;
- slapt_pkg_err_list_t *missing_err;
- slapt_queue_t *queue;
+ slapt_vector_t *install_pkgs;
+ slapt_vector_t *upgrade_pkgs;
+ slapt_vector_t *reinstall_pkgs;
+ slapt_vector_t *remove_pkgs;
+ slapt_vector_t *exclude_pkgs;
+ slapt_vector_t *suggests;
+ slapt_vector_t *conflict_err;
+ slapt_vector_t *missing_err;
+ slapt_vector_t *queue;
} slapt_transaction_t;
/* fill in transaction structure with defaults */
@@ -96,16 +93,16 @@ bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
*/
int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
slapt_transaction_t *tran,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs, slapt_pkg_info_t *pkg);
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs, slapt_pkg_info_t *pkg);
/*
check to see if a package has a conflict already present in the transaction
returns conflicted package or NULL if none
*/
-slapt_pkg_list_t *slapt_is_conflicted(slapt_transaction_t *tran,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs,
+slapt_vector_t *slapt_is_conflicted(slapt_transaction_t *tran,
+ slapt_vector_t *avail_pkgs,
+ slapt_vector_t *installed_pkgs,
slapt_pkg_info_t *pkg);
/*
diff --git a/t/test_configuration.c b/t/test_configuration.c
index a7926ab..4e3283a 100644
--- a/t/test_configuration.c
+++ b/t/test_configuration.c
@@ -12,11 +12,11 @@ START_TEST(test_struct_config)
rc = slapt_read_rc_config("./data/rc1");
fail_if(rc == NULL);
{
- slapt_source_list_t *s = rc->sources;
- slapt_list_t *e = rc->exclude_list;
+ slapt_vector_t *s = rc->sources;
+ slapt_vector_t *e = rc->exclude_list;
- fail_if(s->count < 1);
- fail_if(e->count != 5);
+ fail_if(s->size < 1);
+ fail_if(e->size != 5);
}
slapt_free_rc_config(rc);
rc = NULL;
@@ -40,44 +40,6 @@ START_TEST(test_working_dir)
}
END_TEST
-START_TEST(test_exclude_list)
-{
- slapt_list_t *e = slapt_init_list();
-
- fail_if(e == NULL);
- fail_if(e->count != 0);
-
- slapt_add_list_item(e, "^foo$");
- fail_if(e->count != 1);
-
- slapt_remove_list_item(e, "^foo$");
- fail_if(e->count != 0);
-
- slapt_remove_list_item(e, "no_such_exclude");
- fail_if(e->count != 0);
-
- slapt_free_list(e);
-}
-END_TEST
-
-START_TEST(test_source_list)
-{
- slapt_source_t *src = slapt_init_source("http://www.test.org/dist");
- slapt_source_list_t *s = slapt_init_source_list();
- fail_if(s == NULL);
- fail_if(s->count != 0);
-
- fail_if(src == NULL);
- slapt_add_source(s, src);
- fail_if(s->count != 1);
-
- slapt_remove_source(s, "http://www.test.org/dist/");
- fail_if(s->count != 0);
-
- slapt_free_source_list(s);
-}
-END_TEST
-
START_TEST(test_source_trimming)
{
slapt_source_t *src1 = slapt_init_source("http://www.test.org/dist ");
@@ -98,8 +60,6 @@ Suite *configuration_test_suite()
tcase_add_test(tc, test_struct_config);
tcase_add_test(tc, test_working_dir);
- tcase_add_test(tc, test_exclude_list);
- tcase_add_test(tc, test_source_list);
tcase_add_test(tc, test_source_trimming);
suite_add_tcase(s, tc);
diff --git a/t/test_curl.c b/t/test_curl.c
index 8e8aff0..4b71064 100644
--- a/t/test_curl.c
+++ b/t/test_curl.c
@@ -9,7 +9,8 @@ START_TEST(test_slapt_get_mirror_data_from_source)
FILE *f = NULL;
const char *err = NULL;
slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
- const char *url = rc->sources->src[0]->url;
+ slapt_source_t *src = rc->sources->items[0];
+ const char *url = src->url;
char *packages = "PACKAGES.TXT";
char *packages_gz = "PACKAGES.TXT.gz";
char *checksums = "CHECKSUMS.md5";
diff --git a/t/test_packages.c b/t/test_packages.c
index 087cf8e..7fd6b78 100644
--- a/t/test_packages.c
+++ b/t/test_packages.c
@@ -58,9 +58,9 @@ START_TEST(test_pkg_info)
free(string);
string = NULL;
- slapt_add_list_item(rc->exclude_list, "^gslapt$");
+ slapt_vector_t_add(rc->exclude_list, strdup("^gslapt$"));
fail_if(!slapt_is_excluded(rc, &pkg));
- slapt_remove_list_item(rc->exclude_list, "^gslapt$");
+ slapt_vector_t_remove(rc->exclude_list, "^gslapt$");
fail_unless(slapt_download_pkg(rc, &pkg, NULL) == 0);
fail_unless(slapt_verify_downloaded_pkg(rc, &pkg) == 0);
@@ -87,55 +87,12 @@ START_TEST(test_pkg_info)
}
END_TEST
-START_TEST(test_pkg_list)
-{
- slapt_pkg_list_t *list = slapt_init_pkg_list();
- fail_if(list == NULL);
- fail_unless(list->pkg_count == 0);
-
- slapt_add_pkg_to_pkg_list(list, &pkg);
- fail_unless(list->pkg_count == 1);
-
- slapt_free_pkg_list(list);
- list = NULL;
-
- list = slapt_get_installed_pkgs();
- fail_if(list == NULL);
- /* fail_unless (list->pkg_count == 0); could be anything */
- slapt_free_pkg_list(list);
- list = NULL;
-
- /* parse the PACKAGES.TXT file
- slapt_pkg_list_t *slapt_parse_packages_txt(FILE *);
- */
-
- /*
- return a list of available packages must be already chdir'd to
- rc_config->working_dir. Otherwise, open a filehandle to the package data
- and pass it to slapt_parse_packages_txt();
- slapt_pkg_list_t *slapt_get_available_pkgs(void);
- */
-
- /* get a list of obsolete packages
- slapt_pkg_list_t *
- slapt_get_obsolete_pkgs ( const slapt_rc_config *global_config,
- slapt_pkg_list_t *avail_pkgs,
- slapt_pkg_list_t *installed_pkgs);
- */
-
- /*
- fill in the md5sum of the package
- void slapt_get_md5sums(slapt_pkg_list_t *pkgs, FILE *checksum_file);
- */
-}
-END_TEST
-
START_TEST(test_pkg_search)
{
slapt_pkg_info_t *p = NULL;
- slapt_pkg_list_t *l = NULL;
- slapt_pkg_list_t *list = slapt_init_pkg_list();
- slapt_add_pkg_to_pkg_list(list, &pkg);
+ slapt_vector_t *l = NULL;
+ slapt_vector_t *list = slapt_vector_t_init(NULL);
+ slapt_vector_t_add(list, &pkg);
p = slapt_get_newest_pkg(list, "gslapt");
fail_if(p == NULL);
@@ -148,9 +105,9 @@ START_TEST(test_pkg_search)
l = slapt_search_pkg_list(list, "^gslapt$");
fail_if(l == NULL);
- fail_unless(l->pkg_count == 1);
+ fail_unless(l->size == 1);
- slapt_free_pkg_list(list);
+ slapt_vector_t_free(list);
}
END_TEST
@@ -299,25 +256,22 @@ START_TEST(test_dependency)
uint32_t i = 0;
FILE *fh = NULL;
slapt_pkg_info_t *p = NULL;
- slapt_pkg_list_t *avail = NULL;
- slapt_pkg_list_t *required_by = slapt_init_pkg_list();
- slapt_pkg_list_t *installed = slapt_init_pkg_list();
- slapt_pkg_list_t *pkgs_to_install = slapt_init_pkg_list();
- slapt_pkg_list_t *pkgs_to_remove = slapt_init_pkg_list();
- slapt_pkg_list_t *conflicts = NULL,
- *deps = slapt_init_pkg_list();
- slapt_pkg_err_list_t *conflict = slapt_init_pkg_err_list(),
- *missing = slapt_init_pkg_err_list();
+ slapt_vector_t *required_by = slapt_vector_t_init(NULL);
+ slapt_vector_t *pkgs_to_install = slapt_vector_t_init(NULL);
+ slapt_vector_t *pkgs_to_remove = slapt_vector_t_init(NULL);
+ slapt_vector_t *conflicts = NULL, *deps = slapt_vector_t_init(NULL);
+ slapt_vector_t *conflict = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_err_t_free),
+ *missing = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_err_t_free);
slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
fh = fopen("data/avail_deps", "r");
fail_unless(fh != NULL);
- avail = slapt_parse_packages_txt(fh);
+ slapt_vector_t *avail = slapt_parse_packages_txt(fh);
fclose(fh);
fh = fopen("data/installed_deps", "r");
fail_unless(fh != NULL);
- installed = slapt_parse_packages_txt(fh);
+ slapt_vector_t *installed = slapt_parse_packages_txt(fh);
fclose(fh);
/*
@@ -339,9 +293,9 @@ START_TEST(test_dependency)
fail_unless(p != NULL);
conflicts = slapt_get_pkg_conflicts(avail, installed, p);
fail_unless(conflicts != NULL);
- fail_unless(conflicts->pkg_count == 1);
- fail_unless(strcmp(conflicts->pkgs[0]->name, "ibus") == 0);
- slapt_free_pkg_list(conflicts);
+ fail_unless(conflicts->size == 1);
+ fail_unless(strcmp(((slapt_pkg_info_t *)conflicts->items[0])->name, "ibus") == 0);
+ slapt_vector_t_free(conflicts);
/*
required by tests
@@ -350,38 +304,38 @@ START_TEST(test_dependency)
p = slapt_get_newest_pkg(avail, "slapt-get");
fail_unless(p != NULL);
required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
- fail_unless(required_by->pkg_count == 5);
- fail_unless(strcmp(required_by->pkgs[0]->name, "slapt-src") == 0);
- fail_unless(strcmp(required_by->pkgs[1]->name, "gslapt") == 0);
- fail_unless(strcmp(required_by->pkgs[2]->name, "foo") == 0);
- fail_unless(strcmp(required_by->pkgs[3]->name, "boz") == 0);
- fail_unless(strcmp(required_by->pkgs[4]->name, "bar") == 0);
- slapt_free_pkg_list(required_by);
+ fail_unless(required_by->size == 5);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[0]))->name, "slapt-src") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[1]))->name, "gslapt") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[2]))->name, "foo") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[3]))->name, "boz") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[4]))->name, "bar") == 0);
+ slapt_vector_t_free(required_by);
/* glib reverse dep test */
p = slapt_get_newest_pkg(avail, "glib");
fail_unless(p != NULL);
required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
- fail_unless(required_by->pkg_count == 2);
- fail_unless(strcmp(required_by->pkgs[0]->name, "xmms") == 0);
- fail_unless(strcmp(required_by->pkgs[1]->name, "gtk+") == 0);
- slapt_free_pkg_list(required_by);
+ fail_unless(required_by->size == 2);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[0]))->name, "xmms") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[1]))->name, "gtk+") == 0);
+ slapt_vector_t_free(required_by);
/* glib2 reverse dep test */
p = slapt_get_newest_pkg(avail, "glib2");
fail_unless(p != NULL);
required_by = slapt_is_required_by(rc, avail, installed, pkgs_to_install, pkgs_to_remove, p);
- fail_unless(required_by->pkg_count == 4);
- fail_unless(strcmp(required_by->pkgs[0]->name, "ConsoleKit") == 0);
- fail_unless(strcmp(required_by->pkgs[1]->name, "dbus-glib") == 0);
- fail_unless(strcmp(required_by->pkgs[2]->name, "gslapt") == 0);
- fail_unless(strcmp(required_by->pkgs[3]->name, "scim") == 0);
- slapt_free_pkg_list(required_by);
-
- slapt_free_pkg_list(installed);
- slapt_free_pkg_list(pkgs_to_install);
- slapt_free_pkg_list(pkgs_to_remove);
- slapt_free_pkg_list(avail);
+ fail_unless(required_by->size == 4);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[0]))->name, "ConsoleKit") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[1]))->name, "dbus-glib") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[2]))->name, "gslapt") == 0);
+ fail_unless(strcmp(((slapt_pkg_info_t *)(required_by->items[3]))->name, "scim") == 0);
+ slapt_vector_t_free(required_by);
+
+ slapt_vector_t_free(installed);
+ slapt_vector_t_free(pkgs_to_install);
+ slapt_vector_t_free(pkgs_to_remove);
+ slapt_vector_t_free(avail);
slapt_free_rc_config(rc);
}
END_TEST
@@ -393,7 +347,7 @@ START_TEST(test_cache)
slapt_clean_pkg_dir(rc->working_dir);
/* not easily testable due to timeout
- slapt_pkg_list_t *list = slapt_init_pkg_list();
+ slapt_vector_t *list = slapt_vector_t_init();
slapt_purge_old_cached_pkgs(rc, NULL, list);
*/
@@ -401,18 +355,6 @@ START_TEST(test_cache)
}
END_TEST
-START_TEST(test_error)
-{
- slapt_pkg_err_list_t *list = slapt_init_pkg_err_list();
-
- slapt_add_pkg_err_to_list(list, "gslapt", "Server returned 404");
-
- fail_unless(slapt_search_pkg_err_list(list, "gslapt", "Server returned 404") == 1);
-
- slapt_free_pkg_err_list(list);
-}
-END_TEST
-
START_TEST(test_network)
{
char *cwd = get_current_dir_name();
@@ -424,13 +366,13 @@ START_TEST(test_network)
/* write pkg data to disk
void slapt_write_pkg_data(const char *source_url,FILE *d_file,
- slapt_pkg_list_t *pkgs);
+ slapt_vector_t *pkgs);
*/
/* download the PACKAGES.TXT and CHECKSUMS.md5 files
- slapt_pkg_list_t *slapt_get_pkg_source_packages (const slapt_rc_config *global_config,
+ slapt_vector_t *slapt_get_pkg_source_packages (const slapt_rc_config *global_config,
const char *url);
- slapt_pkg_list_t *slapt_get_pkg_source_patches (const slapt_rc_config *global_config,
+ slapt_vector_t *slapt_get_pkg_source_patches (const slapt_rc_config *global_config,
const char *url);
FILE *slapt_get_pkg_source_checksums (const slapt_rc_config *global_config,
const char *url);
@@ -453,14 +395,12 @@ Suite *packages_test_suite()
tcase_add_test(tc, test_struct_pkg);
tcase_add_test(tc, test_pkg_info);
- tcase_add_test(tc, test_pkg_list);
tcase_add_test(tc, test_pkg_search);
tcase_add_test(tc, test_pkgtool);
tcase_add_test(tc, test_pkg_version);
tcase_add_test(tc, test_version);
tcase_add_test(tc, test_dependency);
tcase_add_test(tc, test_cache);
- tcase_add_test(tc, test_error);
tcase_add_test(tc, test_network);
suite_add_tcase(s, tc);
diff --git a/t/test_transaction.c b/t/test_transaction.c
index 1e0adaa..2f11a27 100644
--- a/t/test_transaction.c
+++ b/t/test_transaction.c
@@ -7,19 +7,19 @@ START_TEST(test_transaction)
fail_if(t == NULL);
slapt_add_install_to_transaction(t, &pkg);
- fail_unless(t->install_pkgs->pkg_count == 1);
+ fail_unless(t->install_pkgs->size == 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(t->remove_pkgs->size == 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);
+ fail_unless(t->exclude_pkgs->size == 1);
slapt_add_upgrade_to_transaction(t, &pkg, &pkg);
/* fail_unless (slapt_search_upgrade_transaction(t, &pkg)); */
@@ -46,9 +46,20 @@ END_TEST
START_TEST(test_transaction_dependencies)
{
- slapt_transaction_t *t = slapt_init_transaction();
slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ FILE *fh = fopen("data/avail_deps", "r");
+ fail_unless(fh != NULL);
+ slapt_vector_t *avail = slapt_parse_packages_txt(fh);
+ fclose(fh);
+
+ fh = fopen("data/installed_deps", "r");
+ fail_unless(fh != NULL);
+ slapt_vector_t *installed = slapt_parse_packages_txt(fh);
+ fclose(fh);
+
+ slapt_transaction_t *t = slapt_init_transaction();
+
/*
add dependencies for package to transaction, returns -1 on error, 0 otherwise
int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
@@ -71,6 +82,19 @@ START_TEST(test_transaction_dependencies)
in the transaction
void slapt_generate_suggestions(slapt_transaction_t *tran);
*/
+ slapt_pkg_info_t *p = slapt_get_newest_pkg(avail, "scim");
+ slapt_pkg_info_t *installed_p = slapt_get_newest_pkg(installed, "scim");
+ (void)installed_p;
+
+ slapt_vector_t *conflicts = slapt_is_conflicted(t, avail, installed, p);
+ if (conflicts->size > 0) {
+ slapt_add_install_to_transaction(t, conflicts->items[0]);
+ slapt_add_deps_to_trans(rc, t, avail, installed, conflicts->items[0]);
+ }
+
+ slapt_add_deps_to_trans(rc, t, avail, installed, p);
+ slapt_add_install_to_transaction(t, p);
+
slapt_generate_suggestions(t);
slapt_free_transaction(t);