From f0ab0156696d16374ecd3aae7c3914bbcf1546c7 Mon Sep 17 00:00:00 2001 From: Elbert van de Put Date: Sat, 27 Mar 2021 23:09:24 +0100 Subject: [PATCH] misc: Apply suggestions from code review Co-authored-by: Bruno Dias --- src/clib-install.c | 2 +- src/common/clib-package-installer.c | 2 +- src/registry/github-registry.c | 5 +++-- src/registry/registry-manager.c | 2 +- src/registry/registry-manager.h | 2 +- src/repository/gitlab-repository.c | 4 +++- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/clib-install.c b/src/clib-install.c index db16a696..1146b228 100644 --- a/src/clib-install.c +++ b/src/clib-install.c @@ -281,7 +281,7 @@ static int install_package(const char *slug) { char* author = clib_package_parse_author(slug); char* name = clib_package_parse_name(slug); char* package_id = clib_package_get_id(author, name); - registry_package_ptr_t package_info = registry_manger_find_package(registries, package_id); + registry_package_ptr_t package_info = registry_manager_find_package(registries, package_id); if (!package_info) { debug(&debugger, "Package %s not found in any registry.", slug); return -1; diff --git a/src/common/clib-package-installer.c b/src/common/clib-package-installer.c index 5d879d53..b696c132 100644 --- a/src/common/clib-package-installer.c +++ b/src/common/clib-package-installer.c @@ -88,7 +88,7 @@ static inline int install_packages(list_t *list, const char *dir, int verbose) { if (NULL == slug) goto loop_cleanup; - registry_package_ptr_t package_info = registry_manger_find_package(registries, package_id); + registry_package_ptr_t package_info = registry_manager_find_package(registries, package_id); if (!package_info) { debug(&_debugger, "Package %s not found in any registry.", slug); return -1; diff --git a/src/registry/github-registry.c b/src/registry/github-registry.c index eb431f7a..305d45ed 100644 --- a/src/registry/github-registry.c +++ b/src/registry/github-registry.c @@ -18,6 +18,8 @@ #include #include +#define GITHUB_BASE_URL "https://github.com/" + /** * Add `href` to the given `package`. */ @@ -25,7 +27,7 @@ static void add_package_href(registry_package_ptr_t self) { size_t len = strlen(self->id) + 20; // https://github.com/ \0 self->href = malloc(len); if (self->href) - sprintf(self->href, "https://github.com/%s", self->id); + sprintf(self->href, GITHUB_BASE_URL "%s", self->id); } /** @@ -129,4 +131,3 @@ list_t *github_registry_fetch(const char *url) { http_get_free(res); return list; } - diff --git a/src/registry/registry-manager.c b/src/registry/registry-manager.c index 455a528e..eb6163e2 100644 --- a/src/registry/registry-manager.c +++ b/src/registry/registry-manager.c @@ -48,7 +48,7 @@ void registry_manager_fetch_registries(registries_t registries) { registry_iterator_destroy(it); } -registry_package_ptr_t registry_manger_find_package(registries_t registries, const char* package_id) { +registry_package_ptr_t registry_manager_find_package(registries_t registries, const char* package_id) { registry_iterator_t it = registry_iterator_new(registries); registry_ptr_t reg; while ((reg = registry_iterator_next(it))) { diff --git a/src/registry/registry-manager.h b/src/registry/registry-manager.h index f717ca25..4eaa8962 100644 --- a/src/registry/registry-manager.h +++ b/src/registry/registry-manager.h @@ -39,6 +39,6 @@ void registry_iterator_destroy(registry_iterator_t iterator); * @param package_id the identifier of the package "/" * @return a pointer to the package if it could be found or NULL */ -registry_package_ptr_t registry_manger_find_package(registries_t registries, const char* package_id); +registry_package_ptr_t registry_manager_find_package(registries_t registries, const char* package_id); #endif//CLIB_SRC_REGISTRY_REGISTRY_MANAGER_H diff --git a/src/repository/gitlab-repository.c b/src/repository/gitlab-repository.c index fba873cc..0b272f0b 100644 --- a/src/repository/gitlab-repository.c +++ b/src/repository/gitlab-repository.c @@ -10,6 +10,8 @@ #include #include +#define GITLAB_API_V4_URL "https://%s/api/v4%s/repository/files/%s/raw?ref=master" + // GET :hostname/api/v4/projects/:id/repository/files/:file_path/raw char* gitlab_repository_get_url_for_file(const char*package_url, const char* slug, const char* version, const char *file, const char* secret) { url_data_t *parsed = url_parse(package_url); @@ -17,7 +19,7 @@ char* gitlab_repository_get_url_for_file(const char*package_url, const char* slu int size = strlen(parsed->hostname) + strlen(parsed->pathname) + strlen(file) + 64; char *url = malloc(size); if (url) { - snprintf(url, size, "https://%s/api/v4%s/repository/files/%s/raw?ref=master", parsed->hostname, parsed->pathname, file); + snprintf(url, size, GITLAB_API_V4_URL, parsed->hostname, parsed->pathname, file); } url_free(parsed);