]>
Commit | Line | Data |
---|---|---|
e2faeb46 | 1 | /* |
d980bd40 | 2 | * be_sync.c : backend for sync databases |
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 | |
f6700d5c DM |
40 | static char *get_sync_dir(pmhandle_t *handle) |
41 | { | |
42 | const char *dbpath = alpm_option_get_dbpath(handle); | |
43 | size_t len = strlen(dbpath) + 6; | |
44 | char *syncpath; | |
45 | struct stat buf; | |
46 | ||
47 | MALLOC(syncpath, len, RET_ERR(handle, PM_ERR_MEMORY, NULL)); | |
48 | sprintf(syncpath, "%s%s", dbpath, "sync/"); | |
49 | ||
50 | if(stat(syncpath, &buf) != 0) { | |
51 | _alpm_log(handle, PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n", | |
52 | syncpath); | |
53 | if(_alpm_makepath(syncpath) != 0) { | |
54 | free(syncpath); | |
55 | RET_ERR(handle, PM_ERR_SYSTEM, NULL); | |
56 | } | |
57 | } else if(!S_ISDIR(buf.st_mode)) { | |
58 | _alpm_log(handle, PM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath); | |
59 | if(unlink(syncpath) != 0 || _alpm_makepath(syncpath) != 0) { | |
60 | free(syncpath); | |
61 | RET_ERR(handle, PM_ERR_SYSTEM, NULL); | |
62 | } | |
63 | } | |
64 | ||
65 | return syncpath; | |
66 | } | |
67 | ||
04600384 | 68 | /** Update a package database |
63fc9360 SN |
69 | * |
70 | * An update of the package database \a db will be attempted. Unless | |
71 | * \a force is true, the update will only be performed if the remote | |
72 | * database was modified since the last update. | |
73 | * | |
74 | * A transaction is necessary for this operation, in order to obtain a | |
75 | * database lock. During this transaction the front-end will be informed | |
76 | * of the download progress of the database via the download callback. | |
77 | * | |
78 | * Example: | |
79 | * @code | |
ed1aef7b | 80 | * alpm_list_t *syncs = alpm_option_get_syncdbs(); |
8ff3b870 | 81 | * if(alpm_trans_init(0, NULL, NULL, NULL) == 0) { |
ed1aef7b XC |
82 | * for(i = syncs; i; i = alpm_list_next(i)) { |
83 | * pmdb_t *db = alpm_list_getdata(i); | |
84 | * result = alpm_db_update(0, db); | |
85 | * alpm_trans_release(); | |
63fc9360 | 86 | * |
ed1aef7b XC |
87 | * if(result < 0) { |
88 | * printf("Unable to update database: %s\n", alpm_strerrorlast()); | |
89 | * } else if(result == 1) { | |
90 | * printf("Database already up to date\n"); | |
91 | * } else { | |
92 | * printf("Database updated\n"); | |
93 | * } | |
63fc9360 SN |
94 | * } |
95 | * } | |
96 | * @endcode | |
97 | * | |
98 | * @ingroup alpm_databases | |
99 | * @note After a successful update, the \link alpm_db_get_pkgcache() | |
100 | * package cache \endlink will be invalidated | |
04600384 DM |
101 | * @param force if true, then forces the update, otherwise update only in case |
102 | * the database isn't up to date | |
103 | * @param db pointer to the package database to update | |
ed1aef7b | 104 | * @return 0 on success, -1 on error (pm_errno is set accordingly), 1 if up to |
04600384 | 105 | * to date |
e8275fa9 | 106 | */ |
04600384 | 107 | int SYMEXPORT alpm_db_update(int force, pmdb_t *db) |
e8275fa9 | 108 | { |
9579879b | 109 | char *syncpath; |
9579879b | 110 | alpm_list_t *i; |
9579879b | 111 | int ret = -1; |
f6716ae9 | 112 | mode_t oldmask; |
e2aa9526 | 113 | pmhandle_t *handle; |
1ff04b98 | 114 | pgp_verify_t check_sig; |
04600384 | 115 | |
04600384 | 116 | /* Sanity checks */ |
e2aa9526 DM |
117 | ASSERT(db != NULL, return -1); |
118 | handle = db->handle; | |
ee015f08 | 119 | handle->pm_errno = 0; |
e2aa9526 DM |
120 | ASSERT(db != handle->db_local, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1)); |
121 | ASSERT(db->servers != NULL, RET_ERR(handle, PM_ERR_SERVER_NONE, -1)); | |
0966c33a | 122 | |
f6716ae9 AM |
123 | /* make sure we have a sane umask */ |
124 | oldmask = umask(0022); | |
125 | ||
f6700d5c DM |
126 | syncpath = get_sync_dir(handle); |
127 | if(!syncpath) { | |
128 | return -1; | |
1ff81182 | 129 | } |
9579879b DM |
130 | check_sig = _alpm_db_get_sigverify_level(db); |
131 | ||
132 | for(i = db->servers; i; i = i->next) { | |
133 | const char *server = i->data; | |
134 | char *fileurl; | |
135 | size_t len; | |
136 | int sig_ret = 0; | |
137 | ||
138 | /* print server + filename into a buffer (leave space for .sig) */ | |
139 | len = strlen(server) + strlen(db->treename) + 9; | |
e2aa9526 | 140 | CALLOC(fileurl, len, sizeof(char), RET_ERR(handle, PM_ERR_MEMORY, -1)); |
9579879b DM |
141 | snprintf(fileurl, len, "%s/%s.db", server, db->treename); |
142 | ||
e2aa9526 | 143 | ret = _alpm_download(handle, fileurl, syncpath, force, 0, 0); |
9579879b DM |
144 | |
145 | if(ret == 0 && (check_sig == PM_PGP_VERIFY_ALWAYS || | |
146 | check_sig == PM_PGP_VERIFY_OPTIONAL)) { | |
147 | int errors_ok = (check_sig == PM_PGP_VERIFY_OPTIONAL); | |
148 | /* if we downloaded a DB, we want the .sig from the same server */ | |
149 | snprintf(fileurl, len, "%s/%s.db.sig", server, db->treename); | |
150 | ||
e2aa9526 | 151 | sig_ret = _alpm_download(handle, fileurl, syncpath, 1, 0, errors_ok); |
9579879b DM |
152 | /* errors_ok suppresses error messages, but not the return code */ |
153 | sig_ret = errors_ok ? 0 : sig_ret; | |
154 | } | |
155 | ||
156 | FREE(fileurl); | |
157 | if(ret != -1 && sig_ret != -1) { | |
158 | break; | |
159 | } | |
160 | } | |
04600384 DM |
161 | |
162 | if(ret == 1) { | |
d2dbb04a | 163 | /* files match, do nothing */ |
e2aa9526 | 164 | handle->pm_errno = 0; |
38da050f | 165 | goto cleanup; |
04600384 DM |
166 | } else if(ret == -1) { |
167 | /* pm_errno was set by the download code */ | |
52bffd24 DM |
168 | _alpm_log(handle, PM_LOG_DEBUG, "failed to sync db: %s\n", |
169 | alpm_strerror(handle->pm_errno)); | |
38da050f AM |
170 | goto cleanup; |
171 | } | |
172 | ||
2f4ee434 XC |
173 | /* Cache needs to be rebuilt */ |
174 | _alpm_db_free_pkgcache(db); | |
175 | ||
38da050f AM |
176 | cleanup: |
177 | ||
38da050f AM |
178 | free(syncpath); |
179 | umask(oldmask); | |
180 | return ret; | |
e8275fa9 AG |
181 | } |
182 | ||
94d3d665 | 183 | /* Forward decl so I don't reorganize the whole file right now */ |
3863e487 DM |
184 | static int sync_db_read(pmdb_t *db, struct archive *archive, |
185 | struct archive_entry *entry, pmpkg_t *likely_pkg); | |
94d3d665 | 186 | |
5dae577a DM |
187 | /* |
188 | * This is the data table used to generate the estimating function below. | |
189 | * "Weighted Avg" means averaging the bottom table values; thus each repo, big | |
190 | * or small, will have equal influence. "Unweighted Avg" means averaging the | |
191 | * sums of the top table columns, thus each package has equal influence. The | |
192 | * final values are calculated by (surprise) averaging the averages, because | |
193 | * why the hell not. | |
194 | * | |
195 | * Database Pkgs tar bz2 gz xz | |
196 | * community 2096 5294080 256391 421227 301296 | |
197 | * core 180 460800 25257 36850 29356 | |
198 | * extra 2606 6635520 294647 470818 339392 | |
199 | * multilib 126 327680 16120 23261 18732 | |
200 | * testing 76 204800 10902 14348 12100 | |
201 | * | |
202 | * Bytes Per Package | |
203 | * community 2096 2525.80 122.32 200.97 143.75 | |
204 | * core 180 2560.00 140.32 204.72 163.09 | |
205 | * extra 2606 2546.25 113.06 180.67 130.23 | |
206 | * multilib 126 2600.63 127.94 184.61 148.67 | |
207 | * testing 76 2694.74 143.45 188.79 159.21 | |
208 | ||
209 | * Weighted Avg 2585.48 129.42 191.95 148.99 | |
210 | * Unweighted Avg 2543.39 118.74 190.16 137.93 | |
211 | * Average of Avgs 2564.44 124.08 191.06 143.46 | |
212 | */ | |
d1cc1ef6 | 213 | static size_t estimate_package_count(struct stat *st, struct archive *archive) |
5dae577a DM |
214 | { |
215 | unsigned int per_package; | |
216 | ||
217 | switch(archive_compression(archive)) { | |
218 | case ARCHIVE_COMPRESSION_NONE: | |
219 | per_package = 2564; | |
220 | break; | |
221 | case ARCHIVE_COMPRESSION_GZIP: | |
222 | per_package = 191; | |
223 | break; | |
224 | case ARCHIVE_COMPRESSION_BZIP2: | |
225 | per_package = 124; | |
226 | break; | |
227 | case ARCHIVE_COMPRESSION_COMPRESS: | |
228 | per_package = 193; | |
229 | break; | |
230 | case ARCHIVE_COMPRESSION_LZMA: | |
231 | case ARCHIVE_COMPRESSION_XZ: | |
232 | per_package = 143; | |
233 | break; | |
c3771073 | 234 | #ifdef ARCHIVE_COMPRESSION_UU |
5dae577a DM |
235 | case ARCHIVE_COMPRESSION_UU: |
236 | per_package = 3543; | |
237 | break; | |
c3771073 | 238 | #endif |
5dae577a DM |
239 | default: |
240 | /* assume it is at least somewhat compressed */ | |
241 | per_package = 200; | |
242 | } | |
0303b26b | 243 | return (size_t)((st->st_size / per_package) + 1); |
5dae577a DM |
244 | } |
245 | ||
c00e0599 | 246 | static int sync_db_populate(pmdb_t *db) |
e2faeb46 | 247 | { |
39fd8bc3 | 248 | const char *dbpath; |
d1cc1ef6 DM |
249 | size_t est_count; |
250 | int count = 0; | |
5dae577a | 251 | struct stat buf; |
5e61f077 AM |
252 | struct archive *archive; |
253 | struct archive_entry *entry; | |
3863e487 | 254 | pmpkg_t *pkg = NULL; |
e2faeb46 | 255 | |
b14c5477 | 256 | if((archive = archive_read_new()) == NULL) { |
e2aa9526 | 257 | RET_ERR(db->handle, PM_ERR_LIBARCHIVE, -1); |
b14c5477 | 258 | } |
5e61f077 AM |
259 | |
260 | archive_read_support_compression_all(archive); | |
261 | archive_read_support_format_all(archive); | |
262 | ||
39fd8bc3 DM |
263 | dbpath = _alpm_db_path(db); |
264 | if(!dbpath) { | |
265 | /* pm_errno set in _alpm_db_path() */ | |
b14c5477 | 266 | return -1; |
39fd8bc3 DM |
267 | } |
268 | ||
52bffd24 | 269 | _alpm_log(db->handle, PM_LOG_DEBUG, "opening database archive %s\n", dbpath); |
39fd8bc3 DM |
270 | |
271 | if(archive_read_open_filename(archive, dbpath, | |
5e61f077 | 272 | ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { |
52bffd24 | 273 | _alpm_log(db->handle, PM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath, |
5e61f077 | 274 | archive_error_string(archive)); |
fe76c353 | 275 | archive_read_finish(archive); |
e2aa9526 | 276 | RET_ERR(db->handle, PM_ERR_DB_OPEN, -1); |
14230869 | 277 | } |
39fd8bc3 | 278 | if(stat(dbpath, &buf) != 0) { |
e2aa9526 | 279 | RET_ERR(db->handle, PM_ERR_DB_OPEN, -1); |
5dae577a DM |
280 | } |
281 | est_count = estimate_package_count(&buf, archive); | |
5e61f077 | 282 | |
02108562 DM |
283 | /* initialize hash at 66% full */ |
284 | db->pkgcache = _alpm_pkghash_create(est_count * 3 / 2); | |
be9a60a3 | 285 | if(db->pkgcache == NULL) { |
e2aa9526 | 286 | RET_ERR(db->handle, PM_ERR_MEMORY, -1); |
be9a60a3 | 287 | } |
f8fdce6c | 288 | |
5e61f077 AM |
289 | while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) { |
290 | const struct stat *st; | |
ccc1c731 | 291 | |
5e61f077 AM |
292 | st = archive_entry_stat(entry); |
293 | ||
4a8e396a | 294 | if(S_ISDIR(st->st_mode)) { |
3863e487 DM |
295 | const char *name; |
296 | ||
4a8e396a AM |
297 | pkg = _alpm_pkg_new(); |
298 | if(pkg == NULL) { | |
299 | archive_read_finish(archive); | |
e2aa9526 | 300 | RET_ERR(db->handle, PM_ERR_MEMORY, -1); |
4a8e396a | 301 | } |
5e61f077 | 302 | |
4a8e396a | 303 | name = archive_entry_pathname(entry); |
5e61f077 | 304 | |
e464339e | 305 | if(_alpm_splitname(name, pkg) != 0) { |
52bffd24 | 306 | _alpm_log(db->handle, PM_LOG_ERROR, _("invalid name for database entry '%s'\n"), |
4a8e396a AM |
307 | name); |
308 | _alpm_pkg_free(pkg); | |
cc25576f | 309 | pkg = NULL; |
4a8e396a AM |
310 | continue; |
311 | } | |
7f5dada8 | 312 | |
4a8e396a | 313 | /* duplicated database entries are not allowed */ |
f8fdce6c | 314 | if(_alpm_pkghash_find(db->pkgcache, pkg->name)) { |
52bffd24 | 315 | _alpm_log(db->handle, PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name); |
4a8e396a | 316 | _alpm_pkg_free(pkg); |
cc25576f | 317 | pkg = NULL; |
4a8e396a AM |
318 | continue; |
319 | } | |
444ff956 | 320 | |
4a8e396a | 321 | pkg->origin = PKG_FROM_SYNCDB; |
4a8e396a | 322 | pkg->origin_data.db = db; |
7f98460e | 323 | pkg->ops = &default_pkg_ops; |
307a6de1 | 324 | pkg->handle = db->handle; |
5e61f077 | 325 | |
4a8e396a | 326 | /* add to the collection */ |
52bffd24 | 327 | _alpm_log(db->handle, PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n", |
4a8e396a | 328 | pkg->name, db->treename); |
f8fdce6c | 329 | db->pkgcache = _alpm_pkghash_add(db->pkgcache, pkg); |
4a8e396a AM |
330 | count++; |
331 | } else { | |
332 | /* we have desc, depends or deltas - parse it */ | |
cc25576f | 333 | if(sync_db_read(db, archive, entry, pkg) != 0) { |
52bffd24 | 334 | _alpm_log(db->handle, PM_LOG_ERROR, |
d589a7b5 DM |
335 | _("could not parse package description file '%s' from db '%s'\n"), |
336 | archive_entry_pathname(entry), db->treename); | |
cc25576f DM |
337 | continue; |
338 | } | |
4a8e396a | 339 | } |
e2faeb46 AF |
340 | } |
341 | ||
f8fdce6c AM |
342 | if(count > 0) { |
343 | db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp); | |
344 | } | |
5e61f077 | 345 | archive_read_finish(archive); |
52bffd24 | 346 | _alpm_log(db->handle, PM_LOG_DEBUG, "added %d packages to package cache for db '%s'\n", |
3045f09e | 347 | count, db->treename); |
5e61f077 | 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 | { |
e2aa9526 | 373 | const char *entryname, *filename; |
3863e487 | 374 | char *pkgname, *p, *q; |
4a8e396a | 375 | pmpkg_t *pkg; |
f2dff086 | 376 | struct archive_read_buffer buf; |
e2faeb46 | 377 | |
e2aa9526 | 378 | entryname = archive_entry_pathname(entry); |
c2cce1f4 | 379 | if(entryname == NULL) { |
52bffd24 DM |
380 | _alpm_log(db->handle, PM_LOG_DEBUG, |
381 | "invalid archive entry provided to _alpm_sync_db_read, skipping\n"); | |
0303b26b | 382 | return -1; |
e2faeb46 AF |
383 | } |
384 | ||
52bffd24 | 385 | _alpm_log(db->handle, PM_LOG_FUNCTION, "loading package data from archive entry %s\n", |
4a8e396a AM |
386 | entryname); |
387 | ||
f2dff086 DM |
388 | memset(&buf, 0, sizeof(buf)); |
389 | /* 512K for a line length seems reasonable */ | |
390 | buf.max_line_size = 512 * 1024; | |
391 | ||
4a8e396a | 392 | /* get package and db file names */ |
e2aa9526 | 393 | STRDUP(pkgname, entryname, RET_ERR(db->handle, PM_ERR_MEMORY, -1)); |
4a8e396a AM |
394 | p = pkgname + strlen(pkgname); |
395 | for(q = --p; *q && *q != '/'; q--); | |
3863e487 | 396 | filename = q + 1; |
4a8e396a AM |
397 | for(p = --q; *p && *p != '-'; p--); |
398 | for(q = --p; *q && *q != '-'; q--); | |
399 | *q = '\0'; | |
400 | ||
401 | /* package is already in db due to parsing of directory name */ | |
3863e487 DM |
402 | if(likely_pkg && strcmp(likely_pkg->name, pkgname) == 0) { |
403 | pkg = likely_pkg; | |
404 | } else { | |
be9a60a3 | 405 | if(db->pkgcache == NULL) { |
e2aa9526 | 406 | RET_ERR(db->handle, PM_ERR_MEMORY, -1); |
be9a60a3 | 407 | } |
f8fdce6c | 408 | pkg = _alpm_pkghash_find(db->pkgcache, pkgname); |
3863e487 | 409 | } |
4a8e396a | 410 | if(pkg == NULL) { |
52bffd24 | 411 | _alpm_log(db->handle, PM_LOG_DEBUG, "package %s not found in %s sync database", |
4a8e396a | 412 | pkgname, db->treename); |
0303b26b | 413 | return -1; |
3bf918dc AG |
414 | } |
415 | ||
3030542d DM |
416 | if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0 |
417 | || strcmp(filename, "deltas") == 0) { | |
cc25576f DM |
418 | int ret; |
419 | while((ret = _alpm_archive_fgets(archive, &buf)) == ARCHIVE_OK) { | |
f2dff086 DM |
420 | char *line = _alpm_strtrim(buf.line); |
421 | ||
da1c11cc | 422 | if(strcmp(line, "%NAME%") == 0) { |
8ac7f7e6 DM |
423 | READ_NEXT(line); |
424 | if(strcmp(line, pkg->name) != 0) { | |
52bffd24 | 425 | _alpm_log(db->handle, PM_LOG_ERROR, _("%s database is inconsistent: name " |
4a8e396a | 426 | "mismatch on package %s\n"), db->treename, pkg->name); |
da1c11cc NG |
427 | } |
428 | } else if(strcmp(line, "%VERSION%") == 0) { | |
8ac7f7e6 DM |
429 | READ_NEXT(line); |
430 | if(strcmp(line, pkg->version) != 0) { | |
52bffd24 | 431 | _alpm_log(db->handle, PM_LOG_ERROR, _("%s database is inconsistent: version " |
4a8e396a | 432 | "mismatch on package %s\n"), db->treename, pkg->name); |
da1c11cc NG |
433 | } |
434 | } else if(strcmp(line, "%FILENAME%") == 0) { | |
8ac7f7e6 | 435 | READ_AND_STORE(pkg->filename); |
da1c11cc | 436 | } else if(strcmp(line, "%DESC%") == 0) { |
8ac7f7e6 | 437 | READ_AND_STORE(pkg->desc); |
ccc1c731 | 438 | } else if(strcmp(line, "%GROUPS%") == 0) { |
8ac7f7e6 | 439 | READ_AND_STORE_ALL(pkg->groups); |
ccc1c731 | 440 | } else if(strcmp(line, "%URL%") == 0) { |
8ac7f7e6 | 441 | READ_AND_STORE(pkg->url); |
ccc1c731 | 442 | } else if(strcmp(line, "%LICENSE%") == 0) { |
8ac7f7e6 | 443 | READ_AND_STORE_ALL(pkg->licenses); |
ccc1c731 | 444 | } else if(strcmp(line, "%ARCH%") == 0) { |
8ac7f7e6 | 445 | READ_AND_STORE(pkg->arch); |
ccc1c731 | 446 | } else if(strcmp(line, "%BUILDDATE%") == 0) { |
8ac7f7e6 | 447 | READ_NEXT(line); |
4bc6ed56 | 448 | pkg->builddate = _alpm_parsedate(line); |
ccc1c731 | 449 | } else if(strcmp(line, "%PACKAGER%") == 0) { |
8ac7f7e6 | 450 | READ_AND_STORE(pkg->packager); |
5b17d8f2 | 451 | } else if(strcmp(line, "%CSIZE%") == 0) { |
8ac7f7e6 DM |
452 | /* Note: the CSIZE and SIZE fields both share the "size" field in the |
453 | * pkginfo_t struct. This can be done b/c CSIZE is currently only used | |
454 | * in sync databases, and SIZE is only used in local databases. | |
e2faeb46 | 455 | */ |
8ac7f7e6 DM |
456 | READ_NEXT(line); |
457 | pkg->size = atol(line); | |
5e12d3de | 458 | /* also store this value to isize if isize is unset */ |
4a8e396a AM |
459 | if(pkg->isize == 0) { |
460 | pkg->isize = pkg->size; | |
5e12d3de | 461 | } |
ccc1c731 | 462 | } else if(strcmp(line, "%ISIZE%") == 0) { |
8ac7f7e6 DM |
463 | READ_NEXT(line); |
464 | pkg->isize = atol(line); | |
ccc1c731 | 465 | } else if(strcmp(line, "%MD5SUM%") == 0) { |
8ac7f7e6 | 466 | READ_AND_STORE(pkg->md5sum); |
a31d091f DM |
467 | } else if(strcmp(line, "%SHA256SUM%") == 0) { |
468 | /* we don't do anything with this value right now */ | |
469 | READ_NEXT(line); | |
39ce9b3a | 470 | } else if(strcmp(line, "%PGPSIG%") == 0) { |
225acbbf | 471 | READ_AND_STORE(pkg->base64_sig); |
ccc1c731 | 472 | } else if(strcmp(line, "%REPLACES%") == 0) { |
8ac7f7e6 | 473 | READ_AND_STORE_ALL(pkg->replaces); |
a44c7b89 | 474 | } else if(strcmp(line, "%DEPENDS%") == 0) { |
8ac7f7e6 DM |
475 | /* Different than the rest because of the _alpm_splitdep call. */ |
476 | while(1) { | |
477 | READ_NEXT(line); | |
478 | if(strlen(line) == 0) break; | |
479 | pkg->depends = alpm_list_add(pkg->depends, _alpm_splitdep(line)); | |
e2faeb46 | 480 | } |
ccc1c731 | 481 | } else if(strcmp(line, "%OPTDEPENDS%") == 0) { |
8ac7f7e6 | 482 | READ_AND_STORE_ALL(pkg->optdepends); |
ccc1c731 | 483 | } else if(strcmp(line, "%CONFLICTS%") == 0) { |
8ac7f7e6 | 484 | READ_AND_STORE_ALL(pkg->conflicts); |
ccc1c731 | 485 | } else if(strcmp(line, "%PROVIDES%") == 0) { |
8ac7f7e6 | 486 | READ_AND_STORE_ALL(pkg->provides); |
3030542d | 487 | } else if(strcmp(line, "%DELTAS%") == 0) { |
b48f7184 | 488 | /* Different than the rest because of the _alpm_delta_parse call. */ |
489 | while(1) { | |
490 | READ_NEXT(line); | |
491 | if(strlen(line) == 0) break; | |
492 | pkg->deltas = alpm_list_add(pkg->deltas, _alpm_delta_parse(line)); | |
493 | } | |
3030542d | 494 | } |
e2faeb46 | 495 | } |
cc25576f DM |
496 | if(ret != ARCHIVE_EOF) { |
497 | goto error; | |
498 | } | |
f2023176 AM |
499 | } else if(strcmp(filename, "files") == 0) { |
500 | /* currently do nothing with this file */ | |
4a8e396a | 501 | } else { |
f2023176 | 502 | /* unknown database file */ |
52bffd24 | 503 | _alpm_log(db->handle, PM_LOG_DEBUG, "unknown database file: %s\n", filename); |
e2faeb46 AF |
504 | } |
505 | ||
2668782d | 506 | FREE(pkgname); |
cc25576f DM |
507 | return 0; |
508 | ||
e2faeb46 | 509 | error: |
52bffd24 | 510 | _alpm_log(db->handle, PM_LOG_DEBUG, "error parsing database file: %s\n", filename); |
4a8e396a | 511 | FREE(pkgname); |
cc25576f | 512 | return -1; |
e2faeb46 AF |
513 | } |
514 | ||
7680f461 | 515 | static int sync_db_version(pmdb_t UNUSED *db) |
f4536980 | 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 | ||
307a6de1 | 526 | pmdb_t *_alpm_db_register_sync(pmhandle_t *handle, const char *treename) |
fc32faaa AM |
527 | { |
528 | pmdb_t *db; | |
fc32faaa | 529 | |
52bffd24 | 530 | _alpm_log(handle, PM_LOG_DEBUG, "registering sync database '%s'\n", treename); |
fc32faaa AM |
531 | |
532 | db = _alpm_db_new(treename, 0); | |
fc32faaa | 533 | if(db == NULL) { |
e2aa9526 | 534 | RET_ERR(handle, PM_ERR_DB_CREATE, NULL); |
fc32faaa | 535 | } |
be9a60a3 | 536 | db->ops = &sync_db_ops; |
c47d25d7 | 537 | db->handle = handle; |
fc32faaa AM |
538 | |
539 | handle->dbs_sync = alpm_list_add(handle->dbs_sync, db); | |
0303b26b | 540 | return db; |
fc32faaa AM |
541 | } |
542 | ||
543 | ||
e2faeb46 | 544 | /* vim: set ts=2 sw=2 noet: */ |