From c0630703409ca28628ae952b3a3c1b6bcc081796 Mon Sep 17 00:00:00 2001 From: Elbert van de Put Date: Sat, 27 Mar 2021 11:42:01 +0100 Subject: [PATCH] update: Fix clib-update with the new way of fetching packages, fix a bug with downloading packages from gitlab, move common definitinos to clib-settings --- src/clib-build.c | 9 +- src/clib-configure.c | 9 +- src/clib-install.c | 9 +- src/clib-search.c | 232 ++++++++++++++-------------- src/clib-settings.h | 13 ++ src/clib-uninstall.c | 3 +- src/clib-update.c | 22 ++- src/clib-upgrade.c | 8 +- src/common/clib-package-installer.c | 46 ++---- src/common/clib-package.c | 6 +- src/repository/github-repository.c | 14 +- src/repository/github-repository.h | 2 +- src/repository/repository.c | 9 +- 13 files changed, 179 insertions(+), 203 deletions(-) create mode 100644 src/clib-settings.h diff --git a/src/clib-build.c b/src/clib-build.c index ab57e226..160ed3bf 100644 --- a/src/clib-build.c +++ b/src/clib-build.c @@ -40,19 +40,14 @@ #include #include #include - +#include "clib-settings.h" #include "version.h" -#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60 #define PROGRAM_NAME "clib-build" #define SX(s) #s #define S(s) SX(s) -#ifdef HAVE_PTHREADS -#define MAX_THREADS 4 -#endif - #ifndef DEFAULT_MAKE_CLEAN_TARGET #define DEFAULT_MAKE_CLEAN_TARGET "clean" #endif @@ -83,8 +78,6 @@ struct options { #endif }; -const char *manifest_names[] = {"clib.json", "package.json", 0}; - clib_package_opts_t build_package_opts = {0}; clib_package_t *root_package = 0; diff --git a/src/clib-configure.c b/src/clib-configure.c index 6a000859..b07af853 100644 --- a/src/clib-configure.c +++ b/src/clib-configure.c @@ -40,19 +40,14 @@ #include #include #include - +#include "clib-settings.h" #include "version.h" -#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60 #define PROGRAM_NAME "clib-configure" #define SX(s) #s #define S(s) SX(s) -#ifdef HAVE_PTHREADS -#define MAX_THREADS 4 -#endif - #if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \ defined(__MINGW64__) || defined(__CYGWIN__) #define setenv(k, v, _) _putenv_s(k, v) @@ -74,8 +69,6 @@ struct options { #endif }; -const char *manifest_names[] = {"clib.json", "package.json", 0}; - clib_package_opts_t configure_package_opts = {0}; clib_package_t *root_package = 0; diff --git a/src/clib-install.c b/src/clib-install.c index 33aae0a9..23f1e01e 100644 --- a/src/clib-install.c +++ b/src/clib-install.c @@ -23,16 +23,11 @@ #include #include #include "clib-package-installer.h" - -#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60 +#include "clib-settings.h" #define SX(s) #s #define S(s) SX(s) -#ifdef HAVE_PTHREADS -#define MAX_THREADS 12 -#endif - #if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \ defined(__MINGW64__) || defined(__CYGWIN__) #define setenv(k, v, _) _putenv_s(k, v) @@ -61,8 +56,6 @@ struct options { static struct options opts = {0}; -static const char *manifest_names[] = {"clib.json", "package.json", NULL}; - static clib_package_t *root_package = NULL; static clib_secrets_t secrets = NULL; static registries_t registries = NULL; diff --git a/src/clib-search.c b/src/clib-search.c index fa29617a..c77638af 100644 --- a/src/clib-search.c +++ b/src/clib-search.c @@ -27,11 +27,11 @@ #include #include #include +#include "clib-settings.h" #define CLIB_SEARCH_CACHE_TIME 1 * 24 * 60 * 60 -#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \ - defined(__MINGW64__) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__MINGW64__) || defined(__CYGWIN__) #define setenv(k, v, _) _putenv_s(k, v) #define realpath(a, b) _fullpath(a, b, strlen(a)) #endif @@ -48,50 +48,50 @@ static void setopt_nocache(command_t *self) { opt_cache = 0; } static void setopt_json(command_t *self) { opt_json = 1; } -#define COMPARE(v) \ - { \ - if (NULL == v) { \ - rc = 0; \ - goto cleanup; \ - } \ - case_lower(v); \ - for (int i = 0; i < count; i++) { \ - if (strstr(v, args[i])) { \ - rc = 1; \ - break; \ - } \ - } \ +#define COMPARE(v) \ + { \ + if (NULL == v) { \ + rc = 0; \ + goto cleanup; \ + } \ + case_lower(v); \ + for (int i = 0; i < count; i++) { \ + if (strstr(v, args[i])) { \ + rc = 1; \ + break; \ + } \ + } \ } static int matches(int count, char *args[], registry_package_ptr_t pkg) { - // Display all packages if there's no query - if (0 == count) - return 1; - - char *description = NULL; - char *name = NULL; - char *repo = NULL; - char *href = NULL; - int rc = 0; - - name = clib_package_parse_name(registry_package_get_id(pkg)); - COMPARE(name); - - description = strdup(registry_package_get_description(pkg)); - COMPARE(description); - - repo = strdup(registry_package_get_id(pkg)); - COMPARE(repo); - - href = strdup(registry_package_get_href(pkg)); - COMPARE(href); - - cleanup: - free(description); - free(name); - free(repo); - free(href); - return rc; + // Display all packages if there's no query + if (0 == count) + return 1; + + char *description = NULL; + char *name = NULL; + char *repo = NULL; + char *href = NULL; + int rc = 0; + + name = clib_package_parse_name(registry_package_get_id(pkg)); + COMPARE(name); + + description = strdup(registry_package_get_description(pkg)); + COMPARE(description); + + repo = strdup(registry_package_get_id(pkg)); + COMPARE(repo); + + href = strdup(registry_package_get_href(pkg)); + COMPARE(href); + +cleanup: + free(description); + free(name); + free(repo); + free(href); + return rc; } /* @@ -125,67 +125,67 @@ static char *wiki_html_cache() { static void display_package(const registry_package_ptr_t pkg, cc_color_t fg_color_highlight, cc_color_t fg_color_text) { - cc_fprintf(fg_color_highlight, stdout, " %s\n", registry_package_get_id(pkg)); - printf(" url: "); - cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_href(pkg)); - printf(" desc: "); - cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_description(pkg)); - printf("\n"); + cc_fprintf(fg_color_highlight, stdout, " %s\n", registry_package_get_id(pkg)); + printf(" url: "); + cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_href(pkg)); + printf(" desc: "); + cc_fprintf(fg_color_text, stdout, "%s\n", registry_package_get_description(pkg)); + printf("\n"); } static void add_package_to_json(const registry_package_ptr_t pkg, JSON_Array *json_list) { - JSON_Value *json_pkg_root = json_value_init_object(); - JSON_Object *json_pkg = json_value_get_object(json_pkg_root); + JSON_Value *json_pkg_root = json_value_init_object(); + JSON_Object *json_pkg = json_value_get_object(json_pkg_root); - json_object_set_string(json_pkg, "repo", registry_package_get_id(pkg)); - json_object_set_string(json_pkg, "href", registry_package_get_href(pkg)); - json_object_set_string(json_pkg, "description", registry_package_get_description(pkg)); - json_object_set_string(json_pkg, "category", registry_package_get_category(pkg)); + json_object_set_string(json_pkg, "repo", registry_package_get_id(pkg)); + json_object_set_string(json_pkg, "href", registry_package_get_href(pkg)); + json_object_set_string(json_pkg, "description", registry_package_get_description(pkg)); + json_object_set_string(json_pkg, "category", registry_package_get_category(pkg)); - json_array_append_value(json_list, json_pkg_root); + json_array_append_value(json_list, json_pkg_root); } int main(int argc, char *argv[]) { - opt_color = 1; - opt_cache = 1; + opt_color = 1; + opt_cache = 1; - debug_init(&debugger, "clib-search"); + debug_init(&debugger, "clib-search"); - clib_cache_init(CLIB_SEARCH_CACHE_TIME); + clib_cache_init(CLIB_SEARCH_CACHE_TIME); - command_t program; - command_init(&program, "clib-search", CLIB_VERSION); - program.usage = "[options] [query ...]"; + command_t program; + command_init(&program, "clib-search", CLIB_VERSION); + program.usage = "[options] [query ...]"; - command_option(&program, "-n", "--no-color", "don't colorize output", - setopt_nocolor); + command_option(&program, "-n", "--no-color", "don't colorize output", + setopt_nocolor); - command_option(&program, "-c", "--skip-cache", "skip the search cache", - setopt_nocache); + command_option(&program, "-c", "--skip-cache", "skip the search cache", + setopt_nocache); - command_option(&program, "-j", "--json", "generate a serialized JSON output", - setopt_json); + command_option(&program, "-j", "--json", "generate a serialized JSON output", + setopt_json); - command_parse(&program, argc, argv); + command_parse(&program, argc, argv); - for (int i = 0; i < program.argc; i++) - case_lower(program.argv[i]); + for (int i = 0; i < program.argc; i++) + case_lower(program.argv[i]); - // set color theme - cc_color_t fg_color_highlight = opt_color ? CC_FG_DARK_CYAN : CC_FG_NONE; - cc_color_t fg_color_text = opt_color ? CC_FG_DARK_GRAY : CC_FG_NONE; + // set color theme + cc_color_t fg_color_highlight = opt_color ? CC_FG_DARK_CYAN : CC_FG_NONE; + cc_color_t fg_color_text = opt_color ? CC_FG_DARK_GRAY : CC_FG_NONE; - // We search the local manifest for extra registries. - // It is important to give the extra registries preference over the default registry. - clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json"); + // We search the local manifest for extra registries. + // It is important to give the extra registries preference over the default registry. + clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json"); - clib_package_t *package = clib_package_load_local_manifest(0); - registries_t registries = registry_manager_init_registries(package->registries, secrets); - registry_manager_fetch_registries(registries); + clib_package_t *package = clib_package_load_local_manifest(0); + registries_t registries = registry_manager_init_registries(package->registries, secrets); + registry_manager_fetch_registries(registries); - // TODO, implement caching for the new registries. - /* + // TODO, implement caching for the new registries. + /* char *html = wiki_html_cache(); if (NULL == html) { command_free(&program); @@ -197,45 +197,45 @@ int main(int argc, char *argv[]) { debug(&debugger, "found %zu packages", pkgs->len); */ - registry_iterator_t it = registry_iterator_new(registries); - registry_ptr_t registry = NULL; - while ((registry = registry_iterator_next(it))) { - printf("SEARCH: packages from %s\n", registry_get_url(registry)); - registry_package_ptr_t pkg; - registry_package_iterator_t it = registry_package_iterator_new(registry); + registry_iterator_t it = registry_iterator_new(registries); + registry_ptr_t registry = NULL; + while ((registry = registry_iterator_next(it))) { + printf("SEARCH: packages from %s\n", registry_get_url(registry)); + registry_package_ptr_t pkg; + registry_package_iterator_t it = registry_package_iterator_new(registry); - JSON_Array *json_list = NULL; - JSON_Value *json_list_root = NULL; + JSON_Array *json_list = NULL; + JSON_Value *json_list_root = NULL; - if (opt_json) { - json_list_root = json_value_init_array(); - json_list = json_value_get_array(json_list_root); - } + if (opt_json) { + json_list_root = json_value_init_array(); + json_list = json_value_get_array(json_list_root); + } - printf("\n"); - - while ((pkg = registry_package_iterator_next(it))) { - if (matches(program.argc, program.argv, pkg)) { - if (opt_json) { - add_package_to_json(pkg, json_list); - } else { - display_package(pkg, fg_color_highlight, fg_color_text); - } - } else { - debug(&debugger, "skipped package %s", registry_package_get_id(pkg)); - } - } + printf("\n"); + while ((pkg = registry_package_iterator_next(it))) { + if (matches(program.argc, program.argv, pkg)) { if (opt_json) { - char *serialized = json_serialize_to_string_pretty(json_list_root); - puts(serialized); - - json_free_serialized_string(serialized); - json_value_free(json_list_root); + add_package_to_json(pkg, json_list); + } else { + display_package(pkg, fg_color_highlight, fg_color_text); } + } else { + debug(&debugger, "skipped package %s", registry_package_get_id(pkg)); + } + } - registry_package_iterator_destroy(it); + if (opt_json) { + char *serialized = json_serialize_to_string_pretty(json_list_root); + puts(serialized); + + json_free_serialized_string(serialized); + json_value_free(json_list_root); } - command_free(&program); - return 0; + + registry_package_iterator_destroy(it); + } + command_free(&program); + return 0; } diff --git a/src/clib-settings.h b/src/clib-settings.h new file mode 100644 index 00000000..bdd17902 --- /dev/null +++ b/src/clib-settings.h @@ -0,0 +1,13 @@ +#ifndef CLIB_SRC_CLIB_SETTINGS_H +#define CLIB_SRC_CLIB_SETTINGS_H + +// Shared settings +#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60 + +#ifdef HAVE_PTHREADS +#define MAX_THREADS 12 +#endif + +const char *manifest_names[] = {"clib.json", "package.json", 0}; + +#endif//CLIB_SRC_CLIB_SETTINGS_H diff --git a/src/clib-uninstall.c b/src/clib-uninstall.c index 77ed5839..e4aabf01 100644 --- a/src/clib-uninstall.c +++ b/src/clib-uninstall.c @@ -18,6 +18,7 @@ #include "version.h" #include #include +#include "clib-settings.h" #define CLIB_UNINSTALL_DEFAULT_TARGET "make uninstall" @@ -26,8 +27,6 @@ #define setenv(k, v, _) _putenv_s(k, v) #endif -const char *manifest_names[] = {"clib.json", "package.json", NULL}; - debug_t debugger; static void setopt_prefix(command_t *self) { diff --git a/src/clib-update.c b/src/clib-update.c index 86193632..5d0a6bd5 100644 --- a/src/clib-update.c +++ b/src/clib-update.c @@ -20,19 +20,15 @@ #include #include #include +#include #include #include #include - -#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60 +#include "clib-settings.h" #define SX(s) #s #define S(s) SX(s) -#ifdef HAVE_PTHREADS -#define MAX_THREADS 12 -#endif - #if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \ defined(__MINGW64__) || defined(__CYGWIN__) #define setenv(k, v, _) _putenv_s(k, v) @@ -56,9 +52,9 @@ struct options { static struct options opts = {0}; -static const char *manifest_names[] = {"clib.json", "package.json", NULL}; - static clib_package_t *root_package = NULL; +static clib_secrets_t secrets = NULL; +static registries_t registries = NULL; /** * Option setters. @@ -362,6 +358,16 @@ int main(int argc, char *argv[]) { clib_package_set_opts(package_opts); + // Read local config files. + secrets = clib_secrets_load_from_file("clib_secrets.json"); + root_package = clib_package_load_local_manifest(0); + + repository_init(secrets); // The repository requires the secrets for authentication. + registries = registry_manager_init_registries(root_package->registries, secrets); + registry_manager_fetch_registries(registries); + + clib_package_installer_init(registries, secrets); + int code = 0 == program.argc ? install_local_packages() : install_packages(program.argc, program.argv); diff --git a/src/clib-upgrade.c b/src/clib-upgrade.c index f33efc3b..53ba143a 100644 --- a/src/clib-upgrade.c +++ b/src/clib-upgrade.c @@ -25,16 +25,12 @@ #include #include #include +#include "clib-settings.h" -#define CLIB_PACKAGE_CACHE_TIME 30 * 24 * 60 * 60 #define SX(s) #s #define S(s) SX(s) -#ifdef HAVE_PTHREADS -#define MAX_THREADS 16 -#endif - #if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \ defined(__MINGW64__) || defined(__CYGWIN__) #define setenv(k, v, _) _putenv_s(k, v) @@ -60,8 +56,6 @@ struct options { static struct options opts = {0}; -static const char *manifest_names[] = {"clib.json", "package.json", NULL}; - static clib_package_opts_t upgrade_package_opts = {0}; static clib_package_t *root_package = NULL; diff --git a/src/common/clib-package-installer.c b/src/common/clib-package-installer.c index 0087a504..e05a5bde 100644 --- a/src/common/clib-package-installer.c +++ b/src/common/clib-package-installer.c @@ -20,28 +20,25 @@ #include #include #include - -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -#include -#endif +#include CURLSH *clib_package_curl_share; //TODO, cleanup somewhere curl_share_cleanup(clib_package_curl_share); static debug_t _debugger; -#define _debug(...) \ - ({ \ - if (!(_debugger.name)) \ +#define _debug(...) \ + ({ \ + if (!(_debugger.name)) \ debug_init(&_debugger, "package-installer"); \ - debug(&_debugger, __VA_ARGS__); \ + debug(&_debugger, __VA_ARGS__); \ }) -#define E_FORMAT(...) \ - ({ \ - rc = asprintf(__VA_ARGS__); \ - if (-1 == rc) \ - goto cleanup; \ +#define E_FORMAT(...) \ + ({ \ + rc = asprintf(__VA_ARGS__); \ + if (-1 == rc) \ + goto cleanup; \ }); static hash_t *visited_packages = 0; @@ -86,7 +83,7 @@ static inline int install_packages(list_t *list, const char *dir, int verbose) { int error = 1; dep = (clib_package_dependency_t *) node->val; - char* package_id = clib_package_get_id(dep->author, dep->name); + char *package_id = clib_package_get_id(dep->author, dep->name); slug = clib_package_slug(dep->author, dep->name, dep->version); if (NULL == slug) goto loop_cleanup; @@ -315,18 +312,6 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) { int max = package_opts.concurrency; #endif -#ifdef CLIB_PACKAGE_PREFIX - if (0 == opts.prefix) { -#ifdef HAVE_PTHREADS - pthread_mutex_lock(&lock.mutex); -#endif - opts.prefix = CLIB_PACKAGE_PREFIX; -#ifdef HAVE_PTHREADS - pthread_mutex_unlock(&lock.mutex); -#endif - } -#endif - if (0 == package_opts.prefix) { #ifdef HAVE_PTHREADS pthread_mutex_lock(&lock.mutex); @@ -441,7 +426,7 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) { // fetch makefile if (!package_opts.global && pkg->makefile) { _debug("fetch: %s/%s", pkg->repo, pkg->makefile); - repository_file_handle_t handle = repository_download_package_file(pkg->url, pkg_dir, pkg->version, pkg->makefile, pkg_dir); + repository_file_handle_t handle = repository_download_package_file(pkg->url, clib_package_get_id(pkg->author, pkg->name), pkg->version, pkg->makefile, pkg_dir); if (handle == NULL) { goto cleanup; } @@ -497,7 +482,7 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) { list_node_t *source; repository_file_handle_t *handles = malloc(pkg->src->len * sizeof(repository_file_handle_t)); while ((source = list_iterator_next(iterator))) { - handles[i] = repository_download_package_file(pkg->url, pkg_dir, pkg->version, source->val, pkg_dir); + handles[i] = repository_download_package_file(pkg->url, clib_package_get_id(pkg->author, pkg->name), pkg->version, source->val, pkg_dir); if (handles[i] == NULL) { list_iterator_destroy(iterator); @@ -507,7 +492,7 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) { } #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) - struct timespec ts = {0, 1000*1000*10}; + struct timespec ts = {0, 1000 * 1000 * 10}; nanosleep(&ts, NULL); #endif @@ -527,7 +512,8 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) { (void) pending--; #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) - usleep(1024 * 10); + struct timespec ts = {0, 1000 * 1000 * 10}; + nanosleep(&ts, NULL); #endif } } diff --git a/src/common/clib-package.c b/src/common/clib-package.c index 165f6e0b..63f402dc 100644 --- a/src/common/clib-package.c +++ b/src/common/clib-package.c @@ -549,7 +549,7 @@ clib_package_new_from_slug_with_package_name(const char *slug, const char* url, } else { _debug("Fetching package manifest for %s", slug); // clean up when retrying - res = repository_fetch_package_manifest(url, slug, version); + res = repository_fetch_package_manifest(url, clib_package_get_id(author, name), version); json = res->data; _debug("status: %d", res->status); @@ -580,10 +580,10 @@ clib_package_new_from_slug_with_package_name(const char *slug, const char* url, if (!pkg) goto error; - // force version number + // force version number if the registry returned a different version from what we expected. if (pkg->version) { if (version) { - if (0 != strcmp(version, DEFAULT_REPO_VERSION)) { + if (0 != strcmp(version, DEFAULT_REPO_VERSION) && 0 != strcmp(pkg->version, version)) { _debug("forcing version number: %s (%s)", version, pkg->version); free(pkg->version); pkg->version = version; diff --git a/src/repository/github-repository.c b/src/repository/github-repository.c index be72990f..99a578d0 100644 --- a/src/repository/github-repository.c +++ b/src/repository/github-repository.c @@ -12,24 +12,24 @@ #define GITHUB_CONTENT_URL "https://raw.githubusercontent.com/" #define GITHUB_CONTENT_URL_WITH_TOKEN "https://%s@raw.githubusercontent.com/" -char* github_repository_get_url_for_file(const char* hostname, const char* slug, const char* version, const char *file_path, const char* secret) { +char *github_repository_get_url_for_file(const char *hostname, const char *package_id, const char *version, const char *file_path, const char *secret) { - int size = strlen(GITHUB_CONTENT_URL) + strlen(slug) + 1 // / - + strlen(version) + 1 // \0 - ; + int size = strlen(GITHUB_CONTENT_URL) + strlen(package_id) + 1// / + + strlen(version) + 1 + strlen(file_path) + 1 // \0 + ; if (secret != NULL) { size += strlen(secret); - size += 1; // @ + size += 1;// @ } char *url = malloc(size); if (url) { memset(url, '\0', size); if (secret != NULL) { - sprintf(url, GITHUB_CONTENT_URL_WITH_TOKEN "%s/%s", secret, slug, version); + sprintf(url, GITHUB_CONTENT_URL_WITH_TOKEN "%s/%s/%s", secret, package_id, version, file_path); } else { - sprintf(url, GITHUB_CONTENT_URL "%s/%s", slug, version); + sprintf(url, GITHUB_CONTENT_URL "%s/%s/%s", package_id, version, file_path); } } diff --git a/src/repository/github-repository.h b/src/repository/github-repository.h index 6a996c23..93579775 100644 --- a/src/repository/github-repository.h +++ b/src/repository/github-repository.h @@ -7,6 +7,6 @@ #ifndef CLIB_SRC_REPOSITORY_GITHUB_REPOSITORY_H #define CLIB_SRC_REPOSITORY_GITHUB_REPOSITORY_H -char* github_repository_get_url_for_file(const char* hostname, const char* slug, const char* version, const char *file, const char* secret); +char* github_repository_get_url_for_file(const char* hostname, const char*package_id, const char* version, const char *file, const char* secret); #endif//CLIB_SRC_REPOSITORY_GITHUB_REPOSITORY_H diff --git a/src/repository/repository.c b/src/repository/repository.c index c922c34a..050421f6 100644 --- a/src/repository/repository.c +++ b/src/repository/repository.c @@ -68,11 +68,11 @@ void repository_init(clib_secrets_t _secrets) { secrets = _secrets; } -static char *repository_create_url_for_file(const char *package_url, const char *slug, const char *version, const char *file_path, const char *secret) { +static char *repository_create_url_for_file(const char *package_url, const char *package_id, const char *version, const char *file_path, const char *secret) { if (strstr(package_url, "github.com") != NULL) { - return github_repository_get_url_for_file(package_url, slug, version, file_path, secret); + return github_repository_get_url_for_file(package_url, package_id, version, file_path, secret); } else if (strstr(package_url, "gitlab") != NULL) { - return gitlab_repository_get_url_for_file(package_url, slug, version, file_path, secret); + return gitlab_repository_get_url_for_file(package_url, package_id, version, file_path, secret); } else { return NULL; } @@ -148,8 +148,7 @@ static int fetch_package_file_work(const char *url, const char *dir, const char pthread_mutex_lock(&mutex); #endif - // TODO, add force again. (1 == opts.force) - if (-1 == fs_exists(path)) { + if (package_opts.force || -1 == fs_exists(path)) { logger_info("fetch", "%s:%s", url, file); fflush(stdout);