|
12 | 12 | #include "common/clib-validate.h" |
13 | 13 | #include "debug/debug.h" |
14 | 14 | #include "fs/fs.h" |
15 | | -#include "http-get/http-get.h" |
16 | 15 | #include "logger/logger.h" |
17 | 16 | #include "parson/parson.h" |
18 | | -#include "str-replace/str-replace.h" |
19 | 17 | #include "version.h" |
20 | 18 | #include <clib-secrets.h> |
21 | 19 | #include <curl/curl.h> |
22 | | -#include <libgen.h> |
23 | 20 | #include <limits.h> |
24 | 21 | #include <registry-manager.h> |
25 | 22 | #include <repository.h> |
26 | 23 | #include <stdio.h> |
27 | 24 | #include <stdlib.h> |
28 | 25 | #include <string.h> |
| 26 | +#include "clib-package-installer.h" |
29 | 27 |
|
30 | 28 | #define SX(s) #s |
31 | 29 | #define S(s) SX(s) |
@@ -58,8 +56,9 @@ struct options { |
58 | 56 |
|
59 | 57 | static struct options opts = {0}; |
60 | 58 |
|
61 | | -static clib_package_opts_t package_opts = {0}; |
62 | 59 | static clib_package_t *root_package = NULL; |
| 60 | +static clib_secrets_t secrets = NULL; |
| 61 | +static registries_t registries = NULL; |
63 | 62 |
|
64 | 63 | /** |
65 | 64 | * Option setters. |
@@ -279,27 +278,18 @@ static int install_package(const char *slug) { |
279 | 278 | } |
280 | 279 | } |
281 | 280 |
|
282 | | - // Read local config files. |
283 | | - clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json"); |
284 | | - repository_init(secrets); // The repository requires the secrets for authentication. |
285 | | - clib_package_t *package = clib_package_load_local_manifest(0); |
286 | | - |
287 | | - registries_t registries = registry_manager_init_registries(package->registries, secrets); |
288 | | - registry_manager_fetch_registries(registries); |
289 | 281 | registry_package_ptr_t package_info = registry_manger_find_package(registries, slug); |
290 | 282 | if (!package_info) { |
291 | 283 | debug(&debugger, "Package %s not found in any registry.", slug); |
292 | 284 | return -1; |
293 | 285 | } |
294 | 286 |
|
295 | | - |
296 | 287 | pkg = clib_package_new_from_slug_and_url(slug, registry_package_get_href(package_info), opts.verbose); |
297 | 288 | if (NULL == pkg) |
298 | 289 | return -1; |
299 | 290 |
|
300 | 291 | if (root_package && root_package->prefix) { |
301 | 292 | package_opts.prefix = root_package->prefix; |
302 | | - clib_package_set_opts(package_opts); |
303 | 293 | } |
304 | 294 |
|
305 | 295 | rc = clib_package_install(pkg, opts.dir, opts.verbose); |
@@ -418,38 +408,34 @@ int main(int argc, char *argv[]) { |
418 | 408 | realpath(opts.prefix, prefix); |
419 | 409 | unsigned long int size = strlen(prefix) + 1; |
420 | 410 | opts.prefix = malloc(size); |
421 | | - memset((void *)opts.prefix, 0, size); |
422 | | - memcpy((void *)opts.prefix, prefix, size); |
| 411 | + memset((void *) opts.prefix, 0, size); |
| 412 | + memcpy((void *) opts.prefix, prefix, size); |
423 | 413 | } |
424 | 414 |
|
425 | 415 | clib_cache_init(CLIB_PACKAGE_CACHE_TIME); |
426 | 416 |
|
427 | | - package_opts.skip_cache = opts.skip_cache; |
428 | | - package_opts.prefix = opts.prefix; |
429 | | - package_opts.global = opts.global; |
430 | | - package_opts.force = opts.force; |
431 | | - package_opts.token = opts.token; |
| 417 | + clib_package_opts_t install_package_opts = {0}; |
| 418 | + install_package_opts.skip_cache = opts.skip_cache; |
| 419 | + install_package_opts.prefix = opts.prefix; |
| 420 | + install_package_opts.global = opts.global; |
| 421 | + install_package_opts.force = opts.force; |
| 422 | + install_package_opts.token = opts.token; |
432 | 423 |
|
433 | 424 | #ifdef HAVE_PTHREADS |
434 | | - package_opts.concurrency = opts.concurrency; |
| 425 | + install_package_opts.concurrency = opts.concurrency; |
435 | 426 | #endif |
436 | 427 |
|
437 | | - clib_package_set_opts(package_opts); |
| 428 | + clib_package_set_opts(install_package_opts); |
438 | 429 |
|
439 | | - if (!root_package) { |
440 | | - const char *name = NULL; |
441 | | - char *json = NULL; |
442 | | - unsigned int i = 0; |
| 430 | + // Read local config files. |
| 431 | + secrets = clib_secrets_load_from_file("clib_secrets.json"); |
| 432 | + root_package = clib_package_load_local_manifest(0); |
443 | 433 |
|
444 | | - do { |
445 | | - name = manifest_names[i]; |
446 | | - json = fs_read(name); |
447 | | - } while (NULL != manifest_names[++i] && !json); |
| 434 | + repository_init(secrets); // The repository requires the secrets for authentication. |
| 435 | + registries = registry_manager_init_registries(root_package->registries, secrets); |
| 436 | + registry_manager_fetch_registries(registries); |
448 | 437 |
|
449 | | - if (json) { |
450 | | - root_package = clib_package_new(json, opts.verbose); |
451 | | - } |
452 | | - } |
| 438 | + clib_package_installer_init(registries, secrets); |
453 | 439 |
|
454 | 440 | int code = 0 == program.argc ? install_local_packages() |
455 | 441 | : install_packages(program.argc, program.argv); |
|
0 commit comments