summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2005-05-10 04:53:58 +0000
committerJason Woodward2005-05-10 04:53:58 +0000
commit00be7404a50a67ddaf5351e4518cb159a83e5b20 (patch)
treed8cc19204ae515b07ceca7da6071a802b69e83c8 /src
parentee9beade0dfc447c683e2009e130f49fdda17bf2 (diff)
downloadslapt-get-00be7404a50a67ddaf5351e4518cb159a83e5b20.tar.gz
code formatting updates
Diffstat (limited to 'src')
-rw-r--r--src/action.c1056
-rw-r--r--src/action.h6
-rw-r--r--src/common.c403
-rw-r--r--src/configuration.c400
-rw-r--r--src/curl.c524
-rw-r--r--src/curl.h9
-rw-r--r--src/main.c631
-rw-r--r--src/package.c4305
-rw-r--r--src/package.h27
-rw-r--r--src/transaction.c1477
-rw-r--r--src/transaction.h7
11 files changed, 4582 insertions, 4263 deletions
diff --git a/src/action.c b/src/action.c
index 4fcad86..7fa2a52 100644
--- a/src/action.c
+++ b/src/action.c
@@ -19,602 +19,612 @@
#include <main.h>
/* install pkg */
-void pkg_action_install(const rc_config *global_config,const pkg_action_args_t *action_args){
- unsigned int i;
- transaction_t tran;
- struct pkg_list *installed_pkgs;
- struct pkg_list *avail_pkgs;
- sg_regex pkg_regex;
+void pkg_action_install(const rc_config *global_config,
+ const pkg_action_args_t *action_args)
+{
+ unsigned int i;
+ transaction_t tran;
+ struct pkg_list *installed_pkgs;
+ struct pkg_list *avail_pkgs;
+ sg_regex pkg_regex;
- printf( _("Reading Package Lists... ") );
- installed_pkgs = get_installed_pkgs();
- avail_pkgs = get_available_pkgs();
- if( avail_pkgs == NULL || avail_pkgs->pkg_count == 0 ) exit(1);
- printf( _("Done\n") );
+ printf( _("Reading Package Lists... ") );
+ installed_pkgs = get_installed_pkgs();
+ avail_pkgs = get_available_pkgs();
+ if( avail_pkgs == NULL || avail_pkgs->pkg_count == 0 ) exit(1);
+ printf( _("Done\n") );
- init_transaction(&tran);
+ init_transaction(&tran);
- init_regex(&pkg_regex,PKG_LOG_PATTERN);
+ init_regex(&pkg_regex,PKG_LOG_PATTERN);
- for(i = 0; i < action_args->count; i++){
- pkg_info_t *pkg = NULL;
- pkg_info_t *installed_pkg = NULL;
+ for(i = 0; i < action_args->count; i++) {
+ pkg_info_t *pkg = NULL;
+ pkg_info_t *installed_pkg = NULL;
- /* Use regex to see if they specified a particular version */
- execute_regex(&pkg_regex,action_args->pkgs[i]);
+ /* Use regex to see if they specified a particular version */
+ execute_regex(&pkg_regex,action_args->pkgs[i]);
- /* If so, parse it out and try to get that version only */
- if( pkg_regex.reg_return == 0 ){
- char *pkg_name,*pkg_version;
+ /* If so, parse it out and try to get that version only */
+ if( pkg_regex.reg_return == 0 ) {
+ char *pkg_name,*pkg_version;
- pkg_name = strndup(
- action_args->pkgs[i] + pkg_regex.pmatch[1].rm_so,
- pkg_regex.pmatch[1].rm_eo - pkg_regex.pmatch[1].rm_so
- );
+ pkg_name = strndup(
+ action_args->pkgs[i] + 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,
- pkg_regex.pmatch[2].rm_eo - pkg_regex.pmatch[2].rm_so
- );
+ pkg_version = strndup(
+ action_args->pkgs[i] + pkg_regex.pmatch[2].rm_so,
+ pkg_regex.pmatch[2].rm_eo - pkg_regex.pmatch[2].rm_so
+ );
- pkg = get_exact_pkg(avail_pkgs, pkg_name, pkg_version);
- free(pkg_name);
- free(pkg_version);
+ pkg = get_exact_pkg(avail_pkgs, pkg_name, pkg_version);
+ free(pkg_name);
+ free(pkg_version);
- }
+ }
- /* If regex doesnt match */
- if( pkg_regex.reg_return != 0 || pkg == NULL ){
- /* make sure there is a package called action_args->pkgs[i] */
- pkg = get_newest_pkg(avail_pkgs,action_args->pkgs[i]);
+ /* If regex doesnt match */
+ if( pkg_regex.reg_return != 0 || pkg == NULL ) {
+ /* make sure there is a package called action_args->pkgs[i] */
+ pkg = get_newest_pkg(avail_pkgs,action_args->pkgs[i]);
- if( pkg == NULL ){
- fprintf(stderr,_("No such package: %s\n"),action_args->pkgs[i]);
- continue;
- }
+ if( pkg == NULL ) {
+ fprintf(stderr,_("No such package: %s\n"),action_args->pkgs[i]);
+ continue;
+ }
- }
+ }
- installed_pkg = get_newest_pkg(installed_pkgs,pkg->name);
+ installed_pkg = get_newest_pkg(installed_pkgs,pkg->name);
- /* if it is not already installed, install it */
- if( installed_pkg == NULL ){
+ /* if it is not already installed, install it */
+ if( installed_pkg == NULL ) {
- if( add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,pkg) == 0 ){
- pkg_info_t *conflicted_pkg = NULL;
+ if( add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,pkg) == 0 ) {
+ pkg_info_t *conflicted_pkg = NULL;
- /* if there is a conflict, we schedule the conflict for removal */
- if ( (conflicted_pkg = is_conflicted(&tran,avail_pkgs,installed_pkgs,pkg)) != NULL ){
- add_remove_to_transaction(&tran,conflicted_pkg);
- }
- add_install_to_transaction(&tran,pkg);
+ /* if there is a conflict, we schedule the conflict for removal */
+ if ( (conflicted_pkg = is_conflicted(&tran,avail_pkgs,installed_pkgs,pkg)) != NULL ) {
+ add_remove_to_transaction(&tran,conflicted_pkg);
+ }
+ add_install_to_transaction(&tran,pkg);
- }else{
- add_exclude_to_transaction(&tran,pkg);
- }
+ }else{
+ add_exclude_to_transaction(&tran,pkg);
+ }
- }else{ /* else we upgrade or reinstall */
+ }else{ /* else we upgrade or reinstall */
- /* it is already installed, attempt an upgrade */
- if(
- ((cmp_pkg_versions(installed_pkg->version,pkg->version)) < 0) ||
- (global_config->re_install == TRUE)
- ){
+ /* it is already installed, attempt an upgrade */
+ if(
+ ((cmp_pkg_versions(installed_pkg->version,pkg->version)) < 0) ||
+ (global_config->re_install == TRUE)
+ ) {
- if( add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,pkg) == 0 ){
- pkg_info_t *conflicted_pkg = NULL;
+ if( add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,pkg) == 0 ) {
+ pkg_info_t *conflicted_pkg = NULL;
- if ( (conflicted_pkg = is_conflicted(&tran,avail_pkgs,installed_pkgs,pkg)) != NULL ){
- add_remove_to_transaction(&tran,conflicted_pkg);
- }
- add_upgrade_to_transaction(&tran,installed_pkg,pkg);
+ if ( (conflicted_pkg = is_conflicted(&tran,avail_pkgs,installed_pkgs,pkg)) != NULL ) {
+ add_remove_to_transaction(&tran,conflicted_pkg);
+ }
+ add_upgrade_to_transaction(&tran,installed_pkg,pkg);
- }else{
- add_exclude_to_transaction(&tran,pkg);
- }
+ }else{
+ add_exclude_to_transaction(&tran,pkg);
+ }
- }else{
- printf(_("%s is up to date.\n"),installed_pkg->name);
- }
+ }else{
+ printf(_("%s is up to date.\n"),installed_pkg->name);
+ }
- }
+ }
- }
+ }
- free_pkg_list(installed_pkgs);
- free_pkg_list(avail_pkgs);
+ free_pkg_list(installed_pkgs);
+ free_pkg_list(avail_pkgs);
- free_regex(&pkg_regex);
+ free_regex(&pkg_regex);
- handle_transaction(global_config,&tran);
+ handle_transaction(global_config,&tran);
- free_transaction(&tran);
- return;
+ free_transaction(&tran);
+ return;
}
/* list pkgs */
-void pkg_action_list(const int show){
- struct pkg_list *pkgs = NULL;
- struct pkg_list *installed_pkgs = NULL;
- unsigned int i;
-
- pkgs = get_available_pkgs();
- installed_pkgs = get_installed_pkgs();
-
- if( show == LIST || show == AVAILABLE ){
- for(i = 0; i < pkgs->pkg_count; i++ ){
- /* this should eliminate the printing of updates */
- if( strstr(pkgs->pkgs[i]->description,"no description") == NULL ){
- unsigned int bool_installed = 0;
- char *short_description = gen_short_pkg_description(pkgs->pkgs[i]);
-
- /* is it installed? */
- if( get_exact_pkg(installed_pkgs,pkgs->pkgs[i]->name,pkgs->pkgs[i]->version) != NULL )
- bool_installed = 1;
-
- printf("%s %s [inst=%s]: %s\n",
- pkgs->pkgs[i]->name,
- pkgs->pkgs[i]->version,
- bool_installed == 1
- ? _("yes")
- : _("no"),
- (short_description == NULL) ? "" : short_description
- );
- free(short_description);
- }
- }
- }
- if( show == LIST || show == INSTALLED ){
- for(i = 0; i < installed_pkgs->pkg_count;++i){
- char *short_description = NULL;
-
- if( show == LIST ){
- if( get_exact_pkg(pkgs,
- installed_pkgs->pkgs[i]->name,
- installed_pkgs->pkgs[i]->version
- ) != NULL
- ) continue;
- }
-
- short_description = gen_short_pkg_description(installed_pkgs->pkgs[i]);
-
- printf("%s %s [inst=%s]: %s\n",
- installed_pkgs->pkgs[i]->name,
- installed_pkgs->pkgs[i]->version,
- _("yes"),
- (short_description == NULL) ? "" : short_description
- );
- free(short_description);
-
- }
- }
-
- free_pkg_list(pkgs);
- free_pkg_list(installed_pkgs);
+void pkg_action_list(const int show)
+{
+ struct pkg_list *pkgs = NULL;
+ struct pkg_list *installed_pkgs = NULL;
+ unsigned int i;
+
+ pkgs = get_available_pkgs();
+ installed_pkgs = get_installed_pkgs();
+
+ if( show == LIST || show == AVAILABLE ) {
+ for(i = 0; i < pkgs->pkg_count; i++ ) {
+ /* this should eliminate the printing of updates */
+ if( strstr(pkgs->pkgs[i]->description,"no description") == NULL ) {
+ unsigned int bool_installed = 0;
+ char *short_description = gen_short_pkg_description(pkgs->pkgs[i]);
+
+ /* is it installed? */
+ if( get_exact_pkg(installed_pkgs,pkgs->pkgs[i]->name,pkgs->pkgs[i]->version) != NULL )
+ bool_installed = 1;
+
+ printf("%s %s [inst=%s]: %s\n",
+ pkgs->pkgs[i]->name,
+ pkgs->pkgs[i]->version,
+ bool_installed == 1
+ ? _("yes")
+ : _("no"),
+ (short_description == NULL) ? "" : short_description
+ );
+ free(short_description);
+ }
+ }
+ }
+ if( show == LIST || show == INSTALLED ) {
+ for(i = 0; i < installed_pkgs->pkg_count;++i) {
+ char *short_description = NULL;
+
+ if( show == LIST ) {
+ if( get_exact_pkg(pkgs,
+ installed_pkgs->pkgs[i]->name,
+ installed_pkgs->pkgs[i]->version
+ ) != NULL
+ ) continue;
+ }
+
+ short_description = gen_short_pkg_description(installed_pkgs->pkgs[i]);
+
+ printf("%s %s [inst=%s]: %s\n",
+ installed_pkgs->pkgs[i]->name,
+ installed_pkgs->pkgs[i]->version,
+ _("yes"),
+ (short_description == NULL) ? "" : short_description
+ );
+ free(short_description);
+
+ }
+ }
+
+ free_pkg_list(pkgs);
+ free_pkg_list(installed_pkgs);
}
/* remove/uninstall pkg */
-void pkg_action_remove(const rc_config *global_config,const pkg_action_args_t *action_args){
- unsigned int i;
- struct pkg_list *installed_pkgs;
- struct pkg_list *avail_pkgs;
- sg_regex pkg_regex;
- transaction_t tran;
+void pkg_action_remove(const rc_config *global_config,
+ const pkg_action_args_t *action_args)
+{
+ unsigned int i;
+ struct pkg_list *installed_pkgs;
+ struct pkg_list *avail_pkgs;
+ sg_regex pkg_regex;
+ transaction_t tran;
- installed_pkgs = get_installed_pkgs();
- avail_pkgs = get_available_pkgs();
- init_transaction(&tran);
- init_regex(&pkg_regex,PKG_LOG_PATTERN);
+ installed_pkgs = get_installed_pkgs();
+ avail_pkgs = get_available_pkgs();
+ init_transaction(&tran);
+ init_regex(&pkg_regex,PKG_LOG_PATTERN);
- for(i = 0; i < action_args->count; i++){
- unsigned int c;
- struct pkg_list *deps;
- pkg_info_t *pkg = NULL;
+ for(i = 0; i < action_args->count; i++) {
+ unsigned int c;
+ struct pkg_list *deps;
+ pkg_info_t *pkg = NULL;
- /* Use regex to see if they specified a particular version */
- execute_regex(&pkg_regex,action_args->pkgs[i]);
+ /* Use regex to see if they specified a particular version */
+ execute_regex(&pkg_regex,action_args->pkgs[i]);
- /* If so, parse it out and try to get that version only */
- if( pkg_regex.reg_return == 0 ){
- char *pkg_name,*pkg_version;
+ /* If so, parse it out and try to get that version only */
+ if( pkg_regex.reg_return == 0 ) {
+ char *pkg_name,*pkg_version;
- pkg_name = strndup(
- action_args->pkgs[i] + pkg_regex.pmatch[1].rm_so,
- pkg_regex.pmatch[1].rm_eo - pkg_regex.pmatch[1].rm_so
- );
+ pkg_name = strndup(
+ action_args->pkgs[i] + 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,
- pkg_regex.pmatch[2].rm_eo - pkg_regex.pmatch[2].rm_so
- );
+ pkg_version = strndup(
+ action_args->pkgs[i] + pkg_regex.pmatch[2].rm_so,
+ pkg_regex.pmatch[2].rm_eo - pkg_regex.pmatch[2].rm_so
+ );
- pkg = get_exact_pkg(installed_pkgs, pkg_name, pkg_version);
- free(pkg_name);
- free(pkg_version);
+ pkg = get_exact_pkg(installed_pkgs, pkg_name, pkg_version);
+ free(pkg_name);
+ free(pkg_version);
- }
+ }
- /* If regex doesnt match */
- if( pkg_regex.reg_return != 0 || pkg == NULL ){
- /* make sure there is a package called action_args->pkgs[i] */
- pkg = get_newest_pkg(installed_pkgs,action_args->pkgs[i]);
+ /* If regex doesnt match */
+ if( pkg_regex.reg_return != 0 || pkg == NULL ) {
+ /* make sure there is a package called action_args->pkgs[i] */
+ pkg = get_newest_pkg(installed_pkgs,action_args->pkgs[i]);
- if( pkg == NULL ){
- printf(_("%s is not installed.\n"),action_args->pkgs[i]);
- continue;
- }
+ if( pkg == NULL ) {
+ printf(_("%s is not installed.\n"),action_args->pkgs[i]);
+ continue;
+ }
- }
+ }
- deps = is_required_by(global_config,avail_pkgs,pkg);
+ deps = is_required_by(global_config,avail_pkgs,pkg);
- for(c = 0; c < deps->pkg_count;c++){
+ for(c = 0; c < deps->pkg_count;c++) {
- if( get_exact_pkg(installed_pkgs,deps->pkgs[c]->name,
- deps->pkgs[c]->version) != NULL ){
- add_remove_to_transaction(&tran,deps->pkgs[c]);
- }
+ if( get_exact_pkg(installed_pkgs,deps->pkgs[c]->name,
+ deps->pkgs[c]->version) != NULL ) {
+ add_remove_to_transaction(&tran,deps->pkgs[c]);
+ }
- }
+ }
- free_pkg_list(deps);
+ free_pkg_list(deps);
- add_remove_to_transaction(&tran,pkg);
+ add_remove_to_transaction(&tran,pkg);
- }
+ }
- free_pkg_list(installed_pkgs);
- free_pkg_list(avail_pkgs);
- free_regex(&pkg_regex);
+ free_pkg_list(installed_pkgs);
+ free_pkg_list(avail_pkgs);
+ free_regex(&pkg_regex);
- handle_transaction(global_config,&tran);
+ handle_transaction(global_config,&tran);
- free_transaction(&tran);
+ free_transaction(&tran);
}
/* search for a pkg (support extended POSIX regex) */
-void pkg_action_search(const char *pattern){
- unsigned int i;
- struct pkg_list *pkgs = NULL;
- struct pkg_list *installed_pkgs = NULL;
- struct pkg_list *matches = NULL,*i_matches = NULL;
-
- /* read in pkg data */
- pkgs = get_available_pkgs();
- installed_pkgs = get_installed_pkgs();
-
- matches = search_pkg_list(pkgs,pattern);
- i_matches = search_pkg_list(installed_pkgs,pattern);
-
- for(i = 0; i < matches->pkg_count; ++i){
- char *short_description = gen_short_pkg_description(matches->pkgs[i]);
-
- printf("%s %s [inst=%s]: %s\n",
- matches->pkgs[i]->name,
- matches->pkgs[i]->version,
- ( get_exact_pkg( installed_pkgs,
- matches->pkgs[i]->name,matches->pkgs[i]->version)
- != NULL )
- ? _("yes")
- : _("no"),
- short_description
- );
- free(short_description);
- }
-
- for(i = 0; i < i_matches->pkg_count; ++i){
- char *short_description = NULL;
-
- if( get_exact_pkg(matches,i_matches->pkgs[i]->name,
- i_matches->pkgs[i]->version) != NULL) continue;
-
- short_description = gen_short_pkg_description(i_matches->pkgs[i]);
-
- printf("%s %s [inst=%s]: %s\n",
- i_matches->pkgs[i]->name,
- i_matches->pkgs[i]->version,
- _("yes"),
- short_description
- );
- free(short_description);
- }
-
- free_pkg_list(matches);
- free_pkg_list(i_matches);
- free_pkg_list(pkgs);
- free_pkg_list(installed_pkgs);
-
-}/* end search */
+void pkg_action_search(const char *pattern)
+{
+ unsigned int i;
+ struct pkg_list *pkgs = NULL;
+ struct pkg_list *installed_pkgs = NULL;
+ struct pkg_list *matches = NULL,*i_matches = NULL;
+
+ /* read in pkg data */
+ pkgs = get_available_pkgs();
+ installed_pkgs = get_installed_pkgs();
+
+ matches = search_pkg_list(pkgs,pattern);
+ i_matches = search_pkg_list(installed_pkgs,pattern);
+
+ for(i = 0; i < matches->pkg_count; ++i) {
+ char *short_description = gen_short_pkg_description(matches->pkgs[i]);
+
+ printf("%s %s [inst=%s]: %s\n",
+ matches->pkgs[i]->name,
+ matches->pkgs[i]->version,
+ ( get_exact_pkg( installed_pkgs,
+ matches->pkgs[i]->name,matches->pkgs[i]->version)
+ != NULL )
+ ? _("yes")
+ : _("no"),
+ short_description
+ );
+ free(short_description);
+ }
+
+ for(i = 0; i < i_matches->pkg_count; ++i) {
+ char *short_description = NULL;
+
+ if( get_exact_pkg(matches,i_matches->pkgs[i]->name,
+ i_matches->pkgs[i]->version) != NULL) continue;
+
+ short_description = gen_short_pkg_description(i_matches->pkgs[i]);
+
+ printf("%s %s [inst=%s]: %s\n",
+ i_matches->pkgs[i]->name,
+ i_matches->pkgs[i]->version,
+ _("yes"),
+ short_description
+ );
+ free(short_description);
+ }
+
+ free_pkg_list(matches);
+ free_pkg_list(i_matches);
+ free_pkg_list(pkgs);
+ free_pkg_list(installed_pkgs);
+
+}
/* show the details for a specific package */
-void pkg_action_show(const char *pkg_name){
- struct pkg_list *avail_pkgs;
- struct pkg_list *installed_pkgs;
- sg_regex pkg_regex;
- unsigned int bool_installed = 0;
- pkg_info_t *pkg = NULL;
-
- avail_pkgs = get_available_pkgs();
- installed_pkgs = get_installed_pkgs();
- if( avail_pkgs == NULL || installed_pkgs == NULL ) exit(1);
-
- init_regex(&pkg_regex,PKG_LOG_PATTERN);
-
- /* Use regex to see if they specified a particular version */
- execute_regex(&pkg_regex,pkg_name);
-
- /* If so, parse it out and try to get that version only */
- if( pkg_regex.reg_return == 0 ){
- char *p_name,*p_version;
-
- p_name = strndup(
- pkg_name + pkg_regex.pmatch[1].rm_so,
- pkg_regex.pmatch[1].rm_eo - pkg_regex.pmatch[1].rm_so
- );
-
- p_version = strndup(
- pkg_name + pkg_regex.pmatch[2].rm_so,
- pkg_regex.pmatch[2].rm_eo - pkg_regex.pmatch[2].rm_so
- );
-
- pkg = get_exact_pkg(avail_pkgs, p_name, p_version);
-
- if( pkg == NULL )
- pkg = get_exact_pkg(installed_pkgs,p_name,p_version);
-
- free(p_name);
- free(p_version);
-
- }else{
- pkg = get_newest_pkg(avail_pkgs,pkg_name);
- if( pkg == NULL ) pkg = get_newest_pkg(installed_pkgs,pkg_name);
- }
-
- if( pkg != NULL ){
-
- if( get_exact_pkg(installed_pkgs,pkg->name,pkg->version) != NULL)
- bool_installed = 1;
-
- printf(_("Package Name: %s\n"),pkg->name);
- printf(_("Package Mirror: %s\n"),pkg->mirror);
- printf(_("Package Location: %s\n"),pkg->location);
- printf(_("Package Version: %s\n"),pkg->version);
- printf(_("Package Size: %d K\n"),pkg->size_c);
- printf(_("Package Installed Size: %d K\n"),pkg->size_u);
- printf(_("Package Required: %s\n"),pkg->required);
- printf(_("Package Conflicts: %s\n"),pkg->conflicts);
- printf(_("Package Suggests: %s\n"),pkg->suggests);
- printf(_("Package MD5 Sum: %s\n"),pkg->md5);
- printf(_("Package Description:\n"));
- printf("%s",pkg->description);
- printf(_("Package Installed: %s\n"),
- bool_installed == 1
- ? _("yes")
- : _("no")
- );
-
- }else{
- printf(_("No such package: %s\n"),pkg_name);
- }
-
- free_pkg_list(avail_pkgs);
- free_pkg_list(installed_pkgs);
- free_regex(&pkg_regex);
+void pkg_action_show(const char *pkg_name)
+{
+ struct pkg_list *avail_pkgs;
+ struct pkg_list *installed_pkgs;
+ sg_regex pkg_regex;
+ unsigned int bool_installed = 0;
+ pkg_info_t *pkg = NULL;
+
+ avail_pkgs = get_available_pkgs();
+ installed_pkgs = get_installed_pkgs();
+ if( avail_pkgs == NULL || installed_pkgs == NULL ) exit(1);
+
+ init_regex(&pkg_regex,PKG_LOG_PATTERN);
+
+ /* Use regex to see if they specified a particular version */
+ execute_regex(&pkg_regex,pkg_name);
+
+ /* If so, parse it out and try to get that version only */
+ if( pkg_regex.reg_return == 0 ) {
+ char *p_name,*p_version;
+
+ p_name = strndup(
+ pkg_name + pkg_regex.pmatch[1].rm_so,
+ pkg_regex.pmatch[1].rm_eo - pkg_regex.pmatch[1].rm_so
+ );
+
+ p_version = strndup(
+ pkg_name + pkg_regex.pmatch[2].rm_so,
+ pkg_regex.pmatch[2].rm_eo - pkg_regex.pmatch[2].rm_so
+ );
+
+ pkg = get_exact_pkg(avail_pkgs, p_name, p_version);
+
+ if( pkg == NULL )
+ pkg = get_exact_pkg(installed_pkgs,p_name,p_version);
+
+ free(p_name);
+ free(p_version);
+
+ }else{
+ pkg = get_newest_pkg(avail_pkgs,pkg_name);
+ if( pkg == NULL ) pkg = get_newest_pkg(installed_pkgs,pkg_name);
+ }
+
+ if( pkg != NULL ) {
+
+ if( get_exact_pkg(installed_pkgs,pkg->name,pkg->version) != NULL)
+ bool_installed = 1;
+
+ printf(_("Package Name: %s\n"),pkg->name);
+ printf(_("Package Mirror: %s\n"),pkg->mirror);
+ printf(_("Package Location: %s\n"),pkg->location);
+ printf(_("Package Version: %s\n"),pkg->version);
+ printf(_("Package Size: %d K\n"),pkg->size_c);
+ printf(_("Package Installed Size: %d K\n"),pkg->size_u);
+ printf(_("Package Required: %s\n"),pkg->required);
+ printf(_("Package Conflicts: %s\n"),pkg->conflicts);
+ printf(_("Package Suggests: %s\n"),pkg->suggests);
+ printf(_("Package MD5 Sum: %s\n"),pkg->md5);
+ printf(_("Package Description:\n"));
+ printf("%s",pkg->description);
+ printf(_("Package Installed: %s\n"),
+ bool_installed == 1
+ ? _("yes")
+ : _("no")
+ );
+
+ }else{
+ printf(_("No such package: %s\n"),pkg_name);
+ }
+
+ free_pkg_list(avail_pkgs);
+ free_pkg_list(installed_pkgs);
+ free_regex(&pkg_regex);
}
/* upgrade all installed pkgs with available updates */
-void pkg_action_upgrade_all(const rc_config *global_config){
- unsigned int i;
- struct pkg_list *installed_pkgs;
- struct pkg_list *avail_pkgs;
- transaction_t tran;
-
- printf(_("Reading Package Lists... "));
- installed_pkgs = get_installed_pkgs();
- avail_pkgs = get_available_pkgs();
- if( avail_pkgs == NULL || installed_pkgs == NULL ) exit(1);
- if( avail_pkgs->pkg_count == 0 ) exit(1);
- printf(_("Done\n"));
- init_transaction(&tran);
-
- if( global_config->dist_upgrade == TRUE ){
- struct pkg_list *matches = search_pkg_list(avail_pkgs,SLACK_BASE_SET_REGEX);
-
- for(i = 0; i < matches->pkg_count; i++){
- pkg_info_t *installed_pkg = NULL;
- pkg_info_t *newer_avail_pkg = NULL;
- pkg_info_t *upgrade_pkg = NULL;
-
- installed_pkg = get_newest_pkg(
- installed_pkgs,
- matches->pkgs[i]->name
- );
- newer_avail_pkg = get_newest_pkg(
- avail_pkgs,
- matches->pkgs[i]->name
- );
- /* if there is a newer available version (such as from patches/) use it instead */
- if( cmp_pkg_versions(matches->pkgs[i]->version,newer_avail_pkg->version) < 0 ){
- upgrade_pkg = newer_avail_pkg;
- }else{
- upgrade_pkg = matches->pkgs[i];
- }
-
- /* add to install list if not already installed */
- if( installed_pkg == NULL ){
- if( is_excluded(global_config,upgrade_pkg) == 1 ){
- add_exclude_to_transaction(&tran,upgrade_pkg);
- }else{
-
- /* add install if all deps are good and it doesn't have conflicts */
- if(
- (add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == 0)
- && ( is_conflicted(&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == NULL )
- ){
- add_install_to_transaction(&tran,upgrade_pkg);
- }else{
- /* otherwise exclude */
- add_exclude_to_transaction(&tran,upgrade_pkg);
- }
-
- }
- /* even if it's installed, check to see that the packages are different */
- /* simply running a version comparison won't do it since sometimes the */
- /* arch is the only thing that changes */
- }else if(
- (cmp_pkg_versions(installed_pkg->version,upgrade_pkg->version) <= 0) &&
- strcmp(installed_pkg->version,upgrade_pkg->version) != 0
- ){
-
- if( is_excluded(global_config,upgrade_pkg) == 1 ){
- add_exclude_to_transaction(&tran,upgrade_pkg);
- }else{
- /* if all deps are added and there is no conflicts, add on */
- if(
- (add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == 0)
- && ( is_conflicted(&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == NULL )
- ){
- add_upgrade_to_transaction(&tran,installed_pkg,upgrade_pkg);
- }else{
- /* otherwise exclude */
- add_exclude_to_transaction(&tran,upgrade_pkg);
- }
- }
-
- }
-
- }
-
- free_pkg_list(matches);
-
- /* remove obsolete packages if prompted to */
- if( global_config->remove_obsolete == TRUE ){
- unsigned int r;
-
- for(r = 0; r < installed_pkgs->pkg_count; r++){
-
- /* if we can't find the installed package in our available pkg list, it must be obsolete */
- if( get_newest_pkg(avail_pkgs,installed_pkgs->pkgs[r]->name) == NULL ){
- struct pkg_list *deps;
- unsigned int c;
- /*
- any packages that require this package we are about to remove should be
- scheduled to remove as well
- */
- deps = is_required_by(global_config,avail_pkgs,installed_pkgs->pkgs[r]);
- for(c = 0; c < deps->pkg_count; c++ ){
- if( get_exact_pkg(avail_pkgs,deps->pkgs[c]->name,
- deps->pkgs[c]->version) == NULL ){
- if( is_excluded(global_config,deps->pkgs[c]) != 1 ){
- add_remove_to_transaction(&tran,deps->pkgs[c]);
- }else{
- add_exclude_to_transaction(&tran,deps->pkgs[c]);
- }
- }
- }
- free_pkg_list(deps);
- if( is_excluded(global_config,installed_pkgs->pkgs[r]) != 1 ){
- add_remove_to_transaction(&tran,installed_pkgs->pkgs[r]);
- }else{
- add_exclude_to_transaction(&tran,installed_pkgs->pkgs[r]);
- }
- }
-
- }
-
- }/* end if remove_obsolete */
-
- /* insurance so that all of slapt-get's requirements are also installed */
- add_deps_to_trans(
- global_config,&tran,avail_pkgs,installed_pkgs,
- get_newest_pkg(avail_pkgs,"slapt-get")
- );
-
- }
-
- for(i = 0; i < installed_pkgs->pkg_count;i++){
- pkg_info_t *update_pkg = NULL;
- pkg_info_t *newer_installed_pkg = NULL;
-
- /*
- we need to see if there is another installed
- package that is newer than this one
- */
- if( (newer_installed_pkg = get_newest_pkg(installed_pkgs,installed_pkgs->pkgs[i]->name)) != NULL ){
- if( cmp_pkg_versions(installed_pkgs->pkgs[i]->version,newer_installed_pkg->version) < 0 ) continue;
- }
-
- /* see if we have an available update for the pkg */
- update_pkg = get_newest_pkg(
- avail_pkgs,
- installed_pkgs->pkgs[i]->name
- );
- if( update_pkg != NULL ){
- int cmp_r = 0;
-
- /* if the update has a newer version, attempt to upgrade */
- cmp_r = cmp_pkg_versions(installed_pkgs->pkgs[i]->version,update_pkg->version);
- if(
- /* either it's greater, or we want to reinstall */
- cmp_r < 0 || (global_config->re_install == TRUE) ||
- /* or this is a dist upgrade and the versions are the save except for the arch */
- (
- global_config->dist_upgrade == TRUE &&
- cmp_r == 0 &&
- strcmp(installed_pkgs->pkgs[i]->version,update_pkg->version) != 0
- )
- ){
-
- if( (is_excluded(global_config,update_pkg) == 1)
- || (is_excluded(global_config,installed_pkgs->pkgs[i]) == 1)
- ){
- add_exclude_to_transaction(&tran,update_pkg);
- }else{
- /* if all deps are added and there is no conflicts, add on */
- if(
- (add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,update_pkg) == 0)
- && ( is_conflicted(&tran,avail_pkgs,installed_pkgs,update_pkg) == NULL )
- ){
- add_upgrade_to_transaction(&tran,installed_pkgs->pkgs[i],update_pkg);
- }else{
- /* otherwise exclude */
- add_exclude_to_transaction(&tran,update_pkg);
- }
- }
-
- }
-
- }/* end upgrade pkg found */
-
- }/* end for */
-
- free_pkg_list(installed_pkgs);
- free_pkg_list(avail_pkgs);
-
- handle_transaction(global_config,&tran);
-
- free_transaction(&tran);
+void pkg_action_upgrade_all(const rc_config *global_config)
+{
+ unsigned int i;
+ struct pkg_list *installed_pkgs;
+ struct pkg_list *avail_pkgs;
+ transaction_t tran;
+
+ printf(_("Reading Package Lists... "));
+ installed_pkgs = get_installed_pkgs();
+ avail_pkgs = get_available_pkgs();
+ if( avail_pkgs == NULL || installed_pkgs == NULL ) exit(1);
+ if( avail_pkgs->pkg_count == 0 ) exit(1);
+ printf(_("Done\n"));
+ init_transaction(&tran);
+
+ if( global_config->dist_upgrade == TRUE ) {
+ struct pkg_list *matches = search_pkg_list(avail_pkgs,SLACK_BASE_SET_REGEX);
+
+ for(i = 0; i < matches->pkg_count; i++) {
+ pkg_info_t *installed_pkg = NULL;
+ pkg_info_t *newer_avail_pkg = NULL;
+ pkg_info_t *upgrade_pkg = NULL;
+
+ installed_pkg = get_newest_pkg(
+ installed_pkgs,
+ matches->pkgs[i]->name
+ );
+ newer_avail_pkg = get_newest_pkg(
+ avail_pkgs,
+ matches->pkgs[i]->name
+ );
+ /* if there is a newer available version (such as from patches/) use it instead */
+ if( cmp_pkg_versions(matches->pkgs[i]->version,newer_avail_pkg->version) < 0 ) {
+ upgrade_pkg = newer_avail_pkg;
+ }else{
+ upgrade_pkg = matches->pkgs[i];
+ }
+
+ /* add to install list if not already installed */
+ if( installed_pkg == NULL ) {
+ if( is_excluded(global_config,upgrade_pkg) == 1 ) {
+ add_exclude_to_transaction(&tran,upgrade_pkg);
+ }else{
+
+ /* add install if all deps are good and it doesn't have conflicts */
+ if(
+ (add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == 0)
+ && ( is_conflicted(&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == NULL )
+ ) {
+ add_install_to_transaction(&tran,upgrade_pkg);
+ }else{
+ /* otherwise exclude */
+ add_exclude_to_transaction(&tran,upgrade_pkg);
+ }
+
+ }
+ /* even if it's installed, check to see that the packages are different */
+ /* simply running a version comparison won't do it since sometimes the */
+ /* arch is the only thing that changes */
+ }else if(
+ (cmp_pkg_versions(installed_pkg->version,upgrade_pkg->version) <= 0) &&
+ strcmp(installed_pkg->version,upgrade_pkg->version) != 0
+ ) {
+
+ if( is_excluded(global_config,upgrade_pkg) == 1 ) {
+ add_exclude_to_transaction(&tran,upgrade_pkg);
+ }else{
+ /* if all deps are added and there is no conflicts, add on */
+ if(
+ (add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == 0)
+ && ( is_conflicted(&tran,avail_pkgs,installed_pkgs,upgrade_pkg) == NULL )
+ ) {
+ add_upgrade_to_transaction(&tran,installed_pkg,upgrade_pkg);
+ }else{
+ /* otherwise exclude */
+ add_exclude_to_transaction(&tran,upgrade_pkg);
+ }
+ }
+
+ }
+
+ }
+
+ free_pkg_list(matches);
+
+ /* remove obsolete packages if prompted to */
+ if( global_config->remove_obsolete == TRUE ) {
+ unsigned int r;
+
+ for(r = 0; r < installed_pkgs->pkg_count; r++) {
+
+ /* if we can't find the installed package in our available pkg list, it must be obsolete */
+ if( get_newest_pkg(avail_pkgs,installed_pkgs->pkgs[r]->name) == NULL ) {
+ struct pkg_list *deps;
+ unsigned int c;
+ /*
+ any packages that require this package we are about to remove should be
+ scheduled to remove as well
+ */
+ deps = is_required_by(global_config,avail_pkgs,installed_pkgs->pkgs[r]);
+ for(c = 0; c < deps->pkg_count; c++ ) {
+ if( get_exact_pkg(avail_pkgs,deps->pkgs[c]->name,
+ deps->pkgs[c]->version) == NULL ) {
+ if( is_excluded(global_config,deps->pkgs[c]) != 1 ) {
+ add_remove_to_transaction(&tran,deps->pkgs[c]);
+ }else{
+ add_exclude_to_transaction(&tran,deps->pkgs[c]);
+ }
+ }
+ }
+ free_pkg_list(deps);
+ if( is_excluded(global_config,installed_pkgs->pkgs[r]) != 1 ) {
+ add_remove_to_transaction(&tran,installed_pkgs->pkgs[r]);
+ }else{
+ add_exclude_to_transaction(&tran,installed_pkgs->pkgs[r]);
+ }
+ }
+
+ }
+
+ }/* end if remove_obsolete */
+
+ /* insurance so that all of slapt-get's requirements are also installed */
+ add_deps_to_trans(
+ global_config,&tran,avail_pkgs,installed_pkgs,
+ get_newest_pkg(avail_pkgs,"slapt-get")
+ );
+
+ }
+
+ for(i = 0; i < installed_pkgs->pkg_count;i++) {
+ pkg_info_t *update_pkg = NULL;
+ pkg_info_t *newer_installed_pkg = NULL;
+
+ /*
+ we need to see if there is another installed
+ package that is newer than this one
+ */
+ if( (newer_installed_pkg = get_newest_pkg(installed_pkgs,installed_pkgs->pkgs[i]->name)) != NULL ) {
+ if( cmp_pkg_versions(installed_pkgs->pkgs[i]->version,newer_installed_pkg->version) < 0 ) continue;
+ }
+
+ /* see if we have an available update for the pkg */
+ update_pkg = get_newest_pkg(
+ avail_pkgs,
+ installed_pkgs->pkgs[i]->name
+ );
+ if( update_pkg != NULL ) {
+ int cmp_r = 0;
+
+ /* if the update has a newer version, attempt to upgrade */
+ cmp_r = cmp_pkg_versions(installed_pkgs->pkgs[i]->version,update_pkg->version);
+ if(
+ /* either it's greater, or we want to reinstall */
+ cmp_r < 0 || (global_config->re_install == TRUE) ||
+ /* or this is a dist upgrade and the versions are the save except for the arch */
+ (
+ global_config->dist_upgrade == TRUE &&
+ cmp_r == 0 &&
+ strcmp(installed_pkgs->pkgs[i]->version,update_pkg->version) != 0
+ )
+ ) {
+
+ if( (is_excluded(global_config,update_pkg) == 1)
+ || (is_excluded(global_config,installed_pkgs->pkgs[i]) == 1)
+ ) {
+ add_exclude_to_transaction(&tran,update_pkg);
+ }else{
+ /* if all deps are added and there is no conflicts, add on */
+ if(
+ (add_deps_to_trans(global_config,&tran,avail_pkgs,installed_pkgs,update_pkg) == 0)
+ && ( is_conflicted(&tran,avail_pkgs,installed_pkgs,update_pkg) == NULL )
+ ) {
+ add_upgrade_to_transaction(&tran,installed_pkgs->pkgs[i],update_pkg);
+ }else{
+ /* otherwise exclude */
+ add_exclude_to_transaction(&tran,update_pkg);
+ }
+ }
+
+ }
+
+ }/* end upgrade pkg found */
+
+ }/* end for */
+
+ free_pkg_list(installed_pkgs);
+ free_pkg_list(avail_pkgs);
+
+ handle_transaction(global_config,&tran);
+
+ free_transaction(&tran);
}
-pkg_action_args_t *init_pkg_action_args(int arg_count){
- pkg_action_args_t *paa;
+pkg_action_args_t *init_pkg_action_args(int arg_count)
+{
+ pkg_action_args_t *paa;
- paa = slapt_malloc( sizeof *paa );
- paa->pkgs = slapt_malloc( sizeof *paa->pkgs * arg_count );
- paa->count = 0;
+ paa = slapt_malloc( sizeof *paa );
+ paa->pkgs = slapt_malloc( sizeof *paa->pkgs * arg_count );
+ paa->count = 0;
- return paa;
+ return paa;
}
-void free_pkg_action_args(pkg_action_args_t *paa){
- unsigned int i;
+void free_pkg_action_args(pkg_action_args_t *paa)
+{
+ unsigned int i;
- for(i = 0; i < paa->count; i++){
- free(paa->pkgs[i]);
- }
+ for(i = 0; i < paa->count; i++) {
+ free(paa->pkgs[i]);
+ }
- free(paa->pkgs);
- free(paa);
+ free(paa->pkgs);
+ free(paa);
}
diff --git a/src/action.h b/src/action.h
index 79e8f7d..baa02ec 100644
--- a/src/action.h
+++ b/src/action.h
@@ -24,9 +24,11 @@ typedef struct {
pkg_action_args_t *init_pkg_action_args(int arg_count);
void free_pkg_action_args(pkg_action_args_t *paa);
-void pkg_action_install(const rc_config *global_config,const pkg_action_args_t *action_args);
+void pkg_action_install(const rc_config *global_config,
+ const pkg_action_args_t *action_args);
void pkg_action_list(const int show);
-void pkg_action_remove(const rc_config *global_config,const pkg_action_args_t *action_args);
+void pkg_action_remove(const rc_config *global_config,
+ const pkg_action_args_t *action_args);
void pkg_action_search(const char *pattern);
void pkg_action_show(const char *pkg_name);
void pkg_action_upgrade_all(const rc_config *global_config);
diff --git a/src/common.c b/src/common.c
index d7f5a2d..128e8d2 100644
--- a/src/common.c
+++ b/src/common.c
@@ -19,235 +19,248 @@
#include "main.h"
-FILE *open_file(const char *file_name,const char *mode){
- FILE *fh = NULL;
- if( (fh = fopen(file_name,mode)) == NULL ){
- fprintf(stderr,_("Failed to open %s\n"),file_name);
- if( errno ){
- perror(file_name);
- }
- return NULL;
- }
- return fh;
+FILE *open_file(const char *file_name,const char *mode)
+{
+ FILE *fh = NULL;
+ if( (fh = fopen(file_name,mode)) == NULL ) {
+ fprintf(stderr,_("Failed to open %s\n"),file_name);
+ if( errno ) {
+ perror(file_name);
+ }
+ return NULL;
+ }
+ return fh;
}
/* initialize regex structure and compilie the regular expression */
-int init_regex(sg_regex *regex_t, const char *regex_string){
-
- regex_t->nmatch = MAX_REGEX_PARTS;
-
- /* compile our regex */
- regex_t->reg_return = regcomp(&regex_t->regex, regex_string, REG_EXTENDED|REG_NEWLINE|REG_ICASE);
- if( regex_t->reg_return != 0 ){
- size_t regerror_size;
- char errbuf[1024];
- size_t errbuf_size = 1024;
- fprintf(stderr, _("Failed to compile regex\n"));
-
- if( (regerror_size = regerror(regex_t->reg_return, &regex_t->regex,errbuf,errbuf_size)) ){
- printf(_("Regex Error: %s\n"),errbuf);
- }
- return -1;
- }
-
- return 0;
+int init_regex(sg_regex *regex_t, const char *regex_string)
+{
+
+ regex_t->nmatch = MAX_REGEX_PARTS;
+
+ /* compile our regex */
+ regex_t->reg_return = regcomp(&regex_t->regex, regex_string,
+ REG_EXTENDED|REG_NEWLINE|REG_ICASE);
+ if( regex_t->reg_return != 0 ) {
+ size_t regerror_size;
+ char errbuf[1024];
+ size_t errbuf_size = 1024;
+ fprintf(stderr, _("Failed to compile regex\n"));
+
+ if( (regerror_size =
+ regerror(regex_t->reg_return, &regex_t->regex,errbuf,errbuf_size)) ) {
+ printf(_("Regex Error: %s\n"),errbuf);
+ }
+ return -1;
+ }
+
+ return 0;
}
/*
- execute the regular expression and set the return code
- in the passed in structure
+ execute the regular expression and set the return code
+ in the passed in structure
*/
-void execute_regex(sg_regex *regex_t,const char *string){
- regex_t->reg_return = regexec(&regex_t->regex, string, regex_t->nmatch,regex_t->pmatch,0);
+void execute_regex(sg_regex *regex_t,const char *string)
+{
+ regex_t->reg_return = regexec(&regex_t->regex, string,
+ regex_t->nmatch,regex_t->pmatch,0);
}
-void free_regex(sg_regex *regex_t){
- regfree(&regex_t->regex);
+void free_regex(sg_regex *regex_t)
+{
+ regfree(&regex_t->regex);
}
-void gen_md5_sum_of_file(FILE *f,char *result_sum){
- EVP_MD_CTX mdctx;
- const EVP_MD *md;
- unsigned char md_value[EVP_MAX_MD_SIZE];
- unsigned int md_len = 0, i;
- ssize_t getline_read;
- size_t getline_size;
- char *result_sum_tmp = NULL;
- char *getline_buffer = NULL;
+void gen_md5_sum_of_file(FILE *f,char *result_sum)
+{
+ EVP_MD_CTX mdctx;
+ const EVP_MD *md;
+ unsigned char md_value[EVP_MAX_MD_SIZE];
+ unsigned int md_len = 0, i;
+ ssize_t getline_read;
+ size_t getline_size;
+ char *result_sum_tmp = NULL;
+ char *getline_buffer = NULL;
- md = EVP_md5();
+ md = EVP_md5();
- EVP_MD_CTX_init(&mdctx);
- EVP_DigestInit_ex(&mdctx, md, NULL);
+ EVP_MD_CTX_init(&mdctx);
+ EVP_DigestInit_ex(&mdctx, md, NULL);
- rewind(f);
+ rewind(f);
- while( (getline_read = getline(&getline_buffer, &getline_size, f)) != EOF )
- EVP_DigestUpdate(&mdctx, getline_buffer, getline_read);
+ while( (getline_read = getline(&getline_buffer, &getline_size, f)) != EOF )
+ EVP_DigestUpdate(&mdctx, getline_buffer, getline_read);
- free(getline_buffer);
+ free(getline_buffer);
- EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
- EVP_MD_CTX_cleanup(&mdctx);
+ EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
+ EVP_MD_CTX_cleanup(&mdctx);
- result_sum[0] = '\0';
+ result_sum[0] = '\0';
- for(i = 0; i < md_len; i++){
- char *p = slapt_malloc( sizeof *p * 3 );
+ for(i = 0; i < md_len; i++) {
+ char *p = slapt_malloc( sizeof *p * 3 );
- if( snprintf(p,3,"%02x",md_value[i]) > 0 ){
+ if( snprintf(p,3,"%02x",md_value[i]) > 0 ) {
- if( (result_sum_tmp = strncat(result_sum,p,3)) != NULL )
- result_sum = result_sum_tmp;
+ if( (result_sum_tmp = strncat(result_sum,p,3)) != NULL )
+ result_sum = result_sum_tmp;
- }
+ }
- free(p);
- }
+ free(p);
+ }
}
/* recursively create dirs */
-void create_dir_structure(const char *dir_name){
- char *cwd = NULL;
- int position = 0,len = 0;
-
- cwd = getcwd(NULL,0);
- if( cwd == NULL ){
- fprintf(stderr,_("Failed to get cwd\n"));
- return;
- }else{
- #if DEBUG == 1
- fprintf(stderr,_("\tCurrent working directory: %s\n"),cwd);
- #endif
- }
-
- len = strlen(dir_name);
- while( position < len ){
-
- char *pointer = NULL;
- char *dir_name_buffer = NULL;
-
- /* if no more directory delim, then this must be last dir */
- if( strstr(dir_name + position,"/" ) == NULL ){
-
- dir_name_buffer = strndup(
- dir_name + position,
- strlen(dir_name + position)
- );
-
- if( strcmp(dir_name_buffer,".") != 0 ){
- if( (mkdir(dir_name_buffer,0755)) == -1){
- #if DEBUG == 1
- fprintf(stderr,_("Failed to mkdir: %s\n"),dir_name_buffer);
- #endif
- }else{
- #if DEBUG == 1
- fprintf(stderr,_("\tCreated directory: %s\n"),dir_name_buffer);
- #endif
- }
- if( (chdir(dir_name_buffer)) == -1 ){
- fprintf(stderr,_("Failed to chdir to %s\n"),dir_name_buffer);
- return;
- }else{
- #if DEBUG == 1
- fprintf(stderr,_("\tchdir into %s\n"),dir_name_buffer);
- #endif
- }
- }/* don't create . */
-
- free(dir_name_buffer);
- break;
- }else{
- if( dir_name[position] == '/' ){
- /* move on ahead */
- ++position;
- }else{
-
- /* figure our dir name and mk it */
- pointer = strchr(dir_name + position,'/');
- dir_name_buffer = strndup(
- dir_name + position,
- strlen(dir_name + position) - strlen(pointer)
- );
-
- if( strcmp(dir_name_buffer,".") != 0 ){
- if( (mkdir(dir_name_buffer,0755)) == -1 ){
- #if DEBUG == 1
- fprintf(stderr,_("Failed to mkdir: %s\n"),dir_name_buffer);
- #endif
- }
- if( (chdir(dir_name_buffer)) == -1 ){
- fprintf(stderr,_("Failed to chdir to %s\n"),dir_name_buffer);
- free(dir_name_buffer);
- return;
- }
- } /* don't create . */
-
- free(dir_name_buffer);
- position += (strlen(dir_name + position) - strlen(pointer));
- }
- }
- }/* end while */
-
- if( (chdir(cwd)) == -1 ){
- fprintf(stderr,_("Failed to chdir to %s\n"),cwd);
- return;
- }
-
- free(cwd);
+void create_dir_structure(const char *dir_name)
+{
+ char *cwd = NULL;
+ int position = 0,len = 0;
+
+ cwd = getcwd(NULL,0);
+ if( cwd == NULL ) {
+ fprintf(stderr,_("Failed to get cwd\n"));
+ return;
+ }else{
+ #if DEBUG == 1
+ fprintf(stderr,_("\tCurrent working directory: %s\n"),cwd);
+ #endif
+ }
+
+ len = strlen(dir_name);
+ while( position < len ) {
+
+ char *pointer = NULL;
+ char *dir_name_buffer = NULL;
+
+ /* if no more directory delim, then this must be last dir */
+ if( strstr(dir_name + position,"/" ) == NULL ) {
+
+ dir_name_buffer = strndup(
+ dir_name + position,
+ strlen(dir_name + position)
+ );
+
+ if( strcmp(dir_name_buffer,".") != 0 ) {
+ if( (mkdir(dir_name_buffer,0755)) == -1) {
+ #if DEBUG == 1
+ fprintf(stderr,_("Failed to mkdir: %s\n"),dir_name_buffer);
+ #endif
+ }else{
+ #if DEBUG == 1
+ fprintf(stderr,_("\tCreated directory: %s\n"),dir_name_buffer);
+ #endif
+ }
+ if( (chdir(dir_name_buffer)) == -1 ) {
+ fprintf(stderr,_("Failed to chdir to %s\n"),dir_name_buffer);
+ return;
+ }else{
+ #if DEBUG == 1
+ fprintf(stderr,_("\tchdir into %s\n"),dir_name_buffer);
+ #endif
+ }
+ }/* don't create . */
+
+ free(dir_name_buffer);
+ break;
+ }else{
+ if( dir_name[position] == '/' ) {
+ /* move on ahead */
+ ++position;
+ }else{
+
+ /* figure our dir name and mk it */
+ pointer = strchr(dir_name + position,'/');
+ dir_name_buffer = strndup(
+ dir_name + position,
+ strlen(dir_name + position) - strlen(pointer)
+ );
+
+ if( strcmp(dir_name_buffer,".") != 0 ) {
+ if( (mkdir(dir_name_buffer,0755)) == -1 ) {
+ #if DEBUG == 1
+ fprintf(stderr,_("Failed to mkdir: %s\n"),dir_name_buffer);
+ #endif
+ }
+ if( (chdir(dir_name_buffer)) == -1 ) {
+ fprintf(stderr,_("Failed to chdir to %s\n"),dir_name_buffer);
+ free(dir_name_buffer);
+ return;
+ }
+ } /* don't create . */
+
+ free(dir_name_buffer);
+ position += (strlen(dir_name + position) - strlen(pointer));
+ }
+ }
+ }/* end while */
+
+ if( (chdir(cwd)) == -1 ) {
+ fprintf(stderr,_("Failed to chdir to %s\n"),cwd);
+ return;
+ }
+
+ free(cwd);
}
-int ask_yes_no(const char *format, ...){
- char prompt_answer[10];
- va_list arg_list;
-
- va_start(arg_list, format);
- vprintf(format, arg_list);
- va_end(arg_list);
-
- fgets(prompt_answer,10,stdin);
- if( tolower(prompt_answer[0]) == 'y' )
- return 1;
- if( tolower(prompt_answer[0]) == 'n' )
- return 0;
- return -1;
+int ask_yes_no(const char *format, ...)
+{
+ char prompt_answer[10];
+ va_list arg_list;
+
+ va_start(arg_list, format);
+ vprintf(format, arg_list);
+ va_end(arg_list);
+
+ fgets(prompt_answer,10,stdin);
+ if( tolower(prompt_answer[0]) == 'y' )
+ return 1;
+ if( tolower(prompt_answer[0]) == 'n' )
+ return 0;
+ return -1;
}
-char *str_replace_chr(const char *string,const char find, const char replace){
- unsigned int i,len = 0;
- char *clean = slapt_calloc( strlen(string) + 1, sizeof *clean);;
-
- len = strlen(string);
- for(i = 0;i < len; ++i){
- if(string[i] == find ){
- clean[i] = replace;
- }else{
- clean[i] = string[i];
- }
- }
- clean[ strlen(string) ] = '\0';
-
- return clean;
+char *str_replace_chr(const char *string,const char find, const char replace)
+{
+ unsigned int i,len = 0;
+ char *clean = slapt_calloc( strlen(string) + 1, sizeof *clean);;
+
+ len = strlen(string);
+ for(i = 0;i < len; ++i) {
+ if(string[i] == find ) {
+ clean[i] = replace;
+ }else{
+ clean[i] = string[i];
+ }
+ }
+ clean[ strlen(string) ] = '\0';
+
+ return clean;
}
-__inline void *slapt_malloc(size_t s){
- void *p;
- if( ! (p = malloc(s)) ){
- fprintf(stderr,_("Failed to malloc\n"));
- if( errno ) perror("malloc");
- exit(1);
- }
- return p;
+__inline void *slapt_malloc(size_t s)
+{
+ void *p;
+ if( ! (p = malloc(s)) ) {
+ fprintf(stderr,_("Failed to malloc\n"));
+ if( errno ) perror("malloc");
+ exit(1);
+ }
+ return p;
}
-__inline void *slapt_calloc(size_t n,size_t s){
- void *p;
- if( ! (p = calloc(n,s)) ){
- fprintf(stderr,_("Failed to calloc\n"));
- if( errno ) perror("calloc");
- exit(1);
- }
- return p;
+__inline void *slapt_calloc(size_t n,size_t s)
+{
+ void *p;
+ if( ! (p = calloc(n,s)) ) {
+ fprintf(stderr,_("Failed to calloc\n"));
+ if( errno ) perror("calloc");
+ exit(1);
+ }
+ return p;
}
diff --git a/src/configuration.c b/src/configuration.c
index b65e614..473a50f 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -21,237 +21,255 @@
static struct exclude_list *parse_exclude(char *line);
-rc_config *read_rc_config(const char *file_name){
- FILE *rc = NULL;
- rc_config *global_config;
- char *getline_buffer = NULL;
- size_t gb_length = 0;
- ssize_t g_size;
-
- global_config = slapt_malloc( sizeof *global_config );
- /* initialize */
- global_config->download_only = FALSE;
- global_config->simulate = FALSE;
- global_config->ignore_excludes = FALSE;
- global_config->no_md5_check = FALSE;
- global_config->dist_upgrade = FALSE;
- global_config->ignore_dep = FALSE;
- global_config->disable_dep_check = FALSE;
- global_config->print_uris = FALSE;
- global_config->dl_stats = FALSE;
- global_config->no_prompt = FALSE;
- global_config->re_install = FALSE;
- global_config->exclude_list = NULL;
- global_config->working_dir[0] = '\0';
- global_config->remove_obsolete = FALSE;
- global_config->progress_cb = NULL;
- global_config->sources = slapt_malloc(sizeof *global_config->sources );
- global_config->sources->url = slapt_malloc(sizeof *global_config->sources->url );
- global_config->sources->count = 0;
-
- rc = open_file(file_name,"r");
- if( rc == NULL ) exit(1);
-
- while( (g_size = getline(&getline_buffer,&gb_length,rc) ) != EOF ){
- getline_buffer[g_size - 1] = '\0';
-
- /* check to see if it has our key and value seperated by our token */
- /* and extract them */
-
- if( getline_buffer[0] == '#' ){
- continue;
- }
-
- if( strstr(getline_buffer,SOURCE_TOKEN) != NULL ){ /* SOURCE URL */
-
- if( strlen(getline_buffer) > strlen(SOURCE_TOKEN) )
- add_source(global_config->sources,getline_buffer + strlen(SOURCE_TOKEN));
-
- } else if( strstr(getline_buffer,WORKINGDIR_TOKEN) != NULL ){ /* WORKING DIR */
-
- if( strlen(getline_buffer) > strlen(WORKINGDIR_TOKEN) ){
- strncpy(
- global_config->working_dir,
- getline_buffer + strlen(WORKINGDIR_TOKEN),
- (strlen(getline_buffer) - strlen(WORKINGDIR_TOKEN))
- );
- global_config->working_dir[
- (strlen(getline_buffer) - strlen(WORKINGDIR_TOKEN))
- ] = '\0';
- }
-
- }else if( strstr(getline_buffer,EXCLUDE_TOKEN) != NULL ){ /* exclude list */
- global_config->exclude_list = parse_exclude(getline_buffer);
- }/* end if/else if */
-
- }/* end while */
- fclose(rc);
- if( getline_buffer ) free(getline_buffer);
-
- if( strcmp(global_config->working_dir,"") == 0 ){
- fprintf(stderr,_("WORKINGDIR directive not set within %s.\n"),file_name);
- return NULL;
- }
- if( global_config->exclude_list == NULL ){
- /* at least initialize */
- global_config->exclude_list = slapt_malloc( sizeof *global_config->exclude_list );
- global_config->exclude_list->excludes = slapt_malloc( sizeof *global_config->exclude_list->excludes );
- global_config->exclude_list->count = 0;
- }
- if( global_config->sources->count == 0 ){
- fprintf(stderr,_("SOURCE directive not set within %s.\n"),file_name);
- return NULL;
- }
-
- return global_config;
+rc_config *read_rc_config(const char *file_name)
+{
+ FILE *rc = NULL;
+ rc_config *global_config;
+ char *getline_buffer = NULL;
+ size_t gb_length = 0;
+ ssize_t g_size;
+
+ global_config = slapt_malloc( sizeof *global_config );
+ /* initialize */
+ global_config->download_only = FALSE;
+ global_config->simulate = FALSE;
+ global_config->ignore_excludes = FALSE;
+ global_config->no_md5_check = FALSE;
+ global_config->dist_upgrade = FALSE;
+ global_config->ignore_dep = FALSE;
+ global_config->disable_dep_check = FALSE;
+ global_config->print_uris = FALSE;
+ global_config->dl_stats = FALSE;
+ global_config->no_prompt = FALSE;
+ global_config->re_install = FALSE;
+ global_config->exclude_list = NULL;
+ global_config->working_dir[0] = '\0';
+ global_config->remove_obsolete = FALSE;
+ global_config->progress_cb = NULL;
+ global_config->sources = slapt_malloc(sizeof *global_config->sources );
+ global_config->sources->url =
+ slapt_malloc(sizeof *global_config->sources->url );
+ global_config->sources->count = 0;
+
+ rc = open_file(file_name,"r");
+ if( rc == NULL ) exit(1);
+
+ while( (g_size = getline(&getline_buffer,&gb_length,rc) ) != EOF ) {
+ getline_buffer[g_size - 1] = '\0';
+
+ /* check to see if it has our key and value seperated by our token */
+ /* and extract them */
+
+ if( getline_buffer[0] == '#' ) {
+ continue;
+ }
+
+ if( strstr(getline_buffer,SOURCE_TOKEN) != NULL ) {
+ /* SOURCE URL */
+
+ if( strlen(getline_buffer) > strlen(SOURCE_TOKEN) ) {
+ add_source(global_config->sources,getline_buffer +
+ strlen(SOURCE_TOKEN));
+ }
+
+ } else if( strstr(getline_buffer,WORKINGDIR_TOKEN) != NULL ) {
+ /* WORKING DIR */
+
+ if( strlen(getline_buffer) > strlen(WORKINGDIR_TOKEN) ) {
+ strncpy(
+ global_config->working_dir,
+ getline_buffer + strlen(WORKINGDIR_TOKEN),
+ (strlen(getline_buffer) - strlen(WORKINGDIR_TOKEN))
+ );
+ global_config->working_dir[
+ (strlen(getline_buffer) - strlen(WORKINGDIR_TOKEN))
+ ] = '\0';
+ }
+
+ }else if( strstr(getline_buffer,EXCLUDE_TOKEN) != NULL ) {
+ /* exclude list */
+ global_config->exclude_list = parse_exclude(getline_buffer);
+ }
+
+ }
+
+ fclose(rc);
+ if( getline_buffer ) free(getline_buffer);
+
+ if( strcmp(global_config->working_dir,"") == 0 ) {
+ fprintf(stderr,_("WORKINGDIR directive not set within %s.\n"),file_name);
+ return NULL;
+ }
+ if( global_config->exclude_list == NULL ) {
+ /* at least initialize */
+ global_config->exclude_list =
+ slapt_malloc( sizeof *global_config->exclude_list );
+ global_config->exclude_list->excludes =
+ slapt_malloc( sizeof *global_config->exclude_list->excludes );
+ global_config->exclude_list->count = 0;
+ }
+ if( global_config->sources->count == 0 ) {
+ fprintf(stderr,_("SOURCE directive not set within %s.\n"),file_name);
+ return NULL;
+ }
+
+ return global_config;
}
-void working_dir_init(const rc_config *global_config){
- DIR *working_dir;
-
- if( (working_dir = opendir(global_config->working_dir)) == NULL ){
- if( mkdir(global_config->working_dir,
- S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) == -1
- ){
- printf(_("Failed to build working directory [%s]\n"),global_config->working_dir);
- if( errno ) perror(global_config->working_dir);
- exit(1);
- }
- }
- closedir(working_dir);
-
- if( access(global_config->working_dir,W_OK) == -1 ){
- if( errno ) perror(global_config->working_dir);
- fprintf(stderr,_("Please update permissions on %s or run with appropriate privileges\n"),
- global_config->working_dir);
- exit(1);
- }
-
- return;
+void working_dir_init(const rc_config *global_config)
+{
+ DIR *working_dir;
+
+ if( (working_dir = opendir(global_config->working_dir)) == NULL ) {
+ if( mkdir(global_config->working_dir,
+ S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) == -1
+ ) {
+ printf(_("Failed to build working directory [%s]\n"),
+ global_config->working_dir);
+ if( errno ) perror(global_config->working_dir);
+ exit(1);
+ }
+ }
+ closedir(working_dir);
+
+ if( access(global_config->working_dir,W_OK) == -1 ) {
+ if( errno ) perror(global_config->working_dir);
+ fprintf(stderr,
+ _("Please update permissions on %s or run with appropriate privileges\n"),
+ global_config->working_dir);
+ exit(1);
+ }
+
+ return;
}
-void free_rc_config(rc_config *global_config){
- unsigned int i;
-
- for(i = 0; i < global_config->exclude_list->count; ++i){
- free(global_config->exclude_list->excludes[i]);
- }
- free(global_config->exclude_list->excludes);
- free(global_config->exclude_list);
+void free_rc_config(rc_config *global_config)
+{
+ unsigned int i;
+
+ for(i = 0; i < global_config->exclude_list->count; ++i) {
+ free(global_config->exclude_list->excludes[i]);
+ }
+ free(global_config->exclude_list->excludes);
+ free(global_config->exclude_list);
- for(i = 0; i < global_config->sources->count; ++i){
- free(global_config->sources->url[i]);
- }
- free(global_config->sources->url);
- free(global_config->sources);
+ for(i = 0; i < global_config->sources->count; ++i) {
+ free(global_config->sources->url[i]);
+ }
+ free(global_config->sources->url);
+ free(global_config->sources);
- free(global_config);
+ free(global_config);
}
-static struct exclude_list *parse_exclude(char *line){
- struct exclude_list *list;
- unsigned int position = 0, len = 0;
+static struct exclude_list *parse_exclude(char *line)
+{
+ struct exclude_list *list;
+ unsigned int position = 0, len = 0;
- list = slapt_malloc( sizeof *list );
- list->excludes = slapt_malloc( sizeof *list->excludes );
- list->count = 0;
+ list = slapt_malloc( sizeof *list );
+ list->excludes = slapt_malloc( sizeof *list->excludes );
+ list->count = 0;
- /* skip ahead past the = */
- line = strchr(line,'=') + 1;
+ /* skip ahead past the = */
+ line = strchr(line,'=') + 1;
- len = strlen(line);
- while( position < len ){
+ len = strlen(line);
+ while( position < len ) {
- if( strstr(line + position,",") == NULL ){
- char *pointer = NULL;
+ if( strstr(line + position,",") == NULL ) {
+ char *pointer = NULL;
- pointer = line + position;
+ pointer = line + position;
- add_exclude(list,pointer);
+ add_exclude(list,pointer);
- break;
- }else{
+ break;
+ }else{
- if( line[position] == ',' ){
- ++position;
- continue;
- }else{
- char *buffer = NULL,*pointer = NULL;
+ if( line[position] == ',' ) {
+ ++position;
+ continue;
+ }else{
+ char *buffer = NULL,*pointer = NULL;
- pointer = strchr(line + position,',');
- buffer = strndup(
- line + position,
- strlen(line + position) - strlen(pointer)
- );
+ pointer = strchr(line + position,',');
+ buffer = strndup(
+ line + position,
+ strlen(line + position) - strlen(pointer)
+ );
- add_exclude(list,buffer);
- free(buffer);
- position += (strlen(line + position) - strlen(pointer) );
- }
- continue;
- }
- }
-
- return list;
+ add_exclude(list,buffer);
+ free(buffer);
+ position += (strlen(line + position) - strlen(pointer) );
+ }
+ continue;
+ }
+ }
+
+ return list;
}
-void add_exclude(struct exclude_list *list,const char *e){
- char **realloc_tmp;
+void add_exclude(struct exclude_list *list,const char *e)
+{
+ char **realloc_tmp;
- realloc_tmp = realloc( list->excludes, sizeof *list->excludes * (list->count + 1) );
+ realloc_tmp =
+ realloc( list->excludes, sizeof *list->excludes * (list->count + 1) );
- if( realloc_tmp == NULL ) return;
+ if( realloc_tmp == NULL ) return;
- list->excludes = realloc_tmp;
- list->excludes[ list->count ] = strndup(e, strlen(e));
- list->excludes[ list->count ][strlen(e)] = '\0';
- ++list->count;
+ list->excludes = realloc_tmp;
+ list->excludes[ list->count ] = strndup(e, strlen(e));
+ list->excludes[ list->count ][strlen(e)] = '\0';
+ ++list->count;
}
-void add_source(struct source_list *list,const char *s){
- char **realloc_tmp;
- int source_len = 0;
+void add_source(struct source_list *list,const char *s)
+{
+ char **realloc_tmp;
+ int source_len = 0;
- if( s == NULL ) return;
- source_len = strlen(s);
+ if( s == NULL ) return;
+ source_len = strlen(s);
- realloc_tmp = realloc(list->url,sizeof *list->url * (list->count + 1) );
+ realloc_tmp = realloc(list->url,sizeof *list->url * (list->count + 1) );
- if( realloc_tmp == NULL ) return;
+ if( realloc_tmp == NULL ) return;
- list->url = realloc_tmp;
+ list->url = realloc_tmp;
- if( s[source_len - 1] == '/' ){
+ if( s[source_len - 1] == '/' ) {
- list->url[ list->count ] = strndup(s,source_len);
- list->url[ list->count ][source_len] = '\0';
+ list->url[ list->count ] = strndup(s,source_len);
+ list->url[ list->count ][source_len] = '\0';
- }else{
+ }else{
- list->url[ list->count ] = slapt_malloc(
- sizeof *list->url[list->count] * (source_len + 2)
- );
- list->url[list->count][0] = '\0';
+ list->url[ list->count ] = slapt_malloc(
+ sizeof *list->url[list->count] * (source_len + 2)
+ );
+ list->url[list->count][0] = '\0';
- list->url[list->count] = strncat(
- list->url[list->count],
- s,
- source_len
- );
+ list->url[list->count] = strncat(
+ list->url[list->count],
+ s,
+ source_len
+ );
- list->url[list->count] = strncat(
- list->url[list->count],
- "/",
- strlen("/")
- );
+ list->url[list->count] = strncat(
+ list->url[list->count],
+ "/",
+ strlen("/")
+ );
- list->url[list->count][source_len + 1] = '\0';
+ list->url[list->count][source_len + 1] = '\0';
- }
+ }
- ++list->count;
+ ++list->count;
}
diff --git a/src/curl.c b/src/curl.c
index e16ccf1..a15c9a0 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -17,294 +17,310 @@
*/
#include <main.h>
-static size_t write_header_callback(void *buffer, size_t size, size_t nmemb, void *userp);
-
-int download_data(FILE *fh,const char *url,size_t bytes,const rc_config *global_config){
- CURL *ch = NULL;
- CURLcode response;
- char curl_err_buff[1024];
- int return_code = 0;
- struct curl_slist *headers = NULL;
+static size_t write_header_callback(void *buffer,
+ size_t size, size_t nmemb, void *userp);
+
+int download_data(FILE *fh,const char *url,size_t bytes,
+ const rc_config *global_config)
+{
+ CURL *ch = NULL;
+ CURLcode response;
+ char curl_err_buff[1024];
+ int return_code = 0;
+ struct curl_slist *headers = NULL;
#if DEBUG == 1
- printf(_("Fetching url:[%s]\n"),url);
+ printf(_("Fetching url:[%s]\n"),url);
#endif
- ch = curl_easy_init();
- curl_easy_setopt(ch, CURLOPT_URL, url);
- curl_easy_setopt(ch, CURLOPT_WRITEDATA, fh);
- curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 0);
- curl_easy_setopt(ch, CURLOPT_USERAGENT, PROGRAM_NAME );
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV, 0);
+ ch = curl_easy_init();
+ curl_easy_setopt(ch, CURLOPT_URL, url);
+ curl_easy_setopt(ch, CURLOPT_WRITEDATA, fh);
+ curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 0);
+ curl_easy_setopt(ch, CURLOPT_USERAGENT, PROGRAM_NAME );
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV, 0);
/* this is a check for slack 9.0's curl libs */
#ifdef CURLOPT_FTP_USE_EPRT
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
#endif
- curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
#ifdef CURLOPT_HTTPAUTH
- curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
+ curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
#endif
- curl_easy_setopt(ch, CURLOPT_FILETIME, 1 );
- curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1 );
-
- headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
-
- if( global_config->dl_stats != 1 ){
- if( global_config->progress_cb == NULL ){
- curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, progress_callback );
- }else{
- curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, global_config->progress_cb );
- }
- curl_easy_setopt(ch, CURLOPT_PROGRESSDATA, &bytes);
- }
-
- curl_easy_setopt(ch, CURLOPT_ERRORBUFFER, curl_err_buff );
-
- /* resume */
- if( bytes > 0 ){
- fseek(fh,0,SEEK_END);
- curl_easy_setopt(ch, CURLOPT_RESUME_FROM, bytes);
- }
-
- if( (response = curl_easy_perform(ch)) != CURLE_OK ){
- /*
- * this is for proxy servers that can't resume
- */
- if( response == CURLE_HTTP_RANGE_ERROR ){
- return_code = CURLE_HTTP_RANGE_ERROR;
- /*
- * this is a simple hack for all ftp sources that won't have a patches dir
- * we don't want an ugly error to confuse the user
- */
- }else if( strstr(url,PATCHES_LIST) != NULL ){
- return_code = 0;
- }else{
- fprintf(stderr,_("Failed to download: %s\n"),curl_err_buff);
- return_code = -1;
- }
- }
- /*
+ curl_easy_setopt(ch, CURLOPT_FILETIME, 1 );
+ curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1 );
+
+ headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
+
+ if( global_config->dl_stats != 1 ) {
+ if( global_config->progress_cb == NULL ) {
+ curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, progress_callback );
+ }else{
+ curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION,
+ global_config->progress_cb );
+ }
+ curl_easy_setopt(ch, CURLOPT_PROGRESSDATA, &bytes);
+ }
+
+ curl_easy_setopt(ch, CURLOPT_ERRORBUFFER, curl_err_buff );
+
+ /* resume */
+ if( bytes > 0 ) {
+ fseek(fh,0,SEEK_END);
+ curl_easy_setopt(ch, CURLOPT_RESUME_FROM, bytes);
+ }
+
+ if( (response = curl_easy_perform(ch)) != CURLE_OK ) {
+ /*
+ * this is for proxy servers that can't resume
+ */
+ if( response == CURLE_HTTP_RANGE_ERROR ) {
+ return_code = CURLE_HTTP_RANGE_ERROR;
+ /*
+ * this is a simple hack for all ftp sources that won't have a patches dir
+ * we don't want an ugly error to confuse the user
+ */
+ }else if( strstr(url,PATCHES_LIST) != NULL ) {
+ return_code = 0;
+ }else{
+ fprintf(stderr,_("Failed to download: %s\n"),curl_err_buff);
+ return_code = -1;
+ }
+ }
+ /*
* need to use curl_easy_cleanup() so that we don't
- * have tons of open connections, getting rejected
- * by ftp servers for being naughty.
- */
- curl_easy_cleanup(ch);
- /* can't do a curl_free() after curl_easy_cleanup() */
- /* curl_free(ch); */
- curl_slist_free_all(headers);
-
- return return_code;
+ * have tons of open connections, getting rejected
+ * by ftp servers for being naughty.
+ */
+ curl_easy_cleanup(ch);
+ /* can't do a curl_free() after curl_easy_cleanup() */
+ /* curl_free(ch); */
+ curl_slist_free_all(headers);
+
+ return return_code;
}
-static size_t write_header_callback(void *buffer, size_t size, size_t nmemb, void *userp){
- char *tmp;
- register int a_size = size * nmemb;
- struct head_data_t *head_t = (struct head_data_t *)userp;
-
- tmp = (char *)realloc( head_t->data, head_t->size + a_size + 1);
- if( tmp != NULL ){
- head_t->data = tmp;
- memcpy(&(head_t->data[head_t->size]),buffer,a_size);
- head_t->size += a_size;
- head_t->data[head_t->size] = '\0';
- }
-
- return nmemb;
+static size_t write_header_callback(void *buffer, size_t size,
+ size_t nmemb, void *userp)
+{
+ char *tmp;
+ register int a_size = size * nmemb;
+ struct head_data_t *head_t = (struct head_data_t *)userp;
+
+ tmp = (char *)realloc( head_t->data, head_t->size + a_size + 1);
+ if( tmp != NULL ) {
+ head_t->data = tmp;
+ memcpy(&(head_t->data[head_t->size]),buffer,a_size);
+ head_t->size += a_size;
+ head_t->data[head_t->size] = '\0';
+ }
+
+ return nmemb;
}
-char *head_request(const char *url){
- CURL *ch = NULL;
- CURLcode response;
- struct head_data_t head_t;
- struct curl_slist *headers = NULL;
-
- head_t.data = slapt_malloc( sizeof *head_t.data );
- head_t.size = 0;
-
- ch = curl_easy_init();
- curl_easy_setopt(ch, CURLOPT_URL, url);
- curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, write_header_callback);
- curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1);
- curl_easy_setopt(ch, CURLOPT_USERAGENT, PROGRAM_NAME );
- curl_easy_setopt(ch, CURLOPT_FILE, &head_t);
- curl_easy_setopt(ch, CURLOPT_HEADER, 1);
- curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV , 0);
+char *head_request(const char *url)
+{
+ CURL *ch = NULL;
+ CURLcode response;
+ struct head_data_t head_t;
+ struct curl_slist *headers = NULL;
+
+ head_t.data = slapt_malloc( sizeof *head_t.data );
+ head_t.size = 0;
+
+ ch = curl_easy_init();
+ curl_easy_setopt(ch, CURLOPT_URL, url);
+ curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, write_header_callback);
+ curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1);
+ curl_easy_setopt(ch, CURLOPT_USERAGENT, PROGRAM_NAME );
+ curl_easy_setopt(ch, CURLOPT_FILE, &head_t);
+ curl_easy_setopt(ch, CURLOPT_HEADER, 1);
+ curl_easy_setopt(ch, CURLOPT_NOBODY, 1);
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPSV , 0);
/* this is a check for slack 9.0's curl libs */
#ifdef CURLOPT_FTP_USE_EPRT
- curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
+ curl_easy_setopt(ch, CURLOPT_FTP_USE_EPRT, 0);
#endif
- curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
#ifdef CURLOPT_HTTPAUTH
- curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
+ curl_easy_setopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
#endif
- curl_easy_setopt(ch, CURLOPT_FILETIME, 1 );
- curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1 );
+ curl_easy_setopt(ch, CURLOPT_FILETIME, 1 );
+ curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1 );
- headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
+ headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
- if( (response = curl_easy_perform(ch)) != 0 ){
- free(head_t.data);
- curl_easy_cleanup(ch);
- curl_slist_free_all(headers);
- return NULL;
- }
+ if( (response = curl_easy_perform(ch)) != 0 ) {
+ free(head_t.data);
+ curl_easy_cleanup(ch);
+ curl_slist_free_all(headers);
+ return NULL;
+ }
- curl_easy_cleanup(ch);
- curl_slist_free_all(headers);
- return head_t.data;
+ curl_easy_cleanup(ch);
+ curl_slist_free_all(headers);
+ return head_t.data;
}
-int get_mirror_data_from_source(FILE *fh,const rc_config *global_config,const char *base_url,const char *filename){
- int return_code = 0;
- char *url = NULL;
+int get_mirror_data_from_source(FILE *fh,const rc_config *global_config,
+ const char *base_url,const char *filename)
+{
+ int return_code = 0;
+ char *url = NULL;
- url = slapt_calloc(
- strlen(base_url) + strlen(filename) + 1, sizeof *url
- );
+ url = slapt_calloc(
+ strlen(base_url) + strlen(filename) + 1, sizeof *url
+ );
- strncpy(url,base_url,strlen(base_url) );
- url[ strlen(base_url) ] = '\0';
- strncat(url,filename,strlen(filename) );
+ strncpy(url,base_url,strlen(base_url) );
+ url[ strlen(base_url) ] = '\0';
+ strncat(url,filename,strlen(filename) );
- return_code = download_data(fh,url,0,global_config);
+ return_code = download_data(fh,url,0,global_config);
- free(url);
- /* make sure we are back at the front of the file */
- /* DISABLED */
- /* rewind(fh); */
- return return_code;
+ free(url);
+ /* make sure we are back at the front of the file */
+ /* DISABLED */
+ /* rewind(fh); */
+ return return_code;
}
-int download_pkg(const rc_config *global_config,pkg_info_t *pkg){
- FILE *fh = NULL;
- char *file_name = NULL;
- char *url = NULL;
- size_t f_size = 0;
- int pkg_verify_return = -1;
- int dl_return = -1;
-
- if( verify_downloaded_pkg(global_config,pkg) == 0 ) return 0;
-
- chdir(global_config->working_dir); /* just in case */
- create_dir_structure(pkg->location);
-
- /* build the url, file name, and get the file size if the file is present */
- url = gen_pkg_url(pkg);
- file_name = gen_pkg_file_name(global_config,pkg);
- f_size = get_pkg_file_size(global_config,pkg);
-
- if( global_config->dl_stats == TRUE ){
- int dl_total_size = pkg->size_c - (f_size/1024);
- printf(_("Downloading %s %s %s [%.1d%s]...\n"),
- pkg->mirror,pkg->name,pkg->version,
- ( dl_total_size > 1024 ) ? dl_total_size / 1024 : dl_total_size,
- ( dl_total_size > 1024 ) ? "MB" : "kB"
- );
- }else{
- int dl_total_size = pkg->size_c - (f_size/1024);
- printf(_("Downloading %s %s %s [%.1d%s]..."),
- pkg->mirror,pkg->name,pkg->version,
- ( dl_total_size > 1024 ) ? dl_total_size / 1024 : dl_total_size,
- ( dl_total_size > 1024 ) ? "MB" : "kB"
- );
- }
-
- /* open the file to write, append if already present */
- fh = open_file(file_name,"a+b");
- if( fh == NULL ){
- free(file_name);
- free(url);
- return -1;
- }
-
- /* download the file to our file handle */
- dl_return = download_data(fh,url,f_size,global_config);
- if( dl_return == 0 ){
- if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
- }else if( dl_return == CURLE_HTTP_RANGE_ERROR ){
- /*
- * this is for errors trying to resume. unlink the file and
- * try again.
- */
- printf("\r");
- fclose(fh);
- if( unlink(file_name) == -1 ){
- fprintf(stderr,_("Failed to unlink %s\n"),file_name);
- if( errno ) perror(file_name);
- exit(1);
- }
- free(file_name);
- free(url);
- return download_pkg(global_config,pkg);
- }else{
- fclose(fh);
- #if DEBUG == 1
- printf("Failure: %s-%s from %s %s\n",pkg->name,pkg->version,pkg->mirror,pkg->location);
- #endif
- #if DO_NOT_UNLINK_BAD_FILES == 0
- /* if the d/l fails, unlink the empty file */
- if( unlink(file_name) == -1 ){
- fprintf(stderr,_("Failed to unlink %s\n"),file_name);
- if( errno ) perror(file_name);
- }
- #endif
- free(url);
- free(file_name);
- return -1;
- }
-
- fclose(fh);
- free(url);
-
- /* check to make sure we have the complete file */
- pkg_verify_return = verify_downloaded_pkg(global_config,pkg);
- if( pkg_verify_return == 0 ){
- free(file_name);
- return 0;
- }else if( pkg_verify_return == MD5_CHECKSUM_FAILED ){
- fprintf(stderr,_("md5 sum for %s is not correct, override with --no-md5!\n"),pkg->name);
- #if DO_NOT_UNLINK_BAD_FILES == 0
- /* if the checksum fails, unlink the bogus file */
- if( unlink(file_name) == -1 ){
- fprintf(stderr,_("Failed to unlink %s\n"),file_name);
- if( errno ) perror("unlink");
- }
- #endif
- free(file_name);
- return -1;
- }else{
- printf(_("Download of %s incomplete\n"),pkg->name);
- free(file_name);
- return -1;
- }
+int download_pkg(const rc_config *global_config,pkg_info_t *pkg)
+{
+ FILE *fh = NULL;
+ char *file_name = NULL;
+ char *url = NULL;
+ size_t f_size = 0;
+ int pkg_verify_return = -1;
+ int dl_return = -1;
+
+ if( verify_downloaded_pkg(global_config,pkg) == 0 ) return 0;
+
+ chdir(global_config->working_dir); /* just in case */
+ create_dir_structure(pkg->location);
+
+ /* build the url, file name, and get the file size if the file is present */
+ url = gen_pkg_url(pkg);
+ file_name = gen_pkg_file_name(global_config,pkg);
+ f_size = get_pkg_file_size(global_config,pkg);
+
+ if( global_config->dl_stats == TRUE ) {
+ int dl_total_size = pkg->size_c - (f_size/1024);
+ printf(_("Downloading %s %s %s [%.1d%s]...\n"),
+ pkg->mirror,pkg->name,pkg->version,
+ ( dl_total_size > 1024 ) ? dl_total_size / 1024 : dl_total_size,
+ ( dl_total_size > 1024 ) ? "MB" : "kB"
+ );
+ }else{
+ int dl_total_size = pkg->size_c - (f_size/1024);
+ printf(_("Downloading %s %s %s [%.1d%s]..."),
+ pkg->mirror,pkg->name,pkg->version,
+ ( dl_total_size > 1024 ) ? dl_total_size / 1024 : dl_total_size,
+ ( dl_total_size > 1024 ) ? "MB" : "kB"
+ );
+ }
+
+ /* open the file to write, append if already present */
+ fh = open_file(file_name,"a+b");
+ if( fh == NULL ) {
+ free(file_name);
+ free(url);
+ return -1;
+ }
+
+ /* download the file to our file handle */
+ dl_return = download_data(fh,url,f_size,global_config);
+ if( dl_return == 0 ) {
+ if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
+ }else if( dl_return == CURLE_HTTP_RANGE_ERROR ) {
+ /*
+ * this is for errors trying to resume. unlink the file and
+ * try again.
+ */
+ printf("\r");
+ fclose(fh);
+ if( unlink(file_name) == -1 ) {
+ fprintf(stderr,_("Failed to unlink %s\n"),file_name);
+ if( errno ) perror(file_name);
+ exit(1);
+ }
+ free(file_name);
+ free(url);
+ return download_pkg(global_config,pkg);
+ }else{
+ fclose(fh);
+ #if DEBUG == 1
+ printf("Failure: %s-%s from %s %s\n",pkg->name,pkg->version,
+ pkg->mirror,pkg->location);
+ #endif
+ #if DO_NOT_UNLINK_BAD_FILES == 0
+ /* if the d/l fails, unlink the empty file */
+ if( unlink(file_name) == -1 ) {
+ fprintf(stderr,_("Failed to unlink %s\n"),file_name);
+ if( errno ) perror(file_name);
+ }
+ #endif
+ free(url);
+ free(file_name);
+ return -1;
+ }
+
+ fclose(fh);
+ free(url);
+
+ /* check to make sure we have the complete file */
+ pkg_verify_return = verify_downloaded_pkg(global_config,pkg);
+ if( pkg_verify_return == 0 ) {
+ free(file_name);
+ return 0;
+ }else if( pkg_verify_return == MD5_CHECKSUM_FAILED ) {
+ fprintf(stderr,
+ _("md5 sum for %s is not correct, override with --no-md5!\n"),
+ pkg->name);
+ #if DO_NOT_UNLINK_BAD_FILES == 0
+ /* if the checksum fails, unlink the bogus file */
+ if( unlink(file_name) == -1 ) {
+ fprintf(stderr,_("Failed to unlink %s\n"),file_name);
+ if( errno ) perror("unlink");
+ }
+ #endif
+ free(file_name);
+ return -1;
+ }else{
+ printf(_("Download of %s incomplete\n"),pkg->name);
+ free(file_name);
+ return -1;
+ }
}
-int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow){
- size_t percent = 0;
- size_t *bytes = (size_t *)clientp;
- (void) ultotal;
- (void) ulnow;
-
- if( (dltotal + *bytes) == 0 ){
- percent = 0;
- }else{
- percent = ((*bytes + dlnow)*100)/(dltotal + *bytes);
- }
- printf("%3d%%\b\b\b\b",percent);
- return 0;
+int progress_callback(void *clientp, double dltotal, double dlnow,
+ double ultotal, double ulnow)
+{
+ size_t percent = 0;
+ size_t *bytes = (size_t *)clientp;
+ (void) ultotal;
+ (void) ulnow;
+
+ if( (dltotal + *bytes) == 0 ) {
+ percent = 0;
+ }else{
+ percent = ((*bytes + dlnow)*100)/(dltotal + *bytes);
+ }
+ printf("%3d%%\b\b\b\b",percent);
+ return 0;
}
-char spinner(void){
- static int spinner_index = 0;
- static const char spinner_parts[] = "\\|/-";
-
- if( spinner_index > 3 ){
- spinner_index = 0;
- return spinner_parts[spinner_index];
- }else{
- return spinner_parts[spinner_index++];
- }
+char spinner(void)
+{
+ static int spinner_index = 0;
+ static const char spinner_parts[] = "\\|/-";
+
+ if( spinner_index > 3 ) {
+ spinner_index = 0;
+ return spinner_parts[spinner_index];
+ }else{
+ return spinner_parts[spinner_index++];
+ }
}
diff --git a/src/curl.h b/src/curl.h
index 126a321..972c91c 100644
--- a/src/curl.h
+++ b/src/curl.h
@@ -22,18 +22,21 @@ struct head_data_t {
};
/* this is the main download routine */
-int download_data(FILE *fh,const char *url,size_t bytes,const rc_config *global_config);
+int download_data(FILE *fh,const char *url,size_t bytes,
+ const rc_config *global_config);
char *head_request(const char *url);
/*
this fills FILE with data from url, used for PACKAGES.TXT and CHECKSUMS
*/
-int get_mirror_data_from_source(FILE *fh,const rc_config *global_config,const char *base_url,const char *filename);
+int get_mirror_data_from_source(FILE *fh,const rc_config *global_config,
+ const char *base_url,const char *filename);
/* download pkg, cals download_data */
int download_pkg(const rc_config *global_config,pkg_info_t *pkg);
/* callback for curl progress */
char spinner(void);
-int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
+int progress_callback(void *clientp, double dltotal, double dlnow,
+ double ultotal, double ulnow);
diff --git a/src/main.c b/src/main.c
index 3437c0b..22a8773 100644
--- a/src/main.c
+++ b/src/main.c
@@ -20,334 +20,337 @@
static void usage(void);
static void version_info(void);
-int main( int argc, char *argv[] ){
- rc_config *global_config; /* our config struct */
- pkg_action_args_t *paa;
- /* getopt needs these */
- int c = 0;
- extern char *optarg;
- extern int optind, opterr, optopt;
- enum action do_action = 0;
- int option_index = 0;
- static struct option long_options[] = {
- {"update", 0, 0, UPDATE_OPT},
- {"upgrade", 0, 0, UPGRADE_OPT},
- {"install", 0, 0, INSTALL_OPT},
- {"remove", 0, 0, REMOVE_OPT},
- {"show", 0, 0, SHOW_OPT},
- {"search", 0, 0, SEARCH_OPT},
- {"list", 0, 0, LIST_OPT},
- {"installed", 0, 0, INSTALLED_OPT},
- {"clean", 0, 0, CLEAN_OPT},
- {"download-only", 0, 0, DOWNLOAD_ONLY_OPT},
- {"simulate", 0, 0, SIMULATE_OPT},
- {"s", 0, 0, SIMULATE_OPT},
- {"version", 0, 0, VERSION_OPT},
- {"no-prompt", 0, 0, NO_PROMPT_OPT},
- {"y", 0, 0, NO_PROMPT_OPT},
- {"reinstall", 0, 0, REINSTALL_OPT},
- {"ignore-excludes", 0, 0, IGNORE_EXCLUDES_OPT},
- {"no-md5", 0, 0, NO_MD5_OPT},
- {"dist-upgrade",0, 0, DIST_UPGRADE_OPT},
- {"help",0, 0, HELP_OPT},
- {"h",0, 0, HELP_OPT},
- {"ignore-dep",0, 0, IGNORE_DEP_OPT},
- {"no-dep",0, 0, NO_DEP_OPT},
- {"print-uris",0, 0, PRINT_URIS_OPT},
- {"show-stats",0, 0, SHOW_STATS_OPT},
- {"S",0, 0, SHOW_STATS_OPT},
- {"config",1, 0, CONFIG_OPT},
- {"autoclean", 0, 0, AUTOCLEAN_OPT},
- {"remove-obsolete", 0, 0, OBSOLETE_OPT},
- {"available", 0, 0, AVAILABLE_OPT},
- {0, 0, 0, 0},
- };
+int main( int argc, char *argv[] )
+{
+ rc_config *global_config; /* our config struct */
+ pkg_action_args_t *paa;
+ /* getopt needs these */
+ int c = 0;
+ extern char *optarg;
+ extern int optind, opterr, optopt;
+ enum action do_action = 0;
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"update", 0, 0, UPDATE_OPT},
+ {"upgrade", 0, 0, UPGRADE_OPT},
+ {"install", 0, 0, INSTALL_OPT},
+ {"remove", 0, 0, REMOVE_OPT},
+ {"show", 0, 0, SHOW_OPT},
+ {"search", 0, 0, SEARCH_OPT},
+ {"list", 0, 0, LIST_OPT},
+ {"installed", 0, 0, INSTALLED_OPT},
+ {"clean", 0, 0, CLEAN_OPT},
+ {"download-only", 0, 0, DOWNLOAD_ONLY_OPT},
+ {"simulate", 0, 0, SIMULATE_OPT},
+ {"s", 0, 0, SIMULATE_OPT},
+ {"version", 0, 0, VERSION_OPT},
+ {"no-prompt", 0, 0, NO_PROMPT_OPT},
+ {"y", 0, 0, NO_PROMPT_OPT},
+ {"reinstall", 0, 0, REINSTALL_OPT},
+ {"ignore-excludes", 0, 0, IGNORE_EXCLUDES_OPT},
+ {"no-md5", 0, 0, NO_MD5_OPT},
+ {"dist-upgrade",0, 0, DIST_UPGRADE_OPT},
+ {"help",0, 0, HELP_OPT},
+ {"h",0, 0, HELP_OPT},
+ {"ignore-dep",0, 0, IGNORE_DEP_OPT},
+ {"no-dep",0, 0, NO_DEP_OPT},
+ {"print-uris",0, 0, PRINT_URIS_OPT},
+ {"show-stats",0, 0, SHOW_STATS_OPT},
+ {"S",0, 0, SHOW_STATS_OPT},
+ {"config",1, 0, CONFIG_OPT},
+ {"autoclean", 0, 0, AUTOCLEAN_OPT},
+ {"remove-obsolete", 0, 0, OBSOLETE_OPT},
+ {"available", 0, 0, AVAILABLE_OPT},
+ {0, 0, 0, 0},
+ };
- setbuf(stdout,NULL);
+ setbuf(stdout,NULL);
- #ifdef ENABLE_NLS
- setlocale(LC_ALL,"");
- bindtextdomain(PROGRAM_NAME,LOCALESDIR);
- textdomain(PROGRAM_NAME);
- #endif
+ #ifdef ENABLE_NLS
+ setlocale(LC_ALL,"");
+ bindtextdomain(PROGRAM_NAME,LOCALESDIR);
+ textdomain(PROGRAM_NAME);
+ #endif
- if( argc < 2 ) usage(), exit(1);
+ if( argc < 2 ) usage(), exit(1);
- /* load up the configuration file */
- global_config = read_rc_config(RC_LOCATION);
- if( global_config == NULL ){
- exit(1);
- }
- curl_global_init(CURL_GLOBAL_ALL);
+ /* load up the configuration file */
+ global_config = read_rc_config(RC_LOCATION);
+ if( global_config == NULL ) {
+ exit(1);
+ }
+ curl_global_init(CURL_GLOBAL_ALL);
- while( ( c = getopt_long_only(argc,argv,"",long_options,&option_index ) ) != -1 ){
- switch(c){
- case UPDATE_OPT: /* update */
- do_action = UPDATE;
- break;
- case INSTALL_OPT: /* install */
- do_action = INSTALL;
- break;
- case REMOVE_OPT: /* remove */
- do_action = REMOVE;
- break;
- case SHOW_OPT: /* show */
- do_action = SHOW;
- break;
- case SEARCH_OPT: /* search */
- do_action = SEARCH;
- break;
- case LIST_OPT: /* list */
- do_action = LIST;
- break;
- case INSTALLED_OPT: /* installed */
- do_action = INSTALLED;
- break;
- case CLEAN_OPT: /* clean */
- do_action = CLEAN;
- break;
- case UPGRADE_OPT: /* upgrade */
- do_action = UPGRADE;
- break;
- case DOWNLOAD_ONLY_OPT: /* download only flag */
- global_config->download_only = TRUE;
- break;
- case SIMULATE_OPT: /* simulate */
- global_config->simulate = TRUE;
- break;
- case VERSION_OPT: /* version */
- do_action = SHOWVERSION;
- break;
- case NO_PROMPT_OPT: /* auto */
- global_config->no_prompt = TRUE;
- break;
- case REINSTALL_OPT: /* reinstall */
- global_config->re_install = TRUE;
- break;
- case IGNORE_EXCLUDES_OPT: /* ignore-excludes */
- global_config->ignore_excludes = TRUE;
- break;
- case NO_MD5_OPT: /* no-md5 */
- global_config->no_md5_check = TRUE;
- break;
- case DIST_UPGRADE_OPT: /* dist-upgrade */
- global_config->dist_upgrade = TRUE;
- do_action = UPGRADE;
- break;
- case HELP_OPT: /* help */
- usage();
- free_rc_config(global_config);
- curl_global_cleanup();
- exit(1);
- case IGNORE_DEP_OPT: /* ignore-dep */
- global_config->ignore_dep = TRUE;
- break;
- case NO_DEP_OPT: /* no-dep */
- global_config->disable_dep_check = TRUE;
- break;
- case PRINT_URIS_OPT: /* print-uris */
- global_config->print_uris = TRUE;
- break;
- case SHOW_STATS_OPT: /* download-stats */
- global_config->dl_stats = TRUE;
- break;
- case CONFIG_OPT: /* override rc location */
- {
- rc_config *tmp_gc = global_config;
- global_config = read_rc_config(optarg);
- if( global_config == NULL ){
- free_rc_config(tmp_gc);
- curl_global_cleanup();
- exit(1);
- }
- /* preserve existing command line options */
- global_config->download_only = tmp_gc->download_only;
- global_config->dist_upgrade = tmp_gc->dist_upgrade;
- global_config->simulate = tmp_gc->simulate;
- global_config->no_prompt = tmp_gc->no_prompt;
- global_config->re_install = tmp_gc->re_install;
- global_config->ignore_excludes = tmp_gc->ignore_excludes;
- global_config->no_md5_check = tmp_gc->no_md5_check;
- global_config->ignore_dep = tmp_gc->ignore_dep;
- global_config->disable_dep_check = tmp_gc->disable_dep_check;
- global_config->print_uris = tmp_gc->print_uris;
- global_config->dl_stats = tmp_gc->dl_stats;
- free_rc_config(tmp_gc);
- }
- break;
- case AUTOCLEAN_OPT: /* clean old old package versions */
- do_action = AUTOCLEAN;
- break;
- case OBSOLETE_OPT: /* remove obsolete packages */
- global_config->remove_obsolete = TRUE;
- break;
- case AVAILABLE_OPT: /* show available packages */
- do_action = AVAILABLE;
- break;
- default:
- usage();
- free_rc_config(global_config);
- curl_global_cleanup();
- exit(1);
- }
- }
+ while( ( c = getopt_long_only(argc,argv,"",long_options,&option_index ) ) != -1 ) {
+ switch(c) {
+ case UPDATE_OPT: /* update */
+ do_action = UPDATE;
+ break;
+ case INSTALL_OPT: /* install */
+ do_action = INSTALL;
+ break;
+ case REMOVE_OPT: /* remove */
+ do_action = REMOVE;
+ break;
+ case SHOW_OPT: /* show */
+ do_action = SHOW;
+ break;
+ case SEARCH_OPT: /* search */
+ do_action = SEARCH;
+ break;
+ case LIST_OPT: /* list */
+ do_action = LIST;
+ break;
+ case INSTALLED_OPT: /* installed */
+ do_action = INSTALLED;
+ break;
+ case CLEAN_OPT: /* clean */
+ do_action = CLEAN;
+ break;
+ case UPGRADE_OPT: /* upgrade */
+ do_action = UPGRADE;
+ break;
+ case DOWNLOAD_ONLY_OPT: /* download only flag */
+ global_config->download_only = TRUE;
+ break;
+ case SIMULATE_OPT: /* simulate */
+ global_config->simulate = TRUE;
+ break;
+ case VERSION_OPT: /* version */
+ do_action = SHOWVERSION;
+ break;
+ case NO_PROMPT_OPT: /* auto */
+ global_config->no_prompt = TRUE;
+ break;
+ case REINSTALL_OPT: /* reinstall */
+ global_config->re_install = TRUE;
+ break;
+ case IGNORE_EXCLUDES_OPT: /* ignore-excludes */
+ global_config->ignore_excludes = TRUE;
+ break;
+ case NO_MD5_OPT: /* no-md5 */
+ global_config->no_md5_check = TRUE;
+ break;
+ case DIST_UPGRADE_OPT: /* dist-upgrade */
+ global_config->dist_upgrade = TRUE;
+ do_action = UPGRADE;
+ break;
+ case HELP_OPT: /* help */
+ usage();
+ free_rc_config(global_config);
+ curl_global_cleanup();
+ exit(1);
+ case IGNORE_DEP_OPT: /* ignore-dep */
+ global_config->ignore_dep = TRUE;
+ break;
+ case NO_DEP_OPT: /* no-dep */
+ global_config->disable_dep_check = TRUE;
+ break;
+ case PRINT_URIS_OPT: /* print-uris */
+ global_config->print_uris = TRUE;
+ break;
+ case SHOW_STATS_OPT: /* download-stats */
+ global_config->dl_stats = TRUE;
+ break;
+ case CONFIG_OPT: /* override rc location */
+ {
+ rc_config *tmp_gc = global_config;
+ global_config = read_rc_config(optarg);
+ if( global_config == NULL ) {
+ free_rc_config(tmp_gc);
+ curl_global_cleanup();
+ exit(1);
+ }
+ /* preserve existing command line options */
+ global_config->download_only = tmp_gc->download_only;
+ global_config->dist_upgrade = tmp_gc->dist_upgrade;
+ global_config->simulate = tmp_gc->simulate;
+ global_config->no_prompt = tmp_gc->no_prompt;
+ global_config->re_install = tmp_gc->re_install;
+ global_config->ignore_excludes = tmp_gc->ignore_excludes;
+ global_config->no_md5_check = tmp_gc->no_md5_check;
+ global_config->ignore_dep = tmp_gc->ignore_dep;
+ global_config->disable_dep_check = tmp_gc->disable_dep_check;
+ global_config->print_uris = tmp_gc->print_uris;
+ global_config->dl_stats = tmp_gc->dl_stats;
+ free_rc_config(tmp_gc);
+ }
+ break;
+ case AUTOCLEAN_OPT: /* clean old old package versions */
+ do_action = AUTOCLEAN;
+ break;
+ case OBSOLETE_OPT: /* remove obsolete packages */
+ global_config->remove_obsolete = TRUE;
+ break;
+ case AVAILABLE_OPT: /* show available packages */
+ do_action = AVAILABLE;
+ break;
+ default:
+ usage();
+ free_rc_config(global_config);
+ curl_global_cleanup();
+ exit(1);
+ }
+ }
- /* Check optionnal arguments presence */
- switch(do_action){
- case INSTALL:
- case REMOVE:
- case SHOW:
- case SEARCH:
- if( optind >= argc )
- do_action = 0;
- break;
- default:
- if (optind < argc)
- do_action = USAGE;
- break;
- }
+ /* Check optionnal arguments presence */
+ switch(do_action) {
+ case INSTALL:
+ case REMOVE:
+ case SHOW:
+ case SEARCH:
+ if( optind >= argc )
+ do_action = 0;
+ break;
+ default:
+ if (optind < argc)
+ do_action = USAGE;
+ break;
+ }
- if( do_action == USAGE ){
- usage();
- free_rc_config(global_config);
- curl_global_cleanup();
- exit(1);
- }
+ if( do_action == USAGE ) {
+ usage();
+ free_rc_config(global_config);
+ curl_global_cleanup();
+ exit(1);
+ }
- /* create the working directory if needed */
- working_dir_init(global_config);
- chdir(global_config->working_dir);
+ /* create the working directory if needed */
+ working_dir_init(global_config);
+ chdir(global_config->working_dir);
- switch(do_action){
- case UPDATE:
- if( update_pkg_cache(global_config) == 1 ){
- free_rc_config(global_config);
- curl_global_cleanup();
- exit(1);
- }
- break;
- case INSTALL:
- paa = init_pkg_action_args((argc - optind));
- while (optind < argc){
- paa->pkgs[paa->count] = slapt_malloc(
- ( strlen(argv[optind]) + 1 ) * sizeof *paa->pkgs[paa->count]
- );
- memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]) + 1);
- ++optind;
- ++paa->count;
- }
- pkg_action_install( global_config, paa );
- free_pkg_action_args(paa);
- break;
- case REMOVE:
- paa = init_pkg_action_args((argc - optind));
- while (optind < argc){
- paa->pkgs[paa->count] = slapt_malloc(
- ( strlen(argv[optind]) + 1 ) * sizeof *paa->pkgs[paa->count]
- );
- memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]) + 1);
- ++optind;
- ++paa->count;
- }
- pkg_action_remove( global_config, paa );
- free_pkg_action_args(paa);
- break;
- case SHOW:
- while (optind < argc){
- pkg_action_show( argv[optind++] );
- }
- break;
- case SEARCH:
- while (optind < argc){
- pkg_action_search( argv[optind++] );
- }
- break;
- case UPGRADE:
- pkg_action_upgrade_all(global_config);
- break;
- case LIST:
- pkg_action_list(LIST);
- break;
- case INSTALLED:
- pkg_action_list(INSTALLED);
- break;
- case CLEAN:
- /* clean out local cache */
- clean_pkg_dir(global_config->working_dir);
- chdir(global_config->working_dir);
- break;
- case SHOWVERSION:
- version_info();
- break;
- case AUTOCLEAN:
- purge_old_cached_pkgs(global_config, NULL, NULL);
- break;
- case AVAILABLE:
- pkg_action_list(AVAILABLE);
- break;
- case USAGE:
- default:
- printf("main.c(l.%d): This should never be reached\n", __LINE__);
- exit(255);
- }
+ switch(do_action) {
+ case UPDATE:
+ if( update_pkg_cache(global_config) == 1 ) {
+ free_rc_config(global_config);
+ curl_global_cleanup();
+ exit(1);
+ }
+ break;
+ case INSTALL:
+ paa = init_pkg_action_args((argc - optind));
+ while (optind < argc) {
+ paa->pkgs[paa->count] = slapt_malloc(
+ ( strlen(argv[optind]) + 1 ) * sizeof *paa->pkgs[paa->count]
+ );
+ memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]) + 1);
+ ++optind;
+ ++paa->count;
+ }
+ pkg_action_install( global_config, paa );
+ free_pkg_action_args(paa);
+ break;
+ case REMOVE:
+ paa = init_pkg_action_args((argc - optind));
+ while (optind < argc) {
+ paa->pkgs[paa->count] = slapt_malloc(
+ ( strlen(argv[optind]) + 1 ) * sizeof *paa->pkgs[paa->count]
+ );
+ memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]) + 1);
+ ++optind;
+ ++paa->count;
+ }
+ pkg_action_remove( global_config, paa );
+ free_pkg_action_args(paa);
+ break;
+ case SHOW:
+ while (optind < argc) {
+ pkg_action_show( argv[optind++] );
+ }
+ break;
+ case SEARCH:
+ while (optind < argc) {
+ pkg_action_search( argv[optind++] );
+ }
+ break;
+ case UPGRADE:
+ pkg_action_upgrade_all(global_config);
+ break;
+ case LIST:
+ pkg_action_list(LIST);
+ break;
+ case INSTALLED:
+ pkg_action_list(INSTALLED);
+ break;
+ case CLEAN:
+ /* clean out local cache */
+ clean_pkg_dir(global_config->working_dir);
+ chdir(global_config->working_dir);
+ break;
+ case SHOWVERSION:
+ version_info();
+ break;
+ case AUTOCLEAN:
+ purge_old_cached_pkgs(global_config, NULL, NULL);
+ break;
+ case AVAILABLE:
+ pkg_action_list(AVAILABLE);
+ break;
+ case USAGE:
+ default:
+ printf("main.c(l.%d): This should never be reached\n", __LINE__);
+ exit(255);
+ }
- free_rc_config(global_config);
- curl_global_cleanup();
- return 0;
+ free_rc_config(global_config);
+ curl_global_cleanup();
+ return 0;
}
-void usage(void){
- printf("%s - Jason Woodward <woodwardj at jaos dot org>\n",PROGRAM_NAME);
- printf(_("An implementation of the Debian APT system to Slackware\n"));
- printf(_("Usage:\n"));
- printf(_("%s [option(s)] [target]\n"),PROGRAM_NAME);
- printf("\n");
- printf(_("Targets:\n"));
- printf(" --update - %s\n",_("retrieves pkg data from MIRROR"));
- printf(" --upgrade - %s\n",_("upgrade installed pkgs"));
- printf(" --dist-upgrade - %s\n",_("upgrade to newer release"));
- printf(" --install %s\n",_("[pkg name(s)] - install specified pkg(s)"));
- printf(" --remove %s\n",_("[pkg name(s)] - remove specified pkg(s)"));
- printf(" --show %s\n",_("[pkg name] - show pkg description"));
- printf(" --search %s\n",_("[expression] - search available pkgs"));
- printf(" --list - %s\n",_("list pkgs"));
- printf(" --available - %s\n",_("list available pkgs"));
- printf(" --installed - %s\n",_("list installed pkgs"));
- printf(" --clean - %s\n",_("purge cached pkgs"));
- printf(" --autoclean - %s\n",_("only purge cache of older, unreacheable pkgs"));
- printf(" --version - %s\n",_("print version and license info"));
- printf("\n");
- printf(_("Options:\n"));
- printf(" --download-only - %s\n",_("only download pkg on install/upgrade"));
- printf(" --simulate|-s - %s\n",_("show pkgs to be installed/upgraded"));
- printf(" --no-prompt|-y - %s\n",_("do not prompt during install/upgrade"));
- printf(" --reinstall - %s\n",_("re-install the pkg"));
- printf(" --ignore-excludes - %s\n",_("install/upgrade excludes"));
- printf(" --no-md5 - %s\n",_("do not perform md5 check sum"));
- printf(" --no-dep - %s\n",_("skip dependency check"));
- printf(" --ignore-dep - %s\n",_("ignore dependency failures"));
- printf(" --print-uris - %s\n",_("print URIs only, do not download"));
- printf(" --show-stats|-S - %s\n",_("show download statistics"));
- printf(" --config [] - %s\n",_("specify alternate slapt-getrc location"));
- printf(" --remove-obsolete - %s\n",_("remove obsolete packages (dist-upgrade only)"));
+void usage(void)
+{
+ printf("%s - Jason Woodward <woodwardj at jaos dot org>\n",PROGRAM_NAME);
+ printf(_("An implementation of the Debian APT system to Slackware\n"));
+ printf(_("Usage:\n"));
+ printf(_("%s [option(s)] [target]\n"),PROGRAM_NAME);
+ printf("\n");
+ printf(_("Targets:\n"));
+ printf(" --update - %s\n",_("retrieves pkg data from MIRROR"));
+ printf(" --upgrade - %s\n",_("upgrade installed pkgs"));
+ printf(" --dist-upgrade - %s\n",_("upgrade to newer release"));
+ printf(" --install %s\n",_("[pkg name(s)] - install specified pkg(s)"));
+ printf(" --remove %s\n",_("[pkg name(s)] - remove specified pkg(s)"));
+ printf(" --show %s\n",_("[pkg name] - show pkg description"));
+ printf(" --search %s\n",_("[expression] - search available pkgs"));
+ printf(" --list - %s\n",_("list pkgs"));
+ printf(" --available - %s\n",_("list available pkgs"));
+ printf(" --installed - %s\n",_("list installed pkgs"));
+ printf(" --clean - %s\n",_("purge cached pkgs"));
+ printf(" --autoclean - %s\n",_("only purge cache of older, unreacheable pkgs"));
+ printf(" --version - %s\n",_("print version and license info"));
+ printf("\n");
+ printf(_("Options:\n"));
+ printf(" --download-only - %s\n",_("only download pkg on install/upgrade"));
+ printf(" --simulate|-s - %s\n",_("show pkgs to be installed/upgraded"));
+ printf(" --no-prompt|-y - %s\n",_("do not prompt during install/upgrade"));
+ printf(" --reinstall - %s\n",_("re-install the pkg"));
+ printf(" --ignore-excludes - %s\n",_("install/upgrade excludes"));
+ printf(" --no-md5 - %s\n",_("do not perform md5 check sum"));
+ printf(" --no-dep - %s\n",_("skip dependency check"));
+ printf(" --ignore-dep - %s\n",_("ignore dependency failures"));
+ printf(" --print-uris - %s\n",_("print URIs only, do not download"));
+ printf(" --show-stats|-S - %s\n",_("show download statistics"));
+ printf(" --config [] - %s\n",_("specify alternate slapt-getrc location"));
+ printf(" --remove-obsolete - %s\n",_("remove obsolete packages (dist-upgrade only)"));
}
-void version_info(void){
- printf(_("%s version %s\n"),PROGRAM_NAME,VERSION);
- printf("\n");
- printf("This program is free software; you can redistribute it and/or modify\n");
- printf("it under the terms of the GNU General Public License as published by\n");
- printf("the Free Software Foundation; either version 2 of the License, or\n");
- printf("any later version.\n");
- printf("This program is distributed in the hope that it will be useful,\n");
- printf("\n");
- printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
- printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
- printf("GNU Library General Public License for more details.\n");
- printf("\n");
- printf("You should have received a copy of the GNU General Public License\n");
- printf("along with this program; if not, write to the Free Software\n");
- printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
+void version_info(void)
+{
+ printf(_("%s version %s\n"),PROGRAM_NAME,VERSION);
+ printf("\n");
+ printf("This program is free software; you can redistribute it and/or modify\n");
+ printf("it under the terms of the GNU General Public License as published by\n");
+ printf("the Free Software Foundation; either version 2 of the License, or\n");
+ printf("any later version.\n");
+ printf("This program is distributed in the hope that it will be useful,\n");
+ printf("\n");
+ printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
+ printf("GNU Library General Public License for more details.\n");
+ printf("\n");
+ printf("You should have received a copy of the GNU General Public License\n");
+ printf("along with this program; if not, write to the Free Software\n");
+ printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
}
diff --git a/src/package.c b/src/package.c
index 41ca574..3a10cfa 100644
--- a/src/package.c
+++ b/src/package.c
@@ -20,2242 +20,2443 @@
/* analyze the pkg version hunk by hunk */
static struct pkg_version_parts *break_down_pkg_version(const char *version);
/* parse the meta lines */
-static pkg_info_t *parse_meta_entry(struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,char *dep_entry);
+static pkg_info_t *parse_meta_entry(struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,
+ char *dep_entry);
/* called by is_required_by */
-static void required_by(const rc_config *global_config,struct pkg_list *avail, pkg_info_t *pkg,struct pkg_list *required_by_list);
+static void required_by(const rc_config *global_config,
+ struct pkg_list *avail, pkg_info_t *pkg,
+ struct pkg_list *required_by_list);
/* free pkg_version_parts struct */
static void free_pkg_version_parts(struct pkg_version_parts *parts);
/* find dependency from "or" requirement */
-static pkg_info_t *find_or_requirement(struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,char *required_str);
+static pkg_info_t *find_or_requirement(struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,
+ char *required_str);
/* parse the PACKAGES.TXT file */
-struct pkg_list *get_available_pkgs(void){
- FILE *pkg_list_fh;
- struct pkg_list *list;
-
- /* open pkg list */
- pkg_list_fh = open_file(PKG_LIST_L,"r");
- if( pkg_list_fh == NULL ){
- fprintf(stderr,_("Perhaps you want to run --update?\n"));
- list = init_pkg_list();
- return list; /* return an empty list */
- }
- list = parse_packages_txt(pkg_list_fh);
- fclose(pkg_list_fh);
-
- return list;
+struct pkg_list *get_available_pkgs(void)
+{
+ FILE *pkg_list_fh;
+ struct pkg_list *list;
+
+ /* open pkg list */
+ pkg_list_fh = open_file(PKG_LIST_L,"r");
+ if( pkg_list_fh == NULL ) {
+ fprintf(stderr,_("Perhaps you want to run --update?\n"));
+ list = init_pkg_list();
+ return list; /* return an empty list */
+ }
+ list = parse_packages_txt(pkg_list_fh);
+ fclose(pkg_list_fh);
+
+ return list;
}
-struct pkg_list *parse_packages_txt(FILE *pkg_list_fh){
- sg_regex name_regex, mirror_regex,location_regex, size_c_regex, size_u_regex;
- ssize_t bytes_read;
- struct pkg_list *list;
- long f_pos = 0;
- size_t getline_len = 0;
- char *getline_buffer = NULL;
- char *char_pointer = NULL;
-
- list = init_pkg_list();
-
- /* compile our regexen */
- init_regex(&name_regex,PKG_NAME_PATTERN);
- init_regex(&mirror_regex,PKG_MIRROR_PATTERN);
- init_regex(&location_regex,PKG_LOCATION_PATTERN);
- init_regex(&size_c_regex,PKG_SIZEC_PATTERN);
- init_regex(&size_u_regex,PKG_SIZEU_PATTERN);
-
- while( (bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh) ) != EOF ){
-
- pkg_info_t *tmp_pkg;
-
- getline_buffer[bytes_read - 1] = '\0';
-
- /* pull out package data */
- if( strstr(getline_buffer,"PACKAGE NAME") == NULL ) continue;
-
- execute_regex(&name_regex,getline_buffer);
-
- /* skip this line if we didn't find a package name */
- if( name_regex.reg_return != 0 ){
- fprintf(stderr,_("regex failed on [%s]\n"),getline_buffer);
- continue;
- }
- /* otherwise keep going and parse out the rest of the pkg data */
-
- tmp_pkg = init_pkg();
-
- /* pkg name base */
- tmp_pkg->name = slapt_malloc(sizeof *tmp_pkg->name * (name_regex.pmatch[1].rm_eo - name_regex.pmatch[1].rm_so + 1));
- strncpy(tmp_pkg->name,
- getline_buffer + name_regex.pmatch[1].rm_so,
- name_regex.pmatch[1].rm_eo - name_regex.pmatch[1].rm_so
- );
- tmp_pkg->name[
- name_regex.pmatch[1].rm_eo - name_regex.pmatch[1].rm_so
- ] = '\0';
-
- /* pkg version */
- tmp_pkg->version = slapt_malloc(sizeof *tmp_pkg->version * (name_regex.pmatch[2].rm_eo - name_regex.pmatch[2].rm_so + 1));
- strncpy(tmp_pkg->version,
- getline_buffer + name_regex.pmatch[2].rm_so,
- name_regex.pmatch[2].rm_eo - name_regex.pmatch[2].rm_so
- );
- tmp_pkg->version[
- name_regex.pmatch[2].rm_eo - name_regex.pmatch[2].rm_so
- ] = '\0';
-
- /* mirror */
- f_pos = ftell(pkg_list_fh);
- if(getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF){
-
- execute_regex(&mirror_regex,getline_buffer);
-
- if( mirror_regex.reg_return == 0 ){
-
- tmp_pkg->mirror = slapt_malloc( sizeof *tmp_pkg->mirror * (mirror_regex.pmatch[1].rm_eo - mirror_regex.pmatch[1].rm_so + 1) );
- strncpy( tmp_pkg->mirror,
- getline_buffer + mirror_regex.pmatch[1].rm_so,
- mirror_regex.pmatch[1].rm_eo - mirror_regex.pmatch[1].rm_so
- );
- tmp_pkg->mirror[
- mirror_regex.pmatch[1].rm_eo - mirror_regex.pmatch[1].rm_so
- ] = '\0';
-
- }else{
- /* mirror isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
- }
-
- /* location */
- if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) ){
-
- execute_regex(&location_regex,getline_buffer);
-
- if( location_regex.reg_return == 0){
-
- tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location * (location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so + 1) );
- strncpy(tmp_pkg->location,
- getline_buffer + location_regex.pmatch[1].rm_so,
- location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
- );
- tmp_pkg->location[
- location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
- ] = '\0';
-
- /*
- extra, testing, and pasture support
- they add in extraneous /extra/, /testing/, or /pasture/ in the
- PACKAGES.TXT location. this fixes the downloads and md5 checksum matching
- */
- if( strstr(tmp_pkg->location,"./testing/") != NULL ){
- char *tmp_location = slapt_malloc(sizeof *tmp_location * (strlen(tmp_pkg->location) - strlen("./testing") + 2) );
- tmp_location[0] = '.';
- tmp_location[1] = '\0';
- strncat(tmp_location,&tmp_pkg->location[0] + strlen("./testing"), strlen(tmp_pkg->location) - strlen("./testing"));
- free(tmp_pkg->location);
- tmp_pkg->location = tmp_location;
- }else if( strstr(tmp_pkg->location,"./extra/") != NULL ){
- char *tmp_location = slapt_malloc(sizeof *tmp_location * (strlen(tmp_pkg->location) - strlen("./extra") + 2) );
- tmp_location[0] = '.';
- tmp_location[1] = '\0';
- strncat(tmp_location,&tmp_pkg->location[0] + strlen("./extra"), strlen(tmp_pkg->location) - strlen("./extra"));
- free(tmp_pkg->location);
- tmp_pkg->location = tmp_location;
- }else if( strstr(tmp_pkg->location,"./pasture/") != NULL ){
- char *tmp_location = slapt_malloc(sizeof *tmp_location * (strlen(tmp_pkg->location) - strlen("./pasture") + 2) );
- tmp_location[0] = '.';
- tmp_location[1] = '\0';
- strncat(tmp_location,&tmp_pkg->location[0] + strlen("./pasture"), strlen(tmp_pkg->location) - strlen("./pasture"));
- free(tmp_pkg->location);
- tmp_pkg->location = tmp_location;
- }
-
- }else{
- fprintf(stderr,_("regexec failed to parse location\n"));
- free_pkg(tmp_pkg);
- continue;
- }
- }else{
- fprintf(stderr,_("getline reached EOF attempting to read location\n"));
- free_pkg(tmp_pkg);
- continue;
- }
-
- /* size_c */
- if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)){
-
- char *size_c = NULL;
-
- execute_regex(&size_c_regex,getline_buffer);
-
- if( size_c_regex.reg_return == 0 ){
- size_c = strndup(
- getline_buffer + size_c_regex.pmatch[1].rm_so,
- (size_c_regex.pmatch[1].rm_eo - size_c_regex.pmatch[1].rm_so)
- );
- tmp_pkg->size_c = strtol(size_c, (char **)NULL, 10);
- free(size_c);
- }else{
- fprintf(stderr,_("regexec failed to parse size_c\n"));
- free_pkg(tmp_pkg);
- continue;
- }
- }else{
- fprintf(stderr,_("getline reached EOF attempting to read size_c\n"));
- free_pkg(tmp_pkg);
- continue;
- }
-
- /* size_u */
- if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)){
-
- char *size_u = NULL;
-
- execute_regex(&size_u_regex,getline_buffer);
-
- if( size_u_regex.reg_return == 0 ){
- size_u = strndup(
- getline_buffer + size_u_regex.pmatch[1].rm_so,
- (size_u_regex.pmatch[1].rm_eo - size_u_regex.pmatch[1].rm_so)
- );
- tmp_pkg->size_u = strtol(size_u, (char **)NULL, 10);
- free(size_u);
- }else{
- fprintf(stderr,_("regexec failed to parse size_u\n"));
- free_pkg(tmp_pkg);
- continue;
- }
- }else{
- fprintf(stderr,_("getline reached EOF attempting to read size_u\n"));
- free_pkg(tmp_pkg);
- continue;
- }
-
- /* required, if provided */
- f_pos = ftell(pkg_list_fh);
- if(
- ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
- ((char_pointer = strstr(getline_buffer,"PACKAGE REQUIRED")) != NULL)
- ){
- char *tmp_realloc = NULL;
- size_t req_len = strlen("PACKAGE REQUIRED") + 2;
- getline_buffer[bytes_read - 1] = '\0';
-
- tmp_realloc = realloc(
- tmp_pkg->required,
- sizeof *tmp_pkg->required * (strlen(char_pointer + req_len) + 1)
- );
- if( tmp_realloc != NULL ){
- tmp_pkg->required = tmp_realloc;
- strncpy(tmp_pkg->required,char_pointer + req_len, strlen(char_pointer + req_len));
- tmp_pkg->required[ strlen(char_pointer + req_len) ] = '\0';
- }
- }else{
- /* required isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* conflicts, if provided */
- f_pos = ftell(pkg_list_fh);
- if(
- ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
- ((char_pointer = strstr(getline_buffer,"PACKAGE CONFLICTS")) != NULL)
- ){
- char *tmp_realloc = NULL;
- char *conflicts = (char *)strpbrk(char_pointer,":") + 3;
- getline_buffer[bytes_read - 1] = '\0';
- tmp_realloc = realloc(tmp_pkg->conflicts, sizeof *tmp_pkg->conflicts * (strlen(conflicts) + 1));
- if( tmp_realloc != NULL ){
- tmp_pkg->conflicts = tmp_realloc;
- strncat(tmp_pkg->conflicts,conflicts,strlen(conflicts));
- tmp_pkg->conflicts[ strlen(conflicts) ] = '\0';
- }
- }else{
- /* conflicts isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* suggests, if provided */
- f_pos = ftell(pkg_list_fh);
- if(
- ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
- ((char_pointer = strstr(getline_buffer,"PACKAGE SUGGESTS")) != NULL)
- ){
- char *tmp_realloc = NULL;
- char *suggests = (char *)strpbrk(char_pointer,":") + 3;
- getline_buffer[bytes_read - 1] = '\0';
- tmp_realloc = realloc(tmp_pkg->suggests, sizeof *tmp_pkg->suggests * (strlen(suggests) + 1));
- if( tmp_realloc != NULL ){
- tmp_pkg->suggests = tmp_realloc;
- strncat(tmp_pkg->suggests,suggests,strlen(suggests));
- tmp_pkg->suggests[ strlen(suggests) ] = '\0';
- }
- }else{
- /* suggests isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* md5 checksum */
- f_pos = ftell(pkg_list_fh);
- if(
- ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
- (strstr(getline_buffer,"PACKAGE MD5 SUM") != NULL)
- ){
- char *md5sum;
- getline_buffer[bytes_read - 1] = '\0';
- md5sum = (char *)strpbrk(getline_buffer,":") + 3;
- /* don't overflow the buffer */
- if( strlen(md5sum) > MD5_STR_LEN ){
- fprintf( stderr, _("md5 sum too long\n"));
- free_pkg(tmp_pkg);
- continue;
- }
-
- strncpy( tmp_pkg->md5,md5sum,MD5_STR_LEN);
- tmp_pkg->md5[MD5_STR_LEN] = '\0';
- }else{
- /* md5 sum isn't provided... rewind one line */
- fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
- }
-
- /* description */
- if(
- (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) &&
- (strstr(getline_buffer,"PACKAGE DESCRIPTION") != NULL)
- ){
-
- while( 1 ){
- char *tmp_desc = NULL;
-
- if( (bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) == EOF ){
- break;
- }
-
- if( strcmp(getline_buffer,"\n") == 0){
- break;
- }
-
- tmp_desc = realloc(tmp_pkg->description,sizeof *tmp_pkg->description * (strlen(tmp_pkg->description) + bytes_read + 1) );
- if( tmp_desc == NULL ){
- break;
- }
- tmp_pkg->description = tmp_desc;
- strncat(tmp_pkg->description,getline_buffer,bytes_read);
-
- }
- }else{
- fprintf(stderr,_("error attempting to read pkg description\n"));
- free_pkg(tmp_pkg);
- continue;
- }
-
- /* fillin details */
- if( tmp_pkg->location == NULL ){
- tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->location[0] = '\0';
- }
- if( tmp_pkg->description == NULL ){
- tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->description[0] = '\0';
- }
- if( tmp_pkg->mirror == NULL ){
- tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->mirror[0] = '\0';
- }
-
- add_pkg_to_pkg_list(list,tmp_pkg);
- tmp_pkg = NULL;
- }
-
- if( getline_buffer) free(getline_buffer);
- free_regex(&name_regex);
- free_regex(&mirror_regex);
- free_regex(&location_regex);
- free_regex(&size_c_regex);
- free_regex(&size_u_regex);
-
- list->free_pkgs = TRUE;
- return list;
+struct pkg_list *parse_packages_txt(FILE *pkg_list_fh)
+{
+ sg_regex name_regex, mirror_regex,location_regex, size_c_regex, size_u_regex;
+ ssize_t bytes_read;
+ struct pkg_list *list;
+ long f_pos = 0;
+ size_t getline_len = 0;
+ char *getline_buffer = NULL;
+ char *char_pointer = NULL;
+
+ list = init_pkg_list();
+
+ /* compile our regexen */
+ init_regex(&name_regex,PKG_NAME_PATTERN);
+ init_regex(&mirror_regex,PKG_MIRROR_PATTERN);
+ init_regex(&location_regex,PKG_LOCATION_PATTERN);
+ init_regex(&size_c_regex,PKG_SIZEC_PATTERN);
+ init_regex(&size_u_regex,PKG_SIZEU_PATTERN);
+
+ while( (bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh) ) != EOF ) {
+
+ pkg_info_t *tmp_pkg;
+
+ getline_buffer[bytes_read - 1] = '\0';
+
+ /* pull out package data */
+ if( strstr(getline_buffer,"PACKAGE NAME") == NULL ) continue;
+
+ execute_regex(&name_regex,getline_buffer);
+
+ /* skip this line if we didn't find a package name */
+ if( name_regex.reg_return != 0 ) {
+ fprintf(stderr,_("regex failed on [%s]\n"),getline_buffer);
+ continue;
+ }
+ /* otherwise keep going and parse out the rest of the pkg data */
+
+ tmp_pkg = init_pkg();
+
+ /* pkg name base */
+ tmp_pkg->name = slapt_malloc(
+ sizeof *tmp_pkg->name *
+ (name_regex.pmatch[1].rm_eo - name_regex.pmatch[1].rm_so + 1)
+ );
+
+ strncpy(tmp_pkg->name,
+ getline_buffer + name_regex.pmatch[1].rm_so,
+ name_regex.pmatch[1].rm_eo - name_regex.pmatch[1].rm_so
+ );
+ tmp_pkg->name[
+ name_regex.pmatch[1].rm_eo - name_regex.pmatch[1].rm_so
+ ] = '\0';
+
+ /* pkg version */
+ tmp_pkg->version = slapt_malloc(
+ sizeof *tmp_pkg->version *
+ (name_regex.pmatch[2].rm_eo - name_regex.pmatch[2].rm_so + 1)
+ );
+
+ strncpy(tmp_pkg->version,
+ getline_buffer + name_regex.pmatch[2].rm_so,
+ name_regex.pmatch[2].rm_eo - name_regex.pmatch[2].rm_so
+ );
+ tmp_pkg->version[
+ name_regex.pmatch[2].rm_eo - name_regex.pmatch[2].rm_so
+ ] = '\0';
+
+ /* mirror */
+ f_pos = ftell(pkg_list_fh);
+ if(getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) {
+
+ execute_regex(&mirror_regex,getline_buffer);
+
+ if( mirror_regex.reg_return == 0 ) {
+
+ tmp_pkg->mirror = slapt_malloc(
+ sizeof *tmp_pkg->mirror *
+ (mirror_regex.pmatch[1].rm_eo - mirror_regex.pmatch[1].rm_so + 1)
+ );
+
+ strncpy( tmp_pkg->mirror,
+ getline_buffer + mirror_regex.pmatch[1].rm_so,
+ mirror_regex.pmatch[1].rm_eo - mirror_regex.pmatch[1].rm_so
+ );
+ tmp_pkg->mirror[
+ mirror_regex.pmatch[1].rm_eo - mirror_regex.pmatch[1].rm_so
+ ] = '\0';
+
+ }else{
+ /* mirror isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+ }
+
+ /* location */
+ if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) ) {
+
+ execute_regex(&location_regex,getline_buffer);
+
+ if( location_regex.reg_return == 0) {
+
+ tmp_pkg->location = slapt_malloc(
+ sizeof *tmp_pkg->location *
+ (location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so + 1)
+ );
+
+ strncpy(tmp_pkg->location,
+ getline_buffer + location_regex.pmatch[1].rm_so,
+ location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
+ );
+ tmp_pkg->location[
+ location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
+ ] = '\0';
+
+ /*
+ extra, testing, and pasture support
+ they add in extraneous /extra/, /testing/, or /pasture/ in the
+ PACKAGES.TXT location. this fixes the downloads and md5 checksum matching
+ */
+ if( strstr(tmp_pkg->location,"./testing/") != NULL ) {
+ char *tmp_location = slapt_malloc(
+ sizeof *tmp_location *
+ (strlen(tmp_pkg->location) - strlen("./testing") + 2)
+ );
+ tmp_location[0] = '.';
+ tmp_location[1] = '\0';
+ strncat(tmp_location,
+ &tmp_pkg->location[0] + strlen("./testing"),
+ strlen(tmp_pkg->location) - strlen("./testing")
+ );
+ free(tmp_pkg->location);
+ tmp_pkg->location = tmp_location;
+ }else if( strstr(tmp_pkg->location,"./extra/") != NULL ) {
+ char *tmp_location = slapt_malloc(
+ sizeof *tmp_location *
+ (strlen(tmp_pkg->location) - strlen("./extra") + 2)
+ );
+ tmp_location[0] = '.';
+ tmp_location[1] = '\0';
+ strncat(tmp_location,
+ &tmp_pkg->location[0] + strlen("./extra"),
+ strlen(tmp_pkg->location) - strlen("./extra")
+ );
+ free(tmp_pkg->location);
+ tmp_pkg->location = tmp_location;
+ }else if( strstr(tmp_pkg->location,"./pasture/") != NULL ) {
+ char *tmp_location = slapt_malloc(
+ sizeof *tmp_location *
+ (strlen(tmp_pkg->location) - strlen("./pasture") + 2)
+ );
+ tmp_location[0] = '.';
+ tmp_location[1] = '\0';
+ strncat(tmp_location,
+ &tmp_pkg->location[0] + strlen("./pasture"),
+ strlen(tmp_pkg->location) - strlen("./pasture")
+ );
+ free(tmp_pkg->location);
+ tmp_pkg->location = tmp_location;
+ }
+
+ }else{
+ fprintf(stderr,_("regexec failed to parse location\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+ }else{
+ fprintf(stderr,_("getline reached EOF attempting to read location\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+
+ /* size_c */
+ if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)) {
+
+ char *size_c = NULL;
+
+ execute_regex(&size_c_regex,getline_buffer);
+
+ if( size_c_regex.reg_return == 0 ) {
+ size_c = strndup(
+ getline_buffer + size_c_regex.pmatch[1].rm_so,
+ (size_c_regex.pmatch[1].rm_eo - size_c_regex.pmatch[1].rm_so)
+ );
+ tmp_pkg->size_c = strtol(size_c, (char **)NULL, 10);
+ free(size_c);
+ }else{
+ fprintf(stderr,_("regexec failed to parse size_c\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+ }else{
+ fprintf(stderr,_("getline reached EOF attempting to read size_c\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+
+ /* size_u */
+ if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)) {
+
+ char *size_u = NULL;
+
+ execute_regex(&size_u_regex,getline_buffer);
+
+ if( size_u_regex.reg_return == 0 ) {
+ size_u = strndup(
+ getline_buffer + size_u_regex.pmatch[1].rm_so,
+ (size_u_regex.pmatch[1].rm_eo - size_u_regex.pmatch[1].rm_so)
+ );
+ tmp_pkg->size_u = strtol(size_u, (char **)NULL, 10);
+ free(size_u);
+ }else{
+ fprintf(stderr,_("regexec failed to parse size_u\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+ }else{
+ fprintf(stderr,_("getline reached EOF attempting to read size_u\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+
+ /* required, if provided */
+ f_pos = ftell(pkg_list_fh);
+ if(
+ ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
+ ((char_pointer = strstr(getline_buffer,"PACKAGE REQUIRED")) != NULL)
+ ) {
+ char *tmp_realloc = NULL;
+ size_t req_len = strlen("PACKAGE REQUIRED") + 2;
+ getline_buffer[bytes_read - 1] = '\0';
+
+ tmp_realloc = realloc(
+ tmp_pkg->required,
+ sizeof *tmp_pkg->required * (strlen(char_pointer + req_len) + 1)
+ );
+ if( tmp_realloc != NULL ) {
+ tmp_pkg->required = tmp_realloc;
+ strncpy(tmp_pkg->required,char_pointer + req_len, strlen(char_pointer + req_len));
+ tmp_pkg->required[ strlen(char_pointer + req_len) ] = '\0';
+ }
+ }else{
+ /* required isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+
+ /* conflicts, if provided */
+ f_pos = ftell(pkg_list_fh);
+ if(
+ ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
+ ((char_pointer = strstr(getline_buffer,"PACKAGE CONFLICTS")) != NULL)
+ ) {
+ char *tmp_realloc = NULL;
+ char *conflicts = (char *)strpbrk(char_pointer,":") + 3;
+ getline_buffer[bytes_read - 1] = '\0';
+
+ tmp_realloc = realloc(tmp_pkg->conflicts,
+ sizeof *tmp_pkg->conflicts * (strlen(conflicts) + 1)
+ );
+ if( tmp_realloc != NULL ) {
+ tmp_pkg->conflicts = tmp_realloc;
+ strncat(tmp_pkg->conflicts,conflicts,strlen(conflicts));
+ tmp_pkg->conflicts[ strlen(conflicts) ] = '\0';
+ }
+ }else{
+ /* conflicts isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+
+ /* suggests, if provided */
+ f_pos = ftell(pkg_list_fh);
+ if(
+ ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
+ ((char_pointer = strstr(getline_buffer,"PACKAGE SUGGESTS")) != NULL)
+ ) {
+ char *tmp_realloc = NULL;
+ char *suggests = (char *)strpbrk(char_pointer,":") + 3;
+ getline_buffer[bytes_read - 1] = '\0';
+
+ tmp_realloc = realloc(tmp_pkg->suggests,
+ sizeof *tmp_pkg->suggests * (strlen(suggests) + 1)
+ );
+ if( tmp_realloc != NULL ) {
+ tmp_pkg->suggests = tmp_realloc;
+ strncat(tmp_pkg->suggests,suggests,strlen(suggests));
+ tmp_pkg->suggests[ strlen(suggests) ] = '\0';
+ }
+ }else{
+ /* suggests isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+
+ /* md5 checksum */
+ f_pos = ftell(pkg_list_fh);
+ if(
+ ((bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) != EOF) &&
+ (strstr(getline_buffer,"PACKAGE MD5 SUM") != NULL)
+ ) {
+ char *md5sum;
+ getline_buffer[bytes_read - 1] = '\0';
+ md5sum = (char *)strpbrk(getline_buffer,":") + 3;
+ /* don't overflow the buffer */
+ if( strlen(md5sum) > MD5_STR_LEN ) {
+ fprintf( stderr, _("md5 sum too long\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+
+ strncpy( tmp_pkg->md5,md5sum,MD5_STR_LEN);
+ tmp_pkg->md5[MD5_STR_LEN] = '\0';
+ }else{
+ /* md5 sum isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+
+ /* description */
+ if(
+ (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF) &&
+ (strstr(getline_buffer,"PACKAGE DESCRIPTION") != NULL)
+ ) {
+
+ while( 1 ) {
+ char *tmp_desc = NULL;
+
+ if( (bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh)) == EOF ) {
+ break;
+ }
+
+ if( strcmp(getline_buffer,"\n") == 0) {
+ break;
+ }
+
+ tmp_desc = realloc(tmp_pkg->description,
+ sizeof *tmp_pkg->description *
+ (strlen(tmp_pkg->description) + bytes_read + 1)
+ );
+ if( tmp_desc == NULL ) {
+ break;
+ }
+ tmp_pkg->description = tmp_desc;
+ strncat(tmp_pkg->description,getline_buffer,bytes_read);
+
+ }
+ }else{
+ fprintf(stderr,_("error attempting to read pkg description\n"));
+ free_pkg(tmp_pkg);
+ continue;
+ }
+
+ /* fillin details */
+ if( tmp_pkg->location == NULL ) {
+ tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->location[0] = '\0';
+ }
+ if( tmp_pkg->description == NULL ) {
+ tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->description[0] = '\0';
+ }
+ if( tmp_pkg->mirror == NULL ) {
+ tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->mirror[0] = '\0';
+ }
+
+ add_pkg_to_pkg_list(list,tmp_pkg);
+ tmp_pkg = NULL;
+ }
+
+ if( getline_buffer) free(getline_buffer);
+ free_regex(&name_regex);
+ free_regex(&mirror_regex);
+ free_regex(&location_regex);
+ free_regex(&size_c_regex);
+ free_regex(&size_u_regex);
+
+ list->free_pkgs = TRUE;
+ return list;
}
-char *gen_short_pkg_description(pkg_info_t *pkg){
- char *short_description = NULL;
- size_t string_size = 0;
+char *gen_short_pkg_description(pkg_info_t *pkg)
+{
+ char *short_description = NULL;
+ size_t string_size = 0;
- if( strchr(pkg->description,'\n') != NULL ){
- string_size = strlen(pkg->description) - (strlen(pkg->name) + 2) - strlen( strchr(pkg->description,'\n') );
- }
+ if( strchr(pkg->description,'\n') != NULL ) {
+ string_size = strlen(pkg->description) -
+ (strlen(pkg->name) + 2) - strlen( strchr(pkg->description,'\n') );
+ }
- /* quit now if the description is going to be empty */
- if( (int)string_size < 0 ) return NULL;
+ /* quit now if the description is going to be empty */
+ if( (int)string_size < 0 ) return NULL;
- short_description = strndup(
- pkg->description + (strlen(pkg->name) + 2),
- string_size
- );
+ short_description = strndup(
+ pkg->description + (strlen(pkg->name) + 2),
+ string_size
+ );
- return short_description;
+ return short_description;
}
-struct pkg_list *get_installed_pkgs(void){
- DIR *pkg_log_dir;
- char *root_env_entry = NULL;
- char *pkg_log_dirname = NULL;
- struct dirent *file;
- sg_regex ip_regex, compressed_size_reg, uncompressed_size_reg,location_regex;
- struct pkg_list *list;
-
- list = init_pkg_list();
-
- init_regex(&ip_regex,PKG_LOG_PATTERN);
- init_regex(&compressed_size_reg,PKG_LOG_SIZEC_PATTERN);
- init_regex(&uncompressed_size_reg,PKG_LOG_SIZEU_PATTERN);
- init_regex(&location_regex,PKG_LOCATION_PATTERN);
-
- /* Generate package log directory using ROOT env variable if set */
- if( getenv(ROOT_ENV_NAME) && strlen(getenv(ROOT_ENV_NAME)) < ROOT_ENV_LEN ){
- root_env_entry = getenv(ROOT_ENV_NAME);
- }
- pkg_log_dirname = slapt_calloc(
- strlen(PKG_LOG_DIR)+
- (root_env_entry ? strlen(root_env_entry) : 0) + 1 ,
- sizeof *pkg_log_dirname
- );
- *pkg_log_dirname = '\0';
- if(root_env_entry){
- strncpy(pkg_log_dirname, root_env_entry,strlen(root_env_entry));
- strncat(pkg_log_dirname, PKG_LOG_DIR,strlen(PKG_LOG_DIR));
- }else{
- strncat(pkg_log_dirname, PKG_LOG_DIR,strlen(PKG_LOG_DIR));
- }
-
- if( (pkg_log_dir = opendir(pkg_log_dirname)) == NULL ){
- if( errno ){
- perror(pkg_log_dirname);
- }
- free(pkg_log_dirname);
- return list;
- }
-
- while( (file = readdir(pkg_log_dir)) != NULL ){
- pkg_info_t *tmp_pkg;
- FILE *pkg_f;
- char *pkg_f_name;
- size_t getline_len;
- ssize_t bytes_read;
- char *getline_buffer = NULL;
-
- execute_regex(&ip_regex,file->d_name);
-
- /* skip if it doesn't match our regex */
- if( ip_regex.reg_return != 0 ) continue;
-
- tmp_pkg = init_pkg();
-
- tmp_pkg->name = slapt_malloc(sizeof *tmp_pkg->name * (ip_regex.pmatch[1].rm_eo - ip_regex.pmatch[1].rm_so + 1) );
- strncpy(
- tmp_pkg->name,
- file->d_name + ip_regex.pmatch[1].rm_so,
- ip_regex.pmatch[1].rm_eo - ip_regex.pmatch[1].rm_so
- );
- tmp_pkg->name[ ip_regex.pmatch[1].rm_eo - ip_regex.pmatch[1].rm_so ] = '\0';
-
- tmp_pkg->version = slapt_malloc(sizeof *tmp_pkg->version * (ip_regex.pmatch[2].rm_eo - ip_regex.pmatch[2].rm_so + 1) );
- strncpy(
- tmp_pkg->version,
- file->d_name + ip_regex.pmatch[2].rm_so,
- ip_regex.pmatch[2].rm_eo - ip_regex.pmatch[2].rm_so
- );
- tmp_pkg->version[ ip_regex.pmatch[2].rm_eo - ip_regex.pmatch[2].rm_so ] = '\0';
-
- /* build the package filename including the package directory */
- pkg_f_name = slapt_malloc( sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(file->d_name) + 2) );
- pkg_f_name[0] = '\0';
- strncat(pkg_f_name,pkg_log_dirname,strlen(pkg_log_dirname));
- strncat(pkg_f_name,"/",strlen("/"));
- strncat(pkg_f_name,file->d_name,strlen(file->d_name));
-
- /* open the package log file to grok data about the package from it */
- pkg_f = open_file(pkg_f_name,"r");
- free(pkg_f_name);
- if( pkg_f == NULL ) exit(1);
- while( (bytes_read = getline(&getline_buffer,&getline_len,pkg_f)) != EOF ){
- execute_regex(&compressed_size_reg,getline_buffer);
- execute_regex(&uncompressed_size_reg,getline_buffer);
- execute_regex(&location_regex,getline_buffer);
-
- /* ignore unless we matched */
- if( compressed_size_reg.reg_return == 0 ){
- char *size_c = strndup(
- getline_buffer + compressed_size_reg.pmatch[1].rm_so,
- (compressed_size_reg.pmatch[1].rm_eo - compressed_size_reg.pmatch[1].rm_so)
- );
- tmp_pkg->size_c = strtol(size_c,(char **)NULL,10);
- free(size_c);
- }else if(uncompressed_size_reg.reg_return == 0 ){
- char *size_u = strndup(
- getline_buffer + uncompressed_size_reg.pmatch[1].rm_so,
- (uncompressed_size_reg.pmatch[1].rm_eo - uncompressed_size_reg.pmatch[1].rm_so)
- );
- tmp_pkg->size_u = strtol(size_u,(char **)NULL,10);
- free(size_u);
- }else if( location_regex.reg_return == 0 ){
- tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location * (location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so + 1));
- strncpy(tmp_pkg->location,
- getline_buffer + location_regex.pmatch[1].rm_so,
- location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
- );
- tmp_pkg->location[
- location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
- ] = '\0';
-
- }else{
- if(strstr(getline_buffer,"PACKAGE DESCRIPTION") != NULL){
- while(1){
- char *tmp_desc = NULL;
-
- if((bytes_read = getline(&getline_buffer,&getline_len,pkg_f)) == EOF ) break;
-
- if( strstr(getline_buffer,"FILE LIST:") != NULL ) break;
-
- if( strcmp(getline_buffer,"\n") == 0) break;
-
- tmp_desc = realloc(tmp_pkg->description,sizeof *tmp_pkg->description * (strlen(tmp_pkg->description) + bytes_read + 1) );
- if( tmp_desc == NULL ){
- break;
- }
- tmp_pkg->description = tmp_desc;
- strncat(tmp_pkg->description,getline_buffer,bytes_read);
-
- }
- }else{
- continue;
- }
- }
- }
- if(getline_buffer) free(getline_buffer);
- fclose(pkg_f);
-
- /* fillin details */
- if( tmp_pkg->location == NULL ){
- tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->location[0] = '\0';
- }
- if( tmp_pkg->description == NULL ){
- tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->description[0] = '\0';
- }
- if( tmp_pkg->mirror == NULL ){
- tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->location);
- tmp_pkg->mirror[0] = '\0';
- }
-
- add_pkg_to_pkg_list(list,tmp_pkg);
- tmp_pkg = NULL;
-
- }/* end while */
- closedir(pkg_log_dir);
- free_regex(&ip_regex);
- free(pkg_log_dirname);
- free_regex(&compressed_size_reg);
- free_regex(&uncompressed_size_reg);
- free_regex(&location_regex);
-
- list->free_pkgs = TRUE;
- return list;
+struct pkg_list *get_installed_pkgs(void)
+{
+ DIR *pkg_log_dir;
+ char *root_env_entry = NULL;
+ char *pkg_log_dirname = NULL;
+ struct dirent *file;
+ sg_regex ip_regex, compressed_size_reg, uncompressed_size_reg,location_regex;
+ struct pkg_list *list;
+
+ list = init_pkg_list();
+
+ init_regex(&ip_regex,PKG_LOG_PATTERN);
+ init_regex(&compressed_size_reg,PKG_LOG_SIZEC_PATTERN);
+ init_regex(&uncompressed_size_reg,PKG_LOG_SIZEU_PATTERN);
+ init_regex(&location_regex,PKG_LOCATION_PATTERN);
+
+ /* Generate package log directory using ROOT env variable if set */
+ if( getenv(ROOT_ENV_NAME) && strlen(getenv(ROOT_ENV_NAME)) < ROOT_ENV_LEN ) {
+ root_env_entry = getenv(ROOT_ENV_NAME);
+ }
+ pkg_log_dirname = slapt_calloc(
+ strlen(PKG_LOG_DIR)+
+ (root_env_entry ? strlen(root_env_entry) : 0) + 1 ,
+ sizeof *pkg_log_dirname
+ );
+ *pkg_log_dirname = '\0';
+ if(root_env_entry) {
+ strncpy(pkg_log_dirname, root_env_entry,strlen(root_env_entry));
+ strncat(pkg_log_dirname, PKG_LOG_DIR,strlen(PKG_LOG_DIR));
+ }else{
+ strncat(pkg_log_dirname, PKG_LOG_DIR,strlen(PKG_LOG_DIR));
+ }
+
+ if( (pkg_log_dir = opendir(pkg_log_dirname)) == NULL ) {
+ if( errno ) {
+ perror(pkg_log_dirname);
+ }
+ free(pkg_log_dirname);
+ return list;
+ }
+
+ while( (file = readdir(pkg_log_dir)) != NULL ) {
+ pkg_info_t *tmp_pkg;
+ FILE *pkg_f;
+ char *pkg_f_name;
+ size_t getline_len;
+ ssize_t bytes_read;
+ char *getline_buffer = NULL;
+
+ execute_regex(&ip_regex,file->d_name);
+
+ /* skip if it doesn't match our regex */
+ if( ip_regex.reg_return != 0 ) continue;
+
+ tmp_pkg = init_pkg();
+
+ tmp_pkg->name = slapt_malloc(
+ sizeof *tmp_pkg->name *
+ (ip_regex.pmatch[1].rm_eo - ip_regex.pmatch[1].rm_so + 1)
+ );
+ strncpy(
+ tmp_pkg->name,
+ file->d_name + ip_regex.pmatch[1].rm_so,
+ ip_regex.pmatch[1].rm_eo - ip_regex.pmatch[1].rm_so
+ );
+ tmp_pkg->name[ ip_regex.pmatch[1].rm_eo - ip_regex.pmatch[1].rm_so ] = '\0';
+
+ tmp_pkg->version = slapt_malloc(
+ sizeof *tmp_pkg->version *
+ (ip_regex.pmatch[2].rm_eo - ip_regex.pmatch[2].rm_so + 1)
+ );
+ strncpy(
+ tmp_pkg->version,
+ file->d_name + ip_regex.pmatch[2].rm_so,
+ ip_regex.pmatch[2].rm_eo - ip_regex.pmatch[2].rm_so
+ );
+ tmp_pkg->version[ ip_regex.pmatch[2].rm_eo - ip_regex.pmatch[2].rm_so ] = '\0';
+
+ /* build the package filename including the package directory */
+ pkg_f_name = slapt_malloc(
+ sizeof *pkg_f_name * (strlen(pkg_log_dirname) + strlen(file->d_name) + 2)
+ );
+ pkg_f_name[0] = '\0';
+ strncat(pkg_f_name,pkg_log_dirname,strlen(pkg_log_dirname));
+ strncat(pkg_f_name,"/",strlen("/"));
+ strncat(pkg_f_name,file->d_name,strlen(file->d_name));
+
+ /* open the package log file to grok data about the package from it */
+ pkg_f = open_file(pkg_f_name,"r");
+ free(pkg_f_name);
+ if( pkg_f == NULL ) exit(1);
+ while( (bytes_read = getline(&getline_buffer,&getline_len,pkg_f)) != EOF ) {
+
+ execute_regex(&compressed_size_reg,getline_buffer);
+ execute_regex(&uncompressed_size_reg,getline_buffer);
+ execute_regex(&location_regex,getline_buffer);
+
+ /* ignore unless we matched */
+ if( compressed_size_reg.reg_return == 0 ) {
+
+ char *size_c = strndup(
+ getline_buffer + compressed_size_reg.pmatch[1].rm_so,
+ (compressed_size_reg.pmatch[1].rm_eo - compressed_size_reg.pmatch[1].rm_so)
+ );
+ tmp_pkg->size_c = strtol(size_c,(char **)NULL,10);
+ free(size_c);
+
+ }else if(uncompressed_size_reg.reg_return == 0 ) {
+
+ char *size_u = strndup(
+ getline_buffer + uncompressed_size_reg.pmatch[1].rm_so,
+ (uncompressed_size_reg.pmatch[1].rm_eo - uncompressed_size_reg.pmatch[1].rm_so)
+ );
+ tmp_pkg->size_u = strtol(size_u,(char **)NULL,10);
+ free(size_u);
+
+ }else if( location_regex.reg_return == 0 ) {
+
+ tmp_pkg->location = slapt_malloc(
+ sizeof *tmp_pkg->location *
+ (location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so + 1)
+ );
+ strncpy(tmp_pkg->location,
+ getline_buffer + location_regex.pmatch[1].rm_so,
+ location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
+ );
+ tmp_pkg->location[
+ location_regex.pmatch[1].rm_eo - location_regex.pmatch[1].rm_so
+ ] = '\0';
+
+ }else{
+
+ if(strstr(getline_buffer,"PACKAGE DESCRIPTION") == NULL) {
+ continue;
+ }
+
+ while(1) {
+ char *tmp_desc = NULL;
+
+ if((bytes_read = getline(&getline_buffer,&getline_len,pkg_f)) == EOF ) {
+ break;
+ }
+
+ if( strstr(getline_buffer,"FILE LIST:") != NULL ) break;
+
+ if( strcmp(getline_buffer,"\n") == 0) break;
+
+ tmp_desc = realloc(
+ tmp_pkg->description,
+ sizeof *tmp_pkg->description *
+ (strlen(tmp_pkg->description) + bytes_read + 1)
+ );
+ if( tmp_desc == NULL ) {
+ break;
+ }
+ tmp_pkg->description = tmp_desc;
+ strncat(tmp_pkg->description,getline_buffer,bytes_read);
+
+ }
+
+ }
+
+ }
+ if(getline_buffer) free(getline_buffer);
+ fclose(pkg_f);
+
+ /* fillin details */
+ if( tmp_pkg->location == NULL ) {
+ tmp_pkg->location = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->location[0] = '\0';
+ }
+ if( tmp_pkg->description == NULL ) {
+ tmp_pkg->description = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->description[0] = '\0';
+ }
+ if( tmp_pkg->mirror == NULL ) {
+ tmp_pkg->mirror = slapt_malloc(sizeof *tmp_pkg->location);
+ tmp_pkg->mirror[0] = '\0';
+ }
+
+ add_pkg_to_pkg_list(list,tmp_pkg);
+ tmp_pkg = NULL;
+
+ }/* end while */
+ closedir(pkg_log_dir);
+ free_regex(&ip_regex);
+ free(pkg_log_dirname);
+ free_regex(&compressed_size_reg);
+ free_regex(&uncompressed_size_reg);
+ free_regex(&location_regex);
+
+ list->free_pkgs = TRUE;
+ return list;
}
/* lookup newest package from pkg_list */
-pkg_info_t *get_newest_pkg(struct pkg_list *pkg_list,const char *pkg_name){
- unsigned int i;
- pkg_info_t *pkg = NULL;
+pkg_info_t *get_newest_pkg(struct pkg_list *pkg_list,const char *pkg_name)
+{
+ unsigned int i;
+ pkg_info_t *pkg = NULL;
- for(i = 0; i < pkg_list->pkg_count; i++ ){
+ for(i = 0; i < pkg_list->pkg_count; i++ ) {
- /* if pkg has same name as our requested pkg */
- if( (strcmp(pkg_list->pkgs[i]->name,pkg_name)) == 0 ){
- if( (pkg == NULL) || (cmp_pkg_versions(pkg->version,
- pkg_list->pkgs[i]->version) < 0) ){
- pkg = pkg_list->pkgs[i];
- }
- }
+ /* if pkg has same name as our requested pkg */
+ if( (strcmp(pkg_list->pkgs[i]->name,pkg_name)) == 0 ) {
+ if( (pkg == NULL) || (cmp_pkg_versions(pkg->version,
+ pkg_list->pkgs[i]->version) < 0) ) {
+ pkg = pkg_list->pkgs[i];
+ }
+ }
- }
+ }
- return pkg;
+ return pkg;
}
-pkg_info_t *get_exact_pkg(struct pkg_list *list,const char *name,const char *version){
- unsigned int i;
- pkg_info_t *pkg = NULL;
-
- for(i = 0; i < list->pkg_count;i++){
- if( (strcmp(name,list->pkgs[i]->name)==0) && (strcmp(version,list->pkgs[i]->version)==0) )
- return list->pkgs[i];
- }
- return pkg;
+pkg_info_t *get_exact_pkg(struct pkg_list *list,const char *name,const char *version)
+{
+ unsigned int i;
+ pkg_info_t *pkg = NULL;
+
+ for(i = 0; i < list->pkg_count;i++) {
+ if( (strcmp(name,list->pkgs[i]->name)==0) &&
+ (strcmp(version,list->pkgs[i]->version)==0) ) {
+ return list->pkgs[i];
+ }
+ }
+ return pkg;
}
-int install_pkg(const rc_config *global_config,pkg_info_t *pkg){
- char *pkg_file_name = NULL;
- char *command = NULL;
- int cmd_return = 0;
-
- /* build the file name */
- pkg_file_name = gen_pkg_file_name(global_config,pkg);
-
- /* build and execute our command */
- command = slapt_calloc( strlen(INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
- command[0] = '\0';
- command = strncat(command,INSTALL_CMD,strlen(INSTALL_CMD));
- command = strncat(command,pkg_file_name,strlen(pkg_file_name));
-
- printf(_("Preparing to install %s-%s\n"),pkg->name,pkg->version);
- if( (cmd_return = system(command)) != 0 ){
- printf(_("Failed to execute command: [%s]\n"),command);
- free(command);
- free(pkg_file_name);
- return -1;
- }
-
- free(pkg_file_name);
- free(command);
- return cmd_return;
+int install_pkg(const rc_config *global_config,pkg_info_t *pkg)
+{
+ char *pkg_file_name = NULL;
+ char *command = NULL;
+ int cmd_return = 0;
+
+ /* build the file name */
+ pkg_file_name = gen_pkg_file_name(global_config,pkg);
+
+ /* build and execute our command */
+ command = slapt_calloc(
+ strlen(INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof *command
+ );
+ command[0] = '\0';
+ command = strncat(command,INSTALL_CMD,strlen(INSTALL_CMD));
+ command = strncat(command,pkg_file_name,strlen(pkg_file_name));
+
+ printf(_("Preparing to install %s-%s\n"),pkg->name,pkg->version);
+ if( (cmd_return = system(command)) != 0 ) {
+ printf(_("Failed to execute command: [%s]\n"),command);
+ free(command);
+ free(pkg_file_name);
+ return -1;
+ }
+
+ free(pkg_file_name);
+ free(command);
+ return cmd_return;
}
-int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,pkg_info_t *pkg){
- char *pkg_file_name = NULL;
- char *command = NULL;
- int cmd_return = 0;
-
- /* build the file name */
- pkg_file_name = gen_pkg_file_name(global_config,pkg);
-
- /* build and execute our command */
- command = slapt_calloc( strlen(UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
- command[0] = '\0';
- command = strncat(command,UPGRADE_CMD,strlen(UPGRADE_CMD));
- command = strncat(command,pkg_file_name,strlen(pkg_file_name));
-
- printf(_("Preparing to replace %s-%s with %s-%s\n"),pkg->name,installed_pkg->version,pkg->name,pkg->version);
- if( (cmd_return = system(command)) != 0 ){
- printf(_("Failed to execute command: [%s]\n"),command);
- free(command);
- free(pkg_file_name);
- return -1;
- }
-
- free(pkg_file_name);
- free(command);
- return cmd_return;
+int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,
+ pkg_info_t *pkg)
+{
+ char *pkg_file_name = NULL;
+ char *command = NULL;
+ int cmd_return = 0;
+
+ /* build the file name */
+ pkg_file_name = gen_pkg_file_name(global_config,pkg);
+
+ /* build and execute our command */
+ command = slapt_calloc(
+ strlen(UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof *command
+ );
+ command[0] = '\0';
+ command = strncat(command,UPGRADE_CMD,strlen(UPGRADE_CMD));
+ command = strncat(command,pkg_file_name,strlen(pkg_file_name));
+
+ printf(_("Preparing to replace %s-%s with %s-%s\n"),
+ pkg->name,installed_pkg->version,pkg->name,pkg->version);
+ if( (cmd_return = system(command)) != 0 ) {
+ printf(_("Failed to execute command: [%s]\n"),command);
+ free(command);
+ free(pkg_file_name);
+ return -1;
+ }
+
+ free(pkg_file_name);
+ free(command);
+ return cmd_return;
}
-int remove_pkg(const rc_config *global_config,pkg_info_t *pkg){
- char *command = NULL;
- int cmd_return = 0;
-
- (void)global_config;
-
- /* build and execute our command */
- command = slapt_calloc(
- strlen(REMOVE_CMD) + strlen(pkg->name) + strlen("-") + strlen(pkg->version) + 1,
- sizeof *command
- );
- command[0] = '\0';
- command = strncat(command,REMOVE_CMD,strlen(REMOVE_CMD));
- command = strncat(command,pkg->name,strlen(pkg->name));
- command = strncat(command,"-",strlen("-"));
- command = strncat(command,pkg->version,strlen(pkg->version));
- if( (cmd_return = system(command)) != 0 ){
- printf(_("Failed to execute command: [%s]\n"),command);
- free(command);
- return -1;
- }
-
- free(command);
- return cmd_return;
+int remove_pkg(const rc_config *global_config,pkg_info_t *pkg)
+{
+ char *command = NULL;
+ int cmd_return = 0;
+
+ (void)global_config;
+
+ /* build and execute our command */
+ command = slapt_calloc(
+ strlen(REMOVE_CMD) + strlen(pkg->name) + strlen("-") +
+ strlen(pkg->version) + 1,
+ sizeof *command
+ );
+ command[0] = '\0';
+ command = strncat(command,REMOVE_CMD,strlen(REMOVE_CMD));
+ command = strncat(command,pkg->name,strlen(pkg->name));
+ command = strncat(command,"-",strlen("-"));
+ command = strncat(command,pkg->version,strlen(pkg->version));
+ if( (cmd_return = system(command)) != 0 ) {
+ printf(_("Failed to execute command: [%s]\n"),command);
+ free(command);
+ return -1;
+ }
+
+ free(command);
+ return cmd_return;
}
-void free_pkg(pkg_info_t *pkg){
- free(pkg->required);
- free(pkg->conflicts);
- free(pkg->suggests);
- free(pkg->name);
- free(pkg->version);
- free(pkg->mirror);
- free(pkg->location);
- free(pkg->description);
- free(pkg);
+void free_pkg(pkg_info_t *pkg)
+{
+ free(pkg->required);
+ free(pkg->conflicts);
+ free(pkg->suggests);
+ free(pkg->name);
+ free(pkg->version);
+ free(pkg->mirror);
+ free(pkg->location);
+ free(pkg->description);
+ free(pkg);
}
-void free_pkg_list(struct pkg_list *list){
- unsigned int i;
- if( list->free_pkgs == TRUE ){
- for(i = 0;i < list->pkg_count;i++){
- free_pkg(list->pkgs[i]);
- }
- }
- free(list->pkgs);
- free(list);
+void free_pkg_list(struct pkg_list *list)
+{
+ unsigned int i;
+ if( list->free_pkgs == TRUE ) {
+ for(i = 0;i < list->pkg_count;i++) {
+ free_pkg(list->pkgs[i]);
+ }
+ }
+ free(list->pkgs);
+ free(list);
}
-int is_excluded(const rc_config *global_config,pkg_info_t *pkg){
- unsigned int i,pkg_not_excluded = 0, pkg_is_excluded = 1;
- int name_reg_ret = -1,version_reg_ret = -1,location_reg_ret = -1;
- sg_regex exclude_reg;
+int is_excluded(const rc_config *global_config,pkg_info_t *pkg)
+{
+ unsigned int i,pkg_not_excluded = 0, pkg_is_excluded = 1;
+ int name_reg_ret = -1,version_reg_ret = -1,location_reg_ret = -1;
+ sg_regex exclude_reg;
- if( global_config->ignore_excludes == TRUE )
- return pkg_not_excluded;
+ if( global_config->ignore_excludes == TRUE )
+ return pkg_not_excluded;
- /* maybe EXCLUDE= isn't defined in our rc? */
- if( global_config->exclude_list == NULL )
- return pkg_not_excluded;
+ /* maybe EXCLUDE= isn't defined in our rc? */
+ if( global_config->exclude_list == NULL )
+ return pkg_not_excluded;
- for(i = 0; i < global_config->exclude_list->count;i++){
+ for(i = 0; i < global_config->exclude_list->count;i++) {
- /* return if its an exact match */
- if( (strncmp(global_config->exclude_list->excludes[i],pkg->name,strlen(pkg->name)) == 0))
- return pkg_is_excluded;
+ /* return if its an exact match */
+ if( (strncmp(global_config->exclude_list->excludes[i],pkg->name,strlen(pkg->name)) == 0))
+ return pkg_is_excluded;
- /*
- this regex has to be init'd and free'd within the loop b/c the regex is pulled
- from the exclude list
- */
- if( init_regex(&exclude_reg,global_config->exclude_list->excludes[i]) == -1 )
- continue;
+ /*
+ this regex has to be init'd and free'd within the loop b/c the regex is pulled
+ from the exclude list
+ */
+ if( init_regex(&exclude_reg,global_config->exclude_list->excludes[i]) == -1 )
+ continue;
- execute_regex(&exclude_reg,pkg->name);
- name_reg_ret = exclude_reg.reg_return;
- execute_regex(&exclude_reg,pkg->version);
- version_reg_ret = exclude_reg.reg_return;
- execute_regex(&exclude_reg,pkg->location);
- location_reg_ret = exclude_reg.reg_return;
+ execute_regex(&exclude_reg,pkg->name);
+ name_reg_ret = exclude_reg.reg_return;
+ execute_regex(&exclude_reg,pkg->version);
+ version_reg_ret = exclude_reg.reg_return;
+ execute_regex(&exclude_reg,pkg->location);
+ location_reg_ret = exclude_reg.reg_return;
- if( name_reg_ret == 0 || version_reg_ret == 0 || location_reg_ret == 0 ){
- free_regex(&exclude_reg);
- return pkg_is_excluded;
- }
- free_regex(&exclude_reg);
+ if( name_reg_ret == 0 || version_reg_ret == 0 || location_reg_ret == 0 ) {
+ free_regex(&exclude_reg);
+ return pkg_is_excluded;
+ }
+ free_regex(&exclude_reg);
- }
+ }
- return pkg_not_excluded;
+ return pkg_not_excluded;
}
-void get_md5sum(pkg_info_t *pkg,FILE *checksum_file){
- sg_regex md5sum_regex;
- ssize_t getline_read;
- size_t getline_len = 0;
- char *getline_buffer = NULL;
-
- init_regex(&md5sum_regex,MD5SUM_REGEX);
-
- while( (getline_read = getline(&getline_buffer,&getline_len,checksum_file) ) != EOF ){
-
- /* ignore if it is not our package */
- if( strstr(getline_buffer,pkg->name) == NULL) continue;
- if( strstr(getline_buffer,pkg->version) == NULL) continue;
- if( strstr(getline_buffer,".tgz") == NULL) continue;
- if( strstr(getline_buffer,".asc") != NULL) continue;
-
- execute_regex(&md5sum_regex,getline_buffer);
-
- if( md5sum_regex.reg_return == 0 ){
- char sum[MD5_STR_LEN];
- char *location, *name, *version;
-
- /* md5 sum */
- strncpy(
- sum,
- getline_buffer + md5sum_regex.pmatch[1].rm_so,
- md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so
- );
- sum[md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so] = '\0';
-
- /* location/directory */
- location = slapt_malloc(sizeof *location * (md5sum_regex.pmatch[2].rm_eo - md5sum_regex.pmatch[2].rm_so + 1) );
- strncpy(
- location,
- getline_buffer + md5sum_regex.pmatch[2].rm_so,
- md5sum_regex.pmatch[2].rm_eo - md5sum_regex.pmatch[2].rm_so
- );
- location[md5sum_regex.pmatch[2].rm_eo - md5sum_regex.pmatch[2].rm_so] = '\0';
-
- /* pkg name */
- name = slapt_malloc(sizeof *name * (md5sum_regex.pmatch[3].rm_eo - md5sum_regex.pmatch[3].rm_so + 1) );
- strncpy(
- name,
- getline_buffer + md5sum_regex.pmatch[3].rm_so,
- md5sum_regex.pmatch[3].rm_eo - md5sum_regex.pmatch[3].rm_so
- );
- name[md5sum_regex.pmatch[3].rm_eo - md5sum_regex.pmatch[3].rm_so] = '\0';
-
- /* pkg version */
- version = slapt_malloc(sizeof *version * (md5sum_regex.pmatch[4].rm_eo - md5sum_regex.pmatch[4].rm_so + 1));
- strncpy(
- version,
- getline_buffer + md5sum_regex.pmatch[4].rm_so,
- md5sum_regex.pmatch[4].rm_eo - md5sum_regex.pmatch[4].rm_so
- );
- version[md5sum_regex.pmatch[4].rm_eo - md5sum_regex.pmatch[4].rm_so] = '\0';
-
- /* see if we can match up name, version, and location */
- if(
- (strcmp(pkg->name,name) == 0) &&
- (cmp_pkg_versions(pkg->version,version) == 0) &&
- (strcmp(pkg->location,location) == 0)
- ){
- #if DEBUG == 1
- printf("%s-%s@%s, %s-%s@%s: %s\n",pkg->name,pkg->version,pkg->location,name,version,location,sum);
- #endif
- memcpy(pkg->md5,sum,md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so + 1);
- free(name);
- free(version);
- free(location);
- break;
- }
-
- free(name);
- free(version);
- free(location);
- }
- }
- if( getline_buffer ) free(getline_buffer);
- #if DEBUG == 1
- printf("%s-%s@%s = %s\n",pkg->name,pkg->version,pkg->location,pkg->md5);
- #endif
- free_regex(&md5sum_regex);
- rewind(checksum_file);
-
- return;
+void get_md5sum(pkg_info_t *pkg,FILE *checksum_file)
+{
+ sg_regex md5sum_regex;
+ ssize_t getline_read;
+ size_t getline_len = 0;
+ char *getline_buffer = NULL;
+
+ init_regex(&md5sum_regex,MD5SUM_REGEX);
+
+ while( (getline_read = getline(&getline_buffer,&getline_len,checksum_file) ) != EOF ) {
+
+ /* ignore if it is not our package */
+ if( strstr(getline_buffer,pkg->name) == NULL) continue;
+ if( strstr(getline_buffer,pkg->version) == NULL) continue;
+ if( strstr(getline_buffer,".tgz") == NULL) continue;
+ if( strstr(getline_buffer,".asc") != NULL) continue;
+
+ execute_regex(&md5sum_regex,getline_buffer);
+
+ if( md5sum_regex.reg_return == 0 ) {
+ char sum[MD5_STR_LEN];
+ char *location, *name, *version;
+
+ /* md5 sum */
+ strncpy(
+ sum,
+ getline_buffer + md5sum_regex.pmatch[1].rm_so,
+ md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so
+ );
+ sum[md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so] = '\0';
+
+ /* location/directory */
+ location = slapt_malloc(
+ sizeof *location *
+ (md5sum_regex.pmatch[2].rm_eo - md5sum_regex.pmatch[2].rm_so + 1)
+ );
+ strncpy(
+ location,
+ getline_buffer + md5sum_regex.pmatch[2].rm_so,
+ md5sum_regex.pmatch[2].rm_eo - md5sum_regex.pmatch[2].rm_so
+ );
+ location[md5sum_regex.pmatch[2].rm_eo - md5sum_regex.pmatch[2].rm_so] = '\0';
+
+ /* pkg name */
+ name = slapt_malloc(
+ sizeof *name *
+ (md5sum_regex.pmatch[3].rm_eo - md5sum_regex.pmatch[3].rm_so + 1)
+ );
+ strncpy(
+ name,
+ getline_buffer + md5sum_regex.pmatch[3].rm_so,
+ md5sum_regex.pmatch[3].rm_eo - md5sum_regex.pmatch[3].rm_so
+ );
+ name[md5sum_regex.pmatch[3].rm_eo - md5sum_regex.pmatch[3].rm_so] = '\0';
+
+ /* pkg version */
+ version = slapt_malloc(
+ sizeof *version *
+ (md5sum_regex.pmatch[4].rm_eo - md5sum_regex.pmatch[4].rm_so + 1)
+ );
+ strncpy(
+ version,
+ getline_buffer + md5sum_regex.pmatch[4].rm_so,
+ md5sum_regex.pmatch[4].rm_eo - md5sum_regex.pmatch[4].rm_so
+ );
+ version[md5sum_regex.pmatch[4].rm_eo - md5sum_regex.pmatch[4].rm_so] = '\0';
+
+ /* see if we can match up name, version, and location */
+ if(
+ (strcmp(pkg->name,name) == 0) &&
+ (cmp_pkg_versions(pkg->version,version) == 0) &&
+ (strcmp(pkg->location,location) == 0)
+ ) {
+ #if DEBUG == 1
+ printf("%s-%s@%s, %s-%s@%s: %s\n",
+ pkg->name,pkg->version,pkg->location,name,version,location,sum);
+ #endif
+ memcpy(pkg->md5,
+ sum,md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so + 1
+ );
+ free(name);
+ free(version);
+ free(location);
+ break;
+ }
+
+ free(name);
+ free(version);
+ free(location);
+ }
+ }
+ if( getline_buffer ) free(getline_buffer);
+ #if DEBUG == 1
+ printf("%s-%s@%s = %s\n",pkg->name,pkg->version,pkg->location,pkg->md5);
+ #endif
+ free_regex(&md5sum_regex);
+ rewind(checksum_file);
+
+ return;
}
-static void free_pkg_version_parts(struct pkg_version_parts *parts){
- unsigned int i;
- for(i = 0;i < parts->count;i++){
- free(parts->parts[i]);
- }
- free(parts->parts);
- free(parts);
+static void free_pkg_version_parts(struct pkg_version_parts *parts)
+{
+ unsigned int i;
+ for(i = 0;i < parts->count;i++) {
+ free(parts->parts[i]);
+ }
+ free(parts->parts);
+ free(parts);
}
-int cmp_pkg_versions(char *a, char *b){
- unsigned int position = 0;
- int greater = 1,lesser = -1,equal = 0;
- struct pkg_version_parts *a_parts;
- struct pkg_version_parts *b_parts;
-
- /* bail out early if possible */
- if( strcmp(a,b) == 0 ) return equal;
-
- a_parts = break_down_pkg_version(a);
- b_parts = break_down_pkg_version(b);
-
- while( position < a_parts->count && position < b_parts->count ){
- if( strcmp(a_parts->parts[position],b_parts->parts[position]) != 0 ){
-
- /*
- * if the integer value of the version part is the same
- * and the # of version parts is the same (fixes 3.8.1p1-i486-1 to 3.8p1-i486-1)
- */
- if( (atoi(a_parts->parts[position]) == atoi(b_parts->parts[position])) &&
- (a_parts->count == b_parts->count) ){
-
- if( strcmp(a_parts->parts[position],b_parts->parts[position]) < 0 ){
- free_pkg_version_parts(a_parts);
- free_pkg_version_parts(b_parts);
- return lesser;
- }
- if( strcmp(a_parts->parts[position],b_parts->parts[position]) > 0 ){
- free_pkg_version_parts(a_parts);
- free_pkg_version_parts(b_parts);
- return greater;
- }
-
- }
-
- if( atoi(a_parts->parts[position]) < atoi(b_parts->parts[position]) ){
- free_pkg_version_parts(a_parts);
- free_pkg_version_parts(b_parts);
- return lesser;
- }
-
- if( atoi(a_parts->parts[position]) > atoi(b_parts->parts[position]) ){
- free_pkg_version_parts(a_parts);
- free_pkg_version_parts(b_parts);
- return greater;
- }
-
- }
- ++position;
- }
-
- /*
- * if we got this far, we know that some or all of the version
- * parts are equal in both packages. If pkg-a has 3 version parts
- * and pkg-b has 2, then we assume pkg-a to be greater.
- */
- if(a_parts->count != b_parts->count){
- if( a_parts->count > b_parts->count ){
- free_pkg_version_parts(a_parts);
- free_pkg_version_parts(b_parts);
- return greater;
- }else{
- free_pkg_version_parts(a_parts);
- free_pkg_version_parts(b_parts);
- return lesser;
- }
- }
-
- free_pkg_version_parts(a_parts);
- free_pkg_version_parts(b_parts);
-
- /*
- * Now we check to see that the version follows the standard slackware
- * convention. If it does, we will compare the build portions.
- */
- /* make sure the packages have at least two separators */
- if( (index(a,'-') != rindex(a,'-')) && (index(b,'-') != rindex(b,'-')) ){
- char *a_build,*b_build;
-
- /* pointer to build portions */
- a_build = rindex(a,'-');
- b_build = rindex(b,'-');
-
- if( a_build != NULL && b_build != NULL ){
- /* they are equal if the integer values are equal */
- /* for instance, "1rob" and "1" will be equal */
- if( atoi(a_build) == atoi(b_build) ) return equal;
- if( atoi(a_build) < atoi(b_build) ) return greater;
- if( atoi(a_build) > atoi(b_build) ) return lesser;
- }
-
- }
-
- /*
- * If both have the same # of version parts, non-standard version convention,
- * then we fall back on strcmp.
- */
- if( strchr(a,'-') == NULL && strchr(b,'-') == NULL )
- return strcmp(a,b);
-
- return equal;
+int cmp_pkg_versions(char *a, char *b)
+{
+ unsigned int position = 0;
+ int greater = 1,lesser = -1,equal = 0;
+ struct pkg_version_parts *a_parts;
+ struct pkg_version_parts *b_parts;
+
+ /* bail out early if possible */
+ if( strcmp(a,b) == 0 ) return equal;
+
+ a_parts = break_down_pkg_version(a);
+ b_parts = break_down_pkg_version(b);
+
+ while( position < a_parts->count && position < b_parts->count ) {
+ if( strcmp(a_parts->parts[position],b_parts->parts[position]) != 0 ) {
+
+ /*
+ * if the integer value of the version part is the same
+ * and the # of version parts is the same (fixes 3.8.1p1-i486-1
+ * to 3.8p1-i486-1)
+ */
+ if( (atoi(a_parts->parts[position]) == atoi(b_parts->parts[position])) &&
+ (a_parts->count == b_parts->count) ) {
+
+ if( strcmp(a_parts->parts[position],b_parts->parts[position]) < 0 ) {
+ free_pkg_version_parts(a_parts);
+ free_pkg_version_parts(b_parts);
+ return lesser;
+ }
+ if( strcmp(a_parts->parts[position],b_parts->parts[position]) > 0 ) {
+ free_pkg_version_parts(a_parts);
+ free_pkg_version_parts(b_parts);
+ return greater;
+ }
+
+ }
+
+ if( atoi(a_parts->parts[position]) < atoi(b_parts->parts[position]) ) {
+ free_pkg_version_parts(a_parts);
+ free_pkg_version_parts(b_parts);
+ return lesser;
+ }
+
+ if( atoi(a_parts->parts[position]) > atoi(b_parts->parts[position]) ) {
+ free_pkg_version_parts(a_parts);
+ free_pkg_version_parts(b_parts);
+ return greater;
+ }
+
+ }
+ ++position;
+ }
+
+ /*
+ * if we got this far, we know that some or all of the version
+ * parts are equal in both packages. If pkg-a has 3 version parts
+ * and pkg-b has 2, then we assume pkg-a to be greater.
+ */
+ if(a_parts->count != b_parts->count) {
+ if( a_parts->count > b_parts->count ) {
+ free_pkg_version_parts(a_parts);
+ free_pkg_version_parts(b_parts);
+ return greater;
+ }else{
+ free_pkg_version_parts(a_parts);
+ free_pkg_version_parts(b_parts);
+ return lesser;
+ }
+ }
+
+ free_pkg_version_parts(a_parts);
+ free_pkg_version_parts(b_parts);
+
+ /*
+ * Now we check to see that the version follows the standard slackware
+ * convention. If it does, we will compare the build portions.
+ */
+ /* make sure the packages have at least two separators */
+ if( (index(a,'-') != rindex(a,'-')) && (index(b,'-') != rindex(b,'-')) ) {
+ char *a_build,*b_build;
+
+ /* pointer to build portions */
+ a_build = rindex(a,'-');
+ b_build = rindex(b,'-');
+
+ if( a_build != NULL && b_build != NULL ) {
+ /* they are equal if the integer values are equal */
+ /* for instance, "1rob" and "1" will be equal */
+ if( atoi(a_build) == atoi(b_build) ) return equal;
+ if( atoi(a_build) < atoi(b_build) ) return greater;
+ if( atoi(a_build) > atoi(b_build) ) return lesser;
+ }
+
+ }
+
+ /*
+ * If both have the same # of version parts, non-standard version convention,
+ * then we fall back on strcmp.
+ */
+ if( strchr(a,'-') == NULL && strchr(b,'-') == NULL )
+ return strcmp(a,b);
+
+ return equal;
}
-static struct pkg_version_parts *break_down_pkg_version(const char *version){
- int pos = 0,sv_size = 0;
- char *pointer,*short_version;
- struct pkg_version_parts *pvp;
-
- pvp = slapt_malloc( sizeof *pvp );
- pvp->parts = slapt_malloc( sizeof *pvp->parts );
- pvp->count = 0;
-
- /* generate a short version, leave out arch and release */
- if( (pointer = strchr(version,'-')) == NULL ){
- sv_size = strlen(version) + 1;
- short_version = slapt_malloc( sizeof *short_version * sv_size );
- memcpy(short_version,version,sv_size);
- short_version[sv_size - 1] = '\0';
- }else{
- sv_size = ( strlen(version) - strlen(pointer) + 1);
- short_version = slapt_malloc( sizeof *short_version * sv_size );
- memcpy(short_version,version,sv_size);
- short_version[sv_size - 1] = '\0';
- pointer = NULL;
- }
-
- while(pos < (sv_size - 1) ){
- char **tmp;
-
- tmp = realloc(pvp->parts, sizeof *pvp->parts * (pvp->count + 1) );
- if( tmp == NULL ){
- fprintf(stderr,_("Failed to realloc %s\n"),"pvp->parts");
- exit(1);
- }
- pvp->parts = tmp;
-
- /* check for . as a seperator */
- if( (pointer = strchr(short_version + pos,'.')) != NULL ){
- int b_count = ( strlen(short_version + pos) - strlen(pointer) + 1 );
- pvp->parts[pvp->count] = slapt_malloc( sizeof *pvp->parts[pvp->count] * b_count );
- memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
- pvp->parts[pvp->count][b_count - 1] = '\0';
- ++pvp->count;
- pointer = NULL;
- pos += b_count;
- /* check for _ as a seperator */
- }else if( (pointer = strchr(short_version + pos,'_')) != NULL ){
- int b_count = ( strlen(short_version + pos) - strlen(pointer) + 1 );
- pvp->parts[pvp->count] = slapt_malloc( sizeof *pvp->parts[pvp->count] * b_count );
- memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
- pvp->parts[pvp->count][b_count - 1] = '\0';
- ++pvp->count;
- pointer = NULL;
- pos += b_count;
- /* must be the end of the string */
- }else{
- int b_count = ( strlen(short_version + pos) + 1 );
- pvp->parts[pvp->count] = slapt_malloc( sizeof *pvp->parts[pvp->count] * b_count );
- memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
- pvp->parts[pvp->count][b_count - 1] = '\0';
- ++pvp->count;
- pos += b_count;
- }
- }
-
- free(short_version);
- return pvp;
+static struct pkg_version_parts *break_down_pkg_version(const char *version)
+{
+ int pos = 0,sv_size = 0;
+ char *pointer,*short_version;
+ struct pkg_version_parts *pvp;
+
+ pvp = slapt_malloc( sizeof *pvp );
+ pvp->parts = slapt_malloc( sizeof *pvp->parts );
+ pvp->count = 0;
+
+ /* generate a short version, leave out arch and release */
+ if( (pointer = strchr(version,'-')) == NULL ) {
+ sv_size = strlen(version) + 1;
+ short_version = slapt_malloc( sizeof *short_version * sv_size );
+ memcpy(short_version,version,sv_size);
+ short_version[sv_size - 1] = '\0';
+ }else{
+ sv_size = ( strlen(version) - strlen(pointer) + 1);
+ short_version = slapt_malloc( sizeof *short_version * sv_size );
+ memcpy(short_version,version,sv_size);
+ short_version[sv_size - 1] = '\0';
+ pointer = NULL;
+ }
+
+ while(pos < (sv_size - 1) ) {
+ char **tmp;
+
+ tmp = realloc(pvp->parts, sizeof *pvp->parts * (pvp->count + 1) );
+ if( tmp == NULL ) {
+ fprintf(stderr,_("Failed to realloc %s\n"),"pvp->parts");
+ exit(1);
+ }
+ pvp->parts = tmp;
+
+ /* check for . as a seperator */
+ if( (pointer = strchr(short_version + pos,'.')) != NULL ) {
+ int b_count = ( strlen(short_version + pos) - strlen(pointer) + 1 );
+ pvp->parts[pvp->count] = slapt_malloc(
+ sizeof *pvp->parts[pvp->count] * b_count );
+
+ memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
+ pvp->parts[pvp->count][b_count - 1] = '\0';
+ ++pvp->count;
+ pointer = NULL;
+ pos += b_count;
+ /* check for _ as a seperator */
+ }else if( (pointer = strchr(short_version + pos,'_')) != NULL ) {
+ int b_count = ( strlen(short_version + pos) - strlen(pointer) + 1 );
+ pvp->parts[pvp->count] = slapt_malloc(
+ sizeof *pvp->parts[pvp->count] * b_count );
+
+ memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
+ pvp->parts[pvp->count][b_count - 1] = '\0';
+ ++pvp->count;
+ pointer = NULL;
+ pos += b_count;
+ /* must be the end of the string */
+ }else{
+ int b_count = ( strlen(short_version + pos) + 1 );
+ pvp->parts[pvp->count] = slapt_malloc(
+ sizeof *pvp->parts[pvp->count] * b_count );
+
+ memcpy(pvp->parts[pvp->count],short_version + pos,b_count - 1);
+ pvp->parts[pvp->count][b_count - 1] = '\0';
+ ++pvp->count;
+ pos += b_count;
+ }
+ }
+
+ free(short_version);
+ return pvp;
}
-void write_pkg_data(const char *source_url,FILE *d_file,struct pkg_list *pkgs){
- unsigned int i;
-
- for(i=0;i < pkgs->pkg_count;i++){
-
- fprintf(d_file,"PACKAGE NAME: %s-%s.tgz\n",pkgs->pkgs[i]->name,pkgs->pkgs[i]->version);
- if( strlen(pkgs->pkgs[i]->mirror) > 0 ){
- fprintf(d_file,"PACKAGE MIRROR: %s\n",pkgs->pkgs[i]->mirror);
- }else{
- fprintf(d_file,"PACKAGE MIRROR: %s\n",source_url);
- }
- fprintf(d_file,"PACKAGE LOCATION: %s\n",pkgs->pkgs[i]->location);
- fprintf(d_file,"PACKAGE SIZE (compressed): %d K\n",pkgs->pkgs[i]->size_c);
- fprintf(d_file,"PACKAGE SIZE (uncompressed): %d K\n",pkgs->pkgs[i]->size_u);
- fprintf(d_file,"PACKAGE REQUIRED: %s\n",pkgs->pkgs[i]->required);
- fprintf(d_file,"PACKAGE CONFLICTS: %s\n",pkgs->pkgs[i]->conflicts);
- fprintf(d_file,"PACKAGE SUGGESTS: %s\n",pkgs->pkgs[i]->suggests);
- fprintf(d_file,"PACKAGE MD5 SUM: %s\n",pkgs->pkgs[i]->md5);
- fprintf(d_file,"PACKAGE DESCRIPTION:\n");
- /* do we have to make up an empty description? */
- if( strlen(pkgs->pkgs[i]->description) < strlen(pkgs->pkgs[i]->name) ){
- fprintf(d_file,"%s: no description\n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
- fprintf(d_file,"%s: \n\n",pkgs->pkgs[i]->name);
- }else{
- fprintf(d_file,"%s\n",pkgs->pkgs[i]->description);
- }
-
- }
+void write_pkg_data(const char *source_url,FILE *d_file,struct pkg_list *pkgs)
+{
+ unsigned int i;
+
+ for(i=0;i < pkgs->pkg_count;i++) {
+
+ fprintf(d_file,"PACKAGE NAME: %s-%s.tgz\n",
+ pkgs->pkgs[i]->name,pkgs->pkgs[i]->version);
+ if( strlen(pkgs->pkgs[i]->mirror) > 0 ) {
+ fprintf(d_file,"PACKAGE MIRROR: %s\n",pkgs->pkgs[i]->mirror);
+ }else{
+ fprintf(d_file,"PACKAGE MIRROR: %s\n",source_url);
+ }
+ fprintf(d_file,"PACKAGE LOCATION: %s\n",pkgs->pkgs[i]->location);
+ fprintf(d_file,"PACKAGE SIZE (compressed): %d K\n",pkgs->pkgs[i]->size_c);
+ fprintf(d_file,"PACKAGE SIZE (uncompressed): %d K\n",pkgs->pkgs[i]->size_u);
+ fprintf(d_file,"PACKAGE REQUIRED: %s\n",pkgs->pkgs[i]->required);
+ fprintf(d_file,"PACKAGE CONFLICTS: %s\n",pkgs->pkgs[i]->conflicts);
+ fprintf(d_file,"PACKAGE SUGGESTS: %s\n",pkgs->pkgs[i]->suggests);
+ fprintf(d_file,"PACKAGE MD5 SUM: %s\n",pkgs->pkgs[i]->md5);
+ fprintf(d_file,"PACKAGE DESCRIPTION:\n");
+ /* do we have to make up an empty description? */
+ if( strlen(pkgs->pkgs[i]->description) < strlen(pkgs->pkgs[i]->name) ) {
+ fprintf(d_file,"%s: no description\n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n",pkgs->pkgs[i]->name);
+ fprintf(d_file,"%s: \n\n",pkgs->pkgs[i]->name);
+ }else{
+ fprintf(d_file,"%s\n",pkgs->pkgs[i]->description);
+ }
+
+ }
}
-struct pkg_list *search_pkg_list(struct pkg_list *available,const char *pattern){
- unsigned int i;
- int name_r = -1,desc_r = -1,loc_r = -1,version_r = -1;
- sg_regex search_regex;
- struct pkg_list *matches;
+struct pkg_list *search_pkg_list(struct pkg_list *available,const char *pattern)
+{
+ unsigned int i;
+ int name_r = -1,desc_r = -1,loc_r = -1,version_r = -1;
+ sg_regex search_regex;
+ struct pkg_list *matches;
- matches = init_pkg_list();
+ matches = init_pkg_list();
- if( init_regex(&search_regex,pattern) == -1 )
- return matches;
+ if( init_regex(&search_regex,pattern) == -1 )
+ return matches;
- for(i = 0; i < available->pkg_count; i++ ){
+ for(i = 0; i < available->pkg_count; i++ ) {
- execute_regex(&search_regex,available->pkgs[i]->name);
- name_r = search_regex.reg_return;
+ execute_regex(&search_regex,available->pkgs[i]->name);
+ name_r = search_regex.reg_return;
- execute_regex(&search_regex,available->pkgs[i]->version);
- version_r = search_regex.reg_return;
+ execute_regex(&search_regex,available->pkgs[i]->version);
+ version_r = search_regex.reg_return;
- if( available->pkgs[i]->description != NULL ){
- execute_regex(&search_regex,available->pkgs[i]->description);
- desc_r = search_regex.reg_return;
- }
+ if( available->pkgs[i]->description != NULL ) {
+ execute_regex(&search_regex,available->pkgs[i]->description);
+ desc_r = search_regex.reg_return;
+ }
- if( available->pkgs[i]->location != NULL ){
- execute_regex(&search_regex,available->pkgs[i]->location);
- loc_r = search_regex.reg_return;
- }
+ if( available->pkgs[i]->location != NULL ) {
+ execute_regex(&search_regex,available->pkgs[i]->location);
+ loc_r = search_regex.reg_return;
+ }
- /* search pkg name, pkg description, pkg location */
- if( name_r == 0 || version_r == 0 || desc_r == 0 || loc_r == 0 ){
- add_pkg_to_pkg_list(matches,available->pkgs[i]);
- }
- }
- free_regex(&search_regex);
+ /* search pkg name, pkg description, pkg location */
+ if( name_r == 0 || version_r == 0 || desc_r == 0 || loc_r == 0 ) {
+ add_pkg_to_pkg_list(matches,available->pkgs[i]);
+ }
+ }
+ free_regex(&search_regex);
- return matches;
+ return matches;
}
/* lookup dependencies for pkg */
-int get_pkg_dependencies(const rc_config *global_config,struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,pkg_info_t *pkg,struct pkg_list *deps){
- int position = 0, len = 0;
- char *pointer = NULL;
- char *buffer = NULL;
-
- /*
- * don't go any further if the required member is empty
- * or disable_dep_check is set
- */
- if( global_config->disable_dep_check == TRUE ||
- strcmp(pkg->required,"") == 0 ||
- strcmp(pkg->required," ") == 0 ||
- strcmp(pkg->required," ") == 0
- )
- return 1;
-
- #if DEBUG == 1
- printf("Resolving deps for %s, with dep data: %s\n",pkg->name,pkg->required);
- #endif
-
- /* parse dep line */
- len = strlen(pkg->required);
- while( position < len ){
- pkg_info_t *tmp_pkg = NULL;
-
- /* either the last or there was only one to begin with */
- if( strstr(pkg->required + position,",") == NULL ){
- pointer = pkg->required + position;
-
- /* parse the dep entry and try to lookup a package */
- if( strchr(pointer,'|') != NULL ){
- tmp_pkg = find_or_requirement(avail_pkgs,installed_pkgs,pointer);
- }else{
- tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,pointer);
- }
-
- if( tmp_pkg == NULL ){
- /*
- if we can't find a required dep, set the dep pkg_count to -1
- and return... the caller should check to see if its -1, and
- act accordingly
- */
- fprintf(stderr,_("The following packages have unmet dependencies:\n"));
- fprintf(stderr,_(" %s: Depends: %s\n"),pkg->name,pointer);
- return -1;
- }
-
- position += strlen(pointer);
-
- }else{
-
- /* if we have a comma, skip it */
- if( pkg->required[position] == ',' ){
- ++position;
- continue;
- }
-
- /* build the buffer to contain the dep entry */
- pointer = strchr(pkg->required + position,',');
- buffer = strndup(
- pkg->required + position,
- strlen(pkg->required + position) - strlen(pointer)
- );
-
- /* parse the dep entry and try to lookup a package */
- if( strchr(buffer,'|') != NULL ){
- tmp_pkg = find_or_requirement(avail_pkgs,installed_pkgs,buffer);
- }else{
- tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,buffer);
- }
-
- if( tmp_pkg == NULL ){
- /* if we can't find a required dep, stop */
- fprintf(stderr,_("The following packages have unmet dependencies:\n"));
- fprintf(stderr,_(" %s: Depends: %s\n"),pkg->name,buffer);
- free(buffer);
- return -1;
- }
-
- position += strlen(pkg->required + position) - strlen(pointer);
- free(buffer);
- }
-
- /* if this pkg is excluded */
- if( (is_excluded(global_config,tmp_pkg) == 1) && (global_config->ignore_dep == FALSE) ){
- if( get_exact_pkg(installed_pkgs,tmp_pkg->name,tmp_pkg->version) == NULL ){
- printf(_("%s, which is required by %s, is excluded\n"),tmp_pkg->name,pkg->name);
- return -1;
- }
- }
-
- /* if tmp_pkg is not already in the deps pkg_list */
- if( (get_newest_pkg(deps,tmp_pkg->name) == NULL) ){
- int dep_check_return;
-
- /* add tmp_pkg to deps so that we don't needlessly recurse */
- add_pkg_to_pkg_list(deps,tmp_pkg);
-
- /* now check to see if tmp_pkg has dependencies */
- dep_check_return = get_pkg_dependencies(global_config,avail_pkgs,installed_pkgs,tmp_pkg,deps);
- if( dep_check_return == -1 && global_config->ignore_dep == FALSE ){
- return -1;
- }else{
- /* now move the package to the end after it's dependencies */
- pkg_info_t *tmp = NULL;
- unsigned int i = 0;
- while(i < deps->pkg_count){
- if( strcmp(deps->pkgs[i]->name,tmp_pkg->name) == 0 && tmp == NULL )
- tmp = deps->pkgs[i];
- /* move all subsequent packages up */
- if( tmp != NULL && (i+1 < deps->pkg_count) )
- deps->pkgs[i] = deps->pkgs[i + 1];
- ++i;
- }
- /*
- * now put the pkg we found at the end...
- * note no resizing is necessary, we just moved the location
- */
- if( tmp != NULL ) deps->pkgs[deps->pkg_count - 1] = tmp;
- }
-
- #if DEBUG == 1
- }else{
- printf("%s already exists in dep list\n",tmp_pkg->name);
- #endif
- } /* end already exists in dep check */
-
-
- }/* end while */
- return 0;
+int get_pkg_dependencies(const rc_config *global_config,
+ struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,pkg_info_t *pkg,
+ struct pkg_list *deps)
+{
+ int position = 0, len = 0;
+ char *pointer = NULL;
+ char *buffer = NULL;
+
+ /*
+ * don't go any further if the required member is empty
+ * or disable_dep_check is set
+ */
+ if( global_config->disable_dep_check == TRUE ||
+ strcmp(pkg->required,"") == 0 ||
+ strcmp(pkg->required," ") == 0 ||
+ strcmp(pkg->required," ") == 0
+ )
+ return 1;
+
+ #if DEBUG == 1
+ printf("Resolving deps for %s, with dep data: %s\n",pkg->name,pkg->required);
+ #endif
+
+ /* parse dep line */
+ len = strlen(pkg->required);
+ while( position < len ) {
+ pkg_info_t *tmp_pkg = NULL;
+
+ /* either the last or there was only one to begin with */
+ if( strstr(pkg->required + position,",") == NULL ) {
+ pointer = pkg->required + position;
+
+ /* parse the dep entry and try to lookup a package */
+ if( strchr(pointer,'|') != NULL ) {
+ tmp_pkg = find_or_requirement(avail_pkgs,installed_pkgs,pointer);
+ }else{
+ tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,pointer);
+ }
+
+ if( tmp_pkg == NULL ) {
+ /*
+ if we can't find a required dep, set the dep pkg_count to -1
+ and return... the caller should check to see if its -1, and
+ act accordingly
+ */
+ fprintf(stderr,_("The following packages have unmet dependencies:\n"));
+ fprintf(stderr,_(" %s: Depends: %s\n"),pkg->name,pointer);
+ return -1;
+ }
+
+ position += strlen(pointer);
+
+ }else{
+
+ /* if we have a comma, skip it */
+ if( pkg->required[position] == ',' ) {
+ ++position;
+ continue;
+ }
+
+ /* build the buffer to contain the dep entry */
+ pointer = strchr(pkg->required + position,',');
+ buffer = strndup(
+ pkg->required + position,
+ strlen(pkg->required + position) - strlen(pointer)
+ );
+
+ /* parse the dep entry and try to lookup a package */
+ if( strchr(buffer,'|') != NULL ) {
+ tmp_pkg = find_or_requirement(avail_pkgs,installed_pkgs,buffer);
+ }else{
+ tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,buffer);
+ }
+
+ if( tmp_pkg == NULL ) {
+ /* if we can't find a required dep, stop */
+ fprintf(stderr,_("The following packages have unmet dependencies:\n"));
+ fprintf(stderr,_(" %s: Depends: %s\n"),pkg->name,buffer);
+ free(buffer);
+ return -1;
+ }
+
+ position += strlen(pkg->required + position) - strlen(pointer);
+ free(buffer);
+ }
+
+ /* if this pkg is excluded */
+ if( (is_excluded(global_config,tmp_pkg) == 1) &&
+ (global_config->ignore_dep == FALSE) ) {
+ if( get_exact_pkg(installed_pkgs,tmp_pkg->name,tmp_pkg->version) == NULL ) {
+ printf(_("%s, which is required by %s, is excluded\n"),
+ tmp_pkg->name,pkg->name);
+ return -1;
+ }
+ }
+
+ /* if tmp_pkg is not already in the deps pkg_list */
+ if( (get_newest_pkg(deps,tmp_pkg->name) == NULL) ) {
+ int dep_check_return;
+
+ /* add tmp_pkg to deps so that we don't needlessly recurse */
+ add_pkg_to_pkg_list(deps,tmp_pkg);
+
+ /* now check to see if tmp_pkg has dependencies */
+ dep_check_return = get_pkg_dependencies(
+ global_config,avail_pkgs,installed_pkgs,tmp_pkg,deps
+ );
+ if( dep_check_return == -1 && global_config->ignore_dep == FALSE ) {
+ return -1;
+ }else{
+ /* now move the package to the end after it's dependencies */
+ pkg_info_t *tmp = NULL;
+ unsigned int i = 0;
+ while(i < deps->pkg_count) {
+ if( strcmp(deps->pkgs[i]->name,tmp_pkg->name) == 0 && tmp == NULL )
+ tmp = deps->pkgs[i];
+ /* move all subsequent packages up */
+ if( tmp != NULL && (i+1 < deps->pkg_count) )
+ deps->pkgs[i] = deps->pkgs[i + 1];
+ ++i;
+ }
+ /*
+ * now put the pkg we found at the end...
+ * note no resizing is necessary, we just moved the location
+ */
+ if( tmp != NULL ) deps->pkgs[deps->pkg_count - 1] = tmp;
+ }
+
+ #if DEBUG == 1
+ }else{
+ printf("%s already exists in dep list\n",tmp_pkg->name);
+ #endif
+ } /* end already exists in dep check */
+
+
+ }/* end while */
+ return 0;
}
/* lookup conflicts for package */
-struct pkg_list *get_pkg_conflicts(struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,pkg_info_t *pkg){
- struct pkg_list *conflicts;
- int position = 0,len = 0;
- char *pointer = NULL;
- char *buffer = NULL;
-
- conflicts = init_pkg_list();
-
- /*
- * don't go any further if the required member is empty
- */
- if( strcmp(pkg->conflicts,"") == 0 ||
- strcmp(pkg->conflicts," ") == 0 ||
- strcmp(pkg->conflicts," ") == 0
- )
- return conflicts;
-
- /* parse conflict line */
- len = strlen(pkg->conflicts);
- while( position < len ){
- pkg_info_t *tmp_pkg = NULL;
-
- /* either the last or there was only one to begin with */
- if( strstr(pkg->conflicts + position,",") == NULL ){
- pointer = pkg->conflicts + position;
-
- /* parse the conflict entry and try to lookup a package */
- tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,pointer);
-
- position += strlen(pointer);
- }else{
-
- /* if we have a comma, skip it */
- if( pkg->conflicts[position] == ',' ){
- ++position;
- continue;
- }
-
- /* build the buffer to contain the conflict entry */
- pointer = strchr(pkg->conflicts + position,',');
- buffer = strndup(
- pkg->conflicts + position,
- strlen(pkg->conflicts + position) - strlen(pointer)
- );
-
- /* parse the conflict entry and try to lookup a package */
- tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,buffer);
-
- position += strlen(pkg->conflicts + position) - strlen(pointer);
- free(buffer);
- }
-
- if( tmp_pkg != NULL ){
- add_pkg_to_pkg_list(conflicts,tmp_pkg);
- }
-
- }/* end while */
-
- return conflicts;
+struct pkg_list *get_pkg_conflicts(struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,
+ pkg_info_t *pkg)
+{
+ struct pkg_list *conflicts;
+ int position = 0,len = 0;
+ char *pointer = NULL;
+ char *buffer = NULL;
+
+ conflicts = init_pkg_list();
+
+ /*
+ * don't go any further if the required member is empty
+ */
+ if( strcmp(pkg->conflicts,"") == 0 ||
+ strcmp(pkg->conflicts," ") == 0 ||
+ strcmp(pkg->conflicts," ") == 0
+ )
+ return conflicts;
+
+ /* parse conflict line */
+ len = strlen(pkg->conflicts);
+ while( position < len ) {
+ pkg_info_t *tmp_pkg = NULL;
+
+ /* either the last or there was only one to begin with */
+ if( strstr(pkg->conflicts + position,",") == NULL ) {
+ pointer = pkg->conflicts + position;
+
+ /* parse the conflict entry and try to lookup a package */
+ tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,pointer);
+
+ position += strlen(pointer);
+ }else{
+
+ /* if we have a comma, skip it */
+ if( pkg->conflicts[position] == ',' ) {
+ ++position;
+ continue;
+ }
+
+ /* build the buffer to contain the conflict entry */
+ pointer = strchr(pkg->conflicts + position,',');
+ buffer = strndup(
+ pkg->conflicts + position,
+ strlen(pkg->conflicts + position) - strlen(pointer)
+ );
+
+ /* parse the conflict entry and try to lookup a package */
+ tmp_pkg = parse_meta_entry(avail_pkgs,installed_pkgs,buffer);
+
+ position += strlen(pkg->conflicts + position) - strlen(pointer);
+ free(buffer);
+ }
+
+ if( tmp_pkg != NULL ) {
+ add_pkg_to_pkg_list(conflicts,tmp_pkg);
+ }
+
+ }/* end while */
+
+ return conflicts;
}
-static pkg_info_t *parse_meta_entry(struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,char *dep_entry){
- unsigned int i;
- sg_regex parse_dep_regex;
- char *tmp_pkg_name = NULL,*tmp_pkg_ver = NULL;
- char tmp_pkg_cond[3];
- pkg_info_t *newest_avail_pkg;
- pkg_info_t *newest_installed_pkg;
- int tmp_name_len =0, tmp_ver_len = 0, tmp_cond_len = 0;
-
- init_regex(&parse_dep_regex,REQUIRED_REGEX);
-
- /* regex to pull out pieces */
- execute_regex(&parse_dep_regex,dep_entry);
-
- /* if the regex failed, just skip out */
- if( parse_dep_regex.reg_return != 0){
- #if DEBUG == 1
- printf("regex %s failed on %s\n",REQUIRED_REGEX,dep_entry);
- #endif
- free_regex(&parse_dep_regex);
- return NULL;
- }
-
- tmp_name_len = parse_dep_regex.pmatch[1].rm_eo - parse_dep_regex.pmatch[1].rm_so;
- tmp_cond_len = parse_dep_regex.pmatch[2].rm_eo - parse_dep_regex.pmatch[2].rm_so;
- tmp_ver_len = parse_dep_regex.pmatch[3].rm_eo - parse_dep_regex.pmatch[3].rm_so;
-
- tmp_pkg_name = slapt_malloc( sizeof *tmp_pkg_name * (tmp_name_len + 1));
- strncpy( tmp_pkg_name,
- dep_entry + parse_dep_regex.pmatch[1].rm_so,
- tmp_name_len
- );
- tmp_pkg_name[ tmp_name_len ] = '\0';
-
- newest_avail_pkg = get_newest_pkg(avail_pkgs,tmp_pkg_name);
- newest_installed_pkg = get_newest_pkg(installed_pkgs,tmp_pkg_name);
-
- /* if there is no conditional and version, return newest */
- if( tmp_cond_len == 0 ){
- #if DEBUG == 1
- printf("no conditional\n");
- #endif
- if( newest_installed_pkg != NULL ){
- free_regex(&parse_dep_regex);
- free(tmp_pkg_name);
- return newest_installed_pkg;
- }
- if( newest_avail_pkg != NULL ){
- free_regex(&parse_dep_regex);
- free(tmp_pkg_name);
- return newest_avail_pkg;
- }
- }
-
- if( tmp_cond_len > 3 ){
- fprintf( stderr, _("pkg conditional too long\n"));
- free_regex(&parse_dep_regex);
- free(tmp_pkg_name);
- return NULL;
- }
-
- strncpy( tmp_pkg_cond,
- dep_entry + parse_dep_regex.pmatch[2].rm_so,
- tmp_cond_len
- );
- tmp_pkg_cond[ tmp_cond_len ] = '\0';
-
- tmp_pkg_ver = slapt_malloc( sizeof *tmp_pkg_ver * (tmp_ver_len + 1));
- strncpy( tmp_pkg_ver,
- dep_entry + parse_dep_regex.pmatch[3].rm_so,
- tmp_ver_len
- );
- tmp_pkg_ver[ tmp_ver_len ] = '\0';
-
- free_regex(&parse_dep_regex);
-
- /*
- * check the newest version of tmp_pkg_name (in newest_installed_pkg)
- * before we try looping through installed_pkgs
- */
- if( newest_installed_pkg != NULL ){
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if( (strchr(tmp_pkg_cond,'=') != NULL) &&
- (cmp_pkg_versions(tmp_pkg_ver,newest_installed_pkg->version) == 0) ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_installed_pkg;
- }
-
- /* if "<" */
- if( strchr(tmp_pkg_cond,'<') != NULL ){
- if( cmp_pkg_versions(newest_installed_pkg->version,tmp_pkg_ver) < 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_installed_pkg;
- }
- }
-
- /* if ">" */
- if( strchr(tmp_pkg_cond,'>') != NULL ){
- if( cmp_pkg_versions(newest_installed_pkg->version,tmp_pkg_ver) > 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_installed_pkg;
- }
- }
-
- }
-
- for(i = 0; i < installed_pkgs->pkg_count; i++){
-
- if( strcmp(tmp_pkg_name,installed_pkgs->pkgs[i]->name) != 0 )
- continue;
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if( (strchr(tmp_pkg_cond,'=') != NULL) &&
- (cmp_pkg_versions(tmp_pkg_ver,installed_pkgs->pkgs[i]->version) == 0) ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
- }
-
- /* if "<" */
- if( strchr(tmp_pkg_cond,'<') != NULL ){
- if( cmp_pkg_versions(installed_pkgs->pkgs[i]->version,tmp_pkg_ver) < 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
- }
- }
-
- /* if ">" */
- if( strchr(tmp_pkg_cond,'>') != NULL ){
- if( cmp_pkg_versions(installed_pkgs->pkgs[i]->version,tmp_pkg_ver) > 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return installed_pkgs->pkgs[i];
- }
- }
-
- }
-
- /*
- * check the newest version of tmp_pkg_name (in newest_avail_pkg)
- * before we try looping through avail_pkgs
- */
- if( newest_avail_pkg != NULL ){
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if( (strchr(tmp_pkg_cond,'=') != NULL) &&
- (cmp_pkg_versions(tmp_pkg_ver,newest_avail_pkg->version) == 0) ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_avail_pkg;
- }
-
- /* if "<" */
- if( strchr(tmp_pkg_cond,'<') != NULL ){
- if( cmp_pkg_versions(newest_avail_pkg->version,tmp_pkg_ver) < 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_avail_pkg;
- }
- }
-
- /* if ">" */
- if( strchr(tmp_pkg_cond,'>') != NULL ){
- if( cmp_pkg_versions(newest_avail_pkg->version,tmp_pkg_ver) > 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return newest_avail_pkg;
- }
- }
-
- }
-
- /* loop through avail_pkgs */
- for(i = 0; i < avail_pkgs->pkg_count; i++){
-
- if( strcmp(tmp_pkg_name,avail_pkgs->pkgs[i]->name) != 0 )
- continue;
-
- /* if condition is "=",">=", or "=<" and versions are the same */
- if( (strchr(tmp_pkg_cond,'=') != NULL) &&
- (cmp_pkg_versions(tmp_pkg_ver,avail_pkgs->pkgs[i]->version) == 0) ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
- }
-
- /* if "<" */
- if( strchr(tmp_pkg_cond,'<') != NULL ){
- if( cmp_pkg_versions(avail_pkgs->pkgs[i]->version,tmp_pkg_ver) < 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
- }
- }
-
- /* if ">" */
- if( strchr(tmp_pkg_cond,'>') != NULL ){
- if( cmp_pkg_versions(avail_pkgs->pkgs[i]->version,tmp_pkg_ver) > 0 ){
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
- return avail_pkgs->pkgs[i];
- }
- }
-
- }
-
- free(tmp_pkg_name);
- free(tmp_pkg_ver);
-
- return NULL;
+static pkg_info_t *parse_meta_entry(struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,
+ char *dep_entry)
+{
+ unsigned int i;
+ sg_regex parse_dep_regex;
+ char *tmp_pkg_name = NULL,*tmp_pkg_ver = NULL;
+ char tmp_pkg_cond[3];
+ pkg_info_t *newest_avail_pkg;
+ pkg_info_t *newest_installed_pkg;
+ int tmp_name_len =0, tmp_ver_len = 0, tmp_cond_len = 0;
+
+ init_regex(&parse_dep_regex,REQUIRED_REGEX);
+
+ /* regex to pull out pieces */
+ execute_regex(&parse_dep_regex,dep_entry);
+
+ /* if the regex failed, just skip out */
+ if( parse_dep_regex.reg_return != 0) {
+ #if DEBUG == 1
+ printf("regex %s failed on %s\n",REQUIRED_REGEX,dep_entry);
+ #endif
+ free_regex(&parse_dep_regex);
+ return NULL;
+ }
+
+ tmp_name_len =
+ parse_dep_regex.pmatch[1].rm_eo - parse_dep_regex.pmatch[1].rm_so;
+ tmp_cond_len =
+ parse_dep_regex.pmatch[2].rm_eo - parse_dep_regex.pmatch[2].rm_so;
+ tmp_ver_len =
+ parse_dep_regex.pmatch[3].rm_eo - parse_dep_regex.pmatch[3].rm_so;
+
+ tmp_pkg_name = slapt_malloc( sizeof *tmp_pkg_name * (tmp_name_len + 1));
+ strncpy( tmp_pkg_name,
+ dep_entry + parse_dep_regex.pmatch[1].rm_so,
+ tmp_name_len
+ );
+ tmp_pkg_name[ tmp_name_len ] = '\0';
+
+ newest_avail_pkg = get_newest_pkg(avail_pkgs,tmp_pkg_name);
+ newest_installed_pkg = get_newest_pkg(installed_pkgs,tmp_pkg_name);
+
+ /* if there is no conditional and version, return newest */
+ if( tmp_cond_len == 0 ) {
+ #if DEBUG == 1
+ printf("no conditional\n");
+ #endif
+ if( newest_installed_pkg != NULL ) {
+ free_regex(&parse_dep_regex);
+ free(tmp_pkg_name);
+ return newest_installed_pkg;
+ }
+ if( newest_avail_pkg != NULL ) {
+ free_regex(&parse_dep_regex);
+ free(tmp_pkg_name);
+ return newest_avail_pkg;
+ }
+ }
+
+ if( tmp_cond_len > 3 ) {
+ fprintf( stderr, _("pkg conditional too long\n"));
+ free_regex(&parse_dep_regex);
+ free(tmp_pkg_name);
+ return NULL;
+ }
+
+ strncpy( tmp_pkg_cond,
+ dep_entry + parse_dep_regex.pmatch[2].rm_so,
+ tmp_cond_len
+ );
+ tmp_pkg_cond[ tmp_cond_len ] = '\0';
+
+ tmp_pkg_ver = slapt_malloc( sizeof *tmp_pkg_ver * (tmp_ver_len + 1));
+ strncpy( tmp_pkg_ver,
+ dep_entry + parse_dep_regex.pmatch[3].rm_so,
+ tmp_ver_len
+ );
+ tmp_pkg_ver[ tmp_ver_len ] = '\0';
+
+ free_regex(&parse_dep_regex);
+
+ /*
+ * check the newest version of tmp_pkg_name (in newest_installed_pkg)
+ * before we try looping through installed_pkgs
+ */
+ if( newest_installed_pkg != NULL ) {
+
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if( (strchr(tmp_pkg_cond,'=') != NULL) &&
+ (cmp_pkg_versions(tmp_pkg_ver,newest_installed_pkg->version) == 0) ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_installed_pkg;
+ }
+
+ /* if "<" */
+ if( strchr(tmp_pkg_cond,'<') != NULL ) {
+ if( cmp_pkg_versions(newest_installed_pkg->version,tmp_pkg_ver) < 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_installed_pkg;
+ }
+ }
+
+ /* if ">" */
+ if( strchr(tmp_pkg_cond,'>') != NULL ) {
+ if( cmp_pkg_versions(newest_installed_pkg->version,tmp_pkg_ver) > 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_installed_pkg;
+ }
+ }
+
+ }
+
+ for(i = 0; i < installed_pkgs->pkg_count; i++) {
+
+ if( strcmp(tmp_pkg_name,installed_pkgs->pkgs[i]->name) != 0 )
+ continue;
+
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if( (strchr(tmp_pkg_cond,'=') != NULL) &&
+ (cmp_pkg_versions(tmp_pkg_ver,installed_pkgs->pkgs[i]->version) == 0) ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return installed_pkgs->pkgs[i];
+ }
+
+ /* if "<" */
+ if( strchr(tmp_pkg_cond,'<') != NULL ) {
+ if( cmp_pkg_versions(installed_pkgs->pkgs[i]->version,tmp_pkg_ver) < 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return installed_pkgs->pkgs[i];
+ }
+ }
+
+ /* if ">" */
+ if( strchr(tmp_pkg_cond,'>') != NULL ) {
+ if( cmp_pkg_versions(installed_pkgs->pkgs[i]->version,tmp_pkg_ver) > 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return installed_pkgs->pkgs[i];
+ }
+ }
+
+ }
+
+ /*
+ * check the newest version of tmp_pkg_name (in newest_avail_pkg)
+ * before we try looping through avail_pkgs
+ */
+ if( newest_avail_pkg != NULL ) {
+
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if( (strchr(tmp_pkg_cond,'=') != NULL) &&
+ (cmp_pkg_versions(tmp_pkg_ver,newest_avail_pkg->version) == 0) ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_avail_pkg;
+ }
+
+ /* if "<" */
+ if( strchr(tmp_pkg_cond,'<') != NULL ) {
+ if( cmp_pkg_versions(newest_avail_pkg->version,tmp_pkg_ver) < 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_avail_pkg;
+ }
+ }
+
+ /* if ">" */
+ if( strchr(tmp_pkg_cond,'>') != NULL ) {
+ if( cmp_pkg_versions(newest_avail_pkg->version,tmp_pkg_ver) > 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return newest_avail_pkg;
+ }
+ }
+
+ }
+
+ /* loop through avail_pkgs */
+ for(i = 0; i < avail_pkgs->pkg_count; i++) {
+
+ if( strcmp(tmp_pkg_name,avail_pkgs->pkgs[i]->name) != 0 )
+ continue;
+
+ /* if condition is "=",">=", or "=<" and versions are the same */
+ if( (strchr(tmp_pkg_cond,'=') != NULL) &&
+ (cmp_pkg_versions(tmp_pkg_ver,avail_pkgs->pkgs[i]->version) == 0) ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return avail_pkgs->pkgs[i];
+ }
+
+ /* if "<" */
+ if( strchr(tmp_pkg_cond,'<') != NULL ) {
+ if( cmp_pkg_versions(avail_pkgs->pkgs[i]->version,tmp_pkg_ver) < 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return avail_pkgs->pkgs[i];
+ }
+ }
+
+ /* if ">" */
+ if( strchr(tmp_pkg_cond,'>') != NULL ) {
+ if( cmp_pkg_versions(avail_pkgs->pkgs[i]->version,tmp_pkg_ver) > 0 ) {
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+ return avail_pkgs->pkgs[i];
+ }
+ }
+
+ }
+
+ free(tmp_pkg_name);
+ free(tmp_pkg_ver);
+
+ return NULL;
}
-struct pkg_list *is_required_by(const rc_config *global_config,struct pkg_list *avail, pkg_info_t *pkg){
- struct pkg_list *required_by_list;
+struct pkg_list *is_required_by(const rc_config *global_config,
+ struct pkg_list *avail,
+ pkg_info_t *pkg)
+{
+ struct pkg_list *required_by_list;
- required_by_list = init_pkg_list();
+ required_by_list = init_pkg_list();
- required_by(global_config,avail,pkg,required_by_list);
+ required_by(global_config,avail,pkg,required_by_list);
- return required_by_list;
+ return required_by_list;
}
-static void required_by(const rc_config *global_config,struct pkg_list *avail, pkg_info_t *pkg,struct pkg_list *required_by_list){
- unsigned int i;
- sg_regex required_by_reg;
- char *escapedName = NULL, *escaped_ptr;
+static void required_by(const rc_config *global_config,struct pkg_list *avail,
+ pkg_info_t *pkg,struct pkg_list *required_by_list)
+{
+ unsigned int i;
+ sg_regex required_by_reg;
+ char *escapedName = NULL, *escaped_ptr;
- /*
- * don't go any further if disable_dep_check is set
- */
- if( global_config->disable_dep_check == TRUE) return;
+ /*
+ * don't go any further if disable_dep_check is set
+ */
+ if( global_config->disable_dep_check == TRUE) return;
- escapedName = slapt_malloc(sizeof *escapedName * (strlen(pkg->name) + 1) );
+ escapedName = slapt_malloc(sizeof *escapedName * (strlen(pkg->name) + 1) );
- for(i = 0, escaped_ptr = escapedName; i < strlen(pkg->name) && pkg->name[i]; i++){
- if( pkg->name[i] == '+' ){
- *escaped_ptr++ = '\\';
- *escaped_ptr++ = pkg->name[i];
- }else{
- *escaped_ptr++ = pkg->name[i];
- }
- *escaped_ptr = '\0';
- }
+ for(i = 0, escaped_ptr = escapedName; i < strlen(pkg->name) && pkg->name[i]; i++) {
+ if( pkg->name[i] == '+' ) {
+ *escaped_ptr++ = '\\';
+ *escaped_ptr++ = pkg->name[i];
+ }else{
+ *escaped_ptr++ = pkg->name[i];
+ }
+ *escaped_ptr = '\0';
+ }
- init_regex(&required_by_reg,escapedName);
+ init_regex(&required_by_reg,escapedName);
- for(i = 0; i < avail->pkg_count;i++){
+ for(i = 0; i < avail->pkg_count;i++) {
- if( strcmp(avail->pkgs[i]->required,"") == 0 ) continue;
+ if( strcmp(avail->pkgs[i]->required,"") == 0 ) continue;
- execute_regex(&required_by_reg,avail->pkgs[i]->required);
- if( required_by_reg.reg_return != 0 ) continue;
+ execute_regex(&required_by_reg,avail->pkgs[i]->required);
+ if( required_by_reg.reg_return != 0 ) continue;
- add_pkg_to_pkg_list(required_by_list,avail->pkgs[i]);
- }
+ add_pkg_to_pkg_list(required_by_list,avail->pkgs[i]);
+ }
- free(escapedName);
- free_regex(&required_by_reg);
+ free(escapedName);
+ free_regex(&required_by_reg);
}
-pkg_info_t *get_pkg_by_details(struct pkg_list *list,char *name,char *version,char *location){
- unsigned int i;
- for(i = 0; i < list->pkg_count; i++){
-
- if( strcmp(list->pkgs[i]->name,name) == 0 ){
- if( version != NULL ){
- if(strcmp(list->pkgs[i]->version,version) == 0){
- if( location != NULL ){
- if(strcmp(list->pkgs[i]->location,location) == 0){
- return list->pkgs[i];
- }
- }else{
- return list->pkgs[i];
- }
- }
- }
- }
-
- }
- return NULL;
+pkg_info_t *get_pkg_by_details(struct pkg_list *list,char *name,char *version,
+ char *location)
+{
+ unsigned int i;
+ for(i = 0; i < list->pkg_count; i++) {
+
+ if( strcmp(list->pkgs[i]->name,name) == 0 ) {
+ if( version != NULL ) {
+ if(strcmp(list->pkgs[i]->version,version) == 0) {
+ if( location != NULL ) {
+ if(strcmp(list->pkgs[i]->location,location) == 0) {
+ return list->pkgs[i];
+ }
+ }else{
+ return list->pkgs[i];
+ }
+ }
+ }
+ }
+
+ }
+ return NULL;
}
/* do a head request on the mirror data to find out if it's new */
-char *head_mirror_data(const char *wurl,const char *file){
- char *request_header = NULL;
- char *request_header_ptr = NULL;
- char *delim_ptr = NULL;
- char *head_data = NULL;
- int request_header_len = 0;
- char *url;
-
- /* build url */
- url = slapt_calloc( strlen(wurl) + strlen(file) + 2, sizeof *url );
- url[0] = '\0';
- strncat(url,wurl,strlen(wurl));
- strncat(url,"/",1);
- strncat(url,file,strlen(file));
-
- /* retrieve the header info */
- head_data = head_request(url);
- free(url);
- if( head_data == NULL ){
- return NULL;
- }
-
- /* extract the last modified date for storage and later comparison */
- request_header_ptr = strstr(head_data,"Last-Modified");
- if( request_header_ptr == NULL ){
- /* this is ftp, in which case the Content-Length will have to do */
- request_header_ptr = strstr(head_data,"Content-Length");
- if( request_header_ptr == NULL ){
- free(head_data);
- return NULL;
- }/* give up finally */
- }
- delim_ptr = strpbrk(request_header_ptr,"\r\n");
- if( delim_ptr == NULL ){
- free(head_data);
- return NULL;
- }
-
- request_header_len = strlen(request_header_ptr) - strlen(delim_ptr);
- request_header = slapt_calloc( request_header_len + 1, sizeof *request_header );
- memcpy(request_header,request_header_ptr,request_header_len);
-
- free(head_data);
- return request_header;
+char *head_mirror_data(const char *wurl,const char *file)
+{
+ char *request_header = NULL;
+ char *request_header_ptr = NULL;
+ char *delim_ptr = NULL;
+ char *head_data = NULL;
+ int request_header_len = 0;
+ char *url;
+
+ /* build url */
+ url = slapt_calloc( strlen(wurl) + strlen(file) + 2, sizeof *url );
+ url[0] = '\0';
+ strncat(url,wurl,strlen(wurl));
+ strncat(url,"/",1);
+ strncat(url,file,strlen(file));
+
+ /* retrieve the header info */
+ head_data = head_request(url);
+ free(url);
+ if( head_data == NULL ) {
+ return NULL;
+ }
+
+ /* extract the last modified date for storage and later comparison */
+ request_header_ptr = strstr(head_data,"Last-Modified");
+ if( request_header_ptr == NULL ) {
+ /* this is ftp, in which case the Content-Length will have to do */
+ request_header_ptr = strstr(head_data,"Content-Length");
+ if( request_header_ptr == NULL ) {
+ free(head_data);
+ return NULL;
+ }/* give up finally */
+ }
+ delim_ptr = strpbrk(request_header_ptr,"\r\n");
+ if( delim_ptr == NULL ) {
+ free(head_data);
+ return NULL;
+ }
+
+ request_header_len = strlen(request_header_ptr) - strlen(delim_ptr);
+ request_header = slapt_calloc( request_header_len + 1, sizeof *request_header );
+ memcpy(request_header,request_header_ptr,request_header_len);
+
+ free(head_data);
+ return request_header;
}
-void write_head_cache(const char *cache, const char *cache_filename){
- char *head_filename;
- FILE *tmp;
+void write_head_cache(const char *cache, const char *cache_filename)
+{
+ char *head_filename;
+ FILE *tmp;
- head_filename = gen_head_cache_filename(cache_filename);
+ head_filename = gen_head_cache_filename(cache_filename);
- /* store the last modified date */
- if( (tmp = open_file(head_filename,"w")) == NULL ) exit(1);
- fprintf(tmp,"%s",cache);
- fclose(tmp);
+ /* store the last modified date */
+ if( (tmp = open_file(head_filename,"w")) == NULL ) exit(1);
+ fprintf(tmp,"%s",cache);
+ fclose(tmp);
- free(head_filename);
+ free(head_filename);
}
-char *read_head_cache(const char *cache_filename){
- char *head_filename;
- FILE *tmp;
- char *getline_buffer = NULL;
- size_t gl_n;
- ssize_t gl_return_size;
-
- head_filename = gen_head_cache_filename(cache_filename);
-
- tmp = open_file(head_filename,"a+");
- free(head_filename);
- if( tmp == NULL ) exit(1);
- rewind(tmp);
- gl_return_size = getline(&getline_buffer, &gl_n, tmp);
- fclose(tmp);
-
- if( gl_return_size == -1 ){
- free(getline_buffer);
- return NULL;
- }
-
- return getline_buffer;
+char *read_head_cache(const char *cache_filename)
+{
+ char *head_filename;
+ FILE *tmp;
+ char *getline_buffer = NULL;
+ size_t gl_n;
+ ssize_t gl_return_size;
+
+ head_filename = gen_head_cache_filename(cache_filename);
+
+ tmp = open_file(head_filename,"a+");
+ free(head_filename);
+ if( tmp == NULL ) exit(1);
+ rewind(tmp);
+ gl_return_size = getline(&getline_buffer, &gl_n, tmp);
+ fclose(tmp);
+
+ if( gl_return_size == -1 ) {
+ free(getline_buffer);
+ return NULL;
+ }
+
+ return getline_buffer;
}
-char *gen_head_cache_filename(const char *filename_from_url){
- char *head_filename;
+char *gen_head_cache_filename(const char *filename_from_url)
+{
+ char *head_filename;
- head_filename = slapt_calloc( strlen(filename_from_url) + strlen(HEAD_FILE_EXT) + 1, sizeof *head_filename );
- strncat(head_filename,filename_from_url,strlen(filename_from_url));
- strncat(head_filename,HEAD_FILE_EXT,strlen(HEAD_FILE_EXT));
+ head_filename = slapt_calloc(
+ strlen(filename_from_url) + strlen(HEAD_FILE_EXT) + 1, sizeof *head_filename
+ );
+ strncat(head_filename,filename_from_url,strlen(filename_from_url));
+ strncat(head_filename,HEAD_FILE_EXT,strlen(HEAD_FILE_EXT));
- return head_filename;
+ return head_filename;
}
-void clear_head_cache(const char *cache_filename){
- char *head_filename;
- FILE *tmp;
+void clear_head_cache(const char *cache_filename)
+{
+ char *head_filename;
+ FILE *tmp;
- head_filename = gen_head_cache_filename(cache_filename);
+ head_filename = gen_head_cache_filename(cache_filename);
- tmp = open_file(head_filename,"w");
- if( tmp == NULL ) exit(1);
- fclose(tmp);
- free(head_filename);
+ tmp = open_file(head_filename,"w");
+ if( tmp == NULL ) exit(1);
+ fclose(tmp);
+ free(head_filename);
}
/* update package data from mirror url */
-int update_pkg_cache(const rc_config *global_config){
- unsigned int i,source_dl_failed = 0;
- FILE *pkg_list_fh_tmp = NULL;
-
- /* open tmp pkg list file */
- pkg_list_fh_tmp = tmpfile();
- if( pkg_list_fh_tmp == NULL ){
- if( errno ) perror("tmpfile");
- exit(1);
- }
-
- /* go through each package source and download the meta data */
- for(i = 0; i < global_config->sources->count; i++){
- FILE *tmp_pkg_f,*tmp_patch_f,*tmp_checksum_f;
- struct pkg_list *available_pkgs = NULL;
- struct pkg_list *patch_pkgs = NULL;
- char *pkg_filename,*patch_filename,*checksum_filename;
- char *pkg_head,*pkg_local_head;
- char *patch_head,*patch_local_head;
- char *checksum_head,*checksum_local_head;
-
-
- /* download our PKG_LIST */
- printf(_("Retrieving package data [%s]..."),global_config->sources->url[i]);
- pkg_filename = gen_filename_from_url(global_config->sources->url[i],PKG_LIST);
- pkg_head = head_mirror_data(global_config->sources->url[i],PKG_LIST);
- pkg_local_head = read_head_cache(pkg_filename);
-
- /* open for reading if cached, otherwise write it from the downloaded data */
- if( pkg_head != NULL && pkg_local_head != NULL && strcmp(pkg_head,pkg_local_head) == 0){
- printf(_("Cached\n"));
- if( (tmp_pkg_f = open_file(pkg_filename,"r")) == NULL ) exit(1);
- available_pkgs = parse_packages_txt(tmp_pkg_f);
- fclose(tmp_pkg_f);
- }else{
- if( global_config->dl_stats == TRUE ) printf("\n");
- if( (tmp_pkg_f = open_file(pkg_filename,"w+b")) == NULL ) exit(1);
- if( get_mirror_data_from_source(tmp_pkg_f,global_config,global_config->sources->url[i],PKG_LIST) == 0 ){
- rewind(tmp_pkg_f); /* make sure we are back at the front of the file */
- available_pkgs = parse_packages_txt(tmp_pkg_f);
- if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
- }else{
- source_dl_failed = 1;
- clear_head_cache(pkg_filename);
- }
- fclose(tmp_pkg_f);
- }
- free(pkg_local_head);
- if( available_pkgs == NULL || available_pkgs->pkg_count < 1 ){
- clear_head_cache(pkg_filename);
- fprintf(stderr,_("Failed to parse package data from %s\n"),
- global_config->sources->url[i]
- );
- free(pkg_head);
- free(pkg_filename);
- if ( available_pkgs ) free_pkg_list(available_pkgs);
- continue;
- }
- /* if all is good, write it */
- if( source_dl_failed != 1 && pkg_head != NULL ) write_head_cache(pkg_head,pkg_filename);
- free(pkg_head);
- free(pkg_filename);
-
-
- /* download PATCHES_LIST */
- printf(_("Retrieving patch list [%s]..."),global_config->sources->url[i]);
- patch_filename = gen_filename_from_url(global_config->sources->url[i],PATCHES_LIST);
- patch_head = head_mirror_data(global_config->sources->url[i],PATCHES_LIST);
- patch_local_head = read_head_cache(patch_filename);
-
- /* open for reading if cached, otherwise write it from the downloaded data */
- if( patch_head != NULL && patch_local_head != NULL && strcmp(patch_head,patch_local_head) == 0){
- printf(_("Cached\n"));
- if( (tmp_patch_f = open_file(patch_filename,"r")) == NULL ) exit(1);
- patch_pkgs = parse_packages_txt(tmp_patch_f);
- }else{
- if( global_config->dl_stats == TRUE ) printf("\n");
- if( (tmp_patch_f = open_file(patch_filename,"w+b")) == NULL ) exit (1);
- if( get_mirror_data_from_source(tmp_patch_f,global_config,global_config->sources->url[i],PATCHES_LIST) == 0 ){
- rewind(tmp_patch_f); /* make sure we are back at the front of the file */
- patch_pkgs = parse_packages_txt(tmp_patch_f);
- if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
- }else{
- /* we don't care if the patch fails, for example current doesn't have patches */
- /* source_dl_failed = 1; */
- clear_head_cache(patch_filename);
- }
- }
- /* if all is good, write it */
- if( source_dl_failed != 1 && patch_head != NULL ) write_head_cache(patch_head,patch_filename);
- free(patch_head);
- free(patch_local_head);
- free(patch_filename);
- fclose(tmp_patch_f);
-
-
- /* download checksum file */
- printf(_("Retrieving checksum list [%s]..."), global_config->sources->url[i]);
- checksum_filename = gen_filename_from_url(global_config->sources->url[i],CHECKSUM_FILE);
- checksum_head = head_mirror_data(global_config->sources->url[i],CHECKSUM_FILE);
- checksum_local_head = read_head_cache(checksum_filename);
-
- /* open for reading if cached, otherwise write it from the downloaded data */
- if( checksum_head != NULL && checksum_local_head != NULL && strcmp(checksum_head,checksum_local_head) == 0){
- printf(_("Cached\n"));
- if( (tmp_checksum_f = open_file(checksum_filename,"r")) == NULL ) exit(1);
- }else{
- if( global_config->dl_stats == TRUE ) printf("\n");
- if( (tmp_checksum_f = open_file(checksum_filename,"w+b")) == NULL ) exit(1);
- if( get_mirror_data_from_source(
- tmp_checksum_f,global_config,global_config->sources->url[i],CHECKSUM_FILE
- ) != 0
- ){
- source_dl_failed = 1;
- clear_head_cache(checksum_filename);
- }else{
- if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
- }
- rewind(tmp_checksum_f); /* make sure we are back at the front of the file */
- }
- /* if all is good, write it */
- if( source_dl_failed != 1 && checksum_head != NULL ) write_head_cache(checksum_head,checksum_filename);
- free(checksum_head);
- free(checksum_local_head);
-
- /*
- only do this double check if we know it didn't fail
- */
- if( source_dl_failed != 1 ){
- if( available_pkgs->pkg_count == 0 ) source_dl_failed = 1;
- }
-
- /* if the download failed don't do this, do it if cached or d/l was good */
- if( source_dl_failed != 1 ){
- unsigned int a;
-
- /* now map md5 checksums to packages */
- printf(_("Reading Package Lists..."));
- for(a = 0;a < available_pkgs->pkg_count;a++){
- get_md5sum(available_pkgs->pkgs[a],tmp_checksum_f);
- printf("%c\b",spinner());
- }
- for(a = 0;a < patch_pkgs->pkg_count;a++){
- get_md5sum(patch_pkgs->pkgs[a],tmp_checksum_f);
- printf("%c\b",spinner());
- }
- printf(_("Done\n"));
-
- /* write package listings to disk */
- write_pkg_data(global_config->sources->url[i],pkg_list_fh_tmp,available_pkgs);
- write_pkg_data(global_config->sources->url[i],pkg_list_fh_tmp,patch_pkgs);
-
- }
- if ( available_pkgs ) free_pkg_list(available_pkgs);
- if ( patch_pkgs ) free_pkg_list(patch_pkgs);
- free(checksum_filename);
- fclose(tmp_checksum_f);
-
- }/* end for loop */
-
- /* if all our downloads where a success, write to PKG_LIST_L */
- if( source_dl_failed != 1 ){
- ssize_t bytes_read;
- size_t getline_len = 0;
- char *getline_buffer = NULL;
- FILE *pkg_list_fh;
-
- if( (pkg_list_fh = open_file(PKG_LIST_L,"w+")) == NULL ) exit(1);
- if( pkg_list_fh == NULL ) exit(1);
- rewind(pkg_list_fh_tmp);
- while( (bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh_tmp) ) != EOF ){
- fprintf(pkg_list_fh,"%s",getline_buffer);
- }
- if( getline_buffer ) free(getline_buffer);
- fclose(pkg_list_fh);
-
- }else{
- printf(_("Sources failed to download, correct sources and rerun --update\n"));
- }
-
- /* close the tmp pkg list file */
- fclose(pkg_list_fh_tmp);
-
- return source_dl_failed;
+int update_pkg_cache(const rc_config *global_config)
+{
+ unsigned int i,source_dl_failed = 0;
+ FILE *pkg_list_fh_tmp = NULL;
+
+ /* open tmp pkg list file */
+ pkg_list_fh_tmp = tmpfile();
+ if( pkg_list_fh_tmp == NULL ) {
+ if( errno ) perror("tmpfile");
+ exit(1);
+ }
+
+ /* go through each package source and download the meta data */
+ for(i = 0; i < global_config->sources->count; i++) {
+ FILE *tmp_pkg_f,*tmp_patch_f,*tmp_checksum_f;
+ struct pkg_list *available_pkgs = NULL;
+ struct pkg_list *patch_pkgs = NULL;
+ char *pkg_filename,*patch_filename,*checksum_filename;
+ char *pkg_head,*pkg_local_head;
+ char *patch_head,*patch_local_head;
+ char *checksum_head,*checksum_local_head;
+
+
+ /* download our PKG_LIST */
+ printf(_("Retrieving package data [%s]..."),global_config->sources->url[i]);
+ pkg_filename = gen_filename_from_url(global_config->sources->url[i],PKG_LIST);
+ pkg_head = head_mirror_data(global_config->sources->url[i],PKG_LIST);
+ pkg_local_head = read_head_cache(pkg_filename);
+
+ /* open for reading if cached, otherwise write it from the downloaded data */
+ if( pkg_head != NULL && pkg_local_head != NULL && strcmp(pkg_head,pkg_local_head) == 0) {
+ printf(_("Cached\n"));
+ if( (tmp_pkg_f = open_file(pkg_filename,"r")) == NULL ) exit(1);
+ available_pkgs = parse_packages_txt(tmp_pkg_f);
+ fclose(tmp_pkg_f);
+ }else{
+ if( global_config->dl_stats == TRUE ) printf("\n");
+ if( (tmp_pkg_f = open_file(pkg_filename,"w+b")) == NULL ) exit(1);
+ if( get_mirror_data_from_source(tmp_pkg_f,global_config,global_config->sources->url[i],PKG_LIST) == 0 ) {
+ rewind(tmp_pkg_f); /* make sure we are back at the front of the file */
+ available_pkgs = parse_packages_txt(tmp_pkg_f);
+ if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
+ }else{
+ source_dl_failed = 1;
+ clear_head_cache(pkg_filename);
+ }
+ fclose(tmp_pkg_f);
+ }
+ free(pkg_local_head);
+ if( available_pkgs == NULL || available_pkgs->pkg_count < 1 ) {
+ clear_head_cache(pkg_filename);
+ fprintf(stderr,_("Failed to parse package data from %s\n"),
+ global_config->sources->url[i]
+ );
+ free(pkg_head);
+ free(pkg_filename);
+ if ( available_pkgs ) free_pkg_list(available_pkgs);
+ continue;
+ }
+ /* if all is good, write it */
+ if( source_dl_failed != 1 && pkg_head != NULL ) write_head_cache(pkg_head,pkg_filename);
+ free(pkg_head);
+ free(pkg_filename);
+
+
+ /* download PATCHES_LIST */
+ printf(_("Retrieving patch list [%s]..."),global_config->sources->url[i]);
+ patch_filename = gen_filename_from_url(global_config->sources->url[i],PATCHES_LIST);
+ patch_head = head_mirror_data(global_config->sources->url[i],PATCHES_LIST);
+ patch_local_head = read_head_cache(patch_filename);
+
+ /* open for reading if cached, otherwise write it from the downloaded data */
+ if( patch_head != NULL && patch_local_head != NULL && strcmp(patch_head,patch_local_head) == 0) {
+
+ printf(_("Cached\n"));
+ if( (tmp_patch_f = open_file(patch_filename,"r")) == NULL ) exit(1);
+ patch_pkgs = parse_packages_txt(tmp_patch_f);
+
+ }else{
+
+ if( global_config->dl_stats == TRUE ) {
+ printf("\n");
+ }
+
+ if( (tmp_patch_f = open_file(patch_filename,"w+b")) == NULL ) {
+ exit (1);
+ }
+
+ if( get_mirror_data_from_source(tmp_patch_f,global_config,global_config->sources->url[i],PATCHES_LIST) == 0 ) {
+ rewind(tmp_patch_f); /* make sure we are back at the front of the file */
+ patch_pkgs = parse_packages_txt(tmp_patch_f);
+ if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
+
+ }else{
+ /* we don't care if the patch fails, for example current doesn't have patches */
+ /* source_dl_failed = 1; */
+ clear_head_cache(patch_filename);
+
+ }
+
+ }
+ /* if all is good, write it */
+ if( source_dl_failed != 1 && patch_head != NULL ){
+ write_head_cache(patch_head,patch_filename);
+ }
+
+ free(patch_head);
+ free(patch_local_head);
+ free(patch_filename);
+ fclose(tmp_patch_f);
+
+
+ /* download checksum file */
+ printf(_("Retrieving checksum list [%s]..."),
+ global_config->sources->url[i]);
+
+ checksum_filename = gen_filename_from_url(global_config->sources->url[i],
+ CHECKSUM_FILE
+ );
+ checksum_head = head_mirror_data(global_config->sources->url[i],
+ CHECKSUM_FILE
+ );
+ checksum_local_head = read_head_cache(checksum_filename);
+
+ /* open for reading if cached, otherwise write it from the downloaded data */
+ if( checksum_head != NULL && checksum_local_head != NULL &&
+ strcmp(checksum_head,checksum_local_head) == 0) {
+ printf(_("Cached\n"));
+ if( (tmp_checksum_f = open_file(checksum_filename,"r")) == NULL ) exit(1);
+ }else{
+ if( global_config->dl_stats == TRUE ) printf("\n");
+ if( (tmp_checksum_f = open_file(checksum_filename,"w+b")) == NULL ) {
+ exit(1);
+ }
+ if( get_mirror_data_from_source(
+ tmp_checksum_f,global_config,global_config->sources->url[i],
+ CHECKSUM_FILE
+ ) != 0
+ ) {
+ source_dl_failed = 1;
+ clear_head_cache(checksum_filename);
+ }else{
+ if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
+ }
+ /* make sure we are back at the front of the file */
+ rewind(tmp_checksum_f);
+ }
+ /* if all is good, write it */
+ if( source_dl_failed != 1 && checksum_head != NULL ) {
+ write_head_cache(checksum_head,checksum_filename);
+ }
+ free(checksum_head);
+ free(checksum_local_head);
+
+ /*
+ only do this double check if we know it didn't fail
+ */
+ if( source_dl_failed != 1 ) {
+ if( available_pkgs->pkg_count == 0 ) source_dl_failed = 1;
+ }
+
+ /* if the download failed don't do this, do it if cached or d/l was good */
+ if( source_dl_failed != 1 ) {
+ unsigned int a;
+
+ /* now map md5 checksums to packages */
+ printf(_("Reading Package Lists..."));
+ for(a = 0;a < available_pkgs->pkg_count;a++) {
+ get_md5sum(available_pkgs->pkgs[a],tmp_checksum_f);
+ printf("%c\b",spinner());
+ }
+ for(a = 0;a < patch_pkgs->pkg_count;a++) {
+ get_md5sum(patch_pkgs->pkgs[a],tmp_checksum_f);
+ printf("%c\b",spinner());
+ }
+ printf(_("Done\n"));
+
+ /* write package listings to disk */
+ write_pkg_data(global_config->sources->url[i],pkg_list_fh_tmp,available_pkgs);
+ write_pkg_data(global_config->sources->url[i],pkg_list_fh_tmp,patch_pkgs);
+
+ }
+ if ( available_pkgs ) free_pkg_list(available_pkgs);
+ if ( patch_pkgs ) free_pkg_list(patch_pkgs);
+ free(checksum_filename);
+ fclose(tmp_checksum_f);
+
+ }/* end for loop */
+
+ /* if all our downloads where a success, write to PKG_LIST_L */
+ if( source_dl_failed != 1 ) {
+ ssize_t bytes_read;
+ size_t getline_len = 0;
+ char *getline_buffer = NULL;
+ FILE *pkg_list_fh;
+
+ if( (pkg_list_fh = open_file(PKG_LIST_L,"w+")) == NULL ) exit(1);
+ if( pkg_list_fh == NULL ) exit(1);
+ rewind(pkg_list_fh_tmp);
+ while( (bytes_read = getline(&getline_buffer,&getline_len,pkg_list_fh_tmp) ) != EOF ) {
+ fprintf(pkg_list_fh,"%s",getline_buffer);
+ }
+ if( getline_buffer ) free(getline_buffer);
+ fclose(pkg_list_fh);
+
+ }else{
+ printf(_("Sources failed to download, correct sources and rerun --update\n"));
+ }
+
+ /* close the tmp pkg list file */
+ fclose(pkg_list_fh_tmp);
+
+ return source_dl_failed;
}
-struct pkg_list *init_pkg_list(void){
- struct pkg_list *list;
+struct pkg_list *init_pkg_list(void)
+{
+ struct pkg_list *list;
- list = slapt_malloc( sizeof *list );
- list->pkgs = slapt_malloc( sizeof *list->pkgs );
- list->pkg_count = 0;
- list->free_pkgs = FALSE;
+ list = slapt_malloc( sizeof *list );
+ list->pkgs = slapt_malloc( sizeof *list->pkgs );
+ list->pkg_count = 0;
+ list->free_pkgs = FALSE;
- return list;
+ return list;
}
-void add_pkg_to_pkg_list(struct pkg_list *list,pkg_info_t *pkg){
- pkg_info_t **realloc_tmp;
+void add_pkg_to_pkg_list(struct pkg_list *list,pkg_info_t *pkg)
+{
+ 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,_("Failed to realloc %s\n"),"pkgs");
- exit(1);
- }
+ /* grow our struct array */
+ realloc_tmp = realloc(list->pkgs,
+ sizeof *list->pkgs * (list->pkg_count + 1)
+ );
+ if( realloc_tmp == NULL ) {
+ fprintf(stderr,_("Failed to realloc %s\n"),"pkgs");
+ exit(1);
+ }
- list->pkgs = realloc_tmp;
- list->pkgs[list->pkg_count] = pkg;
- ++list->pkg_count;
+ list->pkgs = realloc_tmp;
+ list->pkgs[list->pkg_count] = pkg;
+ ++list->pkg_count;
}
-__inline pkg_info_t *init_pkg(void){
- pkg_info_t *pkg;
+__inline pkg_info_t *init_pkg(void)
+{
+ pkg_info_t *pkg;
- pkg = slapt_malloc( sizeof *pkg );
+ pkg = slapt_malloc( sizeof *pkg );
- pkg->size_c = 0;
- pkg->size_u = 0;
+ pkg->size_c = 0;
+ pkg->size_u = 0;
- pkg->name = NULL;
- pkg->version = NULL;
- pkg->mirror = NULL;
- pkg->location = NULL;
+ pkg->name = NULL;
+ pkg->version = NULL;
+ pkg->mirror = NULL;
+ pkg->location = NULL;
- pkg->description = slapt_malloc(sizeof *pkg->description);
- pkg->description[0] = '\0';
+ pkg->description = slapt_malloc(sizeof *pkg->description);
+ pkg->description[0] = '\0';
- pkg->required = slapt_malloc(sizeof *pkg->required);
- pkg->required[0] = '\0';
+ pkg->required = slapt_malloc(sizeof *pkg->required);
+ pkg->required[0] = '\0';
- pkg->conflicts = slapt_malloc(sizeof *pkg->conflicts);
- pkg->conflicts[0] = '\0';
+ pkg->conflicts = slapt_malloc(sizeof *pkg->conflicts);
+ pkg->conflicts[0] = '\0';
- pkg->suggests = slapt_malloc(sizeof *pkg->suggests);
- pkg->suggests[0] = '\0';
+ pkg->suggests = slapt_malloc(sizeof *pkg->suggests);
+ pkg->suggests[0] = '\0';
- pkg->md5[0] = '\0';
+ pkg->md5[0] = '\0';
- return pkg;
+ return pkg;
}
/* generate the package file name */
-char *gen_pkg_file_name(const rc_config *global_config,pkg_info_t *pkg){
- char *file_name = NULL;
-
- /* build the file name */
- file_name = slapt_calloc(
- strlen(global_config->working_dir)+strlen("/")
- +strlen(pkg->location)+strlen("/")
- +strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 ,
- sizeof *file_name
- );
- file_name = strncpy(file_name,
- global_config->working_dir,strlen(global_config->working_dir)
- );
- file_name[ strlen(global_config->working_dir) ] = '\0';
- file_name = strncat(file_name,"/",strlen("/"));
- file_name = strncat(file_name,pkg->location,strlen(pkg->location));
- file_name = strncat(file_name,"/",strlen("/"));
- file_name = strncat(file_name,pkg->name,strlen(pkg->name));
- file_name = strncat(file_name,"-",strlen("-"));
- file_name = strncat(file_name,pkg->version,strlen(pkg->version));
- file_name = strncat(file_name,".tgz",strlen(".tgz"));
-
- return file_name;
+char *gen_pkg_file_name(const rc_config *global_config,pkg_info_t *pkg)
+{
+ char *file_name = NULL;
+
+ /* build the file name */
+ file_name = slapt_calloc(
+ strlen(global_config->working_dir)+strlen("/") +
+ strlen(pkg->location)+strlen("/") +
+ strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1,
+ sizeof *file_name
+ );
+ file_name = strncpy(file_name,
+ global_config->working_dir,strlen(global_config->working_dir)
+ );
+ file_name[ strlen(global_config->working_dir) ] = '\0';
+ file_name = strncat(file_name,"/",strlen("/"));
+ file_name = strncat(file_name,pkg->location,strlen(pkg->location));
+ file_name = strncat(file_name,"/",strlen("/"));
+ file_name = strncat(file_name,pkg->name,strlen(pkg->name));
+ file_name = strncat(file_name,"-",strlen("-"));
+ file_name = strncat(file_name,pkg->version,strlen(pkg->version));
+ file_name = strncat(file_name,".tgz",strlen(".tgz"));
+
+ return file_name;
}
/* generate the download url for a package */
-char *gen_pkg_url(pkg_info_t *pkg){
- char *url = NULL;
- char *file_name = NULL;
-
- /* build the file name */
- file_name = slapt_calloc(
- strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 ,
- sizeof *file_name
- );
- file_name = strncpy(file_name,pkg->name,strlen(pkg->name));
- file_name = strncat(file_name,"-",strlen("-"));
- file_name = strncat(file_name,pkg->version,strlen(pkg->version));
- file_name = strncat(file_name,".tgz",strlen(".tgz"));
-
- url = slapt_calloc(
- strlen(pkg->mirror) + strlen(pkg->location)
- + strlen(file_name) + strlen("/") + 1,
- sizeof *url
- );
-
- url = strncpy(url,pkg->mirror,strlen(pkg->mirror));
- url[ strlen(pkg->mirror) ] = '\0';
- url = strncat(url,pkg->location,strlen(pkg->location));
- url = strncat(url,"/",strlen("/"));
- url = strncat(url,file_name,strlen(file_name));
-
- free(file_name);
- return url;
+char *gen_pkg_url(pkg_info_t *pkg)
+{
+ char *url = NULL;
+ char *file_name = NULL;
+
+ /* build the file name */
+ file_name = slapt_calloc(
+ strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 ,
+ sizeof *file_name
+ );
+ file_name = strncpy(file_name,pkg->name,strlen(pkg->name));
+ file_name = strncat(file_name,"-",strlen("-"));
+ file_name = strncat(file_name,pkg->version,strlen(pkg->version));
+ file_name = strncat(file_name,".tgz",strlen(".tgz"));
+
+ url = slapt_calloc(
+ strlen(pkg->mirror) + strlen(pkg->location)
+ + strlen(file_name) + strlen("/") + 1,
+ sizeof *url
+ );
+
+ url = strncpy(url,pkg->mirror,strlen(pkg->mirror));
+ url[ strlen(pkg->mirror) ] = '\0';
+ url = strncat(url,pkg->location,strlen(pkg->location));
+ url = strncat(url,"/",strlen("/"));
+ url = strncat(url,file_name,strlen(file_name));
+
+ free(file_name);
+ return url;
}
/* find out the pkg file size (post download) */
-size_t get_pkg_file_size(const rc_config *global_config,pkg_info_t *pkg){
- char *file_name = NULL;
- struct stat file_stat;
- size_t file_size = 0;
+size_t get_pkg_file_size(const rc_config *global_config,pkg_info_t *pkg)
+{
+ char *file_name = NULL;
+ struct stat file_stat;
+ size_t file_size = 0;
- /* build the file name */
- file_name = gen_pkg_file_name(global_config,pkg);
+ /* build the file name */
+ file_name = gen_pkg_file_name(global_config,pkg);
- if( stat(file_name,&file_stat) == 0 ){
- file_size = file_stat.st_size;
- }
- free(file_name);
+ if( stat(file_name,&file_stat) == 0 ) {
+ file_size = file_stat.st_size;
+ }
+ free(file_name);
- return file_size;
+ return file_size;
}
/* package is already downloaded and cached, md5sum if applicable is ok */
-int verify_downloaded_pkg(const rc_config *global_config,pkg_info_t *pkg){
- char *file_name = NULL;
- FILE *fh_test = NULL;
- size_t file_size = 0;
- char md5sum_f[MD5_STR_LEN];
- int is_verified = 0,not_verified = -1;
-
- /*
- check the file size first so we don't run an md5 checksum
- on an incomplete file
- */
- file_size = get_pkg_file_size(global_config,pkg);
- if( (unsigned int)(file_size/1024) != pkg->size_c){
- return not_verified;
- }
- /* if not checking the md5 checksum and the sizes match, assume its good */
- if( global_config->no_md5_check == TRUE ) return is_verified;
-
- /* check to see that we actually have an md5 checksum */
- if( strcmp(pkg->md5,"") == 0){
- printf(_("Could not find MD5 checksum for %s, override with --no-md5\n"),pkg->name);
- return not_verified;
- }
-
- /* build the file name */
- file_name = gen_pkg_file_name(global_config,pkg);
-
- /* return if we can't open the file */
- if( ( fh_test = open_file(file_name,"r") ) == NULL ){
- free(file_name);
- return not_verified;
- }
- free(file_name);
-
- /* generate the md5 checksum */
- gen_md5_sum_of_file(fh_test,md5sum_f);
- fclose(fh_test);
-
- /* check to see if the md5sum is correct */
- if( strcmp(md5sum_f,pkg->md5) == 0 ) return is_verified;
-
- return MD5_CHECKSUM_FAILED;
+int verify_downloaded_pkg(const rc_config *global_config,pkg_info_t *pkg)
+{
+ char *file_name = NULL;
+ FILE *fh_test = NULL;
+ size_t file_size = 0;
+ char md5sum_f[MD5_STR_LEN];
+ int is_verified = 0,not_verified = -1;
+
+ /*
+ check the file size first so we don't run an md5 checksum
+ on an incomplete file
+ */
+ file_size = get_pkg_file_size(global_config,pkg);
+ if( (unsigned int)(file_size/1024) != pkg->size_c) {
+ return not_verified;
+ }
+ /* if not checking the md5 checksum and the sizes match, assume its good */
+ if( global_config->no_md5_check == TRUE ) return is_verified;
+
+ /* check to see that we actually have an md5 checksum */
+ if( strcmp(pkg->md5,"") == 0) {
+ printf(_("Could not find MD5 checksum for %s, override with --no-md5\n"),
+ pkg->name);
+ return not_verified;
+ }
+
+ /* build the file name */
+ file_name = gen_pkg_file_name(global_config,pkg);
+
+ /* return if we can't open the file */
+ if( ( fh_test = open_file(file_name,"r") ) == NULL ) {
+ free(file_name);
+ return not_verified;
+ }
+ free(file_name);
+
+ /* generate the md5 checksum */
+ gen_md5_sum_of_file(fh_test,md5sum_f);
+ fclose(fh_test);
+
+ /* check to see if the md5sum is correct */
+ if( strcmp(md5sum_f,pkg->md5) == 0 ) return is_verified;
+
+ return MD5_CHECKSUM_FAILED;
}
-char *gen_filename_from_url(const char *url,const char *file){
- char *filename,*cleaned;
+char *gen_filename_from_url(const char *url,const char *file)
+{
+ char *filename,*cleaned;
- filename = slapt_calloc( strlen(url) + strlen(file) + 2 , sizeof *filename );
- filename[0] = '.';
- strncat(filename,url,strlen(url));
- strncat(filename,file,strlen(file));
+ filename = slapt_calloc( strlen(url) + strlen(file) + 2 , sizeof *filename );
+ filename[0] = '.';
+ strncat(filename,url,strlen(url));
+ strncat(filename,file,strlen(file));
- cleaned = str_replace_chr(filename,'/','#');
+ cleaned = str_replace_chr(filename,'/','#');
- free(filename);
+ free(filename);
- return cleaned;
+ return cleaned;
}
-void purge_old_cached_pkgs(const rc_config *global_config,char *dir_name,struct pkg_list *avail_pkgs){
- DIR *dir;
- struct dirent *file;
- struct stat file_stat;
- sg_regex cached_pkgs_regex;
- int local_pkg_list = 0;
-
- if( avail_pkgs == NULL ){
- avail_pkgs = get_available_pkgs();
- local_pkg_list = 1;
- }
- if( dir_name == NULL ) dir_name = (char *)global_config->working_dir;
- init_regex(&cached_pkgs_regex,PKG_PARSE_REGEX);
-
- if( (dir = opendir(dir_name)) == NULL ){
- if( errno ) perror(dir_name);
- fprintf(stderr,_("Failed to opendir %s\n"),dir_name);
- return;
- }
-
- if( chdir(dir_name) == -1 ){
- if( errno ) perror(dir_name);
- fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
- return;
- }
-
- while( (file = readdir(dir)) ){
-
- /* make sure we don't have . or .. */
- if( (strcmp(file->d_name,"..")) == 0 || (strcmp(file->d_name,".") == 0) )
- continue;
-
- /* setup file_stat struct */
- if( (stat(file->d_name,&file_stat)) == -1)
- continue;
-
- /* if its a directory, recurse */
- if( S_ISDIR(file_stat.st_mode) ){
- purge_old_cached_pkgs(global_config,file->d_name,avail_pkgs);
- if( (chdir("..")) == -1 ){
- fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
- return;
- }
- continue;
- }
-
- /* if its a package */
- if( strstr(file->d_name,".tgz") !=NULL ){
-
- execute_regex(&cached_pkgs_regex,file->d_name);
-
- /* if our regex matches */
- if( cached_pkgs_regex.reg_return == 0 ){
- char *tmp_pkg_name,*tmp_pkg_version;
- pkg_info_t *tmp_pkg;
-
- tmp_pkg_name = strndup(
- file->d_name + cached_pkgs_regex.pmatch[1].rm_so,
- cached_pkgs_regex.pmatch[1].rm_eo - cached_pkgs_regex.pmatch[1].rm_so
- );
- tmp_pkg_version = strndup(
- file->d_name + cached_pkgs_regex.pmatch[2].rm_so,
- cached_pkgs_regex.pmatch[2].rm_eo - cached_pkgs_regex.pmatch[2].rm_so
- );
-
- tmp_pkg = get_exact_pkg(avail_pkgs,tmp_pkg_name,tmp_pkg_version);
- free(tmp_pkg_name);
- free(tmp_pkg_version);
-
- if( tmp_pkg == NULL ){
-
- if(global_config->no_prompt == TRUE ){
- unlink(file->d_name);
- }else{
- if( ask_yes_no(_("Delete %s ? [y/N]"), file->d_name) == 1 )
- unlink(file->d_name);
- }
-
- }
- tmp_pkg = NULL;
-
- }
-
- }
-
- }
- closedir(dir);
-
- free_regex(&cached_pkgs_regex);
- if( local_pkg_list == 1 ){
- free_pkg_list(avail_pkgs);
- }
+void purge_old_cached_pkgs(const rc_config *global_config,char *dir_name,
+ struct pkg_list *avail_pkgs)
+{
+ DIR *dir;
+ struct dirent *file;
+ struct stat file_stat;
+ sg_regex cached_pkgs_regex;
+ int local_pkg_list = 0;
+
+ if( avail_pkgs == NULL ) {
+ avail_pkgs = get_available_pkgs();
+ local_pkg_list = 1;
+ }
+ if( dir_name == NULL ) dir_name = (char *)global_config->working_dir;
+ init_regex(&cached_pkgs_regex,PKG_PARSE_REGEX);
+
+ if( (dir = opendir(dir_name)) == NULL ) {
+ if( errno ) perror(dir_name);
+ fprintf(stderr,_("Failed to opendir %s\n"),dir_name);
+ return;
+ }
+
+ if( chdir(dir_name) == -1 ) {
+ if( errno ) perror(dir_name);
+ fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
+ return;
+ }
+
+ while( (file = readdir(dir)) ) {
+
+ /* make sure we don't have . or .. */
+ if( (strcmp(file->d_name,"..")) == 0 || (strcmp(file->d_name,".") == 0) )
+ continue;
+
+ /* setup file_stat struct */
+ if( (stat(file->d_name,&file_stat)) == -1)
+ continue;
+
+ /* if its a directory, recurse */
+ if( S_ISDIR(file_stat.st_mode) ) {
+ purge_old_cached_pkgs(global_config,file->d_name,avail_pkgs);
+ if( (chdir("..")) == -1 ) {
+ fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
+ return;
+ }
+ continue;
+ }
+
+ /* if its a package */
+ if( strstr(file->d_name,".tgz") !=NULL ) {
+
+ execute_regex(&cached_pkgs_regex,file->d_name);
+
+ /* if our regex matches */
+ if( cached_pkgs_regex.reg_return == 0 ) {
+ char *tmp_pkg_name,*tmp_pkg_version;
+ pkg_info_t *tmp_pkg;
+
+ tmp_pkg_name = strndup(
+ file->d_name + cached_pkgs_regex.pmatch[1].rm_so,
+ cached_pkgs_regex.pmatch[1].rm_eo - cached_pkgs_regex.pmatch[1].rm_so
+ );
+ tmp_pkg_version = strndup(
+ file->d_name + cached_pkgs_regex.pmatch[2].rm_so,
+ cached_pkgs_regex.pmatch[2].rm_eo - cached_pkgs_regex.pmatch[2].rm_so
+ );
+
+ tmp_pkg = get_exact_pkg(avail_pkgs,tmp_pkg_name,tmp_pkg_version);
+ free(tmp_pkg_name);
+ free(tmp_pkg_version);
+
+ if( tmp_pkg == NULL ) {
+
+ if(global_config->no_prompt == TRUE ) {
+ unlink(file->d_name);
+ }else{
+ if( ask_yes_no(_("Delete %s ? [y/N]"), file->d_name) == 1 )
+ unlink(file->d_name);
+ }
+
+ }
+ tmp_pkg = NULL;
+
+ }
+
+ }
+
+ }
+ closedir(dir);
+
+ free_regex(&cached_pkgs_regex);
+ if( local_pkg_list == 1 ) {
+ free_pkg_list(avail_pkgs);
+ }
}
-void clean_pkg_dir(const char *dir_name){
- DIR *dir;
- struct dirent *file;
- struct stat file_stat;
-
- if( (dir = opendir(dir_name)) == NULL ){
- fprintf(stderr,_("Failed to opendir %s\n"),dir_name);
- return;
- }
-
- if( chdir(dir_name) == -1 ){
- fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
- return;
- }
-
- while( (file = readdir(dir)) ){
-
- /* make sure we don't have . or .. */
- if( (strcmp(file->d_name,"..")) == 0 || (strcmp(file->d_name,".") == 0) )
- continue;
-
- /* setup file_stat struct */
- if( (stat(file->d_name,&file_stat)) == -1)
- continue;
-
- /* if its a directory, recurse */
- if( S_ISDIR(file_stat.st_mode) ){
- clean_pkg_dir(file->d_name);
- if( (chdir("..")) == -1 ){
- fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
- return;
- }
- continue;
- }
- if( strstr(file->d_name,".tgz") !=NULL ){
- #if DEBUG == 1
- printf(_("unlinking %s\n"),file->d_name);
- #endif
- unlink(file->d_name);
- }
- }
- closedir(dir);
+void clean_pkg_dir(const char *dir_name)
+{
+ DIR *dir;
+ struct dirent *file;
+ struct stat file_stat;
+
+ if( (dir = opendir(dir_name)) == NULL ) {
+ fprintf(stderr,_("Failed to opendir %s\n"),dir_name);
+ return;
+ }
+
+ if( chdir(dir_name) == -1 ) {
+ fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
+ return;
+ }
+
+ while( (file = readdir(dir)) ) {
+
+ /* make sure we don't have . or .. */
+ if( (strcmp(file->d_name,"..")) == 0 || (strcmp(file->d_name,".") == 0) )
+ continue;
+
+ /* setup file_stat struct */
+ if( (stat(file->d_name,&file_stat)) == -1)
+ continue;
+
+ /* if its a directory, recurse */
+ if( S_ISDIR(file_stat.st_mode) ) {
+ clean_pkg_dir(file->d_name);
+ if( (chdir("..")) == -1 ) {
+ fprintf(stderr,_("Failed to chdir: %s\n"),dir_name);
+ return;
+ }
+ continue;
+ }
+ if( strstr(file->d_name,".tgz") !=NULL ) {
+ #if DEBUG == 1
+ printf(_("unlinking %s\n"),file->d_name);
+ #endif
+ unlink(file->d_name);
+ }
+ }
+ closedir(dir);
}
/* find dependency from "or" requirement */
-static pkg_info_t *find_or_requirement(struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,char *required_str){
- pkg_info_t *pkg = NULL;
- int position = 0, len = 0;
+static pkg_info_t *find_or_requirement(struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,
+ char *required_str)
+{
+ pkg_info_t *pkg = NULL;
+ int position = 0, len = 0;
- len = strlen(required_str);
- while( position < len ){
+ len = strlen(required_str);
+ while( position < len ) {
- if( strchr(required_str + position,'|') == NULL ){
- char *string = required_str + position;
+ if( strchr(required_str + position,'|') == NULL ) {
+ char *string = required_str + position;
- pkg = parse_meta_entry(avail_pkgs,installed_pkgs,string);
+ pkg = parse_meta_entry(avail_pkgs,installed_pkgs,string);
- if( pkg != NULL ) break;
+ if( pkg != NULL ) break;
- position += strlen(string);
- }else{
- char *string = NULL;
- int str_len = 0;
- char *next_token = NULL;
+ position += strlen(string);
+ }else{
+ char *string = NULL;
+ int str_len = 0;
+ char *next_token = NULL;
- if( required_str[position] == '|' ){ ++position; continue; }
+ if( required_str[position] == '|' ) { ++position; continue; }
- next_token = index(required_str + position,'|');
- str_len = strlen(required_str + position) - strlen(next_token);
+ next_token = index(required_str + position,'|');
+ str_len = strlen(required_str + position) - strlen(next_token);
- string = strndup(
- required_str + position,
- str_len
- );
+ string = strndup(
+ required_str + position,
+ str_len
+ );
- pkg = parse_meta_entry(avail_pkgs,installed_pkgs,string);
- free(string);
+ pkg = parse_meta_entry(avail_pkgs,installed_pkgs,string);
+ free(string);
- if( pkg != NULL ) break;
+ if( pkg != NULL ) break;
- position += str_len;
- }
+ position += str_len;
+ }
- ++position;
- }
+ ++position;
+ }
- return pkg;
+ return pkg;
}
-pkg_info_t *copy_pkg(pkg_info_t *dst,pkg_info_t *src){
- dst = memcpy(dst,src, sizeof *src);
- dst->name = strndup(src->name,strlen(src->name));
- dst->version = strndup(src->version,strlen(src->version));
- dst->mirror = strndup(src->mirror,strlen(src->mirror));
- dst->location = strndup(src->location,strlen(src->location));
- dst->description = strndup(src->description,strlen(src->description));
- dst->suggests = strndup(src->suggests, strlen(src->suggests));
- dst->conflicts = strndup(src->conflicts, strlen(src->conflicts));
- dst->required = strndup(src->required, strlen(src->required));
- return dst;
+pkg_info_t *copy_pkg(pkg_info_t *dst,pkg_info_t *src)
+{
+ dst = memcpy(dst,src, sizeof *src);
+ dst->name = strndup(src->name,strlen(src->name));
+ dst->version = strndup(src->version,strlen(src->version));
+ dst->mirror = strndup(src->mirror,strlen(src->mirror));
+ dst->location = strndup(src->location,strlen(src->location));
+ dst->description = strndup(src->description,strlen(src->description));
+ dst->suggests = strndup(src->suggests, strlen(src->suggests));
+ dst->conflicts = strndup(src->conflicts, strlen(src->conflicts));
+ dst->required = strndup(src->required, strlen(src->required));
+ return dst;
}
diff --git a/src/package.h b/src/package.h
index 9259dc0..0271941 100644
--- a/src/package.h
+++ b/src/package.h
@@ -110,17 +110,21 @@ void write_pkg_data(const char *source_url,FILE *d_file,struct pkg_list *pkgs);
/* retrieve the newest pkg from pkg_info_t list */
pkg_info_t *get_newest_pkg(struct pkg_list *,const char *);
/* get the exact package */
-pkg_info_t *get_exact_pkg(struct pkg_list *list,const char *name,const char *version);
+pkg_info_t *get_exact_pkg(struct pkg_list *list,const char *name,
+ const char *version);
/* lookup package by details */
-pkg_info_t *get_pkg_by_details(struct pkg_list *list,char *name,char *version,char *location);
+pkg_info_t *get_pkg_by_details(struct pkg_list *list,char *name,
+ char *version,char *location);
/* search package list with pattern */
-struct pkg_list *search_pkg_list(struct pkg_list *available,const char *pattern);
+struct pkg_list *search_pkg_list(struct pkg_list *available,
+ const char *pattern);
/* install pkg */
int install_pkg(const rc_config *,pkg_info_t *);
/* upgrade pkg */
-int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,pkg_info_t *pkg);
+int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,
+ pkg_info_t *pkg);
/* remove pkg */
int remove_pkg(const rc_config *,pkg_info_t *);
@@ -148,16 +152,23 @@ size_t get_pkg_file_size(const rc_config *global_config,pkg_info_t *pkg);
int cmp_pkg_versions(char *a, char *b);
/* resolve dependencies */
-int get_pkg_dependencies(const rc_config *global_config,struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,pkg_info_t *pkg,struct pkg_list *deps);
+int get_pkg_dependencies(const rc_config *global_config,
+ struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,pkg_info_t *pkg,
+ struct pkg_list *deps);
/* lookup package conflicts */
-struct pkg_list *get_pkg_conflicts(struct pkg_list *avail_pkgs,struct pkg_list *installed_pkgs,pkg_info_t *pkg);
+struct pkg_list *get_pkg_conflicts(struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs,
+ pkg_info_t *pkg);
/* return list of packages required by */
-struct pkg_list *is_required_by(const rc_config *global_config,struct pkg_list *avail, pkg_info_t *pkg);
+struct pkg_list *is_required_by(const rc_config *global_config,
+ struct pkg_list *avail, pkg_info_t *pkg);
/* empty packages from cache dir */
void clean_pkg_dir(const char *dir_name);
/* clean out old outdated packages in the cache */
-void purge_old_cached_pkgs(const rc_config *global_config,char *dir_name, struct pkg_list *avail_pkgs);
+void purge_old_cached_pkgs(const rc_config *global_config,char *dir_name,
+ struct pkg_list *avail_pkgs);
/* make a copy of a package (needs to be freed with free_pkg) */
pkg_info_t *copy_pkg(pkg_info_t *dst,pkg_info_t *src);
diff --git a/src/transaction.c b/src/transaction.c
index a70d335..102f4a9 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -26,783 +26,822 @@ static void queue_free(queue_t *t);
static void add_suggestion(transaction_t *tran, pkg_info_t *pkg);
static int disk_space(const rc_config *global_config,int space_needed );
-void init_transaction(transaction_t *tran){
+void init_transaction(transaction_t *tran)
+{
- tran->install_pkgs = init_pkg_list();
- tran->install_pkgs->free_pkgs = TRUE;
+ tran->install_pkgs = init_pkg_list();
+ tran->install_pkgs->free_pkgs = TRUE;
- tran->remove_pkgs = init_pkg_list();
- tran->remove_pkgs->free_pkgs = TRUE;
+ tran->remove_pkgs = init_pkg_list();
+ tran->remove_pkgs->free_pkgs = TRUE;
- tran->exclude_pkgs = init_pkg_list();
- tran->exclude_pkgs->free_pkgs = TRUE;
+ tran->exclude_pkgs = init_pkg_list();
+ tran->exclude_pkgs->free_pkgs = TRUE;
- tran->upgrade_pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs );
- tran->upgrade_pkgs->pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs->pkgs );
- tran->upgrade_pkgs->pkg_count = 0;
+ tran->upgrade_pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs );
+ tran->upgrade_pkgs->pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs->pkgs );
+ tran->upgrade_pkgs->pkg_count = 0;
- tran->suggests = slapt_malloc(sizeof *tran->suggests );
- tran->suggests->pkgs = slapt_malloc(sizeof *tran->suggests->pkgs);
- tran->suggests->count = 0;
+ tran->suggests = slapt_malloc(sizeof *tran->suggests );
+ tran->suggests->pkgs = slapt_malloc(sizeof *tran->suggests->pkgs);
+ tran->suggests->count = 0;
- tran->queue = queue_init();
+ tran->queue = queue_init();
}
-int handle_transaction(const rc_config *global_config, transaction_t *tran){
- unsigned int i;
- size_t download_size = 0;
- size_t already_download_size = 0;
- size_t uncompressed_size = 0;
-
- /* show pkgs to exclude */
- if( tran->exclude_pkgs->pkg_count > 0 ){
- unsigned int len = 0;
- printf(_("The following packages have been EXCLUDED:\n"));
- printf(" ");
- for(i = 0; i < tran->exclude_pkgs->pkg_count;i++){
- if( len + strlen(tran->exclude_pkgs->pkgs[i]->name) + 1 < MAX_LINE_LEN ){
- printf("%s ",tran->exclude_pkgs->pkgs[i]->name);
- len += strlen(tran->exclude_pkgs->pkgs[i]->name) + 1;
- }else{
- printf("\n %s ",tran->exclude_pkgs->pkgs[i]->name);
- len = strlen(tran->exclude_pkgs->pkgs[i]->name) + 3;
- }
- }
- printf("\n");
- }
-
- /* show suggested pkgs */
- generate_suggestions(tran);
- if( tran->suggests->count > 0 ){
- unsigned int len = 0;
-
- printf(_("Suggested packages:\n"));
- printf(" ");
- for(i = 0; i < tran->suggests->count; ++i){
- /* don't show suggestion for something we already have in the transaction */
- if( search_transaction(tran,tran->suggests->pkgs[i]) == 1 ) continue;
-
- if( len + strlen(tran->suggests->pkgs[i]) + 1 < MAX_LINE_LEN ){
- printf("%s ",tran->suggests->pkgs[i]);
- len += strlen(tran->suggests->pkgs[i]) + 1;
- }else{
- printf("\n %s ",tran->suggests->pkgs[i]);
- len = strlen(tran->suggests->pkgs[i]) + 3;
- }
- }
- printf("\n");
-
- }
-
- /* show pkgs to install */
- if( tran->install_pkgs->pkg_count > 0 ){
- unsigned int len = 0;
- printf(_("The following NEW packages will be installed:\n"));
- printf(" ");
- for(i = 0; i < tran->install_pkgs->pkg_count;i++){
- if( len + strlen(tran->install_pkgs->pkgs[i]->name) + 1 < MAX_LINE_LEN ){
- printf("%s ",tran->install_pkgs->pkgs[i]->name);
- len += strlen(tran->install_pkgs->pkgs[i]->name) + 1;
- }else{
- printf("\n %s ",tran->install_pkgs->pkgs[i]->name);
- len = strlen(tran->install_pkgs->pkgs[i]->name) + 3;
- }
- already_download_size += get_pkg_file_size(
- global_config,tran->install_pkgs->pkgs[i]
- ) / 1024;
- download_size += tran->install_pkgs->pkgs[i]->size_c;
- uncompressed_size += tran->install_pkgs->pkgs[i]->size_u;
- }
- printf("\n");
- }
-
- /* show pkgs to remove */
- if( tran->remove_pkgs->pkg_count > 0 ){
- unsigned int len = 0;
- printf(_("The following packages will be REMOVED:\n"));
- printf(" ");
- for(i = 0; i < tran->remove_pkgs->pkg_count;i++){
- if( len + strlen(tran->remove_pkgs->pkgs[i]->name) + 1 < MAX_LINE_LEN ){
- printf("%s ",tran->remove_pkgs->pkgs[i]->name);
- len += strlen(tran->remove_pkgs->pkgs[i]->name) + 1;
- }else{
- printf("\n %s ",tran->remove_pkgs->pkgs[i]->name);
- len = strlen(tran->remove_pkgs->pkgs[i]->name) + 3;
- }
- uncompressed_size -= tran->remove_pkgs->pkgs[i]->size_u;
- }
- printf("\n");
- }
-
- /* show pkgs to upgrade */
- if( tran->upgrade_pkgs->pkg_count > 0 ){
- unsigned int len = 0;
- printf(_("The following packages will be upgraded:\n"));
- printf(" ");
- for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++){
- if(len+strlen(tran->upgrade_pkgs->pkgs[i]->upgrade->name)+1<MAX_LINE_LEN){
- printf("%s ",tran->upgrade_pkgs->pkgs[i]->upgrade->name);
- len += strlen(tran->upgrade_pkgs->pkgs[i]->upgrade->name) + 1;
- }else{
- printf("\n %s ",tran->upgrade_pkgs->pkgs[i]->upgrade->name);
- len = strlen(tran->upgrade_pkgs->pkgs[i]->upgrade->name) + 3;
- }
- already_download_size += get_pkg_file_size(
- global_config,tran->upgrade_pkgs->pkgs[i]->upgrade
- ) / 1024;
- download_size += tran->upgrade_pkgs->pkgs[i]->upgrade->size_c;
- uncompressed_size += tran->upgrade_pkgs->pkgs[i]->upgrade->size_u;
- uncompressed_size -= tran->upgrade_pkgs->pkgs[i]->installed->size_u;
- }
- printf("\n");
- }
-
- /* print the summary */
- printf(
- _("%d upgraded, %d newly installed, %d to remove and %d not upgraded.\n"),
- tran->upgrade_pkgs->pkg_count,
- tran->install_pkgs->pkg_count,
- tran->remove_pkgs->pkg_count,
- tran->exclude_pkgs->pkg_count
- );
-
- /* only show this if we are going to do download something */
- if( tran->upgrade_pkgs->pkg_count > 0 || tran->install_pkgs->pkg_count > 0 ){
- /* how much we need to download */
- int need_to_download_size = download_size - already_download_size;
- /* make sure it's not negative due to changing pkg sizes on upgrades */
- if( need_to_download_size < 0 ) need_to_download_size = 0;
-
- if(disk_space(global_config,need_to_download_size+uncompressed_size) != 0){
- printf(
- _("You don't have enough free space in %s\n"),
- global_config->working_dir
- );
- return 1;
- }
-
- if( already_download_size > 0 ){
- printf(_("Need to get %.1d%s/%.1d%s of archives.\n"),
- (need_to_download_size > 1024 ) ? need_to_download_size / 1024
- : need_to_download_size,
- (need_to_download_size > 1024 ) ? "MB" : "kB",
- (download_size > 1024 ) ? download_size / 1024 : download_size,
- (download_size > 1024 ) ? "MB" : "kB"
- );
- }else{
- printf(_("Need to get %.1d%s of archives.\n"),
- (download_size > 1024 ) ? download_size / 1024 : download_size,
- (download_size > 1024 ) ? "MB" : "kB"
- );
- }
- }
-
- if( tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
- tran->install_pkgs->pkg_count > 0 ){
-
- if( global_config->download_only == FALSE ){
- if( (int)uncompressed_size < 0 ){
- uncompressed_size *= -1;
- printf(_("After unpacking %.1d%s disk space will be freed.\n"),
- (uncompressed_size > 1024 ) ? uncompressed_size / 1024
- : uncompressed_size,
- (uncompressed_size > 1024 ) ? "MB" : "kB"
- );
- }else{
- printf(_("After unpacking %.1d%s of additional disk space will be used.\n"),
- (uncompressed_size > 1024 ) ? uncompressed_size / 1024
- : uncompressed_size,
- (uncompressed_size > 1024 ) ? "MB" : "kB"
- );
- }
- }
- }
-
- /* prompt */
- if(
- (tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
- ( tran->install_pkgs->pkg_count > 0 && global_config->dist_upgrade == TRUE ) ) &&
- (global_config->no_prompt == FALSE && global_config->download_only == FALSE &&
- global_config->simulate == FALSE && global_config->print_uris == FALSE )
- ) {
- if( ask_yes_no(_("Do you want to continue? [y/N] ")) != 1 ){
- printf(_("Abort.\n"));
- return 1;
- }
- }
-
- if ( global_config->print_uris == TRUE ){
- for(i = 0; i < tran->install_pkgs->pkg_count;i++) {
- const pkg_info_t *info = tran->install_pkgs->pkgs[i];
- const char *location = info->location + strspn(info->location, "./");
- printf("%s%s/%s-%s.tgz\n", info->mirror, location, info->name, info->version);
- }
- for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++) {
- const pkg_info_t *info = tran->upgrade_pkgs->pkgs[i]->upgrade;
- const char *location = info->location + strspn(info->location, "./");
- printf("%s%s/%s-%s.tgz\n", info->mirror, location, info->name, info->version);
- }
- return 0;
- }
-
- /* if simulate is requested, just show what could happen and return */
- if( global_config->simulate == TRUE ){
- for(i = 0; i < tran->remove_pkgs->pkg_count;i++){
- printf(_("%s-%s is to be removed\n"),
- tran->remove_pkgs->pkgs[i]->name,tran->remove_pkgs->pkgs[i]->version
- );
- }
- for(i = 0;i < tran->queue->count; ++i){
- if( tran->queue->pkgs[i]->type == INSTALL ){
- printf(_("%s-%s is to be installed\n"),
- tran->queue->pkgs[i]->pkg.i->name,
- tran->queue->pkgs[i]->pkg.i->version
- );
- }else if( tran->queue->pkgs[i]->type == UPGRADE ){
- printf(_("%s-%s is to be upgraded to version %s\n"),
- tran->queue->pkgs[i]->pkg.u->upgrade->name,
- tran->queue->pkgs[i]->pkg.u->installed->version,
- tran->queue->pkgs[i]->pkg.u->upgrade->version
- );
- }
- }
- printf(_("Done\n"));
- return 0;
- }
-
- /* download pkgs */
- for(i = 0; i < tran->install_pkgs->pkg_count;i++)
- if( download_pkg(global_config,tran->install_pkgs->pkgs[i]) != 0 ) exit(1);
- for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++)
- if( download_pkg(global_config,tran->upgrade_pkgs->pkgs[i]->upgrade) != 0 ) exit(1);
-
- printf("\n");
-
- /* run transaction, remove, install, and upgrade */
- if( global_config->download_only == FALSE ){
- for(i = 0; i < tran->remove_pkgs->pkg_count;i++){
- if( remove_pkg(global_config,tran->remove_pkgs->pkgs[i]) == -1 ) exit(1);
- }
- for(i = 0;i < tran->queue->count; ++i){
- if( tran->queue->pkgs[i]->type == INSTALL ){
- if( install_pkg(global_config,tran->queue->pkgs[i]->pkg.i) == -1 ) exit(1);
- }else if( tran->queue->pkgs[i]->type == UPGRADE ){
- if( upgrade_pkg( global_config,
- tran->queue->pkgs[i]->pkg.u->installed,
- tran->queue->pkgs[i]->pkg.u->upgrade
- ) == -1 ) exit(1);
- }
- }
- }
-
- printf(_("Done\n"));
-
- return 0;
+int handle_transaction(const rc_config *global_config, transaction_t *tran)
+{
+ unsigned int i;
+ size_t download_size = 0;
+ size_t already_download_size = 0;
+ size_t uncompressed_size = 0;
+
+ /* show pkgs to exclude */
+ if( tran->exclude_pkgs->pkg_count > 0 ) {
+ unsigned int len = 0;
+ printf(_("The following packages have been EXCLUDED:\n"));
+ printf(" ");
+ for(i = 0; i < tran->exclude_pkgs->pkg_count;i++) {
+ if( len + strlen(tran->exclude_pkgs->pkgs[i]->name) + 1 < MAX_LINE_LEN ) {
+ printf("%s ",tran->exclude_pkgs->pkgs[i]->name);
+ len += strlen(tran->exclude_pkgs->pkgs[i]->name) + 1;
+ }else{
+ printf("\n %s ",tran->exclude_pkgs->pkgs[i]->name);
+ len = strlen(tran->exclude_pkgs->pkgs[i]->name) + 3;
+ }
+ }
+ printf("\n");
+ }
+
+ /* show suggested pkgs */
+ generate_suggestions(tran);
+ if( tran->suggests->count > 0 ) {
+ unsigned int len = 0;
+
+ printf(_("Suggested packages:\n"));
+ printf(" ");
+ for(i = 0; i < tran->suggests->count; ++i) {
+ /* don't show suggestion for something we already have in the transaction */
+ if( search_transaction(tran,tran->suggests->pkgs[i]) == 1 ) continue;
+
+ if( len + strlen(tran->suggests->pkgs[i]) + 1 < MAX_LINE_LEN ) {
+ printf("%s ",tran->suggests->pkgs[i]);
+ len += strlen(tran->suggests->pkgs[i]) + 1;
+ }else{
+ printf("\n %s ",tran->suggests->pkgs[i]);
+ len = strlen(tran->suggests->pkgs[i]) + 3;
+ }
+ }
+ printf("\n");
+
+ }
+
+ /* show pkgs to install */
+ if( tran->install_pkgs->pkg_count > 0 ) {
+ unsigned int len = 0;
+ printf(_("The following NEW packages will be installed:\n"));
+ printf(" ");
+ for(i = 0; i < tran->install_pkgs->pkg_count;i++) {
+ if( len + strlen(tran->install_pkgs->pkgs[i]->name) + 1 < MAX_LINE_LEN ) {
+ printf("%s ",tran->install_pkgs->pkgs[i]->name);
+ len += strlen(tran->install_pkgs->pkgs[i]->name) + 1;
+ }else{
+ printf("\n %s ",tran->install_pkgs->pkgs[i]->name);
+ len = strlen(tran->install_pkgs->pkgs[i]->name) + 3;
+ }
+ already_download_size += get_pkg_file_size(
+ global_config,tran->install_pkgs->pkgs[i]
+ ) / 1024;
+ download_size += tran->install_pkgs->pkgs[i]->size_c;
+ uncompressed_size += tran->install_pkgs->pkgs[i]->size_u;
+ }
+ printf("\n");
+ }
+
+ /* show pkgs to remove */
+ if( tran->remove_pkgs->pkg_count > 0 ) {
+ unsigned int len = 0;
+ printf(_("The following packages will be REMOVED:\n"));
+ printf(" ");
+ for(i = 0; i < tran->remove_pkgs->pkg_count;i++) {
+ if( len + strlen(tran->remove_pkgs->pkgs[i]->name) + 1 < MAX_LINE_LEN ) {
+ printf("%s ",tran->remove_pkgs->pkgs[i]->name);
+ len += strlen(tran->remove_pkgs->pkgs[i]->name) + 1;
+ }else{
+ printf("\n %s ",tran->remove_pkgs->pkgs[i]->name);
+ len = strlen(tran->remove_pkgs->pkgs[i]->name) + 3;
+ }
+ uncompressed_size -= tran->remove_pkgs->pkgs[i]->size_u;
+ }
+ printf("\n");
+ }
+
+ /* show pkgs to upgrade */
+ if( tran->upgrade_pkgs->pkg_count > 0 ) {
+ unsigned int len = 0;
+ printf(_("The following packages will be upgraded:\n"));
+ printf(" ");
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++) {
+ if(len+strlen(tran->upgrade_pkgs->pkgs[i]->upgrade->name)+1<MAX_LINE_LEN) {
+ printf("%s ",tran->upgrade_pkgs->pkgs[i]->upgrade->name);
+ len += strlen(tran->upgrade_pkgs->pkgs[i]->upgrade->name) + 1;
+ }else{
+ printf("\n %s ",tran->upgrade_pkgs->pkgs[i]->upgrade->name);
+ len = strlen(tran->upgrade_pkgs->pkgs[i]->upgrade->name) + 3;
+ }
+ already_download_size += get_pkg_file_size(
+ global_config,tran->upgrade_pkgs->pkgs[i]->upgrade
+ ) / 1024;
+ download_size += tran->upgrade_pkgs->pkgs[i]->upgrade->size_c;
+ uncompressed_size += tran->upgrade_pkgs->pkgs[i]->upgrade->size_u;
+ uncompressed_size -= tran->upgrade_pkgs->pkgs[i]->installed->size_u;
+ }
+ printf("\n");
+ }
+
+ /* print the summary */
+ printf(
+ _("%d upgraded, %d newly installed, %d to remove and %d not upgraded.\n"),
+ tran->upgrade_pkgs->pkg_count,
+ tran->install_pkgs->pkg_count,
+ tran->remove_pkgs->pkg_count,
+ tran->exclude_pkgs->pkg_count
+ );
+
+ /* only show this if we are going to do download something */
+ if( tran->upgrade_pkgs->pkg_count > 0 || tran->install_pkgs->pkg_count > 0 ) {
+ /* how much we need to download */
+ int need_to_download_size = download_size - already_download_size;
+ /* make sure it's not negative due to changing pkg sizes on upgrades */
+ if( need_to_download_size < 0 ) need_to_download_size = 0;
+
+ if(disk_space(global_config,need_to_download_size+uncompressed_size) != 0) {
+ printf(
+ _("You don't have enough free space in %s\n"),
+ global_config->working_dir
+ );
+ return 1;
+ }
+
+ if( already_download_size > 0 ) {
+ printf(_("Need to get %.1d%s/%.1d%s of archives.\n"),
+ (need_to_download_size > 1024 ) ? need_to_download_size / 1024
+ : need_to_download_size,
+ (need_to_download_size > 1024 ) ? "MB" : "kB",
+ (download_size > 1024 ) ? download_size / 1024 : download_size,
+ (download_size > 1024 ) ? "MB" : "kB"
+ );
+ }else{
+ printf(_("Need to get %.1d%s of archives.\n"),
+ (download_size > 1024 ) ? download_size / 1024 : download_size,
+ (download_size > 1024 ) ? "MB" : "kB"
+ );
+ }
+ }
+
+ if( tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
+ tran->install_pkgs->pkg_count > 0 ) {
+
+ if( global_config->download_only == FALSE ) {
+ if( (int)uncompressed_size < 0 ) {
+ uncompressed_size *= -1;
+ printf(_("After unpacking %.1d%s disk space will be freed.\n"),
+ (uncompressed_size > 1024 ) ? uncompressed_size / 1024
+ : uncompressed_size,
+ (uncompressed_size > 1024 ) ? "MB" : "kB"
+ );
+ }else{
+ printf(_("After unpacking %.1d%s of additional disk space will be used.\n"),
+ (uncompressed_size > 1024 ) ? uncompressed_size / 1024
+ : uncompressed_size,
+ (uncompressed_size > 1024 ) ? "MB" : "kB"
+ );
+ }
+ }
+ }
+
+ /* prompt */
+ if(
+ (tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0 ||
+ ( tran->install_pkgs->pkg_count > 0 && global_config->dist_upgrade == TRUE ) ) &&
+ (global_config->no_prompt == FALSE && global_config->download_only == FALSE &&
+ global_config->simulate == FALSE && global_config->print_uris == FALSE )
+ ) {
+ if( ask_yes_no(_("Do you want to continue? [y/N] ")) != 1 ) {
+ printf(_("Abort.\n"));
+ return 1;
+ }
+ }
+
+ if ( global_config->print_uris == TRUE ) {
+ for(i = 0; i < tran->install_pkgs->pkg_count;i++) {
+ const pkg_info_t *info = tran->install_pkgs->pkgs[i];
+ const char *location = info->location + strspn(info->location, "./");
+ printf("%s%s/%s-%s.tgz\n", info->mirror, location, info->name, info->version);
+ }
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++) {
+ const pkg_info_t *info = tran->upgrade_pkgs->pkgs[i]->upgrade;
+ const char *location = info->location + strspn(info->location, "./");
+ printf("%s%s/%s-%s.tgz\n", info->mirror, location, info->name, info->version);
+ }
+ return 0;
+ }
+
+ /* if simulate is requested, just show what could happen and return */
+ if( global_config->simulate == TRUE ) {
+ for(i = 0; i < tran->remove_pkgs->pkg_count;i++) {
+ printf(_("%s-%s is to be removed\n"),
+ tran->remove_pkgs->pkgs[i]->name,tran->remove_pkgs->pkgs[i]->version
+ );
+ }
+ for(i = 0;i < tran->queue->count; ++i) {
+ if( tran->queue->pkgs[i]->type == INSTALL ) {
+ printf(_("%s-%s is to be installed\n"),
+ tran->queue->pkgs[i]->pkg.i->name,
+ tran->queue->pkgs[i]->pkg.i->version
+ );
+ }else if( tran->queue->pkgs[i]->type == UPGRADE ) {
+ printf(_("%s-%s is to be upgraded to version %s\n"),
+ tran->queue->pkgs[i]->pkg.u->upgrade->name,
+ tran->queue->pkgs[i]->pkg.u->installed->version,
+ tran->queue->pkgs[i]->pkg.u->upgrade->version
+ );
+ }
+ }
+ printf(_("Done\n"));
+ return 0;
+ }
+
+ /* download pkgs */
+ for(i = 0; i < tran->install_pkgs->pkg_count;i++)
+ if( download_pkg(global_config,tran->install_pkgs->pkgs[i]) != 0 ) exit(1);
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++)
+ if( download_pkg(global_config,tran->upgrade_pkgs->pkgs[i]->upgrade) != 0 ) exit(1);
+
+ printf("\n");
+
+ /* run transaction, remove, install, and upgrade */
+ if( global_config->download_only == FALSE ) {
+ for(i = 0; i < tran->remove_pkgs->pkg_count;i++) {
+ if( remove_pkg(global_config,tran->remove_pkgs->pkgs[i]) == -1 ) exit(1);
+ }
+ for(i = 0;i < tran->queue->count; ++i) {
+ if( tran->queue->pkgs[i]->type == INSTALL ) {
+ if( install_pkg(global_config,tran->queue->pkgs[i]->pkg.i) == -1 ) exit(1);
+ }else if( tran->queue->pkgs[i]->type == UPGRADE ) {
+ if( upgrade_pkg( global_config,
+ tran->queue->pkgs[i]->pkg.u->installed,
+ tran->queue->pkgs[i]->pkg.u->upgrade
+ ) == -1 ) exit(1);
+ }
+ }
+ }
+
+ printf(_("Done\n"));
+
+ return 0;
}
-void add_install_to_transaction(transaction_t *tran,pkg_info_t *pkg){
- pkg_info_t **tmp_list;
-
- /* don't add if already present in the transaction */
- if( search_transaction_by_pkg(tran,pkg) == 1 ) return;
-
- #if DEBUG == 1
- printf("adding install of %s-%s@%s to transaction\n",
- pkg->name,pkg->version,pkg->location);
- #endif
-
- 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] = copy_pkg(
- tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count],
- pkg
- );
- queue_add_install(tran->queue,tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]);
-
- ++tran->install_pkgs->pkg_count;
- }
+void add_install_to_transaction(transaction_t *tran,pkg_info_t *pkg)
+{
+ pkg_info_t **tmp_list;
+
+ /* don't add if already present in the transaction */
+ if( search_transaction_by_pkg(tran,pkg) == 1 ) return;
+
+ #if DEBUG == 1
+ printf("adding install of %s-%s@%s to transaction\n",
+ pkg->name,pkg->version,pkg->location);
+ #endif
+
+ 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] = copy_pkg(
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count],
+ pkg
+ );
+ queue_add_install(
+ tran->queue,
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]
+ );
+
+ ++tran->install_pkgs->pkg_count;
+ }
}
-void add_remove_to_transaction(transaction_t *tran,pkg_info_t *pkg){
- pkg_info_t **tmp_list;
-
- /* don't add if already present in the transaction */
- if( search_transaction_by_pkg(tran,pkg) == 1 ) return;
-
- #if DEBUG == 1
- printf("adding remove of %s-%s@%s to transaction\n",
- pkg->name,pkg->version,pkg->location);
- #endif
-
- 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] = copy_pkg(
- tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count],
- pkg
- );
- ++tran->remove_pkgs->pkg_count;
- }
+void add_remove_to_transaction(transaction_t *tran,pkg_info_t *pkg)
+{
+ pkg_info_t **tmp_list;
+
+ /* don't add if already present in the transaction */
+ if( search_transaction_by_pkg(tran,pkg) == 1 ) return;
+
+ #if DEBUG == 1
+ printf("adding remove of %s-%s@%s to transaction\n",
+ pkg->name,pkg->version,pkg->location);
+ #endif
+
+ 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] = copy_pkg(
+ tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count],
+ pkg
+ );
+ ++tran->remove_pkgs->pkg_count;
+ }
}
-void add_exclude_to_transaction(transaction_t *tran,pkg_info_t *pkg){
- pkg_info_t **tmp_list;
-
- /* don't add if already present in the transaction */
- if( search_transaction_by_pkg(tran,pkg) == 1 ) return;
-
- #if DEBUG == 1
- printf("adding exclude of %s-%s@%s to transaction\n",
- pkg->name,pkg->version,pkg->location);
- #endif
-
- 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] = copy_pkg(
- tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count],
- pkg
- );
- ++tran->exclude_pkgs->pkg_count;
- }
+void add_exclude_to_transaction(transaction_t *tran,pkg_info_t *pkg)
+{
+ pkg_info_t **tmp_list;
+
+ /* don't add if already present in the transaction */
+ if( search_transaction_by_pkg(tran,pkg) == 1 ) return;
+
+ #if DEBUG == 1
+ printf("adding exclude of %s-%s@%s to transaction\n",
+ pkg->name,pkg->version,pkg->location);
+ #endif
+
+ 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] = copy_pkg(
+ tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count],
+ pkg
+ );
+ ++tran->exclude_pkgs->pkg_count;
+ }
}
-void add_upgrade_to_transaction(
- transaction_t *tran, pkg_info_t *installed_pkg, pkg_info_t *upgrade_pkg
-){
- pkg_upgrade_t **tmp_list;
-
- /* don't add if already present in the transaction */
- if( search_transaction_by_pkg(tran,upgrade_pkg) == 1 ) return;
-
- #if DEBUG == 1
- printf("adding upgrade of %s-%s@%s to transaction\n",
- upgrade_pkg->name,upgrade_pkg->version,upgrade_pkg->location);
- #endif
-
- 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;
-
- 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 = copy_pkg(
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed,
- installed_pkg
- );
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = copy_pkg(
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade,
- upgrade_pkg
- );
-
- queue_add_upgrade(
- tran->queue,
- tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]
- );
-
- ++tran->upgrade_pkgs->pkg_count;
-
- }
+void add_upgrade_to_transaction(transaction_t *tran, pkg_info_t *installed_pkg,
+ pkg_info_t *upgrade_pkg
+)
+{
+ pkg_upgrade_t **tmp_list;
+
+ /* don't add if already present in the transaction */
+ if( search_transaction_by_pkg(tran,upgrade_pkg) == 1 ) return;
+
+ #if DEBUG == 1
+ printf("adding upgrade of %s-%s@%s to transaction\n",
+ upgrade_pkg->name,upgrade_pkg->version,upgrade_pkg->location);
+ #endif
+
+ 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;
+
+ 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 = copy_pkg(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed,
+ installed_pkg
+ );
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = copy_pkg(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade,
+ upgrade_pkg
+ );
+
+ queue_add_upgrade(
+ tran->queue,
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]
+ );
+
+ ++tran->upgrade_pkgs->pkg_count;
+
+ }
}
-int search_transaction(transaction_t *tran,char *pkg_name){
- unsigned int i,found = 1, not_found = 0;
-
- for(i = 0; i < tran->install_pkgs->pkg_count;i++){
- if( strcmp(pkg_name,tran->install_pkgs->pkgs[i]->name)==0 )
- return found;
- }
- for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++){
- if( strcmp(pkg_name,tran->upgrade_pkgs->pkgs[i]->upgrade->name)==0 )
- return found;
- }
- for(i = 0; i < tran->remove_pkgs->pkg_count;i++){
- if( strcmp(pkg_name,tran->remove_pkgs->pkgs[i]->name)==0 )
- return found;
- }
- for(i = 0; i < tran->exclude_pkgs->pkg_count;i++){
- if( strcmp(pkg_name,tran->exclude_pkgs->pkgs[i]->name)==0 )
- return found;
- }
- return not_found;
+int search_transaction(transaction_t *tran,char *pkg_name)
+{
+ unsigned int i,found = 1, not_found = 0;
+
+ for(i = 0; i < tran->install_pkgs->pkg_count;i++) {
+ if( strcmp(pkg_name,tran->install_pkgs->pkgs[i]->name)==0 )
+ return found;
+ }
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++) {
+ if( strcmp(pkg_name,tran->upgrade_pkgs->pkgs[i]->upgrade->name)==0 )
+ return found;
+ }
+ for(i = 0; i < tran->remove_pkgs->pkg_count;i++) {
+ if( strcmp(pkg_name,tran->remove_pkgs->pkgs[i]->name)==0 )
+ return found;
+ }
+ for(i = 0; i < tran->exclude_pkgs->pkg_count;i++) {
+ if( strcmp(pkg_name,tran->exclude_pkgs->pkgs[i]->name)==0 )
+ return found;
+ }
+ return not_found;
}
-static int search_upgrade_transaction(transaction_t *tran,pkg_info_t *pkg){
- unsigned int i,found = 1, not_found = 0;
- for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++){
- if( strcmp(pkg->name,tran->upgrade_pkgs->pkgs[i]->upgrade->name)==0 )
- return found;
- }
- return not_found;
+static int search_upgrade_transaction(transaction_t *tran,pkg_info_t *pkg)
+{
+ unsigned int i,found = 1, not_found = 0;
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++) {
+ if( strcmp(pkg->name,tran->upgrade_pkgs->pkgs[i]->upgrade->name)==0 )
+ return found;
+ }
+ return not_found;
}
-void free_transaction(transaction_t *tran){
- unsigned int i;
-
- if( tran->install_pkgs->free_pkgs == TRUE ){
- for(i = 0;i < tran->install_pkgs->pkg_count; i++){
- free_pkg(tran->install_pkgs->pkgs[i]);
- }
- }
- free(tran->install_pkgs->pkgs);
- free(tran->install_pkgs);
-
- if( tran->remove_pkgs->free_pkgs == TRUE ){
- for(i = 0;i < tran->remove_pkgs->pkg_count; i++){
- free_pkg(tran->remove_pkgs->pkgs[i]);
- }
- }
- free(tran->remove_pkgs->pkgs);
- free(tran->remove_pkgs);
-
- for(i = 0;i < tran->upgrade_pkgs->pkg_count; i++){
- free_pkg(tran->upgrade_pkgs->pkgs[i]->upgrade);
- free_pkg(tran->upgrade_pkgs->pkgs[i]->installed);
- free(tran->upgrade_pkgs->pkgs[i]);
- }
- free(tran->upgrade_pkgs->pkgs);
- free(tran->upgrade_pkgs);
-
- if( tran->exclude_pkgs->free_pkgs == TRUE ){
- for(i = 0; i < tran->exclude_pkgs->pkg_count;i++){
- free_pkg(tran->exclude_pkgs->pkgs[i]);
- }
- }
- free(tran->exclude_pkgs->pkgs);
- free(tran->exclude_pkgs);
-
- for(i = 0; i < tran->suggests->count; ++i){
- free(tran->suggests->pkgs[i]);
- }
- free(tran->suggests->pkgs);
- free(tran->suggests);
-
- queue_free(tran->queue);
+void free_transaction(transaction_t *tran)
+{
+ unsigned int i;
+
+ if( tran->install_pkgs->free_pkgs == TRUE ) {
+ for(i = 0;i < tran->install_pkgs->pkg_count; i++) {
+ free_pkg(tran->install_pkgs->pkgs[i]);
+ }
+ }
+ free(tran->install_pkgs->pkgs);
+ free(tran->install_pkgs);
+
+ if( tran->remove_pkgs->free_pkgs == TRUE ) {
+ for(i = 0;i < tran->remove_pkgs->pkg_count; i++) {
+ free_pkg(tran->remove_pkgs->pkgs[i]);
+ }
+ }
+ free(tran->remove_pkgs->pkgs);
+ free(tran->remove_pkgs);
+
+ for(i = 0;i < tran->upgrade_pkgs->pkg_count; i++) {
+ free_pkg(tran->upgrade_pkgs->pkgs[i]->upgrade);
+ free_pkg(tran->upgrade_pkgs->pkgs[i]->installed);
+ free(tran->upgrade_pkgs->pkgs[i]);
+ }
+ free(tran->upgrade_pkgs->pkgs);
+ free(tran->upgrade_pkgs);
+
+ if( tran->exclude_pkgs->free_pkgs == TRUE ) {
+ for(i = 0; i < tran->exclude_pkgs->pkg_count;i++) {
+ free_pkg(tran->exclude_pkgs->pkgs[i]);
+ }
+ }
+ free(tran->exclude_pkgs->pkgs);
+ free(tran->exclude_pkgs);
+
+ for(i = 0; i < tran->suggests->count; ++i) {
+ free(tran->suggests->pkgs[i]);
+ }
+ free(tran->suggests->pkgs);
+ free(tran->suggests);
+
+ queue_free(tran->queue);
}
-transaction_t *remove_from_transaction(transaction_t *tran,pkg_info_t *pkg){
- unsigned int i;
- transaction_t *new_tran = NULL;
-
- if( search_transaction_by_pkg(tran,pkg) == 0 )
- return tran;
-
- /* since this is a pointer, slapt_malloc before calling init */
- new_tran = slapt_malloc(sizeof *new_tran);
- new_tran->install_pkgs = slapt_malloc( sizeof *new_tran->install_pkgs );
- new_tran->remove_pkgs = slapt_malloc( sizeof *new_tran->remove_pkgs );
- new_tran->upgrade_pkgs = slapt_malloc( sizeof *new_tran->upgrade_pkgs );
- new_tran->exclude_pkgs = slapt_malloc( sizeof *new_tran->exclude_pkgs );
- init_transaction(new_tran);
-
- for(i = 0;i < tran->install_pkgs->pkg_count; i++){
- if(
- strcmp(pkg->name,tran->install_pkgs->pkgs[i]->name) != 0 &&
- strcmp(pkg->version,tran->install_pkgs->pkgs[i]->version) != 0 &&
- strcmp(pkg->location,tran->install_pkgs->pkgs[i]->location) != 0
- ) add_install_to_transaction(new_tran,tran->install_pkgs->pkgs[i]);
- }
- for(i = 0;i < tran->remove_pkgs->pkg_count; i++){
- if(
- strcmp(pkg->name,tran->remove_pkgs->pkgs[i]->name) != 0 &&
- strcmp(pkg->version,tran->remove_pkgs->pkgs[i]->version) != 0 &&
- strcmp(pkg->location,tran->remove_pkgs->pkgs[i]->location) != 0
- ) add_remove_to_transaction(new_tran,tran->remove_pkgs->pkgs[i]);
- }
- for(i = 0;i < tran->upgrade_pkgs->pkg_count; i++){
- if(
- strcmp(pkg->name,tran->upgrade_pkgs->pkgs[i]->upgrade->name) != 0 &&
- strcmp(pkg->version,tran->upgrade_pkgs->pkgs[i]->upgrade->version) != 0 &&
- strcmp(pkg->location,tran->upgrade_pkgs->pkgs[i]->upgrade->location) != 0
- ) add_upgrade_to_transaction(
- new_tran,
- tran->upgrade_pkgs->pkgs[i]->installed,
- tran->upgrade_pkgs->pkgs[i]->upgrade
- );
- }
- for(i = 0; i < tran->exclude_pkgs->pkg_count;i++){
- if(
- strcmp(pkg->name,tran->exclude_pkgs->pkgs[i]->name) != 0 &&
- strcmp(pkg->version,tran->exclude_pkgs->pkgs[i]->version) != 0 &&
- strcmp(pkg->location,tran->exclude_pkgs->pkgs[i]->location) != 0
- ) add_exclude_to_transaction(new_tran,tran->exclude_pkgs->pkgs[i]);
- }
-
- return new_tran;
+transaction_t *remove_from_transaction(transaction_t *tran,pkg_info_t *pkg)
+{
+ unsigned int i;
+ transaction_t *new_tran = NULL;
+
+ if( search_transaction_by_pkg(tran,pkg) == 0 )
+ return tran;
+
+ /* since this is a pointer, slapt_malloc before calling init */
+ new_tran = slapt_malloc(sizeof *new_tran);
+ new_tran->install_pkgs = slapt_malloc( sizeof *new_tran->install_pkgs );
+ new_tran->remove_pkgs = slapt_malloc( sizeof *new_tran->remove_pkgs );
+ new_tran->upgrade_pkgs = slapt_malloc( sizeof *new_tran->upgrade_pkgs );
+ new_tran->exclude_pkgs = slapt_malloc( sizeof *new_tran->exclude_pkgs );
+ init_transaction(new_tran);
+
+ for(i = 0;i < tran->install_pkgs->pkg_count; i++) {
+ if(
+ strcmp(pkg->name,tran->install_pkgs->pkgs[i]->name) != 0 &&
+ strcmp(pkg->version,tran->install_pkgs->pkgs[i]->version) != 0 &&
+ strcmp(pkg->location,tran->install_pkgs->pkgs[i]->location) != 0
+ ) add_install_to_transaction(new_tran,tran->install_pkgs->pkgs[i]);
+ }
+ for(i = 0;i < tran->remove_pkgs->pkg_count; i++) {
+ if(
+ strcmp(pkg->name,tran->remove_pkgs->pkgs[i]->name) != 0 &&
+ strcmp(pkg->version,tran->remove_pkgs->pkgs[i]->version) != 0 &&
+ strcmp(pkg->location,tran->remove_pkgs->pkgs[i]->location) != 0
+ ) add_remove_to_transaction(new_tran,tran->remove_pkgs->pkgs[i]);
+ }
+ for(i = 0;i < tran->upgrade_pkgs->pkg_count; i++) {
+ if(
+ strcmp(pkg->name,tran->upgrade_pkgs->pkgs[i]->upgrade->name) != 0 &&
+ strcmp(pkg->version,tran->upgrade_pkgs->pkgs[i]->upgrade->version) != 0 &&
+ strcmp(pkg->location,tran->upgrade_pkgs->pkgs[i]->upgrade->location) != 0
+ ) add_upgrade_to_transaction(
+ new_tran,
+ tran->upgrade_pkgs->pkgs[i]->installed,
+ tran->upgrade_pkgs->pkgs[i]->upgrade
+ );
+ }
+ for(i = 0; i < tran->exclude_pkgs->pkg_count;i++) {
+ if(
+ strcmp(pkg->name,tran->exclude_pkgs->pkgs[i]->name) != 0 &&
+ strcmp(pkg->version,tran->exclude_pkgs->pkgs[i]->version) != 0 &&
+ strcmp(pkg->location,tran->exclude_pkgs->pkgs[i]->location) != 0
+ ) add_exclude_to_transaction(new_tran,tran->exclude_pkgs->pkgs[i]);
+ }
+
+ return new_tran;
}
-/* parse the dependencies for a package, and add them to the transaction as needed */
-/* check to see if a package is conflicted */
-int add_deps_to_trans(const rc_config *global_config, transaction_t *tran, struct pkg_list *avail_pkgs, struct pkg_list *installed_pkgs, pkg_info_t *pkg){
- unsigned int c;
- int dep_return = -1;
- struct pkg_list *deps;
-
- if( global_config->disable_dep_check == TRUE ) return 0;
- if( pkg == NULL ) return 0;
-
- deps = init_pkg_list();
-
- dep_return = get_pkg_dependencies(global_config,avail_pkgs,installed_pkgs,pkg,deps);
-
- /* check to see if there where issues with dep checking */
- /* exclude the package if dep check barfed */
- if( (dep_return == -1) && (global_config->ignore_dep == FALSE) ){
- printf("Excluding %s, use --ignore-dep to override\n",pkg->name);
- add_exclude_to_transaction(tran,pkg);
- free_pkg_list(deps);
- return -1;
- }
-
- /* loop through the deps */
- for(c = 0; c < deps->pkg_count;c++){
- pkg_info_t *dep_installed;
- pkg_info_t *conflicted_pkg = NULL;
-
- /*
- * the dep wouldn't get this far if it where excluded,
- * so we don't check for that here
- */
-
- if ( (conflicted_pkg = is_conflicted(tran,avail_pkgs,installed_pkgs,deps->pkgs[c])) != NULL ){
- add_remove_to_transaction(tran,conflicted_pkg);
- }
-
- if( (dep_installed = get_newest_pkg(installed_pkgs,deps->pkgs[c]->name)) == NULL ){
- add_install_to_transaction(tran,deps->pkgs[c]);
- }else{
- /* add only if its a valid upgrade */
- if(cmp_pkg_versions(dep_installed->version,deps->pkgs[c]->version) < 0 )
- add_upgrade_to_transaction(tran,dep_installed,deps->pkgs[c]);
- }
-
- }
-
- free_pkg_list(deps);
-
- return 0;
+/* parse the dependencies for a package, and add them to the transaction as */
+/* needed check to see if a package is conflicted */
+int add_deps_to_trans(const rc_config *global_config, transaction_t *tran,
+ struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs, pkg_info_t *pkg)
+{
+ unsigned int c;
+ int dep_return = -1;
+ struct pkg_list *deps;
+
+ if( global_config->disable_dep_check == TRUE ) return 0;
+ if( pkg == NULL ) return 0;
+
+ deps = init_pkg_list();
+
+ dep_return = get_pkg_dependencies(
+ global_config,avail_pkgs,installed_pkgs,pkg,deps
+ );
+
+ /* check to see if there where issues with dep checking */
+ /* exclude the package if dep check barfed */
+ if( (dep_return == -1) && (global_config->ignore_dep == FALSE) ) {
+ printf("Excluding %s, use --ignore-dep to override\n",pkg->name);
+ add_exclude_to_transaction(tran,pkg);
+ free_pkg_list(deps);
+ return -1;
+ }
+
+ /* loop through the deps */
+ for(c = 0; c < deps->pkg_count;c++) {
+ pkg_info_t *dep_installed;
+ pkg_info_t *conflicted_pkg = NULL;
+
+ /*
+ * the dep wouldn't get this far if it where excluded,
+ * so we don't check for that here
+ */
+
+ conflicted_pkg = is_conflicted(tran,avail_pkgs,installed_pkgs,deps->pkgs[c]);
+ if ( conflicted_pkg != NULL ) {
+ add_remove_to_transaction(tran,conflicted_pkg);
+ }
+
+ dep_installed = get_newest_pkg(installed_pkgs,deps->pkgs[c]->name);
+ if( dep_installed == NULL ) {
+ add_install_to_transaction(tran,deps->pkgs[c]);
+ }else{
+ /* add only if its a valid upgrade */
+ if(cmp_pkg_versions(dep_installed->version,deps->pkgs[c]->version) < 0 )
+ add_upgrade_to_transaction(tran,dep_installed,deps->pkgs[c]);
+ }
+
+ }
+
+ free_pkg_list(deps);
+
+ return 0;
}
/* make sure pkg isn't conflicted with what's already in the transaction */
-pkg_info_t *is_conflicted(transaction_t *tran, struct pkg_list *avail_pkgs, struct pkg_list *installed_pkgs, pkg_info_t *pkg){
- unsigned int i;
- struct pkg_list *conflicts;
-
- /* if conflicts exist, check to see if they are installed or in the current transaction */
- conflicts = get_pkg_conflicts(avail_pkgs,installed_pkgs,pkg);
- for(i = 0; i < conflicts->pkg_count; i++){
- if(
- search_upgrade_transaction(tran,conflicts->pkgs[i]) == 1
- || get_newest_pkg(tran->install_pkgs,conflicts->pkgs[i]->name) != NULL
- ){
- pkg_info_t *c = conflicts->pkgs[i];
- printf(_("%s, which is to be installed, conflicts with %s\n"),
- conflicts->pkgs[i]->name,pkg->name
- );
- free_pkg_list(conflicts);
- return c;
- }
- if(get_newest_pkg(installed_pkgs,conflicts->pkgs[i]->name) != NULL) {
- pkg_info_t *c = conflicts->pkgs[i];
- printf(_("Installed %s conflicts with %s\n"),conflicts->pkgs[i]->name,pkg->name);
- free_pkg_list(conflicts);
- return c;
- }
- }
-
- free_pkg_list(conflicts);
-
- return NULL;
+pkg_info_t *is_conflicted(transaction_t *tran, struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs, pkg_info_t *pkg)
+{
+ unsigned int i;
+ struct pkg_list *conflicts;
+
+ /* if conflicts exist, check to see if they are installed
+ or in the current transaction
+ */
+ conflicts = get_pkg_conflicts(avail_pkgs,installed_pkgs,pkg);
+ for(i = 0; i < conflicts->pkg_count; i++) {
+ if(
+ search_upgrade_transaction(tran,conflicts->pkgs[i]) == 1
+ || get_newest_pkg(tran->install_pkgs,conflicts->pkgs[i]->name) != NULL
+ ) {
+ pkg_info_t *c = conflicts->pkgs[i];
+ printf(_("%s, which is to be installed, conflicts with %s\n"),
+ conflicts->pkgs[i]->name,pkg->name
+ );
+ free_pkg_list(conflicts);
+ return c;
+ }
+ if(get_newest_pkg(installed_pkgs,conflicts->pkgs[i]->name) != NULL) {
+ pkg_info_t *c = conflicts->pkgs[i];
+ printf(_("Installed %s conflicts with %s\n"),
+ conflicts->pkgs[i]->name,pkg->name);
+ free_pkg_list(conflicts);
+ return c;
+ }
+ }
+
+ free_pkg_list(conflicts);
+
+ return NULL;
}
-static void add_suggestion(transaction_t *tran, pkg_info_t *pkg){
- unsigned int position = 0,len = 0;
-
- if( pkg->suggests == NULL || (len = strlen(pkg->suggests)) == 0 ){
- return;
- }
-
- while( position < len ){
- int total_len = 0,rest_len = 0;
- char *p = NULL,*si = NULL,*tmp_suggests = NULL;
- char **tmp_realloc;
-
- p = pkg->suggests + position;
- if( p == NULL ) break;
-
- si = strpbrk(p," ,");
- if( si == NULL || strlen(si) <= 2 ){
- total_len = strlen(p);
- rest_len = 0;
- tmp_suggests = strndup(p,strlen(p));
- }else{
- si = si + 1;
-
- total_len = strlen(p);
- rest_len = strlen(si);
-
- /* this will always encompass ending space, so we dont + 1 */
- tmp_suggests = slapt_malloc(sizeof *tmp_suggests * (total_len - rest_len) );
- tmp_suggests = strncpy(tmp_suggests,p,(total_len - rest_len));
- tmp_suggests[total_len - rest_len - 1] = '\0';
- }
-
- /* no need to add it if we already have it */
- if( search_transaction(tran,tmp_suggests) == 1 ){
- free(tmp_suggests);
- position += (total_len - rest_len);
- continue;
- }
-
- tmp_realloc = realloc(tran->suggests->pkgs,sizeof *tran->suggests->pkgs * (tran->suggests->count + 1));
- if( tmp_realloc != NULL ){
- tran->suggests->pkgs = tmp_realloc;
- tran->suggests->pkgs[tran->suggests->count] = slapt_malloc(
- sizeof *tran->suggests->pkgs[tran->suggests->count]
- * (strlen(tmp_suggests) + 1)
- );
- tran->suggests->pkgs[tran->suggests->count] = strncpy(
- tran->suggests->pkgs[tran->suggests->count],
- tmp_suggests,strlen(tmp_suggests)
- );
- tran->suggests->pkgs[tran->suggests->count][strlen(tmp_suggests)] = '\0';
- ++tran->suggests->count;
- }
- free(tmp_suggests);
-
- position += (total_len - rest_len);
- }
+static void add_suggestion(transaction_t *tran, pkg_info_t *pkg)
+{
+ unsigned int position = 0,len = 0;
+
+ if( pkg->suggests == NULL || (len = strlen(pkg->suggests)) == 0 ) {
+ return;
+ }
+
+ while( position < len ) {
+ int total_len = 0,rest_len = 0;
+ char *p = NULL,*si = NULL,*tmp_suggests = NULL;
+ char **tmp_realloc;
+
+ p = pkg->suggests + position;
+ if( p == NULL ) break;
+
+ si = strpbrk(p," ,");
+ if( si == NULL || strlen(si) <= 2 ) {
+ total_len = strlen(p);
+ rest_len = 0;
+ tmp_suggests = strndup(p,strlen(p));
+ }else{
+ si = si + 1;
+
+ total_len = strlen(p);
+ rest_len = strlen(si);
+
+ /* this will always encompass ending space, so we dont + 1 */
+ tmp_suggests = slapt_malloc(sizeof *tmp_suggests * (total_len - rest_len) );
+ tmp_suggests = strncpy(tmp_suggests,p,(total_len - rest_len));
+ tmp_suggests[total_len - rest_len - 1] = '\0';
+ }
+
+ /* no need to add it if we already have it */
+ if( search_transaction(tran,tmp_suggests) == 1 ) {
+ free(tmp_suggests);
+ position += (total_len - rest_len);
+ continue;
+ }
+
+ tmp_realloc =
+ realloc(tran->suggests->pkgs,
+ sizeof *tran->suggests->pkgs * (tran->suggests->count + 1)
+ );
+
+ if( tmp_realloc != NULL ) {
+ tran->suggests->pkgs = tmp_realloc;
+ tran->suggests->pkgs[tran->suggests->count] = slapt_malloc(
+ sizeof *tran->suggests->pkgs[tran->suggests->count]
+ * (strlen(tmp_suggests) + 1)
+ );
+ tran->suggests->pkgs[tran->suggests->count] = strncpy(
+ tran->suggests->pkgs[tran->suggests->count],
+ tmp_suggests,strlen(tmp_suggests)
+ );
+ tran->suggests->pkgs[tran->suggests->count][strlen(tmp_suggests)] = '\0';
+ ++tran->suggests->count;
+ }
+ free(tmp_suggests);
+
+ position += (total_len - rest_len);
+ }
}
-static int disk_space(const rc_config *global_config,int space_needed ){
- struct statvfs statvfs_buf;
+static int disk_space(const rc_config *global_config,int space_needed )
+{
+ struct statvfs statvfs_buf;
- space_needed *= 1024;
+ space_needed *= 1024;
- if( space_needed < 0 ) return 0;
+ if( space_needed < 0 ) return 0;
- if( statvfs(global_config->working_dir,&statvfs_buf) != 0 ){
- if( errno ) perror("statvfs");
+ if( statvfs(global_config->working_dir,&statvfs_buf) != 0 ) {
+ if( errno ) perror("statvfs");
return 1;
- }else{
- if( statvfs_buf.f_bfree < ( space_needed / statvfs_buf.f_bsize) )
- return 1;
- }
+ }else{
+ if( statvfs_buf.f_bfree < ( space_needed / statvfs_buf.f_bsize) )
+ return 1;
+ }
- return 0;
+ return 0;
}
-int search_transaction_by_pkg(transaction_t *tran,pkg_info_t *pkg){
- unsigned int i,found = 1, not_found = 0;
-
- for(i = 0; i < tran->install_pkgs->pkg_count;i++){
- if(( strcmp(pkg->name,tran->install_pkgs->pkgs[i]->name)==0 )
- && (strcmp(pkg->version,tran->install_pkgs->pkgs[i]->version)==0))
- return found;
- }
- for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++){
- if(( strcmp(pkg->name,tran->upgrade_pkgs->pkgs[i]->upgrade->name)==0 )
- && (strcmp(pkg->version,tran->upgrade_pkgs->pkgs[i]->upgrade->version)==0 ))
- return found;
- }
- for(i = 0; i < tran->remove_pkgs->pkg_count;i++){
- if(( strcmp(pkg->name,tran->remove_pkgs->pkgs[i]->name)==0 )
- && (strcmp(pkg->version,tran->remove_pkgs->pkgs[i]->version)==0 ))
- return found;
- }
- for(i = 0; i < tran->exclude_pkgs->pkg_count;i++){
- if(( strcmp(pkg->name,tran->exclude_pkgs->pkgs[i]->name)==0 )
- && (strcmp(pkg->version,tran->exclude_pkgs->pkgs[i]->version)==0 ))
- return found;
- }
- return not_found;
+int search_transaction_by_pkg(transaction_t *tran,pkg_info_t *pkg)
+{
+ unsigned int i,found = 1, not_found = 0;
+
+ for(i = 0; i < tran->install_pkgs->pkg_count;i++) {
+ if(( strcmp(pkg->name,tran->install_pkgs->pkgs[i]->name)==0 )
+ && (strcmp(pkg->version,tran->install_pkgs->pkgs[i]->version)==0))
+ return found;
+ }
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++) {
+ if(( strcmp(pkg->name,tran->upgrade_pkgs->pkgs[i]->upgrade->name)==0 )
+ && (strcmp(pkg->version,tran->upgrade_pkgs->pkgs[i]->upgrade->version)==0 ))
+ return found;
+ }
+ for(i = 0; i < tran->remove_pkgs->pkg_count;i++) {
+ if(( strcmp(pkg->name,tran->remove_pkgs->pkgs[i]->name)==0 )
+ && (strcmp(pkg->version,tran->remove_pkgs->pkgs[i]->version)==0 ))
+ return found;
+ }
+ for(i = 0; i < tran->exclude_pkgs->pkg_count;i++) {
+ if(( strcmp(pkg->name,tran->exclude_pkgs->pkgs[i]->name)==0 )
+ && (strcmp(pkg->version,tran->exclude_pkgs->pkgs[i]->version)==0 ))
+ return found;
+ }
+ return not_found;
}
-static queue_t *queue_init(void){
- queue_t *t = NULL;
- t = slapt_malloc(sizeof *t);
- t->pkgs = slapt_malloc(sizeof *t->pkgs);
- t->count = 0;
+static queue_t *queue_init(void)
+{
+ queue_t *t = NULL;
+ t = slapt_malloc(sizeof *t);
+ t->pkgs = slapt_malloc(sizeof *t->pkgs);
+ t->count = 0;
- return t;
+ return t;
}
-static void queue_add_install(queue_t *t, pkg_info_t *p){
- 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_install(queue_t *t, pkg_info_t *p)
+{
+ 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(queue_t *t, pkg_upgrade_t *p){
- 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_add_upgrade(queue_t *t, pkg_upgrade_t *p)
+{
+ 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(queue_t *t){
- unsigned int i;
- for(i = 0; i < t->count; ++i){
- free(t->pkgs[i]);
- }
- free(t->pkgs);
- free(t);
+static void queue_free(queue_t *t)
+{
+ unsigned int i;
+ for(i = 0; i < t->count; ++i) {
+ free(t->pkgs[i]);
+ }
+ free(t->pkgs);
+ free(t);
}
-void generate_suggestions(transaction_t *tran){
- unsigned int i;
- for(i = 0;i < tran->install_pkgs->pkg_count; ++i){
- add_suggestion(tran,tran->install_pkgs->pkgs[i]);
- }
+void generate_suggestions(transaction_t *tran)
+{
+ unsigned int i;
+ for(i = 0;i < tran->install_pkgs->pkg_count; ++i) {
+ add_suggestion(tran,tran->install_pkgs->pkgs[i]);
+ }
}
diff --git a/src/transaction.h b/src/transaction.h
index 064116a..b34bb4e 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -52,9 +52,12 @@ int search_transaction(transaction_t *,char *pkg_name);
int search_transaction_by_pkg(transaction_t *tran,pkg_info_t *pkg);
void free_transaction(transaction_t *);
transaction_t *remove_from_transaction(transaction_t *tran,pkg_info_t *pkg);
-int add_deps_to_trans(const rc_config *global_config, transaction_t *tran, struct pkg_list *avail_pkgs, struct pkg_list *installed_pkgs, pkg_info_t *pkg);
+int add_deps_to_trans(const rc_config *global_config, transaction_t *tran,
+ struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs, pkg_info_t *pkg);
/* check to see if a package is conflicted */
-pkg_info_t *is_conflicted(transaction_t *tran, struct pkg_list *avail_pkgs, struct pkg_list *installed_pkgs, pkg_info_t *pkg);
+pkg_info_t *is_conflicted(transaction_t *tran, struct pkg_list *avail_pkgs,
+ struct pkg_list *installed_pkgs, pkg_info_t *pkg);
void generate_suggestions(transaction_t *tran);