aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2003-10-14 02:25:16 +0000
committerJason Woodward2003-10-14 02:25:16 +0000
commit22e8c4ca55c88c5b852e29b8cd95bdc49eaf13ac (patch)
treebd2d653adf058de8767b1a35ac175e477e78513f
parent86f32a36aeacba29c60c95b982cfefca8777d05d (diff)
downloadslapt-get-22e8c4ca55c88c5b852e29b8cd95bdc49eaf13ac.tar.gz
pkg_action_install() and pkg_action_remove() now take structure of packages for transaction
-rw-r--r--ChangeLog2
-rw-r--r--src/action.c62
-rw-r--r--src/action.h9
-rw-r--r--src/main.c39
-rw-r--r--src/transaction.c10
5 files changed, 89 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index 06703bb..8da87b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,8 @@
* added excludes to transaction, now shows packages excluded/held back
* removed more legacy functions since merging package data and updates...
the new get_available_and_update_pkgs is now gone.
+ * pkg_action_install() and pkg_action_remove() now take structure of
+ packages for transaction
0.9.5e Oct 10, 2003
* added a doinst.sh script (generated from the Makefile) to help
diff --git a/src/action.c b/src/action.c
index 54641f7..ee3c7d6 100644
--- a/src/action.c
+++ b/src/action.c
@@ -24,7 +24,8 @@ void pkg_action_clean(const rc_config *global_config){
}
/* install pkg */
-void pkg_action_install(const rc_config *global_config,const char *pkg_name){
+void pkg_action_install(const rc_config *global_config,const pkg_action_args_t *action_args){
+ int i;
pkg_info_t *installed_pkg;
pkg_info_t *pkg;
transaction tran;
@@ -39,28 +40,36 @@ void pkg_action_install(const rc_config *global_config,const char *pkg_name){
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 ){
- fprintf(stderr,"No Such package: %s\n",pkg_name);
- return;
- }
-
- /* if it's not already installed, install it */
- if((installed_pkg = get_newest_pkg(installed->pkgs,pkg_name,installed->pkg_count)) == NULL){
-
- /* this way we install the most up to date pkg */
- add_install_to_transaction(&tran,pkg);
+ for(i = 0; i < action_args->count; i++){
- }else{ /* else we upgrade or reinstall */
+ /* make sure there is a package called action_args->pkgs[i] */
+ if( (pkg = get_newest_pkg(all->pkgs,action_args->pkgs[i],all->pkg_count)) == NULL ){
+ fprintf(stderr,"No Such package: %s\n",action_args->pkgs[i]);
+ continue;
+ }
- /* it's already installed, attempt an upgrade */
+ /* if it's not already installed, install it */
if(
- ((cmp_pkg_versions(installed_pkg->version,pkg->version)) < 0)
- || (global_config->re_install == 1)
+ (installed_pkg
+ = get_newest_pkg(installed->pkgs,action_args->pkgs[i],installed->pkg_count)
+ ) == NULL
){
- add_upgrade_to_transaction(&tran,installed_pkg,pkg);
- }else{
- printf("%s is up to date.\n",installed_pkg->name);
+
+ /* this way we install the most up to date pkg */
+ add_install_to_transaction(&tran,pkg);
+
+ }else{ /* else we upgrade or reinstall */
+
+ /* it's already installed, attempt an upgrade */
+ if(
+ ((cmp_pkg_versions(installed_pkg->version,pkg->version)) < 0)
+ || (global_config->re_install == 1)
+ ){
+ add_upgrade_to_transaction(&tran,installed_pkg,pkg);
+ }else{
+ printf("%s is up to date.\n",installed_pkg->name);
+ }
+
}
}
@@ -111,7 +120,8 @@ void pkg_action_list_installed(void){
}
/* remove/uninstall pkg */
-void pkg_action_remove(const rc_config *global_config,const char *pkg_name){
+void pkg_action_remove(const rc_config *global_config,const pkg_action_args_t *action_args){
+ int i;
pkg_info_t *pkg;
struct pkg_list *installed;
transaction tran;
@@ -119,10 +129,14 @@ void pkg_action_remove(const rc_config *global_config,const char *pkg_name){
installed = get_installed_pkgs();
init_transaction(&tran);
- if( (pkg = get_newest_pkg(installed->pkgs,pkg_name,installed->pkg_count)) != NULL ){
- add_remove_to_transaction(&tran,pkg);
- }else{
- printf("%s is not installed.\n",pkg_name);
+ for(i = 0; i < action_args->count; i++){
+ if(
+ (pkg = get_newest_pkg(installed->pkgs,action_args->pkgs[i],installed->pkg_count)) != NULL
+ ){
+ add_remove_to_transaction(&tran,pkg);
+ }else{
+ printf("%s is not installed.\n",action_args->pkgs[i]);
+ }
}
handle_transaction(global_config,&tran);
diff --git a/src/action.h b/src/action.h
index 705dae4..1f1d4a6 100644
--- a/src/action.h
+++ b/src/action.h
@@ -17,14 +17,19 @@
*/
/* variable defs */
+struct _pkg_action_args {
+ char **pkgs;
+ int count;
+};
+typedef struct _pkg_action_args pkg_action_args_t;
/* */
/* FUNCTION DEFINITIONS */
void pkg_action_clean(const rc_config *);
-void pkg_action_install(const rc_config *,const char *);
+void pkg_action_install(const rc_config *,const pkg_action_args_t *);
void pkg_action_list(void);
void pkg_action_list_installed(void);
-void pkg_action_remove(const rc_config *,const char *);
+void pkg_action_remove(const rc_config *,const pkg_action_args_t *);
void pkg_action_search(const char *);
void pkg_action_show(const char *);
void pkg_action_upgrade_all(const rc_config *);
diff --git a/src/main.c b/src/main.c
index 0b6db2e..5ae4567 100644
--- a/src/main.c
+++ b/src/main.c
@@ -120,17 +120,52 @@ int main( int argc, char *argv[] ){
pkg_action_update(global_config);
}else if( do_action == INSTALL ){
if (optind < argc) {
+ int i;
+ pkg_action_args_t *paa;
+
+ paa = malloc( sizeof *paa );
+ paa->pkgs = malloc( sizeof *paa->pkgs * (argc - optind) );
+ paa->count = 0;
while (optind < argc){
- pkg_action_install( global_config, argv[optind++] );
+ paa->pkgs[paa->count] = malloc(
+ sizeof *paa->pkgs[paa->count] * ( strlen(argv[optind]) + 1 )
+ );
+ memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]));
+ ++optind;
+ ++paa->count;
+ }
+ pkg_action_install( global_config, paa );
+ for(i = 0; i < paa->count; i++){
+ free(paa->pkgs[i]);
}
+ free(paa->pkgs);
+ free(paa);
}else{
usage();
}
}else if( do_action == REMOVE ){
if (optind < argc) {
+ int i;
+ pkg_action_args_t *paa;
+
+ paa = malloc( sizeof *paa );
+ paa->pkgs = malloc( sizeof *paa->pkgs * (argc - optind) );
+ paa->count = 0;
while (optind < argc){
- pkg_action_remove( global_config, argv[optind++] );
+ paa->pkgs[paa->count] = malloc(
+ sizeof *paa->pkgs[paa->count] * ( strlen(argv[optind]) + 1 )
+ );
+ memcpy(paa->pkgs[paa->count],argv[optind],strlen(argv[optind]));
+ ++optind;
+ ++paa->count;
+ }
+ /* pkg_action_remove( global_config, argv[optind++] ); */
+ pkg_action_remove( global_config, paa );
+ for(i = 0; i < paa->count; i++){
+ free(paa->pkgs[i]);
}
+ free(paa->pkgs);
+ free(paa);
}else{
usage();
}
diff --git a/src/transaction.c b/src/transaction.c
index 30ce07f..c082975 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -44,10 +44,7 @@ int handle_transaction(const rc_config *global_config, transaction *tran){
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)
- ){
+ if( global_config->download_only == 0 && global_config->simulate == 0 ){
/* show pkgs to exclude */
if( tran->exclude_pkgs->pkg_count > 0 ){
@@ -99,7 +96,10 @@ int handle_transaction(const rc_config *global_config, transaction *tran){
);
/* prompt */
- if( global_config->no_prompt == 0 && global_config->interactive == 0 ) {
+ if(
+ (tran->upgrade_pkgs->pkg_count > 0 || tran->remove_pkgs->pkg_count > 0)
+ && (global_config->no_prompt == 0 && global_config->interactive == 0)
+ ) {
printf("Do you want to continue? [y/N] ");
fgets(prompt_answer,10,stdin);
if( tolower(prompt_answer[0]) != 'y' ){