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