pacman-debian 7.2.0 → 7.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +22 -2
  2. package/README_zh-CN.md +89 -19
  3. package/dist/cli/paclink.d.ts.map +1 -0
  4. package/dist/cli/paclink.js +261 -0
  5. package/dist/cli/paclink.js.map +1 -0
  6. package/dist/cli/pacman.d.ts.map +1 -1
  7. package/dist/cli/pacman.js +64 -38
  8. package/dist/cli/pacman.js.map +1 -1
  9. package/dist/core/compress.d.ts.map +1 -1
  10. package/dist/core/compress.js +29 -0
  11. package/dist/core/compress.js.map +1 -1
  12. package/dist/core/deps.d.ts.map +1 -1
  13. package/dist/core/deps.js +133 -68
  14. package/dist/core/deps.js.map +1 -1
  15. package/dist/core/types.d.ts.map +1 -1
  16. package/dist/db/database.d.ts.map +1 -1
  17. package/dist/db/database.js +3 -1
  18. package/dist/db/database.js.map +1 -1
  19. package/dist/db/localdb.d.ts.map +1 -1
  20. package/dist/db/localdb.js +73 -4
  21. package/dist/db/localdb.js.map +1 -1
  22. package/dist/i18n/en.json +6 -0
  23. package/dist/i18n/index.d.ts.map +1 -1
  24. package/dist/i18n/index.js +52 -6
  25. package/dist/i18n/index.js.map +1 -1
  26. package/dist/i18n/paclink/en.d.ts.map +1 -0
  27. package/dist/i18n/paclink/en.js +62 -0
  28. package/dist/i18n/paclink/en.js.map +1 -0
  29. package/dist/i18n/paclink/zh-CN.d.ts.map +1 -0
  30. package/dist/i18n/paclink/zh-CN.js +62 -0
  31. package/dist/i18n/paclink/zh-CN.js.map +1 -0
  32. package/dist/i18n/setup/en.d.ts.map +1 -0
  33. package/dist/i18n/setup/en.js +49 -0
  34. package/dist/i18n/setup/en.js.map +1 -0
  35. package/dist/i18n/setup/zh-CN.d.ts.map +1 -0
  36. package/dist/i18n/setup/zh-CN.js +49 -0
  37. package/dist/i18n/setup/zh-CN.js.map +1 -0
  38. package/dist/i18n/zh-CN.json +6 -0
  39. package/dist/ops/install.d.ts.map +1 -1
  40. package/dist/ops/install.js +238 -45
  41. package/dist/ops/install.js.map +1 -1
  42. package/dist/ops/query.d.ts.map +1 -1
  43. package/dist/ops/query.js +25 -9
  44. package/dist/ops/query.js.map +1 -1
  45. package/dist/ops/remove.d.ts.map +1 -1
  46. package/dist/ops/remove.js +213 -42
  47. package/dist/ops/remove.js.map +1 -1
  48. package/dist/ops/upgrade.d.ts.map +1 -1
  49. package/dist/ops/upgrade.js +13 -15
  50. package/dist/ops/upgrade.js.map +1 -1
  51. package/dist/repo/repository.d.ts.map +1 -1
  52. package/dist/repo/repository.js +246 -90
  53. package/dist/repo/repository.js.map +1 -1
  54. package/dist/scripts/setup.js +119 -116
  55. package/dist/scripts/setup.js.map +1 -1
  56. package/package.json +18 -7
  57. package/README.zh.md +0 -388
  58. package/dist/ar.d.ts +0 -8
  59. package/dist/cli/pacman.d.ts +0 -2
  60. package/dist/compress.d.ts +0 -2
  61. package/dist/config.d.ts +0 -3
  62. package/dist/control.d.ts +0 -2
  63. package/dist/core/ar.d.ts +0 -7
  64. package/dist/core/compress.d.ts +0 -2
  65. package/dist/core/control.d.ts +0 -2
  66. package/dist/core/deb.d.ts +0 -4
  67. package/dist/core/deps.d.ts +0 -25
  68. package/dist/core/options.d.ts +0 -19
  69. package/dist/core/pkgfile.d.ts +0 -35
  70. package/dist/core/tar.d.ts +0 -13
  71. package/dist/core/types.d.ts +0 -83
  72. package/dist/database.d.ts +0 -20
  73. package/dist/db/database.d.ts +0 -17
  74. package/dist/db/dpkg-compat.d.ts +0 -19
  75. package/dist/db/localdb.d.ts +0 -9
  76. package/dist/db/sqlite.d.ts +0 -20
  77. package/dist/deb.d.ts +0 -5
  78. package/dist/dpkg-compat.d.ts +0 -18
  79. package/dist/i18n/index.d.ts +0 -3
  80. package/dist/index.d.ts +0 -3
  81. package/dist/install.d.ts +0 -2
  82. package/dist/makepkg/build.d.ts +0 -19
  83. package/dist/makepkg/index.d.ts +0 -3
  84. package/dist/makepkg/pkgbuild.d.ts +0 -36
  85. package/dist/ops/install.d.ts +0 -5
  86. package/dist/ops/query.d.ts +0 -9
  87. package/dist/ops/remove.d.ts +0 -3
  88. package/dist/ops/upgrade.d.ts +0 -4
  89. package/dist/pacman.d.ts +0 -2
  90. package/dist/query.d.ts +0 -5
  91. package/dist/remove.d.ts +0 -2
  92. package/dist/repo/config.d.ts +0 -3
  93. package/dist/repo/repository.d.ts +0 -10
  94. package/dist/repository.d.ts +0 -10
  95. package/dist/scripts/pacman-conf.d.ts +0 -3
  96. package/dist/scripts/setup.d.ts +0 -3
  97. package/dist/tar.d.ts +0 -17
  98. package/dist/types.d.ts +0 -80
  99. package/dist/ui/colors.d.ts +0 -13
  100. package/dist/ui/format.d.ts +0 -3
  101. package/dist/ui/progress.d.ts +0 -8
  102. package/dist/ui/prompt.d.ts +0 -4
  103. package/lib/pac4deb/Makefile +0 -26
  104. package/lib/pac4deb/README.md +0 -47
  105. package/lib/pac4deb/include/alpm.h +0 -166
  106. package/lib/pac4deb/include/alpm_list.h +0 -42
  107. package/lib/pac4deb/libalpm.so +0 -0
  108. package/lib/pac4deb/src/alpm_list.c +0 -102
  109. package/lib/pac4deb/src/genstubs.sh +0 -51
  110. package/lib/pac4deb/src/genstubs2.sh +0 -72
  111. package/lib/pac4deb/src/genstubs3.sh +0 -43
  112. package/lib/pac4deb/src/libalpm.c +0 -537
  113. package/lib/pac4deb/src/stubs_manual.c +0 -198
  114. package/lib/pac4deb/stubs.c +0 -6
  115. package/lib/pac4deb/update_header.sh +0 -15
  116. package/src/cli/pacman.ts +0 -308
  117. package/src/core/ar.ts +0 -54
  118. package/src/core/compress.ts +0 -27
  119. package/src/core/control.ts +0 -22
  120. package/src/core/deb.ts +0 -47
  121. package/src/core/deps.ts +0 -260
  122. package/src/core/options.ts +0 -20
  123. package/src/core/pkgfile.ts +0 -146
  124. package/src/core/tar.ts +0 -101
  125. package/src/core/types.ts +0 -89
  126. package/src/db/database.ts +0 -102
  127. package/src/db/dpkg-compat.ts +0 -129
  128. package/src/db/localdb.ts +0 -181
  129. package/src/i18n/en.json +0 -114
  130. package/src/i18n/index.ts +0 -32
  131. package/src/i18n/zh-CN.json +0 -114
  132. package/src/index.ts +0 -7
  133. package/src/makepkg/build.ts +0 -351
  134. package/src/makepkg/index.ts +0 -87
  135. package/src/makepkg/pkgbuild.ts +0 -146
  136. package/src/ops/install.ts +0 -260
  137. package/src/ops/query.ts +0 -117
  138. package/src/ops/remove.ts +0 -77
  139. package/src/ops/upgrade.ts +0 -87
  140. package/src/repo/config.ts +0 -96
  141. package/src/repo/repository.ts +0 -520
  142. package/src/scripts/pacman-conf.ts +0 -68
  143. package/src/scripts/setup.ts +0 -261
  144. package/src/ui/colors.ts +0 -40
  145. package/src/ui/format.ts +0 -9
  146. package/src/ui/progress.ts +0 -26
  147. package/src/ui/prompt.ts +0 -21
  148. package/tsconfig.json +0 -19
@@ -1,537 +0,0 @@
1
- /*
2
- * libalpm replacement for pacman-debian
3
- * Reads JSON databases from /var/lib/pacman-debian/
4
- */
5
- #define _GNU_SOURCE
6
- #include <stdio.h>
7
- #include <stdlib.h>
8
- #include <string.h>
9
- #include <stdarg.h>
10
- #include <sys/stat.h>
11
- #include <unistd.h>
12
- #include <fcntl.h>
13
- #include <dirent.h>
14
- #include <sys/mman.h>
15
- #include <dirent.h>
16
- #include <time.h>
17
- #include "alpm.h"
18
- #include "alpm_list.h"
19
-
20
- #define DB_DIR "/var/lib/pacman-debian"
21
- #define PKG_CACHE "/var/cache/pacman-debian/packages"
22
- #define DPKG_STATUS "/var/lib/dpkg/status"
23
-
24
- /* ---- Simple JSON scanner ---- */
25
- typedef struct { char *buf; size_t len; size_t pos; } json_ctx;
26
-
27
- static void json_init(json_ctx *j, char *buf) {
28
- j->buf = buf; j->len = strlen(buf); j->pos = 0;
29
- }
30
-
31
- static void json_skipws(json_ctx *j) {
32
- while (j->pos < j->len) {
33
- char c = j->buf[j->pos];
34
- if (c == ' ' || c == '\t' || c == '\n' || c == '\r') j->pos++;
35
- else break;
36
- }
37
- }
38
-
39
- static int json_peek(json_ctx *j) { json_skipws(j); return j->pos < j->len ? j->buf[j->pos] : 0; }
40
-
41
- static int json_next(json_ctx *j) {
42
- json_skipws(j);
43
- return j->pos < j->len ? j->buf[j->pos++] : 0;
44
- }
45
-
46
- static char *json_string(json_ctx *j) {
47
- if (json_next(j) != '"') return NULL;
48
- size_t start = j->pos;
49
- while (j->pos < j->len && j->buf[j->pos] != '"') {
50
- if (j->buf[j->pos] == '\\') j->pos++;
51
- j->pos++;
52
- }
53
- if (j->pos >= j->len) return NULL;
54
- size_t len = j->pos - start;
55
- char *s = malloc(len + 1);
56
- memcpy(s, j->buf + start, len);
57
- s[len] = 0;
58
- j->pos++; // skip closing quote
59
- return s;
60
- }
61
-
62
- static char *json_value(json_ctx *j) {
63
- json_skipws(j);
64
- if (j->pos >= j->len) return NULL;
65
- char c = j->buf[j->pos];
66
- if (c == '"') return json_string(j);
67
- // number/bool/null (read until , ] } or whitespace)
68
- size_t start = j->pos;
69
- while (j->pos < j->len) {
70
- c = j->buf[j->pos];
71
- if (c == ',' || c == ']' || c == '}' || c == ' ' || c == '\t' || c == '\n' || c == '\r') break;
72
- j->pos++;
73
- }
74
- size_t len = j->pos - start;
75
- char *s = malloc(len + 1);
76
- memcpy(s, j->buf + start, len);
77
- s[len] = 0;
78
- return s;
79
- }
80
-
81
- /* ---- Internal package struct ---- */
82
- typedef struct __alpm_pkg_internal {
83
- char *name, *version, *desc, *url, *arch, *base64_sig, *depends, *conflicts, *provides;
84
- alpm_pkgreason_t reason;
85
- alpm_pkgfrom_t origin;
86
- alpm_time_t builddate, installdate;
87
- off_t size, isize;
88
- alpm_pkgvalidation_t validation;
89
- int has_scriptlet;
90
- } pkg_internal;
91
-
92
- static pkg_internal *pkg_new(const char *name) {
93
- pkg_internal *p = calloc(1, sizeof(pkg_internal));
94
- if (p) p->name = strdup(name);
95
- return p;
96
- }
97
-
98
- static void pkg_free(pkg_internal *p) {
99
- if (!p) return;
100
- free(p->name); free(p->version); free(p->desc); free(p->url);
101
- free(p->arch); free(p->base64_sig); free(p->depends);
102
- free(p->conflicts); free(p->provides);
103
- free(p);
104
- }
105
-
106
- /* ---- Handle ---- */
107
- static alpm_db_t *db_new(const char *name, int is_local);
108
- static alpm_list_t *load_dpkg_status(const char *path);
109
- static alpm_list_t *load_localdb_dir(const char *dirpath);
110
- static int load_local_db(alpm_db_t *db);
111
- static int load_sync_db(alpm_db_t *db);
112
-
113
- struct __alpm_handle_t {
114
- char *dbpath;
115
- char *logfile;
116
- alpm_db_t *localdb;
117
- alpm_list_t *syncdbs;
118
- alpm_errno_t err;
119
- };
120
-
121
- alpm_handle_t *alpm_initialize(const char *root, const char *dbpath, alpm_errno_t *err) {
122
- (void)root;
123
- alpm_handle_t *h = calloc(1, sizeof(alpm_handle_t));
124
- if (!h) { if (err) *err = ALPM_ERR_MEMORY; return NULL; }
125
- h->dbpath = strdup(dbpath && *dbpath ? dbpath : DB_DIR);
126
- h->localdb = db_new("local", 1);
127
- load_local_db(h->localdb);
128
- h->syncdbs = NULL;
129
- h->err = ALPM_ERR_OK;
130
- if (err) *err = ALPM_ERR_OK;
131
- return h;
132
- }
133
-
134
- int alpm_release(alpm_handle_t *handle) {
135
- if (!handle) return -1;
136
- alpm_db_unregister_all(handle);
137
- free(handle->dbpath);
138
- free(handle->logfile);
139
- free(handle);
140
- return 0;
141
- }
142
-
143
- /* ---- Errors ---- */
144
- alpm_errno_t alpm_errno(alpm_handle_t *handle) { return handle ? handle->err : ALPM_ERR_HANDLE_NULL; }
145
- const char *alpm_strerror(alpm_errno_t err) {
146
- switch (err) {
147
- case ALPM_ERR_OK: return "no error";
148
- case ALPM_ERR_MEMORY: return "out of memory";
149
- case ALPM_ERR_PKG_NOT_FOUND: return "package not found";
150
- case ALPM_ERR_DB_NOT_FOUND: return "database not found";
151
- default: return "unknown error";
152
- }
153
- }
154
-
155
- /* ---- Database ---- */
156
- struct __alpm_db_t {
157
- char *treename;
158
- alpm_list_t *pkgs;
159
- int is_local;
160
- };
161
-
162
- static alpm_db_t *db_new(const char *name, int is_local) {
163
- alpm_db_t *db = calloc(1, sizeof(alpm_db_t));
164
- if (db) { db->treename = strdup(name ? name : "local"); db->is_local = is_local; }
165
- return db;
166
- }
167
-
168
- /* Parse a single flat JSON package object and return a pkg_internal */
169
- static pkg_internal *json_to_pkg(json_ctx *j) {
170
- pkg_internal *p = pkg_new("");
171
- while (json_peek(j) == '"') {
172
- char *k = json_string(j);
173
- if (!k) break;
174
- json_next(j);
175
- char *v = json_value(j);
176
- if (strcmp(k, "name") == 0 || strcmp(k, "package") == 0) { free(p->name); p->name = v; v = NULL; }
177
- else if (strcmp(k, "version") == 0) { free(p->version); p->version = v; v = NULL; }
178
- else if (strcmp(k, "description") == 0) { free(p->desc); p->desc = v; v = NULL; }
179
- else if (strcmp(k, "url") == 0 || strcmp(k, "homepage") == 0) { free(p->url); p->url = v; v = NULL; }
180
- else if (strcmp(k, "architecture") == 0 || strcmp(k, "arch") == 0) { free(p->arch); p->arch = v; v = NULL; }
181
- else if (strcmp(k, "installTime") == 0) p->installdate = atol(v ? v : "0");
182
- else if (strcmp(k, "reason") == 0) p->reason = (v && strcmp(v, "explicit") == 0) ? ALPM_PKG_REASON_EXPLICIT : ALPM_PKG_REASON_DEPEND;
183
- else if (strcmp(k, "installedSize") == 0) p->isize = atol(v ? v : "0");
184
- else if (strcmp(k, "size") == 0) p->size = atol(v ? v : "0");
185
- else if (strcmp(k, "depends") == 0) { free(p->depends); p->depends = v; v = NULL; }
186
- else if (strcmp(k, "conflicts") == 0) { free(p->conflicts); p->conflicts = v; v = NULL; }
187
- else if (strcmp(k, "provides") == 0) { free(p->provides); p->provides = v; v = NULL; }
188
- free(k); free(v);
189
- if (json_peek(j) == ',') json_next(j);
190
- }
191
- if (json_peek(j) == '}') json_next(j);
192
- return p;
193
- }
194
-
195
- /* Load JSONL file (one flat JSON object per line) */
196
- static alpm_list_t *load_jsonl_file(const char *filepath) {
197
- alpm_list_t *pkgs = NULL;
198
- int fd = open(filepath, O_RDONLY);
199
- if (fd < 0) return NULL;
200
- struct stat st;
201
- if (fstat(fd, &st) < 0) { close(fd); return NULL; }
202
- if (st.st_size == 0) { close(fd); return NULL; }
203
- char *buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
204
- close(fd);
205
- if (buf == MAP_FAILED) return NULL;
206
-
207
- char *line = buf;
208
- char *end = buf + st.st_size;
209
- while (line < end) {
210
- char *nl = memchr(line, '\n', end - line);
211
- if (nl) *nl = 0;
212
- if (*line == '{') {
213
- json_ctx j;
214
- json_init(&j, line);
215
- if (json_next(&j) == '{') {
216
- pkg_internal *p = json_to_pkg(&j);
217
- if (p->name && *(p->name)) {
218
- p->origin = ALPM_PKG_FROM_SYNCDB;
219
- pkgs = alpm_list_add(pkgs, p);
220
- } else {
221
- pkg_free(p);
222
- }
223
- }
224
- }
225
- line = nl ? nl + 1 : end;
226
- }
227
- munmap(buf, st.st_size);
228
- return pkgs;
229
- }
230
-
231
- static alpm_list_t *load_json_file(const char *filepath) {
232
- return load_jsonl_file(filepath);
233
- }
234
-
235
- /* Load packages from dpkg status file */
236
- static alpm_list_t *load_dpkg_status(const char *path) {
237
- alpm_list_t *pkgs = NULL;
238
- FILE *f = fopen(path, "r");
239
- if (!f) return NULL;
240
- fseek(f, 0, SEEK_END);
241
- long len = ftell(f);
242
- rewind(f);
243
- char *buf = malloc(len + 1);
244
- if (!buf) { fclose(f); return NULL; }
245
- int n = fread(buf, 1, len, f);
246
- buf[n] = 0;
247
- fclose(f);
248
-
249
- char *p = buf;
250
- while (p && *p) {
251
- while (*p == '\n') p++;
252
- if (!*p) break;
253
- char *end = strstr(p, "\n\n");
254
- if (end) *end = 0;
255
-
256
- char name[256] = {0}, version[256] = {0}, arch[64] = {0}, desc[1024] = {0};
257
- char depends[4096] = {0};
258
- int is_installed = 0;
259
-
260
- char *line = p;
261
- while (line && *line) {
262
- char *nl = strchr(line, '\n');
263
- if (nl) *nl = 0;
264
- if (strncmp(line, "Package: ", 9) == 0) strncpy(name, line + 9, sizeof(name) - 1);
265
- else if (strncmp(line, "Version: ", 9) == 0) strncpy(version, line + 9, sizeof(version) - 1);
266
- else if (strncmp(line, "Architecture: ", 14) == 0) strncpy(arch, line + 14, sizeof(arch) - 1);
267
- else if (strncmp(line, "Status: ", 8) == 0 && strstr(line, "install ok installed")) is_installed = 1;
268
- else if (strncmp(line, "Depends: ", 9) == 0) strncpy(depends, line + 9, sizeof(depends) - 1);
269
- else if (strncmp(line, "Description: ", 13) == 0) {
270
- strncpy(desc, line + 13, sizeof(desc) - 1);
271
- if (nl) {
272
- char *n = nl + 1;
273
- while (n && (*n == ' ' || *n == '\t')) {
274
- char *nnl = strchr(n, '\n');
275
- if (nnl) *nnl = 0;
276
- strncat(desc, " ", sizeof(desc) - strlen(desc) - 1);
277
- strncat(desc, n, sizeof(desc) - strlen(desc) - 1);
278
- n = nnl ? nnl + 1 : NULL;
279
- }
280
- }
281
- }
282
- line = nl ? nl + 1 : NULL;
283
- }
284
-
285
- if (is_installed && name[0]) {
286
- pkg_internal *pkg = pkg_new(name);
287
- pkg->version = strdup(version);
288
- pkg->arch = strdup(arch[0] ? arch : "arm64");
289
- pkg->desc = strdup(desc[0] ? desc : "");
290
- pkg->depends = strdup(depends);
291
- pkg->reason = ALPM_PKG_REASON_EXPLICIT;
292
- pkgs = alpm_list_add(pkgs, pkg);
293
- }
294
- p = end ? end + 2 : NULL;
295
- }
296
- free(buf);
297
- return pkgs;
298
- }
299
-
300
- /* Load all packages from local DB directory (each subdir has a desc file) */
301
- static alpm_list_t *load_localdb_dir(const char *dirpath) {
302
- alpm_list_t *pkgs = NULL;
303
- DIR *d = opendir(dirpath);
304
- if (!d) return NULL;
305
- struct dirent *entry;
306
- while ((entry = readdir(d)) != NULL) {
307
- if (entry->d_name[0] == '.') continue;
308
- if (strcmp(entry->d_name, "by-name") == 0) continue;
309
- char path[4096];
310
- snprintf(path, sizeof(path), "%s/%s/desc", dirpath, entry->d_name);
311
- int fd = open(path, O_RDONLY);
312
- if (fd < 0) continue;
313
- struct stat st;
314
- if (fstat(fd, &st) < 0 || st.st_size == 0) { close(fd); continue; }
315
- char *buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
316
- close(fd);
317
- if (buf == MAP_FAILED) continue;
318
- json_ctx j;
319
- json_init(&j, buf);
320
- if (json_next(&j) != '{') { munmap(buf, st.st_size); continue; }
321
- pkg_internal *p = json_to_pkg(&j);
322
- if (p->name && *(p->name)) {
323
- p->origin = ALPM_PKG_FROM_LOCALDB;
324
- pkgs = alpm_list_add(pkgs, p);
325
- } else {
326
- pkg_free(p);
327
- }
328
- munmap(buf, st.st_size);
329
- }
330
- closedir(d);
331
- return pkgs;
332
- }
333
-
334
- /* Load local database: our packages + dpkg status */
335
- static int load_local_db(alpm_db_t *db) {
336
- if (db->pkgs) return 0;
337
- char path[4096];
338
- snprintf(path, sizeof(path), "%s/local", DB_DIR);
339
- db->pkgs = load_localdb_dir(path);
340
-
341
- // Also load dpkg status for system packages
342
- char dpkg_path[4096];
343
- snprintf(dpkg_path, sizeof(dpkg_path), "%s", DPKG_STATUS);
344
- alpm_list_t *dpkg_pkgs = load_dpkg_status(dpkg_path);
345
- if (dpkg_pkgs) {
346
- if (db->pkgs) {
347
- alpm_list_t *last = alpm_list_last(db->pkgs);
348
- last->next = dpkg_pkgs;
349
- dpkg_pkgs->prev = last;
350
- } else {
351
- db->pkgs = dpkg_pkgs;
352
- }
353
- }
354
- return 0;
355
- }
356
-
357
- /* Load sync database from JSONL chunks */
358
- static alpm_list_t *load_jsonl_dir(const char *dirpath) {
359
- alpm_list_t *pkgs = NULL;
360
- DIR *dir = opendir(dirpath);
361
- if (!dir) return NULL;
362
- struct dirent *entry;
363
- while ((entry = readdir(dir)) != NULL) {
364
- if (!strstr(entry->d_name, ".jsonl")) continue;
365
- char path[4096];
366
- snprintf(path, sizeof(path), "%s/%s", dirpath, entry->d_name);
367
- alpm_list_t *chunk = load_json_file(path);
368
- // Append chunk to pkgs
369
- if (chunk) {
370
- if (pkgs) {
371
- alpm_list_t *last = alpm_list_last(pkgs);
372
- last->next = chunk;
373
- chunk->prev = last;
374
- } else {
375
- pkgs = chunk;
376
- }
377
- }
378
- }
379
- closedir(dir);
380
- return pkgs;
381
- }
382
-
383
- static int load_sync_db(alpm_db_t *db) {
384
- if (db->pkgs) return 0;
385
- char path[4096];
386
- snprintf(path, sizeof(path), "%s/%s", PKG_CACHE, db->treename);
387
- db->pkgs = load_jsonl_dir(path);
388
- return 0;
389
- }
390
-
391
- alpm_db_t *alpm_db_register_local(alpm_handle_t *handle) {
392
- if (!handle) return NULL;
393
- handle->localdb = db_new("local", 1);
394
- load_local_db(handle->localdb);
395
- return handle->localdb;
396
- }
397
-
398
- alpm_db_t *alpm_db_register_sync(alpm_handle_t *handle, const char *treename) {
399
- if (!handle || !treename) return NULL;
400
- alpm_db_t *db = db_new(treename, 0);
401
- if (!db) return NULL;
402
- load_sync_db(db);
403
- handle->syncdbs = alpm_list_add(handle->syncdbs, db);
404
- return db;
405
- }
406
-
407
- int alpm_db_unregister_all(alpm_handle_t *handle) {
408
- if (!handle) return -1;
409
- if (handle->localdb) {
410
- alpm_list_free_inner((alpm_list_t *)handle->localdb->pkgs, (void(*)(void*))pkg_free);
411
- free(handle->localdb);
412
- handle->localdb = NULL;
413
- }
414
- alpm_list_t *it;
415
- for (it = handle->syncdbs; it; it = it->next) {
416
- alpm_db_t *db = it->data;
417
- if (db) {
418
- alpm_list_free_inner((alpm_list_t *)db->pkgs, (void(*)(void*))pkg_free);
419
- free(db);
420
- }
421
- }
422
- alpm_list_free(handle->syncdbs);
423
- handle->syncdbs = NULL;
424
- return 0;
425
- }
426
-
427
- alpm_pkg_t *alpm_db_get_pkg(alpm_db_t *db, const char *name) {
428
- if (!db || !name) return NULL;
429
- if (db->is_local) load_local_db(db);
430
- else load_sync_db(db);
431
- alpm_list_t *it;
432
- for (it = db->pkgs; it; it = it->next) {
433
- pkg_internal *p = it->data;
434
- if (p && p->name && strcmp(p->name, name) == 0) return (alpm_pkg_t *)p;
435
- }
436
- return NULL;
437
- }
438
-
439
- alpm_list_t *alpm_db_get_pkgcache(alpm_db_t *db) {
440
- if (!db) return NULL;
441
- if (db->is_local) load_local_db(db);
442
- else load_sync_db(db);
443
- return db->pkgs;
444
- }
445
-
446
- int alpm_db_set_pkgreason(alpm_handle_t *handle, const char *name, alpm_pkgreason_t reason) {
447
- (void)handle; (void)name; (void)reason;
448
- return 0; // no-op for now
449
- }
450
-
451
- /* ---- Package property accessors ---- */
452
- const char *alpm_pkg_get_name(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->name : NULL; }
453
- const char *alpm_pkg_get_version(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->version : NULL; }
454
- const char *alpm_pkg_get_desc(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->desc : NULL; }
455
- const char *alpm_pkg_get_url(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->url : NULL; }
456
- const char *alpm_pkg_get_arch(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->arch : NULL; }
457
- const char *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->base64_sig : NULL; }
458
- alpm_pkgreason_t alpm_pkg_get_reason(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->reason : ALPM_PKG_REASON_DEPEND; }
459
- alpm_pkgfrom_t alpm_pkg_get_origin(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->origin : ALPM_PKG_FROM_LOCALDB; }
460
- alpm_time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg) { (void)pkg; return 0; }
461
- alpm_time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->installdate : 0; }
462
- off_t alpm_pkg_get_size(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->size : 0; }
463
- off_t alpm_pkg_get_isize(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->isize : 0; }
464
- alpm_pkgvalidation_t alpm_pkg_get_validation(alpm_pkg_t *pkg) { (void)pkg; return ALPM_PKG_VALIDATION_NONE; }
465
- int alpm_pkg_has_scriptlet(alpm_pkg_t *pkg) { return pkg ? ((pkg_internal *)pkg)->has_scriptlet : 0; }
466
- void alpm_pkg_free(alpm_pkg_t *pkg) { pkg_free((pkg_internal *)pkg); }
467
-
468
- /* ---- Options ---- */
469
- int alpm_option_add_cachedir(alpm_handle_t *handle, const char *cachedir) { (void)handle; (void)cachedir; return 0; }
470
- int alpm_option_set_logfile(alpm_handle_t *handle, const char *logfile) {
471
- if (handle) { free(handle->logfile); handle->logfile = strdup(logfile ? logfile : ""); }
472
- return 0;
473
- }
474
- int alpm_option_set_cachedirs(alpm_handle_t *handle, alpm_list_t *cachedirs) { (void)handle; (void)cachedirs; return 0; }
475
- int alpm_option_set_dbpath(alpm_handle_t *handle, const char *dbpath) {
476
- if (handle) { free(handle->dbpath); handle->dbpath = strdup(dbpath ? dbpath : DB_DIR); }
477
- return 0;
478
- }
479
- int alpm_option_set_gpgdir(alpm_handle_t *handle, const char *gpgdir) { (void)handle; (void)gpgdir; return 0; }
480
- const char *alpm_option_get_dbpath(alpm_handle_t *handle) { return handle ? handle->dbpath : DB_DIR; }
481
- alpm_db_t *alpm_option_get_localdb(alpm_handle_t *handle) { return handle ? handle->localdb : NULL; }
482
- alpm_list_t *alpm_option_get_syncdbs(alpm_handle_t *handle) { return handle ? handle->syncdbs : NULL; }
483
-
484
- /* ---- Logging ---- */
485
- int alpm_logaction(alpm_handle_t *handle, const char *fmt, ...) {
486
- (void)handle;
487
- va_list ap;
488
- va_start(ap, fmt);
489
- vfprintf(stderr, fmt, ap);
490
- va_end(ap);
491
- return 0;
492
- }
493
-
494
- /* ---- Version comparison ---- */
495
- int alpm_pkg_vercmp(const char *a, const char *b) {
496
- if (!a && !b) return 0;
497
- if (!a) return -1;
498
- if (!b) return 1;
499
- return strcmp(a, b); // simplified
500
- }
501
-
502
- /* ---- Misc ---- */
503
- const char *alpm_version(void) { return "7.1.0"; }
504
- int alpm_capabilities(void) { return ALPM_CAPABILITY_NLS; }
505
-
506
- /* ---- Go/CGO aliases used by AUR helpers ---- */
507
- alpm_db_t *alpm_register_syncdb(alpm_handle_t *handle, const char *treename, int level) {
508
- (void)level;
509
- if (!handle || !treename) return NULL;
510
- alpm_db_t *db = db_new(treename, 0);
511
- if (!db) return NULL;
512
- load_sync_db(db);
513
- handle->syncdbs = alpm_list_add(handle->syncdbs, db);
514
- return db;
515
- }
516
- alpm_db_t *alpm_get_localdb(alpm_handle_t *handle) { return alpm_option_get_localdb(handle); }
517
- alpm_list_t *alpm_get_syncdbs(alpm_handle_t *handle) { return alpm_option_get_syncdbs(handle); }
518
- int alpm_db_unregister(alpm_db_t *db) { (void)db; return 0; }
519
- const char *alpm_option_get_gpgdir(alpm_handle_t *handle) { (void)handle; return NULL; }
520
- const char *alpm_option_get_logfile(alpm_handle_t *handle) { (void)handle; return NULL; }
521
- int alpm_option_set_local_file_siglevel(alpm_handle_t *handle, int level) { (void)handle; (void)level; return 0; }
522
- int alpm_option_get_local_file_siglevel(alpm_handle_t *handle) { (void)handle; return 0; }
523
- int alpm_option_set_remote_file_siglevel(alpm_handle_t *handle, int level) { (void)handle; (void)level; return 0; }
524
- int alpm_option_get_remote_file_siglevel(alpm_handle_t *handle) { (void)handle; return 0; }
525
- int alpm_option_set_dbext(alpm_handle_t *handle, const char *ext) { (void)handle; (void)ext; return 0; }
526
- const char *alpm_option_get_dbext(alpm_handle_t *handle) { (void)handle; return NULL; }
527
- int alpm_option_set_disable_dl_timeout(alpm_handle_t *handle, int disable) { (void)handle; (void)disable; return 0; }
528
- int alpm_option_get_disable_dl_timeout(alpm_handle_t *handle) { (void)handle; return 0; }
529
- int alpm_option_set_disable_sandbox(alpm_handle_t *handle, int disable) { (void)handle; (void)disable; return 0; }
530
- int alpm_option_get_disable_sandbox(alpm_handle_t *handle) { (void)handle; return 0; }
531
- int alpm_trans_init(alpm_handle_t *handle, int flags) { (void)handle; (void)flags; return 0; }
532
- int alpm_trans_prepare(alpm_handle_t *handle) { (void)handle; return 0; }
533
- int alpm_trans_commit(alpm_handle_t *handle) { (void)handle; return 0; }
534
- int alpm_trans_release(alpm_handle_t *handle) { (void)handle; return 0; }
535
- int alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg) { (void)handle; (void)pkg; return 0; }
536
- int alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg) { (void)handle; (void)pkg; return 0; }
537
- int alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade) { (void)handle; (void)enable_downgrade; return 0; }