aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2003-10-12 08:50:46 +0000
committerJason Woodward2003-10-12 08:50:46 +0000
commit9b09b9f67458baf59b7aa5e2c83e99b5440624cd (patch)
treed89e52cceae0084918e81e2bfb73e69a5c125c13
parent652b3278d095e46bb41c62ef5bd56c136eaeee9b (diff)
downloadslapt-get-9b09b9f67458baf59b7aa5e2c83e99b5440624cd.tar.gz
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.
-rw-r--r--ChangeLog3
-rw-r--r--src/action.c103
-rw-r--r--src/action.h11
-rw-r--r--src/package.c37
-rw-r--r--src/package.h2
5 files changed, 74 insertions, 82 deletions
diff --git a/ChangeLog b/ChangeLog
index 2bc51eb..7e5cb6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@
* Prompt to upgrade before downloading (thanks kyotou)
* updated FAQ with dropline question, and upgrade single package question
* options can now be passed in in any order, so --no-prompt at the end now works
+ * 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.
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 691acda..e95ff41 100644
--- a/src/action.c
+++ b/src/action.c
@@ -26,44 +26,42 @@ void pkg_action_clean(const rc_config *global_config){
/* install pkg */
void pkg_action_install(const rc_config *global_config,const char *pkg_name){
pkg_info_t *installed_pkg;
- pkg_info_t *update_pkg;
pkg_info_t *pkg;
struct pkg_list *installed;
- struct pkg_list *updates;
- struct pkg_list *available;
+ struct pkg_list *all;
- updates = get_update_pkgs();
installed = get_installed_pkgs();
- available = get_available_pkgs();
+ all = get_available_and_update_pkgs();
- if( (pkg = get_newest_pkg(available->pkgs,pkg_name,available->pkg_count)) == NULL ){
+ /* 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( ((installed_pkg = get_newest_pkg(installed->pkgs,pkg_name,installed->pkg_count)) != NULL)
- && (global_config->re_install != 1 ) ){
+ /* if it's not already installed, install it */
+ if((installed_pkg = get_newest_pkg(installed->pkgs,pkg_name,installed->pkg_count)) == NULL){
- /* it's already installed, attempt an upgrade */
- pkg_action_upgrade(global_config,installed_pkg,updates,pkg);
+ /* this way we install the most up to date pkg */
+ install_pkg(global_config,pkg);
- }else{
+ }else{ /* else we upgrade or reinstall */
- /* check to see if the package exists in the update list */
- /* this way we install the most up to date pkg */
- if( (update_pkg = get_newest_pkg(updates->pkgs,pkg_name,updates->pkg_count)) != NULL ){
- install_pkg(global_config,update_pkg);
+ /* it's already installed, attempt an upgrade */
+ if(
+ ((cmp_pkg_versions(installed_pkg->version,pkg->version)) < 0)
+ || (global_config->re_install == 1)
+ ){
+ upgrade_pkg(global_config,installed_pkg,pkg);
}else{
- /* install from list */
- install_pkg(global_config,pkg);
+ printf("%s is up to date.\n",installed_pkg->name);
}
}
free_pkg_list(installed);
- free_pkg_list(updates);
- free_pkg_list(available);
+ free_pkg_list(all);
return;
}
@@ -215,65 +213,28 @@ void pkg_action_update(const rc_config *global_config){
return;
}
-/* upgrade pkg */
-/* flesh me out so that pkg_action_upgrade_all() calls me */
-void pkg_action_upgrade(const rc_config *global_config,pkg_info_t *installed_pkg,struct pkg_list *update_pkgs,pkg_info_t *available_pkg){
- pkg_info_t *update_pkg;
- int cmp_result;
-
- /* if we found an update, make sure it's version is greater */
- if(
- (update_pkg = get_newest_pkg(update_pkgs->pkgs,installed_pkg->name,update_pkgs->pkg_count)) != NULL
- && cmp_pkg_versions(available_pkg->version,update_pkg->version) < 0
- ){
-
- cmp_result = cmp_pkg_versions(installed_pkg->version,update_pkg->version);
-
- if( cmp_result < 0 ){ /* update_pkg is newer than installed_pkg */
- upgrade_pkg(global_config,installed_pkg,update_pkg);
- }else{
- if( cmp_result > 0 ){
- printf("Newer version of %s already installed.\n",installed_pkg->name);
- }else if( cmp_result == 0 ){
- printf("%s is up to date.\n",installed_pkg->name);
- }
- }
- }else{
- if( cmp_pkg_versions(installed_pkg->version,available_pkg->version) < 0 ){
- upgrade_pkg(global_config,installed_pkg,available_pkg);
- }else{
- printf("%s is already the newest version.\n",installed_pkg->name);
- }
- }
-
-}
-
/* 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;
- int try_dist_upgrade = 0;
struct pkg_list *installed_pkgs;
- struct pkg_list *update_pkgs;
- struct pkg_list *current_pkgs;
+ struct pkg_list *all_pkgs;
pkg_info_t *update_pkg;
- pkg_info_t *current_pkg;
/* 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();
- update_pkgs = get_update_pkgs();
- current_pkgs = get_available_pkgs();
+ all_pkgs = get_available_and_update_pkgs();
printf("Done\n");
for(iterator = 0; iterator < installed_pkgs->pkg_count;iterator++){
/* see if we have an available update for the pkg */
update_pkg = get_newest_pkg(
- update_pkgs->pkgs,
+ all_pkgs->pkgs,
installed_pkgs->pkgs[iterator]->name,
- update_pkgs->pkg_count
+ all_pkgs->pkg_count
);
if( update_pkg != NULL ){
@@ -283,36 +244,16 @@ void pkg_action_upgrade_all(const rc_config *global_config){
/* attempt to upgrade */
upgrade_pkg(global_config,installed_pkgs->pkgs[iterator],update_pkg);
- }else{
- try_dist_upgrade = 1;
} /* end version check */
- } else {
- try_dist_upgrade = 1;
}/* end upgrade pkg found */
- if( try_dist_upgrade == 1 ){
- current_pkg = get_newest_pkg(
- current_pkgs->pkgs,
- installed_pkgs->pkgs[iterator]->name,
- current_pkgs->pkg_count
- );
- if( current_pkg != NULL ){
- /* the current version of the pkg is greater than the installed version */
- if( (cmp_pkg_versions(installed_pkgs->pkgs[iterator]->version,current_pkg->version)) < 0 ){
- /* attempt to upgrade */
- upgrade_pkg(global_config,installed_pkgs->pkgs[iterator],current_pkg);
- }/* end if cmp_pkg_versions */
- }/* end if current_pkg */
- }
-
}/* end for */
printf("Done.\n");
- free_pkg_list(current_pkgs);
free_pkg_list(installed_pkgs);
- free_pkg_list(update_pkgs);
+ free_pkg_list(all_pkgs);
}
diff --git a/src/action.h b/src/action.h
index 7ff84ca..7e98d48 100644
--- a/src/action.h
+++ b/src/action.h
@@ -15,6 +15,16 @@
* 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 {
+ 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 */
void pkg_action_clean(const rc_config *);
void pkg_action_install(const rc_config *,const char *);
@@ -23,7 +33,6 @@ void pkg_action_list_installed(void);
void pkg_action_remove(const char *);
void pkg_action_search(const char *);
void pkg_action_show(const char *);
-void pkg_action_upgrade(const rc_config *,pkg_info_t *,struct pkg_list *,pkg_info_t *);
void pkg_action_upgrade_all(const rc_config *);
void pkg_action_update(const rc_config *);
diff --git a/src/package.c b/src/package.c
index 9ac5145..710471b 100644
--- a/src/package.c
+++ b/src/package.c
@@ -791,3 +791,40 @@ int break_down_pkg_version(int *v,char *version){
return count;
}
+struct pkg_list *get_available_and_update_pkgs(void){
+ struct pkg_list *updates;
+ struct pkg_list *available;
+ struct pkg_list *all = NULL;
+ pkg_info_t **realloc_tmp;
+ int i;
+
+ updates = get_update_pkgs();
+ available = get_available_pkgs();
+
+ all = malloc( sizeof *all );
+ all->pkgs = malloc( sizeof *all->pkgs );
+ all->pkg_count = 0;
+
+ realloc_tmp = realloc(
+ all->pkgs,
+ sizeof *all->pkgs * ( updates->pkg_count + available->pkg_count + 1 )
+ );
+ if( realloc_tmp != NULL ){
+ all->pkgs = realloc_tmp;
+ }else{
+ fprintf(stderr,"Failed to resize size all package listing\n");
+ exit(1);
+ }
+
+ for(i = 0; i < updates->pkg_count;i++){
+ all->pkgs[all->pkg_count] = updates->pkgs[i];
+ ++all->pkg_count;
+ }
+ for(i = 0; i < available->pkg_count;i++){
+ all->pkgs[all->pkg_count] = available->pkgs[i];
+ ++all->pkg_count;
+ }
+
+ return all;
+}
+
diff --git a/src/package.h b/src/package.h
index b4c3c21..5d225f3 100644
--- a/src/package.h
+++ b/src/package.h
@@ -72,4 +72,6 @@ void get_md5sum(const rc_config *,pkg_info_t *,char *);
int cmp_pkg_versions(char *, char *);
/* analyze the pkg version hunk by hunk */
int break_down_pkg_version(int *,char *);
+/* get available, installed, and update pkgs all in one */
+struct pkg_list *get_available_and_update_pkgs(void);