src/main.c
changeset 475 008c75a5e08d
parent 462 94d7459828ba
child 476 48e45439fd9a
     1.1 --- a/src/main.c	Thu Nov 13 10:44:53 2014 +0000
     1.2 +++ b/src/main.c	Mon Jul 04 10:48:18 2016 +0100
     1.3 @@ -1,7 +1,7 @@
     1.4  /*
     1.5   * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     1.6   * Copyright (C) 2008  Red Hat, Inc
     1.7 - * Copyright (C) 2009, 2011-2012, 2014  J. Ali Harlow <ali@juiblex.co.uk>
     1.8 + * Copyright (C) 2009, 2011-2012, 2014, 2016  J. Ali Harlow <ali@juiblex.co.uk>
     1.9   *
    1.10   * This program is free software; you can redistribute it and/or modify
    1.11   * it under the terms of the GNU General Public License as published by
    1.12 @@ -49,7 +49,7 @@
    1.13  
    1.14  static const char system_repo_filename[] = "system.rzdb";
    1.15  static const char next_repo_filename[] = "system-next.rzdb";
    1.16 -static const char rawhide_repo_filename[] = "rawhide.rzdb";
    1.17 +static const char rawhide_repo_uri[] = "file:rawhide.rzdb";
    1.18  static const char *install_root = "";
    1.19  static const char *repo_filename = system_repo_filename;
    1.20  static const char *yum_url;
    1.21 @@ -150,7 +150,7 @@
    1.22  
    1.23  	opterr = 0;
    1.24  
    1.25 -	opt = getopt_long(argc, argv, "+", longopts, NULL);
    1.26 +	opt = getopt_long(argc, (char **)argv, "+", longopts, NULL);
    1.27  
    1.28  	switch (opt)
    1.29  	{
    1.30 @@ -621,13 +621,13 @@
    1.31  	FILE *wfp, *rfp;
    1.32  	char buffer[256], *ptr, *local;
    1.33  	size_t nb, n;
    1.34 +	struct razor_error *error = NULL;
    1.35  
    1.36 -	local = razor_path_from_url(url);
    1.37 +	local = razor_path_from_uri(url, &error);
    1.38  
    1.39  	if (local == NULL) {
    1.40 -		fprintf(stderr,
    1.41 -			"%s: download manually (curl not available)\n",
    1.42 -			file);
    1.43 +		fprintf(stderr, "%s: %s\n", file, razor_error_get_msg(error));
    1.44 +		razor_error_free(error);
    1.45  		return -1;
    1.46  	} else {
    1.47  		rfp = fopen(local, "rb");
    1.48 @@ -723,24 +723,12 @@
    1.49  	curl_easy_setopt(curl, CURLOPT_URL, url);
    1.50  	res = curl_easy_perform(curl);
    1.51  	fclose(fp);
    1.52 +	putc('\n', stderr);
    1.53  	if (res != CURLE_OK) {
    1.54  		fprintf(stderr, "curl error: %s\n", error);
    1.55  		unlink(file);
    1.56  		return -1;
    1.57  	}
    1.58 -	res = curl_easy_getinfo(curl,
    1.59 -				CURLINFO_RESPONSE_CODE, &response);
    1.60 -	if (res != CURLE_OK) {
    1.61 -		fprintf(stderr, "curl error: %s\n", error);
    1.62 -		unlink(file);
    1.63 -		return -1;
    1.64 -	}
    1.65 -	if (response != 200) {
    1.66 -		fprintf(stderr, " - failed %ld\n", response);
    1.67 -		unlink(file);
    1.68 -		return -1;
    1.69 -	}
    1.70 -	fprintf(stderr, "\n");
    1.71  	curl_easy_cleanup(curl);
    1.72  
    1.73  	return 0;
    1.74 @@ -799,13 +787,13 @@
    1.75  	if (set == NULL)
    1.76  		return 1;
    1.77  	atomic = razor_atomic_open("Yum import repository");
    1.78 -	razor_set_write(set, atomic, rawhide_repo_filename, RAZOR_SECTION_ALL);
    1.79 +	razor_set_write(set, atomic, rawhide_repo_uri, RAZOR_SECTION_ALL);
    1.80  	retval = razor_atomic_commit(atomic);
    1.81  	razor_set_unref(set);
    1.82  	if (retval)
    1.83  		fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
    1.84  	else
    1.85 -		printf("wrote %s\n", rawhide_repo_filename);
    1.86 +		printf("wrote %s\n", rawhide_repo_uri);
    1.87  	razor_atomic_destroy(atomic);
    1.88  
    1.89  	return retval;
    1.90 @@ -994,7 +982,7 @@
    1.91  
    1.92  	set = razor_root_open_read_only(install_root, &error);
    1.93  	if (set)
    1.94 -		updated = razor_set_open(rawhide_repo_filename, 0, &error);
    1.95 +		updated = razor_set_open(rawhide_repo_uri, 0, &error);
    1.96  	else
    1.97  		updated = NULL;
    1.98  	if (updated == NULL) {
    1.99 @@ -1131,7 +1119,9 @@
   1.100  					  RAZOR_DETAIL_LAST);
   1.101  		
   1.102  		s = rpm_filename(name, version, arch);
   1.103 -		url = razor_concat(yum_url, "/Packages/", s, NULL);
   1.104 +		file = razor_concat("Packages/", s, NULL);
   1.105 +		url = razor_path_relative_to_uri(yum_url, file, NULL);
   1.106 +		free(file);
   1.107  		file = razor_concat("rpms/", s, NULL);
   1.108  		free(s);
   1.109  		if (download_if_missing(url, file) < 0)
   1.110 @@ -1166,7 +1156,7 @@
   1.111  	const char *preunprog, *preun, *postunprog, *postun;
   1.112  	const char *install_prefix;
   1.113  	const char *const *prefixes;
   1.114 -	char *file, *s;
   1.115 +	char *file, *s, *uri, *filename;
   1.116  	uint32_t flags;
   1.117  
   1.118  	importer = razor_importer_create();
   1.119 @@ -1185,14 +1175,20 @@
   1.120  					   RAZOR_DETAIL_POSTUNPROG, &postunprog,
   1.121  					   RAZOR_DETAIL_POSTUN, &postun,
   1.122  					   RAZOR_DETAIL_LAST)) {
   1.123 -		s = rpm_filename(name, version, arch);
   1.124 -		file = razor_concat("rpms/", s, NULL);
   1.125 +		filename = rpm_filename(name, version, arch);
   1.126 +		s = razor_concat("Packages/", filename, NULL);
   1.127 +		uri = razor_path_relative_to_uri(yum_url, s, NULL);
   1.128  		free(s);
   1.129 -		rpm = razor_rpm_open(file, &error);
   1.130 +		file = razor_concat("rpms/", filename, NULL);
   1.131 +		free(filename);
   1.132 +		download_if_missing(uri, file);
   1.133 +		free(uri);
   1.134 +		uri = razor_path_to_uri(file);
   1.135  		free(file);
   1.136 +		rpm = razor_rpm_open(uri, &error);
   1.137 +		free(uri);
   1.138  		if (rpm == NULL) {
   1.139  			razor_atomic_propagate_error(atomic, error, NULL);
   1.140 -			razor_error_free(error);
   1.141  			razor_package_iterator_destroy(pkg_iter);
   1.142  			razor_importer_destroy(importer);
   1.143  			return NULL;
   1.144 @@ -1249,7 +1245,7 @@
   1.145  {
   1.146  	int retval;
   1.147  	const char *name, *version, *arch;
   1.148 -	char *file, *s;
   1.149 +	char *file, *s, *uri;
   1.150  	struct razor_rpm *rpm;
   1.151  	struct razor_error *error=NULL;
   1.152  
   1.153 @@ -1265,12 +1261,13 @@
   1.154  	s = rpm_filename(name, version, arch);
   1.155  	file = razor_concat("rpms/", s, NULL);
   1.156  	free(s);
   1.157 -	rpm = razor_rpm_open(file, &error);
   1.158 +	uri = razor_path_to_uri(file);
   1.159  	free(file);
   1.160 +	rpm = razor_rpm_open(uri, &error);
   1.161 +	free(uri);
   1.162  	if (rpm == NULL) {
   1.163  		razor_atomic_propagate_error(atomic, error, NULL);
   1.164  		fprintf(stderr, "%s\n", razor_error_get_msg(error));
   1.165 -		razor_error_free(error);
   1.166  		return -1;
   1.167  	}
   1.168  	if (relocations)
   1.169 @@ -1441,7 +1438,7 @@
   1.170  		}
   1.171  	} while (opt);
   1.172  
   1.173 -	upstream = razor_set_open(rawhide_repo_filename, 0, &error);
   1.174 +	upstream = razor_set_open(rawhide_repo_uri, 0, &error);
   1.175  	if (upstream == NULL) {
   1.176  		fprintf(stderr, "%s\n", razor_error_get_msg(error));
   1.177  		razor_error_free(error);
   1.178 @@ -1513,7 +1510,7 @@
   1.179  		}
   1.180  	}
   1.181  
   1.182 -	if (razor_atomic_create_dir(atomic, "rpms",
   1.183 +	if (razor_atomic_create_dir(atomic, "file:rpms",
   1.184  				    S_IRWXU | S_IRWXG | S_IRWXO) ||
   1.185  	    razor_atomic_commit(atomic)) {
   1.186  		fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
   1.187 @@ -1604,7 +1601,7 @@
   1.188  	struct razor_package_iterator *pi;
   1.189  	struct razor_package *package;
   1.190  	const char *pattern, *name, *version, *arch;
   1.191 -	char url[256], file[256];
   1.192 +	char *url, *file, *s, filename[256];
   1.193  	int matches = 0;
   1.194  
   1.195  	switch (razor_getopt(argc, argv, 0, NULL, "[pattern]", NULL)) {
   1.196 @@ -1621,7 +1618,7 @@
   1.197  
   1.198  	pattern = argv[optind];
   1.199  
   1.200 -	set = razor_set_open(rawhide_repo_filename, 0, &error);
   1.201 +	set = razor_set_open(rawhide_repo_uri, 0, &error);
   1.202  	if (set == NULL) {
   1.203  		fprintf(stderr, "%s\n", razor_error_get_msg(error));
   1.204  		razor_error_free(error);
   1.205 @@ -1630,7 +1627,7 @@
   1.206  
   1.207  	atomic = razor_atomic_open("Download packages");
   1.208  
   1.209 -	if (razor_atomic_create_dir(atomic, "rpms", 
   1.210 +	if (razor_atomic_create_dir(atomic, "file:rpms", 
   1.211  				    S_IRWXU | S_IRWXG | S_IRWXO)) {
   1.212  		fprintf(stderr, "%s\n", razor_atomic_get_error_msg(atomic));
   1.213  		razor_atomic_destroy(atomic);
   1.214 @@ -1654,12 +1651,15 @@
   1.215  			continue;
   1.216  
   1.217  		matches++;
   1.218 -		snprintf(url, sizeof url,
   1.219 -			 "%s/Packages/%s-%s.%s.rpm",
   1.220 -			 yum_url, name, version, arch);
   1.221 -		snprintf(file, sizeof file,
   1.222 -			 "rpms/%s-%s.%s.rpm", name, version, arch);
   1.223 +		snprintf(filename, sizeof filename,
   1.224 +			 "%s-%s.%s.rpm", name, version, arch);
   1.225 +		s = razor_concat("Packages/", filename, NULL);
   1.226 +		url = razor_path_relative_to_uri(yum_url, s, NULL);
   1.227 +		free(s);
   1.228 +		file = razor_concat("rpms/", filename, NULL);
   1.229  		download_if_missing(url, file);
   1.230 +		free(url);
   1.231 +		free(file);
   1.232  	}
   1.233  	razor_package_iterator_destroy(pi);
   1.234  	razor_set_unref(set);
   1.235 @@ -1804,7 +1804,7 @@
   1.236  
   1.237  	snprintf(pattern, sizeof pattern, "*%s*", argv[1]);
   1.238  
   1.239 -	set = razor_set_open(rawhide_repo_filename, 0, &error);
   1.240 +	set = razor_set_open(rawhide_repo_uri, 0, &error);
   1.241  	if (set == NULL) {
   1.242  		fprintf(stderr, "%s\n", razor_error_get_msg(error));
   1.243  		razor_error_free(error);
   1.244 @@ -1939,7 +1939,7 @@
   1.245  	while ((opt = getopt_long(argc, argv, "+", options, NULL)) != -1) {
   1.246  		switch (opt) {
   1.247  			case opt_database:
   1.248 -				razor_set_database_path(optarg);
   1.249 +				razor_set_database_uri(optarg);
   1.250  				break;
   1.251  			case opt_help:
   1.252  			default:
   1.253 @@ -1949,12 +1949,12 @@
   1.254  				printf("  --help              "
   1.255  				       "Show this help message and exit\n");
   1.256  				printf("  --help-commands     List commands\n");
   1.257 -				printf("  --database=PATH     "
   1.258 +				printf("  --database=URI      "
   1.259  				       "Use alternative database\n");
   1.260 -				printf("  --root=ROOT         "
   1.261 -				       "Use ROOT as top level directory\n");
   1.262 -				printf("  --url=URL           "
   1.263 -				       "Use URL as upstream repository\n");
   1.264 +				printf("  --root=URI          "
   1.265 +				       "Use URI as top level directory\n");
   1.266 +				printf("  --url=URI           "
   1.267 +				       "Use URI as upstream repository\n");
   1.268  				return opt != opt_help;
   1.269  			case opt_root:
   1.270  				install_root = optarg;