]>
Commit | Line | Data |
---|---|---|
e2faeb46 | 1 | /* |
5b2de3d8 | 2 | * be_sync.c |
23229097 | 3 | * |
6cebd4e6 DM |
4 | * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org> |
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 | |
e2faeb46 | 23 | #include <errno.h> |
e2faeb46 | 24 | #include <dirent.h> |
47622eef | 25 | #include <ctype.h> |
5e61f077 | 26 | #include <locale.h> |
869e81e1 | 27 | |
2f4ee434 XC |
28 | /* libarchive */ |
29 | #include <archive.h> | |
30 | #include <archive_entry.h> | |
31 | ||
869e81e1 | 32 | /* libalpm */ |
e2faeb46 | 33 | #include "util.h" |
5b2de3d8 | 34 | #include "log.h" |
e2faeb46 | 35 | #include "alpm.h" |
5b2de3d8 | 36 | #include "alpm_list.h" |
aa1c0ba9 | 37 | #include "package.h" |
5b2de3d8 | 38 | #include "handle.h" |
0c2cc108 | 39 | #include "delta.h" |
c244cfec | 40 | #include "deps.h" |
04600384 | 41 | #include "dload.h" |
d37ad048 | 42 | |
04600384 | 43 | /** Update a package database |
63fc9360 SN |
44 | * |
45 | * An update of the package database \a db will be attempted. Unless | |
46 | * \a force is true, the update will only be performed if the remote | |
47 | * database was modified since the last update. | |
48 | * | |
49 | * A transaction is necessary for this operation, in order to obtain a | |
50 | * database lock. During this transaction the front-end will be informed | |
51 | * of the download progress of the database via the download callback. | |
52 | * | |
53 | * Example: | |
54 | * @code | |
55 | * pmdb_t *db; | |
56 | * int result; | |
57 | * db = alpm_list_getdata(alpm_option_get_syncdbs()); | |
8ff3b870 | 58 | * if(alpm_trans_init(0, NULL, NULL, NULL) == 0) { |
63fc9360 SN |
59 | * result = alpm_db_update(0, db); |
60 | * alpm_trans_release(); | |
61 | * | |
62 | * if(result > 0) { | |
63 | * printf("Unable to update database: %s\n", alpm_strerrorlast()); | |
64 | * } else if(result < 0) { | |
65 | * printf("Database already up to date\n"); | |
66 | * } else { | |
67 | * printf("Database updated\n"); | |
68 | * } | |
69 | * } | |
70 | * @endcode | |
71 | * | |
72 | * @ingroup alpm_databases | |
73 | * @note After a successful update, the \link alpm_db_get_pkgcache() | |
74 | * package cache \endlink will be invalidated | |
04600384 DM |
75 | * @param force if true, then forces the update, otherwise update only in case |
76 | * the database isn't up to date | |
77 | * @param db pointer to the package database to update | |
78 | * @return 0 on success, > 0 on error (pm_errno is set accordingly), < 0 if up | |
79 | * to date | |
e8275fa9 | 80 | */ |
04600384 | 81 | int SYMEXPORT alpm_db_update(int force, pmdb_t *db) |
e8275fa9 | 82 | { |
149ab6b2 AM |
83 | char *dbfile, *syncpath; |
84 | const char *dbpath; | |
0966c33a | 85 | size_t len; |
04600384 DM |
86 | int ret; |
87 | ||
da648bc2 AG |
88 | ALPM_LOG_FUNC; |
89 | ||
04600384 DM |
90 | /* Sanity checks */ |
91 | ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); | |
92 | ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1)); | |
04600384 DM |
93 | |
94 | if(!alpm_list_find_ptr(handle->dbs_sync, db)) { | |
95 | RET_ERR(PM_ERR_DB_NOT_FOUND, -1); | |
96 | } | |
97 | ||
68dcabdf | 98 | len = strlen(db->treename) + 4; |
0966c33a | 99 | MALLOC(dbfile, len, RET_ERR(PM_ERR_MEMORY, -1)); |
68dcabdf | 100 | sprintf(dbfile, "%s.db", db->treename); |
0966c33a | 101 | |
04600384 | 102 | dbpath = alpm_option_get_dbpath(); |
a8355994 AM |
103 | len = strlen(dbpath) + 6; |
104 | MALLOC(syncpath, len, RET_ERR(PM_ERR_MEMORY, -1)); | |
105 | sprintf(syncpath, "%s%s", dbpath, "sync/"); | |
04600384 | 106 | |
a8355994 | 107 | ret = _alpm_download_single_file(dbfile, db->servers, syncpath, force); |
0966c33a | 108 | free(dbfile); |
a8355994 | 109 | free(syncpath); |
04600384 DM |
110 | |
111 | if(ret == 1) { | |
d2dbb04a | 112 | /* files match, do nothing */ |
04600384 DM |
113 | pm_errno = 0; |
114 | return(1); | |
115 | } else if(ret == -1) { | |
116 | /* pm_errno was set by the download code */ | |
117 | _alpm_log(PM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerrorlast()); | |
118 | return(-1); | |
2f4ee434 XC |
119 | } |
120 | ||
2f4ee434 XC |
121 | /* Cache needs to be rebuilt */ |
122 | _alpm_db_free_pkgcache(db); | |
123 | ||
04600384 | 124 | return(0); |
e8275fa9 AG |
125 | } |
126 | ||
5b2de3d8 | 127 | int _alpm_sync_db_populate(pmdb_t *db) |
e2faeb46 | 128 | { |
f6711472 | 129 | int count = 0; |
5e61f077 AM |
130 | struct archive *archive; |
131 | struct archive_entry *entry; | |
132 | const char * archive_path; | |
e2faeb46 | 133 | |
da648bc2 AG |
134 | ALPM_LOG_FUNC; |
135 | ||
f6711472 | 136 | ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); |
e2faeb46 | 137 | |
5e61f077 AM |
138 | if((archive = archive_read_new()) == NULL) |
139 | RET_ERR(PM_ERR_LIBARCHIVE, 1); | |
140 | ||
141 | archive_read_support_compression_all(archive); | |
142 | archive_read_support_format_all(archive); | |
143 | ||
144 | if(archive_read_open_filename(archive, _alpm_db_path(db), | |
145 | ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { | |
146 | _alpm_log(PM_LOG_ERROR, _("could not open %s: %s\n"), _alpm_db_path(db), | |
147 | archive_error_string(archive)); | |
148 | RET_ERR(PM_ERR_PKG_OPEN, 1); | |
14230869 | 149 | } |
5e61f077 AM |
150 | |
151 | while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) { | |
152 | const struct stat *st; | |
153 | const char *name; | |
f6711472 | 154 | pmpkg_t *pkg; |
ccc1c731 | 155 | |
5e61f077 AM |
156 | st = archive_entry_stat(entry); |
157 | ||
4a8e396a AM |
158 | if(S_ISDIR(st->st_mode)) { |
159 | archive_path = archive_entry_pathname(entry); | |
5e61f077 | 160 | |
4a8e396a AM |
161 | pkg = _alpm_pkg_new(); |
162 | if(pkg == NULL) { | |
163 | archive_read_finish(archive); | |
164 | return(-1); | |
165 | } | |
5e61f077 | 166 | |
4a8e396a | 167 | name = archive_entry_pathname(entry); |
5e61f077 | 168 | |
e464339e | 169 | if(_alpm_splitname(name, pkg) != 0) { |
4a8e396a AM |
170 | _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"), |
171 | name); | |
172 | _alpm_pkg_free(pkg); | |
173 | continue; | |
174 | } | |
7f5dada8 | 175 | |
4a8e396a AM |
176 | /* duplicated database entries are not allowed */ |
177 | if(_alpm_pkg_find(db->pkgcache, pkg->name)) { | |
178 | _alpm_log(PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name); | |
179 | _alpm_pkg_free(pkg); | |
180 | continue; | |
181 | } | |
444ff956 | 182 | |
4a8e396a AM |
183 | pkg->origin = PKG_FROM_SYNCDB; |
184 | pkg->ops = &default_pkg_ops; | |
185 | pkg->origin_data.db = db; | |
5e61f077 | 186 | |
4a8e396a AM |
187 | /* add to the collection */ |
188 | _alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n", | |
189 | pkg->name, db->treename); | |
190 | db->pkgcache = alpm_list_add(db->pkgcache, pkg); | |
191 | count++; | |
192 | } else { | |
193 | /* we have desc, depends or deltas - parse it */ | |
194 | _alpm_sync_db_read(db, archive, entry); | |
195 | } | |
e2faeb46 AF |
196 | } |
197 | ||
f6711472 | 198 | db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp); |
5e61f077 AM |
199 | archive_read_finish(archive); |
200 | ||
f6711472 | 201 | return(count); |
e2faeb46 AF |
202 | } |
203 | ||
4a8e396a | 204 | int _alpm_sync_db_read(pmdb_t *db, struct archive *archive, struct archive_entry *entry) |
e2faeb46 | 205 | { |
d896527d | 206 | char line[1024]; |
4a8e396a AM |
207 | const char *entryname; |
208 | char *filename, *pkgname, *p, *q; | |
209 | pmpkg_t *pkg; | |
e2faeb46 | 210 | |
da648bc2 AG |
211 | ALPM_LOG_FUNC; |
212 | ||
e8275fa9 AG |
213 | if(db == NULL) { |
214 | RET_ERR(PM_ERR_DB_NULL, -1); | |
215 | } | |
216 | ||
4a8e396a AM |
217 | if(entry == NULL) { |
218 | _alpm_log(PM_LOG_DEBUG, "invalid archive entry provided to _alpm_sync_db_read, skipping\n"); | |
e2faeb46 AF |
219 | return(-1); |
220 | } | |
221 | ||
4a8e396a AM |
222 | entryname = archive_entry_pathname(entry); |
223 | ||
224 | _alpm_log(PM_LOG_FUNCTION, "loading package data from archive entry %s\n", | |
225 | entryname); | |
226 | ||
227 | /* get package and db file names */ | |
228 | STRDUP(pkgname, entryname, RET_ERR(PM_ERR_MEMORY, -1)); | |
229 | p = pkgname + strlen(pkgname); | |
230 | for(q = --p; *q && *q != '/'; q--); | |
231 | STRDUP(filename, q+1, RET_ERR(PM_ERR_MEMORY, -1)); | |
232 | for(p = --q; *p && *p != '-'; p--); | |
233 | for(q = --p; *q && *q != '-'; q--); | |
234 | *q = '\0'; | |
235 | ||
236 | /* package is already in db due to parsing of directory name */ | |
237 | pkg = _alpm_pkg_find(db->pkgcache, pkgname); | |
238 | if(pkg == NULL) { | |
239 | _alpm_log(PM_LOG_DEBUG, "package %s not found in %s sync database", | |
240 | pkgname, db->treename); | |
3bf918dc AG |
241 | return(-1); |
242 | } | |
243 | ||
4a8e396a AM |
244 | if(strcmp(filename, "desc") == 0) { |
245 | while(_alpm_archive_fgets(line, sizeof(line), archive) != NULL) { | |
e2faeb46 | 246 | _alpm_strtrim(line); |
da1c11cc | 247 | if(strcmp(line, "%NAME%") == 0) { |
4a8e396a | 248 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
da1c11cc NG |
249 | goto error; |
250 | } | |
4a8e396a | 251 | if(strcmp(_alpm_strtrim(line), pkg->name) != 0) { |
da1c11cc | 252 | _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: name " |
4a8e396a | 253 | "mismatch on package %s\n"), db->treename, pkg->name); |
da1c11cc NG |
254 | } |
255 | } else if(strcmp(line, "%VERSION%") == 0) { | |
4a8e396a | 256 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
da1c11cc NG |
257 | goto error; |
258 | } | |
4a8e396a | 259 | if(strcmp(_alpm_strtrim(line), pkg->version) != 0) { |
da1c11cc | 260 | _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: version " |
4a8e396a | 261 | "mismatch on package %s\n"), db->treename, pkg->name); |
da1c11cc NG |
262 | } |
263 | } else if(strcmp(line, "%FILENAME%") == 0) { | |
4a8e396a | 264 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
986409f9 AG |
265 | goto error; |
266 | } | |
4a8e396a | 267 | STRDUP(pkg->filename, _alpm_strtrim(line), goto error); |
da1c11cc | 268 | } else if(strcmp(line, "%DESC%") == 0) { |
4a8e396a | 269 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
af48c695 AG |
270 | goto error; |
271 | } | |
4a8e396a | 272 | STRDUP(pkg->desc, _alpm_strtrim(line), goto error); |
ccc1c731 | 273 | } else if(strcmp(line, "%GROUPS%") == 0) { |
4a8e396a | 274 | while(_alpm_archive_fgets(line, sizeof(line), archive) && strlen(_alpm_strtrim(line))) { |
ccc1c731 DM |
275 | char *linedup; |
276 | STRDUP(linedup, _alpm_strtrim(line), goto error); | |
4a8e396a | 277 | pkg->groups = alpm_list_add(pkg->groups, linedup); |
e2faeb46 | 278 | } |
ccc1c731 | 279 | } else if(strcmp(line, "%URL%") == 0) { |
4a8e396a | 280 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
e2faeb46 AF |
281 | goto error; |
282 | } | |
4a8e396a | 283 | STRDUP(pkg->url, _alpm_strtrim(line), goto error); |
ccc1c731 | 284 | } else if(strcmp(line, "%LICENSE%") == 0) { |
4a8e396a AM |
285 | while(_alpm_archive_fgets(line, sizeof(line), archive) && |
286 | strlen(_alpm_strtrim(line))) { | |
ccc1c731 DM |
287 | char *linedup; |
288 | STRDUP(linedup, _alpm_strtrim(line), goto error); | |
4a8e396a | 289 | pkg->licenses = alpm_list_add(pkg->licenses, linedup); |
e2faeb46 | 290 | } |
ccc1c731 | 291 | } else if(strcmp(line, "%ARCH%") == 0) { |
4a8e396a | 292 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
e2faeb46 AF |
293 | goto error; |
294 | } | |
4a8e396a | 295 | STRDUP(pkg->arch, _alpm_strtrim(line), goto error); |
ccc1c731 | 296 | } else if(strcmp(line, "%BUILDDATE%") == 0) { |
4a8e396a | 297 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
e2faeb46 AF |
298 | goto error; |
299 | } | |
ccc1c731 | 300 | _alpm_strtrim(line); |
47622eef | 301 | |
caea098c | 302 | char first = tolower((unsigned char)line[0]); |
47622eef | 303 | if(first > 'a' && first < 'z') { |
ed848b1c | 304 | struct tm tmp_tm = {0}; /* initialize to null in case of failure */ |
e6673544 | 305 | setlocale(LC_TIME, "C"); |
ccc1c731 | 306 | strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm); |
4a8e396a | 307 | pkg->builddate = mktime(&tmp_tm); |
e6673544 | 308 | setlocale(LC_TIME, ""); |
47622eef | 309 | } else { |
4a8e396a | 310 | pkg->builddate = atol(line); |
47622eef | 311 | } |
ccc1c731 | 312 | } else if(strcmp(line, "%PACKAGER%") == 0) { |
4a8e396a | 313 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
e2faeb46 AF |
314 | goto error; |
315 | } | |
4a8e396a | 316 | STRDUP(pkg->packager, _alpm_strtrim(line), goto error); |
5b17d8f2 | 317 | } else if(strcmp(line, "%CSIZE%") == 0) { |
e2faeb46 AF |
318 | /* NOTE: the CSIZE and SIZE fields both share the "size" field |
319 | * in the pkginfo_t struct. This can be done b/c CSIZE | |
320 | * is currently only used in sync databases, and SIZE is | |
321 | * only used in local databases. | |
322 | */ | |
4a8e396a | 323 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
e2faeb46 AF |
324 | goto error; |
325 | } | |
4a8e396a | 326 | pkg->size = atol(_alpm_strtrim(line)); |
5e12d3de | 327 | /* also store this value to isize if isize is unset */ |
4a8e396a AM |
328 | if(pkg->isize == 0) { |
329 | pkg->isize = pkg->size; | |
5e12d3de | 330 | } |
ccc1c731 | 331 | } else if(strcmp(line, "%ISIZE%") == 0) { |
4a8e396a | 332 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
d37ad048 AG |
333 | goto error; |
334 | } | |
4a8e396a | 335 | pkg->isize = atol(_alpm_strtrim(line)); |
ccc1c731 | 336 | } else if(strcmp(line, "%MD5SUM%") == 0) { |
4a8e396a | 337 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { |
e2faeb46 AF |
338 | goto error; |
339 | } | |
4a8e396a | 340 | STRDUP(pkg->md5sum, _alpm_strtrim(line), goto error); |
ccc1c731 | 341 | } else if(strcmp(line, "%REPLACES%") == 0) { |
4a8e396a AM |
342 | while(_alpm_archive_fgets(line, sizeof(line), archive) && |
343 | strlen(_alpm_strtrim(line))) { | |
ccc1c731 DM |
344 | char *linedup; |
345 | STRDUP(linedup, _alpm_strtrim(line), goto error); | |
4a8e396a | 346 | pkg->replaces = alpm_list_add(pkg->replaces, linedup); |
e2faeb46 | 347 | } |
feb9889f DM |
348 | } else if(strcmp(line, "%EPOCH%") == 0) { |
349 | if(_alpm_archive_fgets(line, sizeof(line), archive) == NULL) { | |
350 | goto error; | |
351 | } | |
352 | pkg->epoch = atoi(_alpm_strtrim(line)); | |
ccc1c731 | 353 | } else if(strcmp(line, "%FORCE%") == 0) { |
feb9889f DM |
354 | /* For backward compatibility, treat force as a non-zero epoch |
355 | * but only if we didn't already have a known epoch value. */ | |
356 | if(!pkg->epoch) { | |
357 | pkg->epoch = 1; | |
358 | } | |
e2faeb46 AF |
359 | } |
360 | } | |
4a8e396a AM |
361 | } else if(strcmp(filename, "depends") == 0) { |
362 | while(_alpm_archive_fgets(line, sizeof(line), archive) != NULL) { | |
e2faeb46 | 363 | _alpm_strtrim(line); |
ccc1c731 | 364 | if(strcmp(line, "%DEPENDS%") == 0) { |
4a8e396a AM |
365 | while(_alpm_archive_fgets(line, sizeof(line), archive) && |
366 | strlen(_alpm_strtrim(line))) { | |
b2914bf0 | 367 | pmdepend_t *dep = _alpm_splitdep(_alpm_strtrim(line)); |
4a8e396a | 368 | pkg->depends = alpm_list_add(pkg->depends, dep); |
e2faeb46 | 369 | } |
ccc1c731 | 370 | } else if(strcmp(line, "%OPTDEPENDS%") == 0) { |
4a8e396a AM |
371 | while(_alpm_archive_fgets(line, sizeof(line), archive) && |
372 | strlen(_alpm_strtrim(line))) { | |
ccc1c731 DM |
373 | char *linedup; |
374 | STRDUP(linedup, _alpm_strtrim(line), goto error); | |
4a8e396a | 375 | pkg->optdepends = alpm_list_add(pkg->optdepends, linedup); |
fc0e83f0 | 376 | } |
ccc1c731 | 377 | } else if(strcmp(line, "%CONFLICTS%") == 0) { |
4a8e396a AM |
378 | while(_alpm_archive_fgets(line, sizeof(line), archive) && |
379 | strlen(_alpm_strtrim(line))) { | |
ccc1c731 DM |
380 | char *linedup; |
381 | STRDUP(linedup, _alpm_strtrim(line), goto error); | |
4a8e396a | 382 | pkg->conflicts = alpm_list_add(pkg->conflicts, linedup); |
e2faeb46 | 383 | } |
ccc1c731 | 384 | } else if(strcmp(line, "%PROVIDES%") == 0) { |
4a8e396a AM |
385 | while(_alpm_archive_fgets(line, sizeof(line), archive) && |
386 | strlen(_alpm_strtrim(line))) { | |
ccc1c731 DM |
387 | char *linedup; |
388 | STRDUP(linedup, _alpm_strtrim(line), goto error); | |
4a8e396a | 389 | pkg->provides = alpm_list_add(pkg->provides, linedup); |
e2faeb46 | 390 | } |
13e21110 | 391 | } |
e2faeb46 | 392 | } |
4a8e396a AM |
393 | } else if(strcmp(filename, "deltas") == 0) { |
394 | while(_alpm_archive_fgets(line, sizeof(line), archive) != NULL) { | |
395 | _alpm_strtrim(line); | |
ccc1c731 | 396 | if(strcmp(line, "%DELTAS%") == 0) { |
4a8e396a | 397 | while(_alpm_archive_fgets(line, sizeof(line), archive) && strlen(_alpm_strtrim(line))) { |
b99bebc0 DM |
398 | pmdelta_t *delta = _alpm_delta_parse(line); |
399 | if(delta) { | |
4a8e396a | 400 | pkg->deltas = alpm_list_add(pkg->deltas, delta); |
b99bebc0 | 401 | } |
0c2cc108 NJ |
402 | } |
403 | } | |
e2faeb46 | 404 | } |
4a8e396a AM |
405 | } else { |
406 | /* unknown database file */ | |
407 | _alpm_log(PM_LOG_DEBUG, "unknown database file: %s", filename); | |
e2faeb46 AF |
408 | } |
409 | ||
e2faeb46 | 410 | error: |
4a8e396a AM |
411 | FREE(pkgname); |
412 | FREE(filename); | |
413 | return(0); | |
e2faeb46 AF |
414 | } |
415 | ||
fc32faaa AM |
416 | struct db_operations sync_db_ops = { |
417 | .populate = _alpm_sync_db_populate, | |
418 | .unregister = _alpm_db_unregister, | |
419 | }; | |
420 | ||
421 | pmdb_t *_alpm_db_register_sync(const char *treename) | |
422 | { | |
423 | pmdb_t *db; | |
424 | alpm_list_t *i; | |
425 | ||
426 | ALPM_LOG_FUNC; | |
427 | ||
428 | for(i = handle->dbs_sync; i; i = i->next) { | |
429 | pmdb_t *sdb = i->data; | |
430 | if(strcmp(treename, sdb->treename) == 0) { | |
431 | _alpm_log(PM_LOG_DEBUG, "attempt to re-register the '%s' database, using existing\n", sdb->treename); | |
432 | return sdb; | |
433 | } | |
434 | } | |
435 | ||
436 | _alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename); | |
437 | ||
438 | db = _alpm_db_new(treename, 0); | |
439 | db->ops = &sync_db_ops; | |
440 | if(db == NULL) { | |
441 | RET_ERR(PM_ERR_DB_CREATE, NULL); | |
442 | } | |
443 | ||
444 | handle->dbs_sync = alpm_list_add(handle->dbs_sync, db); | |
445 | return(db); | |
446 | } | |
447 | ||
448 | ||
e2faeb46 | 449 | /* vim: set ts=2 sw=2 noet: */ |