aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2003-10-13 03:00:33 +0000
committerJason Woodward2003-10-13 03:00:33 +0000
commite619ca39f550900b2adcec99ba4bc76591d2f07c (patch)
treede6dc8373b3d472758406bf8b51d1a71ac99954f
parent824c2a8b8d2ec4810ab398a99b83eec084e33c5d (diff)
downloadslapt-get-e619ca39f550900b2adcec99ba4bc76591d2f07c.tar.gz
implemented transaction engine, --interactive option to emulate old upgrade procedure
-rw-r--r--ChangeLog3
-rw-r--r--Makefile4
-rw-r--r--doc/slapt-get.86
-rw-r--r--src/action.c32
-rw-r--r--src/action.h8
-rw-r--r--src/configuration.c1
-rw-r--r--src/configuration.h1
-rw-r--r--src/main.c7
-rw-r--r--src/main.h1
-rw-r--r--src/package.c15
-rw-r--r--src/package.h11
-rw-r--r--src/transaction.c200
-rw-r--r--src/transaction.h35
13 files changed, 300 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index 7e5cb6f..7e1ca58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,9 @@
* created struct pkg_list *get_available_and_update_pkgs(void) to search for
updates and newer available at once, simplified --install and --upgrade
part of roadmap to package action transactions.
+ * implemented transaction engine
+ * --interactive option to emulate old upgrade procedure, prompting for each
+ upgrade.
0.9.5e Oct 10, 2003
* added a doinst.sh script (generated from the Makefile) to help
diff --git a/Makefile b/Makefile
index 920a1c6..8c411d1 100644
--- a/Makefile
+++ b/Makefile
@@ -4,12 +4,12 @@ ARCH=i386
RELEASE=1
CC=gcc
CURLFLAGS=`curl-config --libs`
-OBJS=src/configuration.o src/package.o src/curl.o src/action.o src/main.o
+OBJS=src/configuration.o src/package.o src/curl.o src/transaction.o src/action.o src/main.o
RCDEST=/etc/slapt-getrc
RCSOURCE=example.slapt-getrc
SBINDIR=/sbin/
DEFINES=-DPROGRAM_NAME="\"$(PROGRAM_NAME)\"" -DVERSION="\"$(VERSION)\"" -DRC_LOCATION="\"$(RCDEST)\""
-CFLAGS=-W -Werror -Wall -O2 -ansi -pedantic -Iinclude $(DEFINES)
+CFLAGS=-W -Werror -Wall -g -ansi -pedantic -Iinclude $(DEFINES)
default: $(PROGRAM_NAME)
diff --git a/doc/slapt-get.8 b/doc/slapt-get.8
index 805f84a..35f37e7 100644
--- a/doc/slapt-get.8
+++ b/doc/slapt-get.8
@@ -38,6 +38,9 @@ slapt-get \- frontend to pkgtools
[
.B --no-md5
]
+[
+.B --interactive
+]
.LP
.B targets:
[
@@ -98,6 +101,9 @@ Ignore exclude list and install excluded packages anyway.
.TP
.B --no-md5
Do not perform MD5 check sum on package. This is dangerous!
+.TP
+.B --interactive
+Prompt before each package upgrade.
.SH TARGETS
.TP
.B --update
diff --git a/src/action.c b/src/action.c
index e95ff41..5e30a6a 100644
--- a/src/action.c
+++ b/src/action.c
@@ -27,12 +27,17 @@ void pkg_action_clean(const rc_config *global_config){
void pkg_action_install(const rc_config *global_config,const char *pkg_name){
pkg_info_t *installed_pkg;
pkg_info_t *pkg;
+ transaction tran;
struct pkg_list *installed;
struct pkg_list *all;
+ printf("Reading Package Lists... ");
installed = get_installed_pkgs();
all = get_available_and_update_pkgs();
+ printf("Done\n");
+
+ init_transaction(&tran);
/* make sure there is a package called pkg_name */
if( (pkg = get_newest_pkg(all->pkgs,pkg_name,all->pkg_count)) == NULL ){
@@ -44,7 +49,7 @@ void pkg_action_install(const rc_config *global_config,const char *pkg_name){
if((installed_pkg = get_newest_pkg(installed->pkgs,pkg_name,installed->pkg_count)) == NULL){
/* this way we install the most up to date pkg */
- install_pkg(global_config,pkg);
+ add_install_to_transaction(&tran,pkg);
}else{ /* else we upgrade or reinstall */
@@ -53,15 +58,18 @@ void pkg_action_install(const rc_config *global_config,const char *pkg_name){
((cmp_pkg_versions(installed_pkg->version,pkg->version)) < 0)
|| (global_config->re_install == 1)
){
- upgrade_pkg(global_config,installed_pkg,pkg);
+ add_upgrade_to_transaction(&tran,installed_pkg,pkg);
}else{
printf("%s is up to date.\n",installed_pkg->name);
}
}
+ handle_transaction(global_config,&tran);
+
free_pkg_list(installed);
free_pkg_list(all);
+ free_transaction(&tran);
return;
}
@@ -100,19 +108,24 @@ void pkg_action_list_installed(void){
}
/* remove/uninstall pkg */
-void pkg_action_remove(const char *pkg_name){
+void pkg_action_remove(const rc_config *global_config,const char *pkg_name){
pkg_info_t *pkg;
struct pkg_list *installed;
+ transaction tran;
installed = get_installed_pkgs();
+ init_transaction(&tran);
if( (pkg = get_newest_pkg(installed->pkgs,pkg_name,installed->pkg_count)) != NULL ){
- remove_pkg(pkg);
+ add_remove_to_transaction(&tran,pkg);
}else{
printf("%s is not installed.\n",pkg_name);
}
+ handle_transaction(global_config,&tran);
+
free_pkg_list(installed);
+ free_transaction(&tran);
}
/* search for a pkg (support extended POSIX regex) */
@@ -214,19 +227,18 @@ void pkg_action_update(const rc_config *global_config){
}
/* upgrade all installed pkgs with available updates */
-/* use pkg_action_upgrade() soon, pass in pkg_list(s) */
void pkg_action_upgrade_all(const rc_config *global_config){
int iterator;
struct pkg_list *installed_pkgs;
struct pkg_list *all_pkgs;
pkg_info_t *update_pkg;
+ transaction tran;
- /* faster here to retrieve the listings once */
- /* then use get_newest_pkg() to pull newest from each list */
printf("Reading Package Lists... ");
installed_pkgs = get_installed_pkgs();
all_pkgs = get_available_and_update_pkgs();
printf("Done\n");
+ init_transaction(&tran);
for(iterator = 0; iterator < installed_pkgs->pkg_count;iterator++){
@@ -242,7 +254,7 @@ void pkg_action_upgrade_all(const rc_config *global_config){
if( (cmp_pkg_versions(installed_pkgs->pkgs[iterator]->version,update_pkg->version)) < 0 ){
/* attempt to upgrade */
- upgrade_pkg(global_config,installed_pkgs->pkgs[iterator],update_pkg);
+ add_upgrade_to_transaction(&tran,installed_pkgs->pkgs[iterator],update_pkg);
} /* end version check */
@@ -250,10 +262,10 @@ void pkg_action_upgrade_all(const rc_config *global_config){
}/* end for */
-
- printf("Done.\n");
+ handle_transaction(global_config,&tran);
free_pkg_list(installed_pkgs);
free_pkg_list(all_pkgs);
+ free_transaction(&tran);
}
diff --git a/src/action.h b/src/action.h
index 7e98d48..705dae4 100644
--- a/src/action.h
+++ b/src/action.h
@@ -17,12 +17,6 @@
*/
/* variable defs */
-struct _transaction {
- pkg_info_t **install; int install_count;
- pkg_info_t **upgrade; int upgrade_count;
- pkg_info_t **remove; int remove_count;
-};
-typedef struct _transaction transaction;
/* */
/* FUNCTION DEFINITIONS */
@@ -30,7 +24,7 @@ void pkg_action_clean(const rc_config *);
void pkg_action_install(const rc_config *,const char *);
void pkg_action_list(void);
void pkg_action_list_installed(void);
-void pkg_action_remove(const char *);
+void pkg_action_remove(const rc_config *,const char *);
void pkg_action_search(const char *);
void pkg_action_show(const char *);
void pkg_action_upgrade_all(const rc_config *);
diff --git a/src/configuration.c b/src/configuration.c
index 6dbee5f..71ee48d 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -93,6 +93,7 @@ rc_config *read_rc_config(const char *file_name){
global_config->simulate = 0;
global_config->ignore_excludes = 0;
global_config->no_md5_check = 0;
+ global_config->interactive = 0;
return global_config;
}
diff --git a/src/configuration.h b/src/configuration.h
index e0c4c1d..1cc22f7 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -36,6 +36,7 @@ struct _configuration {
struct exclude_list *exclude_list;
int ignore_excludes;
int no_md5_check;
+ int interactive;
};
typedef struct _configuration rc_config;
diff --git a/src/main.c b/src/main.c
index 6dfbcb2..0b6db2e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,6 +42,7 @@ int main( int argc, char *argv[] ){
{"reinstall", 0, 0, 'n'},
{"ignore-excludes", 0, 0, 'x'},
{"no-md5", 0, 0, '5'},
+ {"interactive", 0, 0, 'f'},
};
int option_index = 0;
/* */
@@ -106,6 +107,9 @@ int main( int argc, char *argv[] ){
case '5': /* no-md5 */
global_config->no_md5_check = 1;
break;
+ case 'f': /* interactive */
+ global_config->interactive = 1;
+ break;
default:
usage();
break;
@@ -125,7 +129,7 @@ int main( int argc, char *argv[] ){
}else if( do_action == REMOVE ){
if (optind < argc) {
while (optind < argc){
- pkg_action_remove( argv[optind++] );
+ pkg_action_remove( global_config, argv[optind++] );
}
}else{
usage();
@@ -193,6 +197,7 @@ void usage(){
printf(" --reinstall - re-install the pkg even if installed\n");
printf(" --ignore-excludes - install excludes anyway\n");
printf(" --no-md5 - do not perform md5 check sum\n");
+ printf(" --interactive - prompt before each pkg upgrade\n");
}
void version_info(void){
diff --git a/src/main.h b/src/main.h
index 18a763c..590ef02 100644
--- a/src/main.h
+++ b/src/main.h
@@ -39,6 +39,7 @@
#include "configuration.h"
#include "package.h"
#include "curl.h"
+#include "transaction.h"
#include "action.h"
/* */
diff --git a/src/package.c b/src/package.c
index 710471b..664e42c 100644
--- a/src/package.c
+++ b/src/package.c
@@ -557,7 +557,11 @@ int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,pkg_inf
return 0;
}
- if( global_config->no_prompt == 0 && global_config->download_only == 0 ){
+ /*
+ only give double check notice if in interactive,
+ w/o no_prompt and download_only
+ */
+ if( global_config->no_prompt == 0 && global_config->download_only == 0 && global_config->interactive == 1 ){
printf("Replace %s-%s with %s-%s? [y|n] ",pkg->name,installed_pkg->version,pkg->name,pkg->version);
fgets(prompt_answer,10,stdin);
if( tolower(prompt_answer[0]) != 'y' ){
@@ -596,10 +600,15 @@ int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,pkg_inf
return cmd_return;
}
-int remove_pkg(pkg_info_t *pkg){
+int remove_pkg(const rc_config *global_config,pkg_info_t *pkg){
char *command = NULL;
int cmd_return;
+ if( global_config->simulate == 1 ){
+ printf("%s-%s is to be removed\n",pkg->name,pkg->version);
+ return 0;
+ }
+
/* build and execute our command */
command = calloc( strlen(REMOVE_CMD) + strlen(pkg->name) + 1 , sizeof *command );
command[0] = '\0';
@@ -749,7 +758,7 @@ int cmp_pkg_versions(char *a, char *b){
}
int break_down_pkg_version(int *v,char *version){
- int pos = 0,count = 0,sv_size;
+ int pos = 0,count = 0,sv_size = 0;
char *pointer,*tmp,*short_version;
diff --git a/src/package.h b/src/package.h
index 5d225f3..ba5fe6a 100644
--- a/src/package.h
+++ b/src/package.h
@@ -42,6 +42,15 @@ struct pkg_list {
pkg_info_t **pkgs;
int pkg_count;
};
+struct _pkg_upgrade {
+ pkg_info_t *installed;
+ pkg_info_t *upgrade;
+};
+typedef struct _pkg_upgrade pkg_upgrade_t;
+struct pkg_upgrade_list {
+ pkg_upgrade_t **pkgs;
+ int pkg_count;
+};
/*
* FUNCTION DEFINITIONS
@@ -61,7 +70,7 @@ int install_pkg(const rc_config *,pkg_info_t *);
/* upgrade pkg */
int upgrade_pkg(const rc_config *,pkg_info_t *,pkg_info_t *);
/* remove pkg */
-int remove_pkg(pkg_info_t *);
+int remove_pkg(const rc_config *,pkg_info_t *);
/* free memory allocated for pkg_list struct */
void free_pkg_list(struct pkg_list *);
/* exclude pkg based on pkg name */
diff --git a/src/transaction.c b/src/transaction.c
new file mode 100644
index 0000000..c70d687
--- /dev/null
+++ b/src/transaction.c
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2003 Jason Woodward <woodwardj at jaos dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <main.h>
+
+void init_transaction(transaction *tran){
+
+ tran->install_pkgs = malloc( sizeof *tran->install_pkgs );
+ tran->remove_pkgs = malloc( sizeof *tran->remove_pkgs );
+ tran->upgrade_pkgs = malloc( sizeof *tran->upgrade_pkgs );
+
+ tran->install_pkgs->pkgs = malloc( sizeof *tran->install_pkgs->pkgs );
+ tran->remove_pkgs->pkgs = malloc( sizeof *tran->remove_pkgs->pkgs );
+ tran->upgrade_pkgs->pkgs = malloc( sizeof *tran->upgrade_pkgs->pkgs );
+
+ tran->install_pkgs->pkg_count = 0;
+ tran->remove_pkgs->pkg_count = 0;
+ tran->upgrade_pkgs->pkg_count = 0;
+}
+
+int handle_transaction(const rc_config *global_config, transaction *tran){
+ int i;
+ char prompt_answer[10];
+
+ /*
+ if we have an update, or a removal...
+ and download_only, simulate, and no_prompt are not set
+ */
+ if(
+ (tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0)
+ && (global_config->download_only == 0 && global_config->simulate == 0
+ && global_config->no_prompt == 0 )
+ ){
+
+ /* show pkgs to install */
+ if( tran->install_pkgs->pkg_count > 0 ){
+ printf("The following NEW packages will be installed:\n");
+ printf(" ");
+ for(i = 0; i < tran->install_pkgs->pkg_count;i++){
+ printf("%s ",tran->install_pkgs->pkgs[i]->name);
+ }
+ printf("\n");
+ }
+
+ /* show pkgs to remove */
+ if( tran->remove_pkgs->pkg_count > 0 ){
+ printf("The following packages will be REMOVED:\n");
+ printf(" ");
+ for(i = 0; i < tran->remove_pkgs->pkg_count;i++){
+ printf("%s ",tran->remove_pkgs->pkgs[i]->name);
+ }
+ printf("\n");
+ }
+
+ /* show pkgs to upgrade */
+ if( tran->upgrade_pkgs->pkg_count > 0 ){
+ printf("The following packages will be upgraded:\n");
+ printf(" ");
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++){
+ printf("%s ",tran->upgrade_pkgs->pkgs[i]->installed->name);
+ }
+ printf("\n");
+ }
+
+ /* print the summary */
+ printf(
+ "%d upgraded, %d newly installed, and %d to remove.\n",
+ tran->upgrade_pkgs->pkg_count,
+ tran->install_pkgs->pkg_count,
+ tran->remove_pkgs->pkg_count
+ );
+
+ /* prompt */
+ printf("Do you want to continue? [Y/n] ");
+ fgets(prompt_answer,10,stdin);
+ if( tolower(prompt_answer[0]) == 'n' ){
+ printf("Abort.\n");
+ return 1;
+ }
+ }
+
+ for(i = 0; i < tran->install_pkgs->pkg_count;i++){
+ install_pkg(global_config,tran->install_pkgs->pkgs[i]);
+ }
+ for(i = 0; i < tran->remove_pkgs->pkg_count;i++){
+ remove_pkg(global_config,tran->remove_pkgs->pkgs[i]);
+ }
+ for(i = 0; i < tran->upgrade_pkgs->pkg_count;i++){
+ upgrade_pkg(
+ global_config,
+ tran->upgrade_pkgs->pkgs[i]->installed,
+ tran->upgrade_pkgs->pkgs[i]->upgrade
+ );
+ }
+
+ printf("Done.\n");
+
+ return 0;
+}
+
+void add_install_to_transaction(transaction *tran,pkg_info_t *pkg){
+ pkg_info_t **tmp_list;
+
+ 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] = pkg;
+ ++tran->install_pkgs->pkg_count;
+ }
+
+}
+
+void add_remove_to_transaction(transaction *tran,pkg_info_t *pkg){
+ pkg_info_t **tmp_list;
+
+ 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] = pkg;
+ ++tran->remove_pkgs->pkg_count;
+ }
+
+}
+
+void add_upgrade_to_transaction(
+ transaction *tran, pkg_info_t *installed_pkg, pkg_info_t *upgrade_pkg
+){
+ pkg_upgrade_t **tmp_list;
+
+ /*
+ struct _pkg_upgrade {
+ pkg_info_t *installed;
+ pkg_info_t *upgrade;
+ };
+ typedef struct _pkg_upgrade pkg_upgrade_t;
+ struct pkg_upgrade_list {
+ pkg_upgrade_t **pkgs;
+ int pkg_count;
+ };
+ */
+
+ 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] = malloc(
+ sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]
+ );
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = malloc(
+ sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed
+ );
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = malloc(
+ sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade
+ );
+
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = installed_pkg;
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = upgrade_pkg;
+ ++tran->upgrade_pkgs->pkg_count;
+ }
+
+}
+
+void free_transaction(transaction *tran){
+
+ free(tran->install_pkgs->pkgs);
+ free(tran->remove_pkgs->pkgs);
+ free(tran->upgrade_pkgs->pkgs);
+
+ free(tran->install_pkgs);
+ free(tran->remove_pkgs);
+ free(tran->upgrade_pkgs);
+
+}
+
diff --git a/src/transaction.h b/src/transaction.h
new file mode 100644
index 0000000..502edef
--- /dev/null
+++ b/src/transaction.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2003 Jason Woodward <woodwardj at jaos dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* variable defs */
+struct _transaction {
+ struct pkg_list *install_pkgs;
+ struct pkg_upgrade_list *upgrade_pkgs;
+ struct pkg_list *remove_pkgs;
+};
+typedef struct _transaction transaction;
+/* */
+
+/* FUNCTION DEFINITIONS */
+void init_transaction(transaction *);
+int handle_transaction(const rc_config *,transaction *);
+void add_install_to_transaction(transaction *,pkg_info_t *);
+void add_remove_to_transaction(transaction *,pkg_info_t *);
+void add_upgrade_to_transaction(transaction *,pkg_info_t *,pkg_info_t *);
+void free_transaction(transaction *);
+