|
2 | 2 | #include <string.h>
|
3 | 3 |
|
4 | 4 | #include "core/sysinfo.h"
|
| 5 | + |
5 | 6 | #include "uppm.h"
|
6 | 7 |
|
| 8 | +static int uppm_formula_repo_url_of_official_core(char buf[], const size_t bufSize) { |
| 9 | + char osType[31] = {0}; |
| 10 | + |
| 11 | + if (sysinfo_type(osType, 30) != 0) { |
| 12 | + return UPPM_ERROR; |
| 13 | + } |
| 14 | + |
| 15 | + char osArch[31] = {0}; |
| 16 | + |
| 17 | + if (sysinfo_arch(osArch, 30) != 0) { |
| 18 | + return UPPM_ERROR; |
| 19 | + } |
| 20 | + |
| 21 | + char osVers[31] = {0}; |
| 22 | + |
| 23 | + if (sysinfo_vers(osVers, 30) != 0) { |
| 24 | + return UPPM_ERROR; |
| 25 | + } |
| 26 | + |
| 27 | + int ret; |
| 28 | + |
| 29 | +#if defined (__APPLE__) |
| 30 | + int osVersMajor = 0; |
| 31 | + |
| 32 | + for (int i = 0; i < 31; i++) { |
| 33 | + if (osVers[i] == '\0') { |
| 34 | + break; |
| 35 | + } |
| 36 | + |
| 37 | + if (osVers[i] == '.') { |
| 38 | + osVers[i] = '\0'; |
| 39 | + osVersMajor = atoi(osVers); |
| 40 | + break; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + if (osVersMajor < 10) { |
| 45 | + fprintf(stderr, "MacOSX %d.x is not supported.\n", osVersMajor); |
| 46 | + return UPPM_ERROR; |
| 47 | + } |
| 48 | + |
| 49 | + if (osVersMajor > 13) { |
| 50 | + osVersMajor = 13; |
| 51 | + } |
| 52 | + |
| 53 | + ret = snprintf(buf, bufSize, "https://github.com/leleliu008/uppm-package-repository-%s-%d.0-%s", osType, osVersMajor, osArch); |
| 54 | +#elif defined (__DragonFly__) |
| 55 | + ret = snprintf(buf, bufSize, "https://github.com/leleliu008/uppm-package-repository-%s-%s-%s", osType, osVers, osArch); |
| 56 | +#elif defined (__FreeBSD__) |
| 57 | + ret = snprintf(buf, bufSize, "https://github.com/leleliu008/uppm-package-repository-%s-%s-%s", osType, osVers, osArch); |
| 58 | +#elif defined (__OpenBSD__) |
| 59 | + ret = snprintf(buf, bufSize, "https://github.com/leleliu008/uppm-package-repository-%s-%s-%s", osType, osVers, osArch); |
| 60 | +#elif defined (__NetBSD__) |
| 61 | + ret = snprintf(buf, bufSize, "https://github.com/leleliu008/uppm-package-repository-%s-%s-%s", osType, osVers, osArch); |
| 62 | +#else |
| 63 | + ret = snprintf(buf, bufSize, "https://github.com/leleliu008/uppm-formula-repository-%s-%s", osType, osArch); |
| 64 | +#endif |
| 65 | + |
| 66 | + if (ret < 0) { |
| 67 | + perror(NULL); |
| 68 | + return UPPM_ERROR; |
| 69 | + } else { |
| 70 | + return UPPM_OK; |
| 71 | + } |
| 72 | +} |
| 73 | + |
7 | 74 | int uppm_formula_repo_list_update() {
|
8 | 75 | UPPMFormulaRepoList * formulaRepoList = NULL;
|
9 | 76 |
|
10 | 77 | int ret = uppm_formula_repo_list(&formulaRepoList);
|
11 | 78 |
|
12 |
| - if (ret == UPPM_OK) { |
13 |
| - bool officialCoreIsThere = false; |
14 |
| - |
15 |
| - for (size_t i = 0; i < formulaRepoList->size; i++) { |
16 |
| - UPPMFormulaRepo * formulaRepo = formulaRepoList->repos[i]; |
| 79 | + if (ret != UPPM_OK) { |
| 80 | + return ret; |
| 81 | + } |
17 | 82 |
|
18 |
| - if (strcmp(formulaRepo->name, "official-core") == 0) { |
19 |
| - officialCoreIsThere = true; |
20 |
| - } |
| 83 | + bool officialCoreIsThere = false; |
21 | 84 |
|
22 |
| - ret = uppm_formula_repo_sync(formulaRepo); |
| 85 | + for (size_t i = 0U; i < formulaRepoList->size; i++) { |
| 86 | + UPPMFormulaRepo * formulaRepo = formulaRepoList->repos[i]; |
23 | 87 |
|
24 |
| - if (ret != UPPM_OK) { |
25 |
| - break; |
26 |
| - } |
| 88 | + if (strcmp(formulaRepo->name, "official-core") == 0) { |
| 89 | + officialCoreIsThere = true; |
27 | 90 | }
|
28 | 91 |
|
29 |
| - uppm_formula_repo_list_free(formulaRepoList); |
| 92 | + ret = uppm_formula_repo_sync(formulaRepo); |
30 | 93 |
|
31 |
| - if (!officialCoreIsThere) { |
32 |
| - char osType[31] = {0}; |
| 94 | + if (ret != UPPM_OK) { |
| 95 | + break; |
| 96 | + } |
| 97 | + } |
33 | 98 |
|
34 |
| - if (sysinfo_type(osType, 30) != 0) { |
35 |
| - return UPPM_ERROR; |
36 |
| - } |
| 99 | + uppm_formula_repo_list_free(formulaRepoList); |
37 | 100 |
|
38 |
| - char osArch[31] = {0}; |
| 101 | + if (officialCoreIsThere) { |
| 102 | + return UPPM_OK; |
| 103 | + } |
39 | 104 |
|
40 |
| - if (sysinfo_arch(osArch, 30) != 0) { |
41 |
| - return UPPM_ERROR; |
42 |
| - } |
| 105 | + char formulaRepoUrl[120]; |
43 | 106 |
|
44 |
| - size_t formulaRepoUrlLength = strlen(osType) + strlen(osArch) + 56U; |
45 |
| - char formulaRepoUrl[formulaRepoUrlLength]; |
46 |
| - snprintf(formulaRepoUrl, formulaRepoUrlLength, "https://github.com/leleliu008/uppm-formula-repository-%s-%s", osType, osArch); |
| 107 | + ret = uppm_formula_repo_url_of_official_core(formulaRepoUrl, 120); |
47 | 108 |
|
48 |
| - ret = uppm_formula_repo_add("official-core", formulaRepoUrl, "master", false, true); |
49 |
| - } |
| 109 | + if (ret != UPPM_OK) { |
| 110 | + return ret; |
50 | 111 | }
|
51 | 112 |
|
52 |
| - return ret; |
| 113 | + return uppm_formula_repo_add("official-core", formulaRepoUrl, "master", false, true); |
53 | 114 | }
|
0 commit comments