Permalink
Browse files

Add fastestmirror module + LRO_FASTESTMIRROR option + example

  • Loading branch information...
1 parent d232e2e commit acf458f29f7234d2d8d93a68391334343beae4b9 @Tojaj Tojaj committed Sep 25, 2013
View
@@ -5,7 +5,11 @@ CC=gcc
CFLAGS= -Wall -Wextra -g -std=c99 -O3 -I../../ `pkg-config --cflags glib-2.0`
LINKFLAGS= -L../../build/librepo/ -lrepo `pkg-config --libs glib-2.0`
-all: download_repo download_packages download_repo_with_callback
+all: \
+ download_repo \
+ download_packages \
+ download_repo_with_callback \
+ fastestmirror
download_repo:
$(CC) $(CFLAGS) download_repo.c $(LINKFLAGS) -o download_repo
@@ -16,8 +20,15 @@ download_packages:
download_repo_with_callback:
$(CC) $(CFLAGS) download_repo_with_callback.c $(LINKFLAGS) -o download_repo_with_callback
+fastestmirror:
+ $(CC) $(CFLAGS) fastestmirror.c $(LINKFLAGS) -o fastestmirror
+
clean:
- rm -f download_repo download_packages download_repo_with_callback
+ rm -f \
+ download_repo \
+ download_packages \
+ download_repo_with_callback \
+ fastestmirror
run:
LD_LIBRARY_PATH="../../build/librepo/" ./download_repo
@@ -0,0 +1,52 @@
+#include <glib.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <librepo/librepo.h>
+
+static void
+log_handler_cb(const gchar *log_domain G_GNUC_UNUSED,
+ GLogLevelFlags log_level G_GNUC_UNUSED,
+ const gchar *message,
+ gpointer user_data G_GNUC_UNUSED)
+{
+ g_print ("%s\n", message);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int rc = EXIT_SUCCESS;
+ GSList *list = NULL;
+ GError *tmp_err = NULL;
+
+ g_log_set_handler("librepo", G_LOG_LEVEL_ERROR |
+ G_LOG_LEVEL_CRITICAL |
+ G_LOG_LEVEL_DEBUG |
+ G_LOG_LEVEL_WARNING,
+ log_handler_cb, NULL);
+
+ if (argc < 2) {
+ g_printerr("Usage: %s <mirror_1> <mirror_2> ...\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ for (int x = 1; x < argc; x++)
+ list = g_slist_prepend(list, argv[x]);
+ list = g_slist_reverse(list);
+
+ gboolean ret = lr_fastestmirror(NULL, &list, &tmp_err);
+ if (!ret) {
+ g_printerr("Error encountered: %s\n", tmp_err->message);
+ g_error_free(tmp_err);
+ rc = EXIT_FAILURE;
+ }
+
+ for (GSList *elem = list; elem; elem = g_slist_next(elem)) {
+ gchar *url = elem->data;
+ g_print("%s\n", url);
+ }
+
+ g_slist_free(list);
+
+ return rc;
+}
@@ -14,7 +14,7 @@
import librepo
# Metalink URL
-METALINK_URL = "https://mirrors.fedoraproject.org/metalink?repo=fedora-18&arch=x86_64"
+METALINK_URL = "https://mirrors.fedoraproject.org/metalink?repo=fedora-19&arch=x86_64"
# Destination directory (note: This directory must exists!)
DESTDIR = "downloaded_metadata"
@@ -28,6 +28,8 @@
h.mirrorlist = METALINK_URL
# Destination directory for metadata
h.destdir = DESTDIR
+ # Use the fastest mirror
+ h.fastestmirror = True
try:
h.perform(r)
@@ -2,6 +2,7 @@ SET (librepo_SRCS
checksum.c
downloader.c
downloadtarget.c
+ fastestmirror.c
gpg.c
handle.c
lrmirrorlist.c
@@ -19,6 +20,7 @@ SET (librepo_SRCS
SET(librepo_HEADERS
checksum.h
+ fastestmirror.h
gpg.h
handle.h
librepo.h
Oops, something went wrong.

0 comments on commit acf458f

Please sign in to comment.