Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Unify the mirroring type into one single option:
Baptiste Daroussin committed 13 years ago
commit 5cba692c3988f11769d7004d789f21438e35ffc6
parent 250bddd
3 files changed +16 -20
modified libpkg/fetch.c
@@ -130,6 +130,7 @@ pkg_fetch_file_to_fd(const char *url, int dest, time_t t)
	char zone[MAXHOSTNAMELEN + 13];
	struct dns_srvinfo *srv_current;
	struct http_mirror *http_current;
+
	const char *mt;

	fetchTimeout = 30;

@@ -142,9 +143,10 @@ pkg_fetch_file_to_fd(const char *url, int dest, time_t t)
	doc = u->doc;
	while (remote == NULL) {
		if (retry == max_retry) {
-
			pkg_config_bool(PKG_CONFIG_SRV_MIRROR, &srv);
-
			pkg_config_bool(PKG_CONFIG_HTTP_MIRROR, &http);
-
			if (srv && strcmp(u->scheme, "file") != 0) {
+
			pkg_config_string(PKG_CONFIG_MIRRORS, &mt);
+
			if (mt != NULL && strncasecmp(mt, "srv", 3) == 0 && \
+
			    strcmp(u->scheme, "file") != 0) {
+
				srv = true;
				snprintf(zone, sizeof(zone),
				    "_%s._tcp.%s", u->scheme, u->host);
				pthread_mutex_lock(&mirror_mtx);
@@ -152,8 +154,10 @@ pkg_fetch_file_to_fd(const char *url, int dest, time_t t)
					srv_mirrors = dns_getsrvinfo(zone);
				pthread_mutex_unlock(&mirror_mtx);
				srv_current = srv_mirrors;
-
			} else if (http && strcmp(u->scheme, "file") != 0 && \
+
			} else if (mt != NULL && strncasecmp(mt, "http", 4) == 0 && \
+
			           strcmp(u->scheme, "file") != 0 && \
			           strcmp(u->scheme, "ftp") != 0) {
+
				http = true;
				snprintf(zone, sizeof(zone),
				    "%s://%s", u->scheme, u->host);
				pthread_mutex_lock(&mirror_mtx);
modified libpkg/pkg.h.in
@@ -303,7 +303,7 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_ABI,
	PKG_CONFIG_DEVELOPER_MODE,
	PKG_CONFIG_PORTAUDIT_SITE,
-
	PKG_CONFIG_SRV_MIRROR,
+
	PKG_CONFIG_MIRRORS,
	PKG_CONFIG_FETCH_RETRY,
	PKG_CONFIG_PLUGINS_DIR,
	PKG_CONFIG_ENABLE_PLUGINS,
@@ -312,7 +312,6 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_PLUGINS_CONF_DIR,
	PKG_CONFIG_PERMISSIVE,
	PKG_CONFIG_REPO_AUTOUPDATE,
-
	PKG_CONFIG_HTTP_MIRROR,
} pkg_config_key;

typedef enum {
modified libpkg/pkg_config.c
@@ -145,13 +145,15 @@ static struct config_entry c[] = {
		"http://portaudit.FreeBSD.org/auditfile.tbz",
#endif
	},
-
	[PKG_CONFIG_SRV_MIRROR] = {
-
		PKG_CONFIG_BOOL,
-
		"SRV_MIRRORS",
+
	[PKG_CONFIG_MIRRORS] = {
+
		PKG_CONFIG_STRING,
+
		"MIRROR_TYPE",
#if DEFAULT_MIRROR_TYPE == 1
-
		"YES",
+
		"SRV",
+
#elif DEFAULT_MIRROR_TYPE == 2
+
		"HTTP",
#else
-
		"NO",
+
		NULL,
#endif
	},
	[PKG_CONFIG_FETCH_RETRY] = {
@@ -194,15 +196,6 @@ static struct config_entry c[] = {
		"REPO_AUTOUPDATE",
		"YES",
	},
-
	[PKG_CONFIG_HTTP_MIRROR] = {
-
		PKG_CONFIG_BOOL,
-
		"HTTP_MIRRORS",
-
#if DEFAULT_MIRROR_TYPE == 2
-
		"YES",
-
#else
-
		"NO",
-
#endif
-
	},
};

static bool parsed = false;