/tests/libpakfire/arch
/tests/libpakfire/archive
/tests/libpakfire/db
+/tests/libpakfire/downloader
/tests/libpakfire/execute
/tests/libpakfire/key
/tests/libpakfire/main
tests/libpakfire/arch \
tests/libpakfire/archive \
tests/libpakfire/db \
+ tests/libpakfire/downloader \
tests/libpakfire/execute \
tests/libpakfire/key \
tests/libpakfire/makefile \
$(TESTSUITE_LDADD) \
$(PAKFIRE_LIBS)
+dist_tests_libpakfire_downloader_SOURCES = \
+ tests/libpakfire/downloader.c \
+ src/libpakfire/downloader.c \
+ src/libpakfire/util.c
+
+tests_libpakfire_downloader_CPPFLAGS = \
+ $(TESTSUITE_CPPFLAGS) \
+ -DPAKFIRE_PRIVATE
+
+tests_libpakfire_downloader_LDADD = \
+ $(TESTSUITE_LDADD) \
+ $(CURL_LIBS) \
+ $(PAKFIRE_LIBS) \
+ $(UUID_LIBS)
+
tests_libpakfire_execute_SOURCES = \
tests/libpakfire/execute.c
tests/testsuite.h
tests_libtestsuite_la_CPPFLAGS = \
- $(TESTSUITE_CPPFLAGS) \
- -DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\" \
- -DTEST_ROOTFS=\"$(TEST_ROOTFS)\"
+ $(TESTSUITE_CPPFLAGS)
TESTSUITE_CPPFLAGS = \
$(AM_CPPFLAGS) \
- $(PAKFIRE_CPPFLAGS)
+ $(PAKFIRE_CPPFLAGS) \
+ -DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\" \
+ -DTEST_ROOTFS=\"$(TEST_ROOTFS)\"
TESTSUITE_LDADD = \
tests/libtestsuite.la
return 0;
}
+int pakfire_downloader_retrieve(struct pakfire_downloader* downloader,
+ const char* url, const char* path) {
+ // Do not run this when there are transfers pending
+ if (!TAILQ_EMPTY(&downloader->transfers))
+ return EBUSY;
+
+ // Add the transfer
+ int r = pakfire_downloader_add(downloader, url, path);
+ if (r)
+ return r;
+
+ // Run it
+ return pakfire_downloader_run(downloader);
+}
+
int pakfire_downloader_add(struct pakfire_downloader* downloader,
const char* url, const char* path) {
DEBUG(downloader->pakfire, "Adding download of %s\n", url);
int pakfire_downloader_add_mirror(struct pakfire_downloader* downloader,
const char* url, unsigned int priority);
+int pakfire_downloader_retrieve(struct pakfire_downloader* downloader,
+ const char* url, const char* path);
int pakfire_downloader_add(struct pakfire_downloader* downloader,
const char* url, const char* path);
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <pakfire/downloader.h>
+
+#include "../testsuite.h"
+
+#define DOWNLOAD_URL "file://" ABS_TOP_SRCDIR "/tests/data/beep-1.3-2.ip3.x86_64.pfm"
+
+#define DOWNLOAD_PATH TEST_ROOTFS "/downloaded.file"
+
+static int test_simple(const struct test* t) {
+ struct pakfire_downloader* d;
+
+ // Create downloader
+ int r = pakfire_downloader_create(&d, t->pakfire);
+ ASSERT(r == 0);
+
+ // Retrieve a file
+ r = pakfire_downloader_retrieve(d, DOWNLOAD_URL, DOWNLOAD_PATH);
+ ASSERT(r == 0);
+
+ // Cleanup
+ pakfire_downloader_unref(d);
+
+ return EXIT_SUCCESS;
+}
+
+int main(int argc, char** argv) {
+ testsuite_add_test(test_simple);
+
+ return testsuite_run();
+}