]>
Commit | Line | Data |
---|---|---|
e2faeb46 | 1 | /* |
5b2de3d8 | 2 | * be_sync.c |
23229097 | 3 | * |
d2882404 | 4 | * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> |
6cebd4e6 | 5 | * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> |
23229097 | 6 | * |
e2faeb46 AF |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
9781d0d6 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e2faeb46 AF |
19 | */ |
20 | ||
21 | #include "config.h" | |
869e81e1 | 22 | |
791928dc | 23 | #include <sys/stat.h> |
869e81e1 | 24 | |
2f4ee434 XC |
25 | /* libarchive */ |
26 | #include <archive.h> | |
27 | #include <archive_entry.h> | |
28 | ||
869e81e1 | 29 | /* libalpm */ |
e2faeb46 | 30 | #include "util.h" |
5b2de3d8 | 31 | #include "log.h" |
e2faeb46 | 32 | #include "alpm.h" |
5b2de3d8 | 33 | #include "alpm_list.h" |
aa1c0ba9 | 34 | #include "package.h" |
5b2de3d8 | 35 | #include "handle.h" |
0c2cc108 | 36 | #include "delta.h" |
c244cfec | 37 | #include "deps.h" |
04600384 | 38 | #include "dload.h" |
d37ad048 | 39 | |
04600384 | 40 | /** Update a package database |
63fc9360 SN |
41 | * |
42 | * An update of the package database \a db will be attempted. Unless | |
43 | * \a force is true, the update will only be performed if the remote | |
44 | * database was modified since the last update. | |
45 | * | |
46 | * A transaction is necessary for this operation, in order to obtain a | |
47 | * database lock. During this transaction the front-end will be informed | |
48 | * of the download progress of the database via the download callback. | |
49 | * | |
50 | * Example: | |
51 | * @code | |
ed1aef7b | 52 | * alpm_list_t *syncs = alpm_option_get_syncdbs(); |
8ff3b870 | 53 | * if(alpm_trans_init(0, NULL, NULL, NULL) == 0) { |
ed1aef7b XC |
54 | * for(i = syncs; i; i = alpm_list_next(i)) { |
55 | * pmdb_t *db = alpm_list_getdata(i); | |
56 | * result = alpm_db_update(0, db); | |
57 | * alpm_trans_release(); | |
63fc9360 | 58 | * |
ed1aef7b XC |
59 | * if(result < 0) { |
60 | * printf("Unable to update database: %s\n", alpm_strerrorlast()); | |
61 | * } else if(result == 1) { | |
62 | * printf("Database already up to date\n"); | |
63 | * } else { | |
64 | * printf("Database updated\n"); | |
65 | * } | |
63fc9360 SN |
66 | * } |
67 | * } | |
68 | * @endcode | |
69 | * | |
70 | * @ingroup alpm_databases | |
71 | * @note After a successful update, the \link alpm_db_get_pkgcache() | |
72 | * package cache \endlink will be invalidated | |
04600384 DM |
73 | * @param force if true, then forces the update, otherwise update only in case |
74 | * the database isn't up to date | |
75 | * @param db pointer to the package database to update | |
ed1aef7b | 76 | * @return 0 on success, -1 on error (pm_errno is set accordingly), 1 if up to |
04600384 | 77 | * to date |
e8275fa9 | 78 | */ |
04600384 | 79 | int SYMEXPORT alpm_db_update(int force, pmdb_t *db) |
e8275fa9 | 80 | { |
149ab6b2 AM |
81 | char *dbfile, *syncpath; |
82 | const char *dbpath; | |
1ff81182 | 83 | struct stat buf; |
0966c33a | 84 | size_t len; |
04600384 | 85 | int ret; |
f6716ae9 | 86 | mode_t oldmask; |
1ff04b98 | 87 | pgp_verify_t check_sig; |
04600384 | 88 | |
da648bc2 AG |
89 | ALPM_LOG_FUNC; |
90 | ||
04600384 DM |
91 | /* Sanity checks */ |
92 | ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); | |
93 | ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1)); | |
04600384 DM |
94 | |
95 | if(!alpm_list_find_ptr(handle->dbs_sync, db)) { | |
96 | RET_ERR(PM_ERR_DB_NOT_FOUND, -1); | |
97 | } | |
98 | ||
68dcabdf | 99 | len = strlen(db->treename) + 4; |
0966c33a | 100 | MALLOC(dbfile, len, RET_ERR(PM_ERR_MEMORY, -1)); |
68dcabdf | 101 | sprintf(dbfile, "%s.db", db->treename); |
0966c33a | 102 | |
04600384 | 103 | dbpath = alpm_option_get_dbpath(); |
a8355994 AM |
104 | len = strlen(dbpath) + 6; |
105 | MALLOC(syncpath, len, RET_ERR(PM_ERR_MEMORY, -1)); | |
106 | sprintf(syncpath, "%s%s", dbpath, "sync/"); | |
04600384 | 107 | |
f6716ae9 AM |
108 | /* make sure we have a sane umask */ |
109 | oldmask = umask(0022); | |
110 | ||
1ff81182 DM |
111 | if(stat(syncpath, &buf) != 0) { |
112 | _alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n", | |
113 | syncpath); | |
114 | if(_alpm_makepath(syncpath) != 0) { | |
115 | free(dbfile); | |
116 | free(syncpath); | |
117 | RET_ERR(PM_ERR_SYSTEM, -1); | |
118 | } | |
119 | } else if(!S_ISDIR(buf.st_mode)) { | |
120 | _alpm_log(PM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath); | |
121 | if(unlink(syncpath) != 0 || _alpm_makepath(syncpath) != 0) { | |
122 | free(dbfile); | |
123 | free(syncpath); | |
124 | RET_ERR(PM_ERR_SYSTEM, -1); | |
125 | } | |
126 | } | |
127 | ||
a8355994 | 128 | ret = _alpm_download_single_file(dbfile, db->servers, syncpath, force); |
04600384 DM |
129 | |
130 | if(ret == 1) { | |
d2dbb04a | 131 | /* files match, do nothing */ |
04600384 | 132 | pm_errno = 0; |
38da050f | 133 | goto cleanup; |
04600384 DM |
134 | } else if(ret == -1) { |
135 | /* pm_errno was set by the download code */ | |
136 | _alpm_log(PM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerrorlast()); | |
38da050f AM |
137 | goto cleanup; |
138 | } | |
139 | ||
1ff04b98 DM |
140 | check_sig = _alpm_db_get_sigverify_level(db); |
141 | ||
38da050f | 142 | /* Download and check the signature of the database if needed */ |
1ff04b98 | 143 | if(check_sig != PM_PGP_VERIFY_NEVER) { |
a8b22e16 | 144 | char *sigfile, *sigfilepath; |
38da050f AM |
145 | int sigret; |
146 | ||
147 | len = strlen(dbfile) + 5; | |
148 | MALLOC(sigfile, len, RET_ERR(PM_ERR_MEMORY, -1)); | |
149 | sprintf(sigfile, "%s.sig", dbfile); | |
150 | ||
a8b22e16 AM |
151 | /* prevent old signature being used if the following download fails */ |
152 | len = strlen(syncpath) + strlen(sigfile) + 1; | |
153 | MALLOC(sigfilepath, len, RET_ERR(PM_ERR_MEMORY, -1)); | |
154 | sprintf(sigfilepath, "%s%s", syncpath, sigfile); | |
155 | _alpm_rmrf(sigfilepath); | |
156 | free(sigfilepath); | |
157 | ||
158 | sigret = _alpm_download_single_file(sigfile, db->servers, syncpath, 0); | |
38da050f AM |
159 | free(sigfile); |
160 | ||
1ff04b98 | 161 | if(sigret == -1 && check_sig == PM_PGP_VERIFY_ALWAYS) { |
38da050f AM |
162 | _alpm_log(PM_LOG_ERROR, _("Failed to download signature for db: %s\n"), |
163 | alpm_strerrorlast()); | |
164 | pm_errno = PM_ERR_SIG_INVALID; | |
165 | ret = -1; | |
166 | goto cleanup; | |
167 | } | |
168 | ||
169 | sigret = alpm_db_check_pgp_signature(db); | |
1ff04b98 DM |
170 | if((check_sig == PM_PGP_VERIFY_ALWAYS && sigret != 0) || |
171 | (check_sig == PM_PGP_VERIFY_OPTIONAL && sigret == 1)) { | |
38da050f AM |
172 | /* pm_errno was set by the checking code */ |
173 | /* TODO: should we just leave the unverified database */ | |
174 | ret = -1; | |
175 | goto cleanup; | |
176 | } | |
2f4ee434 XC |
177 | } |
178 | ||
2f4ee434 XC |
179 | /* Cache needs to be rebuilt */ |
180 | _alpm_db_free_pkgcache(db); | |
181 | ||
38da050f AM |
182 | cleanup: |
183 | ||
184 | free(dbfile); | |
185 | free(syncpath); | |
186 | umask(oldmask); | |
187 | return ret; | |
e8275fa9 AG |
188 | } |
189 | ||
94d3d665 | 190 | /* Forward decl so I don't reorganize the whole file right now */ |
3863e487 DM |
191 | static int sync_db_read(pmdb_t *db, struct archive *archive, |
192 | struct archive_entry *entry, pmpkg_t *likely_pkg); | |
94d3d665 | 193 | |
5dae577a DM |
194 | /* |
195 | * This is the data table used to generate the estimating function below. | |
196 | * "Weighted Avg" means averaging the bottom table values; thus each repo, big | |
197 | * or small, will have equal influence. "Unweighted Avg" means averaging the | |
198 | * sums of the top table columns, thus each package has equal influence. The | |
199 | * final values are calculated by (surprise) averaging the averages, because | |
200 | * why the hell not. | |
201 | * | |
202 | * Database Pkgs tar bz2 gz xz | |
203 | * community 2096 5294080 256391 421227 301296 | |
204 | * core 180 460800 25257 36850 29356 | |
205 | * extra 2606 6635520 294647 470818 339392 | |
206 | * multilib 126 327680 16120 23261 18732 | |
207 | * testing 76 204800 10902 14348 12100 | |
208 | * | |
209 | * Bytes Per Package | |
210 | * community 2096 2525.80 122.32 200.97 143.75 | |
211 | * core 180 2560.00 140.32 204.72 163.09 | |
212 | * extra 2606 2546.25 113.06 180.67 130.23 | |
213 | * multilib 126 2600.63 127.94 184.61 148.67 | |
214 | * testing 76 2694.74 143.45 188.79 159.21 | |
215 | ||
216 | * Weighted Avg 2585.48 129.42 191.95 148.99 | |
217 | * Unweighted Avg 2543.39 118.74 190.16 137.93 | |
218 | * Average of Avgs 2564.44 124.08 191.06 143.46 | |
219 | */ | |
d1cc1ef6 | 220 | static size_t estimate_package_count(struct stat *st, struct archive *archive) |
5dae577a DM |
221 | { |
222 | unsigned int per_package; | |
223 | ||
224 | switch(archive_compression(archive)) { | |
225 | case ARCHIVE_COMPRESSION_NONE: | |
226 | per_package = 2564; | |
227 | break; | |
228 | case ARCHIVE_COMPRESSION_GZIP: | |
229 | per_package = 191; | |
230 | break; | |
231 | case ARCHIVE_COMPRESSION_BZIP2: | |
232 | per_package = 124; | |
233 | break; | |
234 | case ARCHIVE_COMPRESSION_COMPRESS: | |
235 | per_package = 193; | |
236 | break; | |
237 | case ARCHIVE_COMPRESSION_LZMA: | |
238 | case ARCHIVE_COMPRESSION_XZ: | |
239 | per_package = 143; | |
240 | break; | |
c3771073 | 241 | #ifdef ARCHIVE_COMPRESSION_UU |
5dae577a DM |
242 | case ARCHIVE_COMPRESSION_UU: |
243 | per_package = 3543; | |
244 | break; | |
c3771073 | 245 | #endif |
5dae577a DM |
246 | default: |
247 | /* assume it is at least somewhat compressed */ | |
248 | per_package = 200; | |
249 | } | |
0303b26b | 250 | return (size_t)((st->st_size / per_package) + 1); |
5dae577a DM |
251 | } |
252 | ||
c00e0599 | 253 | static int sync_db_populate(pmdb_t *db) |
e2faeb46 | 254 | { |
39fd8bc3 | 255 | const char *dbpath; |
d1cc1ef6 DM |
256 | size_t est_count; |
257 | int count = 0; | |
5dae577a | 258 | struct stat buf; |
5e61f077 AM |
259 | struct archive *archive; |
260 | struct archive_entry *entry; | |
3863e487 | 261 | pmpkg_t *pkg = NULL; |
e2faeb46 | 262 | |
da648bc2 AG |
263 | ALPM_LOG_FUNC; |
264 | ||
f6711472 | 265 | ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); |
e2faeb46 | 266 | |
5e61f077 AM |
267 | if((archive = archive_read_new()) == NULL) |
268 | RET_ERR(PM_ERR_LIBARCHIVE, 1); | |
269 | ||
270 | archive_read_support_compression_all(archive); | |
271 | archive_read_support_format_all(archive); | |
272 | ||
39fd8bc3 DM |
273 | dbpath = _alpm_db_path(db); |
274 | if(!dbpath) { | |
275 | /* pm_errno set in _alpm_db_path() */ | |
276 | return 1; | |
277 | } | |
278 | ||
279 | _alpm_log(PM_LOG_DEBUG, "opening database archive %s\n", dbpath); | |
280 | ||
281 | if(archive_read_open_filename(archive, dbpath, | |
5e61f077 | 282 | ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { |
39fd8bc3 | 283 | _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath, |
5e61f077 | 284 | archive_error_string(archive)); |
fe76c353 DM |
285 | archive_read_finish(archive); |
286 | RET_ERR(PM_ERR_DB_OPEN, 1); | |
14230869 | 287 | } |
39fd8bc3 | 288 | if(stat(dbpath, &buf) != 0) { |
5dae577a DM |
289 | RET_ERR(PM_ERR_DB_OPEN, 1); |
290 | } | |
291 | est_count = estimate_package_count(&buf, archive); | |
5e61f077 | 292 | |
02108562 DM |
293 | /* initialize hash at 66% full */ |
294 | db->pkgcache = _alpm_pkghash_create(est_count * 3 / 2); | |
be9a60a3 PYH |
295 | if(db->pkgcache == NULL) { |
296 | RET_ERR(PM_ERR_MEMORY, -1); | |
297 | } | |
f8fdce6c | 298 | |
5e61f077 AM |
299 | while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) { |
300 | const struct stat *st; | |
ccc1c731 | 301 | |
5e61f077 AM |
302 | st = archive_entry_stat(entry); |
303 | ||
4a8e396a | 304 | if(S_ISDIR(st->st_mode)) { |
3863e487 DM |
305 | const char *name; |
306 | ||
4a8e396a AM |
307 | pkg = _alpm_pkg_new(); |
308 | if(pkg == NULL) { | |
309 | archive_read_finish(archive); | |
fe76c353 | 310 | RET_ERR(PM_ERR_MEMORY, -1); |
4a8e396a | 311 | } |
5e61f077 | 312 | |
4a8e396a | 313 | name = archive_entry_pathname(entry); |
5e61f077 | 314 | |
e464339e | 315 | if(_alpm_splitname(name, pkg) != 0) { |
4a8e396a AM |
316 | _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"), |
317 | name); | |
318 | _alpm_pkg_free(pkg); | |
319 | continue; | |
320 | } | |
7f5dada8 | 321 | |
4a8e396a | 322 | /* duplicated database entries are not allowed */ |
f8fdce6c | 323 | if(_alpm_pkghash_find(db->pkgcache, pkg->name)) { |
4a8e396a AM |
324 | _alpm_log(PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name); |
325 | _alpm_pkg_free(pkg); | |
326 | continue; | |
327 | } | |
444ff956 | 328 | |
4a8e396a AM |
329 | pkg->origin = PKG_FROM_SYNCDB; |
330 | pkg->ops = &default_pkg_ops; | |
331 | pkg->origin_data.db = db; | |
5e61f077 | 332 | |
4a8e396a AM |
333 | /* add to the collection */ |
334 | _alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n", | |
335 | pkg->name, db->treename); | |
f8fdce6c | 336 | db->pkgcache = _alpm_pkghash_add(db->pkgcache, pkg); |
4a8e396a AM |
337 | count++; |
338 | } else { | |
339 | /* we have desc, depends or deltas - parse it */ | |
3863e487 | 340 | sync_db_read(db, archive, entry, pkg); |
4a8e396a | 341 | } |
e2faeb46 AF |
342 | } |
343 | ||
f8fdce6c AM |
344 | if(count > 0) { |
345 | db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp); | |
346 | } | |
5e61f077 AM |
347 | archive_read_finish(archive); |
348 | ||
0303b26b | 349 | return count; |
e2faeb46 AF |
350 | } |
351 | ||
8ac7f7e6 | 352 | #define READ_NEXT(s) do { \ |
f2dff086 DM |
353 | if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) goto error; \ |
354 | s = _alpm_strtrim(buf.line); \ | |
8ac7f7e6 DM |
355 | } while(0) |
356 | ||
357 | #define READ_AND_STORE(f) do { \ | |
358 | READ_NEXT(line); \ | |
359 | STRDUP(f, line, goto error); \ | |
360 | } while(0) | |
361 | ||
362 | #define READ_AND_STORE_ALL(f) do { \ | |
363 | char *linedup; \ | |
364 | READ_NEXT(line); \ | |
365 | if(strlen(line) == 0) break; \ | |
366 | STRDUP(linedup, line, goto error); \ | |
367 | f = alpm_list_add(f, linedup); \ | |
368 | } while(1) /* note the while(1) and not (0) */ | |
369 | ||
3863e487 DM |
370 | static int sync_db_read(pmdb_t *db, struct archive *archive, |
371 | struct archive_entry *entry, pmpkg_t *likely_pkg) | |
e2faeb46 | 372 | { |
3863e487 DM |
373 | const char *entryname = NULL, *filename; |
374 | char *pkgname, *p, *q; | |
4a8e396a | 375 | pmpkg_t *pkg; |
f2dff086 | 376 | struct archive_read_buffer buf; |
e2faeb46 | 377 | |
da648bc2 AG |
378 | ALPM_LOG_FUNC; |
379 | ||
e8275fa9 AG |
380 | if(db == NULL) { |
381 | RET_ERR(PM_ERR_DB_NULL, -1); | |
382 | } | |
383 | ||
c2cce1f4 XC |
384 | if(entry != NULL) { |
385 | entryname = archive_entry_pathname(entry); | |
386 | } | |
387 | if(entryname == NULL) { | |
4a8e396a | 388 | _alpm_log(PM_LOG_DEBUG, "invalid archive entry provided to _alpm_sync_db_read, skipping\n"); |
0303b26b | 389 | return -1; |
e2faeb46 AF |
390 | } |
391 | ||
4a8e396a AM |
392 | _alpm_log(PM_LOG_FUNCTION, "loading package data from archive entry %s\n", |
393 | entryname); | |
394 | ||
f2dff086 DM |
395 | memset(&buf, 0, sizeof(buf)); |
396 | /* 512K for a line length seems reasonable */ | |
397 | buf.max_line_size = 512 * 1024; | |
398 | ||
4a8e396a AM |
399 | /* get package and db file names */ |
400 | STRDUP(pkgname, entryname, RET_ERR(PM_ERR_MEMORY, -1)); | |
401 | p = pkgname + strlen(pkgname); | |
402 | for(q = --p; *q && *q != '/'; q--); | |
3863e487 | 403 | filename = q + 1; |
4a8e396a AM |
404 | for(p = --q; *p && *p != '-'; p--); |
405 | for(q = --p; *q && *q != '-'; q--); | |
406 | *q = '\0'; | |
407 | ||
408 | /* package is already in db due to parsing of directory name */ | |
3863e487 DM |
409 | if(likely_pkg && strcmp(likely_pkg->name, pkgname) == 0) { |
410 | pkg = likely_pkg; | |
411 | } else { | |
be9a60a3 PYH |
412 | if(db->pkgcache == NULL) { |
413 | RET_ERR(PM_ERR_MEMORY, -1); | |
414 | } | |
f8fdce6c | 415 | pkg = _alpm_pkghash_find(db->pkgcache, pkgname); |
3863e487 | 416 | } |
4a8e396a AM |
417 | if(pkg == NULL) { |
418 | _alpm_log(PM_LOG_DEBUG, "package %s not found in %s sync database", | |
419 | pkgname, db->treename); | |
0303b26b | 420 | return -1; |
3bf918dc AG |
421 | } |
422 | ||
3030542d DM |
423 | if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0 |
424 | || strcmp(filename, "deltas") == 0) { | |
f2dff086 DM |
425 | while(_alpm_archive_fgets(archive, &buf) == ARCHIVE_OK) { |
426 | char *line = _alpm_strtrim(buf.line); | |
427 | ||
da1c11cc | 428 | if(strcmp(line, "%NAME%") == 0) { |
8ac7f7e6 DM |
429 | READ_NEXT(line); |
430 | if(strcmp(line, pkg->name) != 0) { | |
da1c11cc | 431 | _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: name " |
4a8e396a | 432 | "mismatch on package %s\n"), db->treename, pkg->name); |
da1c11cc NG |
433 | } |
434 | } else if(strcmp(line, "%VERSION%") == 0) { | |
8ac7f7e6 DM |
435 | READ_NEXT(line); |
436 | if(strcmp(line, pkg->version) != 0) { | |
da1c11cc | 437 | _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: version " |
4a8e396a | 438 | "mismatch on package %s\n"), db->treename, pkg->name); |
da1c11cc NG |
439 | } |
440 | } else if(strcmp(line, "%FILENAME%") == 0) { | |
8ac7f7e6 | 441 | READ_AND_STORE(pkg->filename); |
da1c11cc | 442 | } else if(strcmp(line, "%DESC%") == 0) { |
8ac7f7e6 | 443 | READ_AND_STORE(pkg->desc); |
ccc1c731 | 444 | } else if(strcmp(line, "%GROUPS%") == 0) { |
8ac7f7e6 | 445 | READ_AND_STORE_ALL(pkg->groups); |
ccc1c731 | 446 | } else if(strcmp(line, "%URL%") == 0) { |
8ac7f7e6 | 447 | READ_AND_STORE(pkg->url); |
ccc1c731 | 448 | } else if(strcmp(line, "%LICENSE%") == 0) { |
8ac7f7e6 | 449 | READ_AND_STORE_ALL(pkg->licenses); |
ccc1c731 | 450 | } else if(strcmp(line, "%ARCH%") == 0) { |
8ac7f7e6 | 451 | READ_AND_STORE(pkg->arch); |
ccc1c731 | 452 | } else if(strcmp(line, "%BUILDDATE%") == 0) { |
8ac7f7e6 | 453 | READ_NEXT(line); |
4bc6ed56 | 454 | pkg->builddate = _alpm_parsedate(line); |
ccc1c731 | 455 | } else if(strcmp(line, "%PACKAGER%") == 0) { |
8ac7f7e6 | 456 | READ_AND_STORE(pkg->packager); |
5b17d8f2 | 457 | } else if(strcmp(line, "%CSIZE%") == 0) { |
8ac7f7e6 DM |
458 | /* Note: the CSIZE and SIZE fields both share the "size" field in the |
459 | * pkginfo_t struct. This can be done b/c CSIZE is currently only used | |
460 | * in sync databases, and SIZE is only used in local databases. | |
e2faeb46 | 461 | */ |
8ac7f7e6 DM |
462 | READ_NEXT(line); |
463 | pkg->size = atol(line); | |
5e12d3de | 464 | /* also store this value to isize if isize is unset */ |
4a8e396a AM |
465 | if(pkg->isize == 0) { |
466 | pkg->isize = pkg->size; | |
5e12d3de | 467 | } |
ccc1c731 | 468 | } else if(strcmp(line, "%ISIZE%") == 0) { |
8ac7f7e6 DM |
469 | READ_NEXT(line); |
470 | pkg->isize = atol(line); | |
ccc1c731 | 471 | } else if(strcmp(line, "%MD5SUM%") == 0) { |
8ac7f7e6 | 472 | READ_AND_STORE(pkg->md5sum); |
a31d091f DM |
473 | } else if(strcmp(line, "%SHA256SUM%") == 0) { |
474 | /* we don't do anything with this value right now */ | |
475 | READ_NEXT(line); | |
39ce9b3a | 476 | } else if(strcmp(line, "%PGPSIG%") == 0) { |
442e1420 | 477 | READ_AND_STORE(pkg->pgpsig.base64_data); |
ccc1c731 | 478 | } else if(strcmp(line, "%REPLACES%") == 0) { |
8ac7f7e6 | 479 | READ_AND_STORE_ALL(pkg->replaces); |
a44c7b89 | 480 | } else if(strcmp(line, "%DEPENDS%") == 0) { |
8ac7f7e6 DM |
481 | /* Different than the rest because of the _alpm_splitdep call. */ |
482 | while(1) { | |
483 | READ_NEXT(line); | |
484 | if(strlen(line) == 0) break; | |
485 | pkg->depends = alpm_list_add(pkg->depends, _alpm_splitdep(line)); | |
e2faeb46 | 486 | } |
ccc1c731 | 487 | } else if(strcmp(line, "%OPTDEPENDS%") == 0) { |
8ac7f7e6 | 488 | READ_AND_STORE_ALL(pkg->optdepends); |
ccc1c731 | 489 | } else if(strcmp(line, "%CONFLICTS%") == 0) { |
8ac7f7e6 | 490 | READ_AND_STORE_ALL(pkg->conflicts); |
ccc1c731 | 491 | } else if(strcmp(line, "%PROVIDES%") == 0) { |
8ac7f7e6 | 492 | READ_AND_STORE_ALL(pkg->provides); |
3030542d | 493 | } else if(strcmp(line, "%DELTAS%") == 0) { |
b48f7184 | 494 | /* Different than the rest because of the _alpm_delta_parse call. */ |
495 | while(1) { | |
496 | READ_NEXT(line); | |
497 | if(strlen(line) == 0) break; | |
498 | pkg->deltas = alpm_list_add(pkg->deltas, _alpm_delta_parse(line)); | |
499 | } | |
3030542d | 500 | } |
e2faeb46 | 501 | } |
f2023176 AM |
502 | } else if(strcmp(filename, "files") == 0) { |
503 | /* currently do nothing with this file */ | |
4a8e396a | 504 | } else { |
f2023176 AM |
505 | /* unknown database file */ |
506 | _alpm_log(PM_LOG_DEBUG, "unknown database file: %s\n", filename); | |
e2faeb46 AF |
507 | } |
508 | ||
e2faeb46 | 509 | error: |
4a8e396a | 510 | FREE(pkgname); |
94d3d665 | 511 | /* TODO: return 0 always? */ |
0303b26b | 512 | return 0; |
e2faeb46 AF |
513 | } |
514 | ||
f4536980 DM |
515 | static int sync_db_version(pmdb_t *db) |
516 | { | |
0303b26b | 517 | return 2; |
f4536980 DM |
518 | } |
519 | ||
fc32faaa | 520 | struct db_operations sync_db_ops = { |
c00e0599 | 521 | .populate = sync_db_populate, |
fc32faaa | 522 | .unregister = _alpm_db_unregister, |
f4536980 | 523 | .version = sync_db_version, |
fc32faaa AM |
524 | }; |
525 | ||
526 | pmdb_t *_alpm_db_register_sync(const char *treename) | |
527 | { | |
528 | pmdb_t *db; | |
529 | alpm_list_t *i; | |
530 | ||
531 | ALPM_LOG_FUNC; | |
532 | ||
533 | for(i = handle->dbs_sync; i; i = i->next) { | |
534 | pmdb_t *sdb = i->data; | |
535 | if(strcmp(treename, sdb->treename) == 0) { | |
536 | _alpm_log(PM_LOG_DEBUG, "attempt to re-register the '%s' database, using existing\n", sdb->treename); | |
537 | return sdb; | |
538 | } | |
539 | } | |
540 | ||
541 | _alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename); | |
542 | ||
543 | db = _alpm_db_new(treename, 0); | |
fc32faaa AM |
544 | if(db == NULL) { |
545 | RET_ERR(PM_ERR_DB_CREATE, NULL); | |
546 | } | |
be9a60a3 | 547 | db->ops = &sync_db_ops; |
fc32faaa AM |
548 | |
549 | handle->dbs_sync = alpm_list_add(handle->dbs_sync, db); | |
0303b26b | 550 | return db; |
fc32faaa AM |
551 | } |
552 | ||
553 | ||
e2faeb46 | 554 | /* vim: set ts=2 sw=2 noet: */ |