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