src/main.c
changeset 384 35aa26867cfd
parent 377 5549419824b4
child 389 4aac72ec4537
     1.1 --- a/src/main.c	Wed Jul 08 22:14:16 2009 +0100
     1.2 +++ b/src/main.c	Tue Aug 18 14:04:11 2009 +0100
     1.3 @@ -42,7 +42,6 @@
     1.4  static const char system_repo_filename[] = "system.rzdb";
     1.5  static const char next_repo_filename[] = "system-next.rzdb";
     1.6  static const char rawhide_repo_filename[] = "rawhide.rzdb";
     1.7 -static const char updated_repo_filename[] = "system-updated.rzdb";
     1.8  static const char *install_root = "";
     1.9  static const char *repo_filename = system_repo_filename;
    1.10  static const char *yum_url;
    1.11 @@ -549,50 +548,6 @@
    1.12  }
    1.13  
    1.14  static int
    1.15 -command_update(int argc, const char *argv[])
    1.16 -{
    1.17 -	struct razor_set *set, *upstream;
    1.18 -	struct razor_transaction *trans;
    1.19 -	int i, errors;
    1.20 -
    1.21 -	set = razor_root_open_read_only(install_root);
    1.22 -	if (set == NULL)
    1.23 -		return 1;
    1.24 -
    1.25 -	upstream = razor_set_open(rawhide_repo_filename);
    1.26 -	if (upstream == NULL)
    1.27 -		return 1;
    1.28 -
    1.29 -	trans = razor_transaction_create(set, upstream);
    1.30 -	if (argc == 0)
    1.31 -		razor_transaction_update_all(trans);
    1.32 -	for (i = 0; i < argc; i++) {
    1.33 -		if (mark_packages_for_update(trans, set, argv[i]) == 0) {
    1.34 -			fprintf(stderr, "no match for %s\n", argv[i]);
    1.35 -			razor_transaction_destroy(trans);
    1.36 -			return 1;
    1.37 -		}
    1.38 -	}
    1.39 -
    1.40 -	razor_transaction_resolve(trans);
    1.41 -	errors = razor_transaction_describe(trans);
    1.42 -	if (errors) {
    1.43 -		fprintf(stderr, "unresolved dependencies\n");
    1.44 -		razor_transaction_destroy(trans);
    1.45 -		return 1;
    1.46 -	}
    1.47 -
    1.48 -	set = razor_transaction_commit(trans);
    1.49 -	razor_set_write(set, updated_repo_filename, RAZOR_SECTION_ALL);
    1.50 -	razor_transaction_destroy(trans);
    1.51 -	razor_set_destroy(set);
    1.52 -	razor_set_destroy(upstream);
    1.53 -	printf("wrote system-updated.rzdb\n");
    1.54 -
    1.55 -	return 0;
    1.56 -}
    1.57 -
    1.58 -static int
    1.59  command_remove(int argc, const char *argv[])
    1.60  {
    1.61  	struct razor_root *root;
    1.62 @@ -659,7 +614,7 @@
    1.63  	struct razor_set *set, *updated;
    1.64  
    1.65  	set = razor_root_open_read_only(install_root);
    1.66 -	updated = razor_set_open(updated_repo_filename);
    1.67 +	updated = razor_set_open(rawhide_repo_filename);
    1.68  	if (set == NULL || updated == NULL)
    1.69  		return 1;
    1.70  
    1.71 @@ -756,19 +711,17 @@
    1.72  {
    1.73  	struct razor_install_iterator *ii;
    1.74  	struct razor_package *package;
    1.75 -	struct razor_set *set;
    1.76  	enum razor_install_action action;
    1.77  	const char *name, *version, *arch;
    1.78  	char file[PATH_MAX], url[256];
    1.79  	int errors = 0, count;
    1.80  
    1.81  	ii = razor_set_create_install_iterator(system, next);
    1.82 -	while (razor_install_iterator_next(ii, &set, &package,
    1.83 -					   &action, &count)) {
    1.84 +	while (razor_install_iterator_next(ii, &package, &action, &count)) {
    1.85  		if (action == RAZOR_INSTALL_ACTION_REMOVE)
    1.86  			continue;
    1.87  
    1.88 -		razor_package_get_details(set, package,
    1.89 +		razor_package_get_details(next, package,
    1.90  					  RAZOR_DETAIL_NAME, &name,
    1.91  					  RAZOR_DETAIL_VERSION, &version,
    1.92  					  RAZOR_DETAIL_ARCH, &arch,
    1.93 @@ -920,19 +873,18 @@
    1.94  {
    1.95  	struct razor_install_iterator *ii;
    1.96  	struct razor_package *package;
    1.97 -	struct razor_set *set;
    1.98  	enum razor_install_action action;
    1.99  	int retval = 0, count;
   1.100  
   1.101  	ii = razor_set_create_install_iterator(system, next);
   1.102 -	while (!retval && razor_install_iterator_next(ii, &set, &package,
   1.103 +	while (!retval && razor_install_iterator_next(ii, &package,
   1.104  						      &action, &count)) {
   1.105  		if (action == RAZOR_INSTALL_ACTION_ADD)
   1.106 -			retval = install_package(trans, set, package,
   1.107 +			retval = install_package(trans, next, package,
   1.108  						 relocations);
   1.109  		else if (action == RAZOR_INSTALL_ACTION_REMOVE)
   1.110 -			retval = razor_package_remove(set, package,
   1.111 -						      install_root, 0);
   1.112 +			retval = razor_package_remove(system, next, package,
   1.113 +						      install_root, count);
   1.114  	}
   1.115  	razor_install_iterator_destroy(ii);
   1.116  
   1.117 @@ -940,7 +892,7 @@
   1.118  }
   1.119  
   1.120  static int
   1.121 -command_install(int argc, const char *argv[])
   1.122 +command_install_or_update(int argc, const char *argv[], int do_update)
   1.123  {
   1.124  	struct razor_root *root;
   1.125  	struct razor_relocations *relocations=NULL;
   1.126 @@ -960,7 +912,8 @@
   1.127  			i++;
   1.128  			if (i >= argc || strchr(argv[i], '=') == NULL) {
   1.129  				fprintf(stderr,
   1.130 -				    "Usage: razor install [OPTION...] RPM\n");
   1.131 +				    "Usage: razor %s [OPTION...] RPM\n",
   1.132 +				    do_update ? "update" : "install");
   1.133  				fprintf(stderr, "Options:\n");
   1.134  				fprintf(stderr, "    [--no-dependencies]\n");
   1.135  				fprintf(stderr,
   1.136 @@ -983,10 +936,9 @@
   1.137  	system = razor_root_get_system_set(root);
   1.138  	upstream = razor_set_open(rawhide_repo_filename);
   1.139  	if (upstream == NULL) {
   1.140 -		fprintf(stderr, "couldn't open rawhide repo\n");
   1.141  		razor_root_close(root);
   1.142  		return 1;
   1.143 -	}		
   1.144 +	}
   1.145  
   1.146  	if (relocations) {
   1.147  		set = relocate_packages(upstream, relocations);
   1.148 @@ -996,10 +948,13 @@
   1.149  
   1.150  	trans = razor_transaction_create(system, upstream);
   1.151  
   1.152 +	if (i == argc && do_update)
   1.153 +		razor_transaction_update_all(trans);
   1.154  	for (; i < argc; i++) {
   1.155  		if (mark_packages_for_update(trans, upstream, argv[i]) == 0) {
   1.156  			fprintf(stderr, "no package matched %s\n", argv[i]);
   1.157  			razor_transaction_destroy(trans);
   1.158 +			razor_set_destroy(upstream);
   1.159  			razor_root_close(root);
   1.160  			return 1;
   1.161  		}
   1.162 @@ -1009,22 +964,26 @@
   1.163  		razor_transaction_resolve(trans);
   1.164  		if (razor_transaction_describe(trans) > 0) {
   1.165  			razor_transaction_destroy(trans);
   1.166 +			razor_set_destroy(upstream);
   1.167  			razor_root_close(root);
   1.168  			return 1;
   1.169  		}
   1.170  	}
   1.171  
   1.172 -	next = razor_transaction_commit(trans);
   1.173 -
   1.174  	if (mkdir("rpms", 0777) && errno != EEXIST) {
   1.175  		fprintf(stderr, "failed to create rpms directory.\n");
   1.176  		razor_transaction_destroy(trans);
   1.177 +		razor_set_destroy(upstream);
   1.178  		razor_root_close(root);
   1.179  		return 1;
   1.180  	}
   1.181  
   1.182 +	next = razor_transaction_commit(trans);
   1.183 +
   1.184  	if (download_packages(system, next) < 0) {
   1.185 +		razor_set_destroy(next);
   1.186  		razor_transaction_destroy(trans);
   1.187 +		razor_set_destroy(upstream);
   1.188  		razor_root_close(root);
   1.189                  return 1;
   1.190          }
   1.191 @@ -1043,6 +1002,18 @@
   1.192  }
   1.193  
   1.194  static int
   1.195 +command_update(int argc, const char *argv[])
   1.196 +{
   1.197 +	return command_install_or_update(argc, argv, 1);
   1.198 +}
   1.199 +
   1.200 +static int
   1.201 +command_install(int argc, const char *argv[])
   1.202 +{
   1.203 +	return command_install_or_update(argc, argv, 0);
   1.204 +}
   1.205 +
   1.206 +static int
   1.207  command_init(int argc, const char *argv[])
   1.208  {
   1.209  	return razor_root_create(install_root);