aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2007-09-03 00:10:03 +0000
committerJason Woodward2007-09-03 00:10:03 +0000
commit8b93d4b37c0a694af1f95fcd4f22a349903f71ee (patch)
tree52f8ac9adda818034c7fd65a88cbc76fd6f7b052 /src
parent87c0f0d448cef64b830c96742d976506ca4105e9 (diff)
downloadslapt-get-8b93d4b37c0a694af1f95fcd4f22a349903f71ee.tar.gz
bug fix for detecting reverse dependencies when removing packages
Diffstat (limited to 'src')
-rw-r--r--src/action.c32
-rw-r--r--src/package.c40
2 files changed, 44 insertions, 28 deletions
diff --git a/src/action.c b/src/action.c
index 120657e..5610a49 100644
--- a/src/action.c
+++ b/src/action.c
@@ -46,23 +46,24 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
}
for (i = 0; i < action_args->count; ++i) {
+ char *arg = action_args->pkgs[i];
slapt_pkg_info_t *pkg = NULL;
slapt_pkg_info_t *installed_pkg = NULL;
/* Use regex to see if they specified a particular version */
- slapt_execute_regex(pkg_regex,action_args->pkgs[i]);
+ slapt_execute_regex(pkg_regex,arg);
/* If so, parse it out and try to get that version only */
if ( pkg_regex->reg_return == 0 ) {
char *pkg_name,*pkg_version;
pkg_name = strndup(
- action_args->pkgs[i] + pkg_regex->pmatch[1].rm_so,
+ arg + pkg_regex->pmatch[1].rm_so,
pkg_regex->pmatch[1].rm_eo - pkg_regex->pmatch[1].rm_so
);
pkg_version = strndup(
- action_args->pkgs[i] + pkg_regex->pmatch[2].rm_so,
+ arg + pkg_regex->pmatch[2].rm_so,
pkg_regex->pmatch[2].rm_eo - pkg_regex->pmatch[2].rm_so
);
@@ -74,11 +75,11 @@ void slapt_pkg_action_install(const slapt_rc_config *global_config,
/* If regex doesnt match */
if ( pkg_regex->reg_return != 0 || pkg == NULL ) {
- /* make sure there is a package called action_args->pkgs[i] */
- pkg = slapt_get_newest_pkg(avail_pkgs,action_args->pkgs[i]);
+ /* make sure there is a package called arg */
+ pkg = slapt_get_newest_pkg(avail_pkgs,arg);
if ( pkg == NULL ) {
- fprintf(stderr,gettext("No such package: %s\n"),action_args->pkgs[i]);
+ fprintf(stderr,gettext("No such package: %s\n"),arg);
continue;
}
@@ -242,22 +243,23 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
for (i = 0; i < action_args->count; ++i) {
unsigned int c;
struct slapt_pkg_list *deps = NULL;
+ char *arg = action_args->pkgs[i];
slapt_pkg_info_t *pkg = NULL;
/* Use regex to see if they specified a particular version */
- slapt_execute_regex(pkg_regex,action_args->pkgs[i]);
+ slapt_execute_regex(pkg_regex,arg);
/* If so, parse it out and try to get that version only */
if ( pkg_regex->reg_return == 0 ) {
char *pkg_name,*pkg_version;
pkg_name = strndup(
- action_args->pkgs[i] + pkg_regex->pmatch[1].rm_so,
+ arg + pkg_regex->pmatch[1].rm_so,
pkg_regex->pmatch[1].rm_eo - pkg_regex->pmatch[1].rm_so
);
pkg_version = strndup(
- action_args->pkgs[i] + pkg_regex->pmatch[2].rm_so,
+ arg + pkg_regex->pmatch[2].rm_so,
pkg_regex->pmatch[2].rm_eo - pkg_regex->pmatch[2].rm_so
);
@@ -269,11 +271,11 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
/* If regex doesnt match */
if ( pkg_regex->reg_return != 0 || pkg == NULL ) {
- /* make sure there is a package called action_args->pkgs[i] */
- pkg = slapt_get_newest_pkg(installed_pkgs,action_args->pkgs[i]);
+ /* make sure there is a package called arg */
+ pkg = slapt_get_newest_pkg(installed_pkgs,arg);
if ( pkg == NULL ) {
- printf(gettext("%s is not installed.\n"),action_args->pkgs[i]);
+ printf(gettext("%s is not installed.\n"),arg);
continue;
}
@@ -282,10 +284,10 @@ void slapt_pkg_action_remove(const slapt_rc_config *global_config,
deps = slapt_is_required_by(global_config,avail_pkgs,pkg);
for (c = 0; c < deps->pkg_count; ++c) {
+ slapt_pkg_info_t *dep = deps->pkgs[c];
- if ( slapt_get_exact_pkg(installed_pkgs,deps->pkgs[c]->name,
- deps->pkgs[c]->version) != NULL ) {
- slapt_add_remove_to_transaction(tran,deps->pkgs[c]);
+ if ( slapt_get_exact_pkg(installed_pkgs,dep->name, dep->version) != NULL) {
+ slapt_add_remove_to_transaction(tran,dep);
}
}
diff --git a/src/package.c b/src/package.c
index 8b1e87b..45ba82d 100644
--- a/src/package.c
+++ b/src/package.c
@@ -27,7 +27,7 @@ static slapt_pkg_info_t *parse_meta_entry(struct slapt_pkg_list *avail_pkgs,
struct slapt_pkg_list *installed_pkgs,
char *dep_entry);
/* called by slapt_is_required_by */
-static void required_by(struct slapt_pkg_list *avail, const char *pkg_name,
+static void required_by(struct slapt_pkg_list *avail, slapt_pkg_info_t *pkg,
struct slapt_pkg_list *required_by_list);
static char *escape_package_name(slapt_pkg_info_t *pkg);
/* free pkg_version_parts struct */
@@ -1838,8 +1838,7 @@ struct slapt_pkg_list *slapt_is_required_by(const slapt_rc_config *global_config
struct slapt_pkg_list *avail,
slapt_pkg_info_t *pkg)
{
- struct slapt_pkg_list *required_by_list = slapt_init_pkg_list();
- char *escaped_pkg_name = NULL;
+ struct slapt_pkg_list *required_by_list = NULL;
/*
* don't go any further if disable_dep_check is set
@@ -1847,11 +1846,9 @@ struct slapt_pkg_list *slapt_is_required_by(const slapt_rc_config *global_config
if (global_config->disable_dep_check == SLAPT_TRUE)
return required_by_list;
- escaped_pkg_name = escape_package_name(pkg);
+ required_by_list = slapt_init_pkg_list();
- required_by(avail,escaped_pkg_name,required_by_list);
-
- free(escaped_pkg_name);
+ required_by(avail,pkg,required_by_list);
return required_by_list;
}
@@ -1887,31 +1884,48 @@ static char *escape_package_name(slapt_pkg_info_t *pkg)
}
static void required_by(struct slapt_pkg_list *avail,
- const char *pkg_name,
+ slapt_pkg_info_t *pkg,
struct slapt_pkg_list *required_by_list)
{
unsigned int i;
slapt_regex_t *required_by_reg = NULL;
+ char *pkg_name = escape_package_name(pkg);
+ int reg_str_len = strlen(pkg_name) + 2;
+ char *reg = slapt_malloc(sizeof *reg * reg_str_len);
+ /* add word boundary to search */
+ int sprintf_r = sprintf(reg, "\\W%s\\W", pkg_name);
+
+ if (sprintf_r < reg_str_len) {
+ fprintf(stderr,"sprintf error for %s: %d < %d\n", pkg_name, sprintf_r, reg_str_len);
+ exit(EXIT_FAILURE);
+ }
- if ((required_by_reg = slapt_init_regex(pkg_name)) == NULL) {
+ if ((required_by_reg = slapt_init_regex(reg)) == NULL) {
exit(EXIT_FAILURE);
}
+ free(pkg_name);
+ free(reg);
+
for (i = 0; i < avail->pkg_count;i++) {
slapt_pkg_info_t *pkg_ptr = avail->pkgs[i];
if (strcmp(pkg_ptr->required,"") == 0 )
continue;
+ if (strcmp(pkg_ptr->required," ") == 0 )
+ continue;
+ if (strcmp(pkg_ptr->required," ") == 0 )
+ continue;
+ if (strstr(pkg_ptr->required, pkg->name) == NULL)
+ continue;
slapt_execute_regex(required_by_reg,pkg_ptr->required);
if (required_by_reg->reg_return != 0 )
continue;
- if (slapt_get_newest_pkg(required_by_list, pkg_ptr->name) == NULL) {
- char *escaped_pkg_name = escape_package_name(pkg_ptr);
+ if (slapt_get_exact_pkg(required_by_list, pkg_ptr->name, pkg_ptr->version) == NULL) {
slapt_add_pkg_to_pkg_list(required_by_list,pkg_ptr);
- required_by(avail, escaped_pkg_name, required_by_list );
- free(escaped_pkg_name);
+ required_by(avail, pkg_ptr, required_by_list );
}
}