2 * be_local.c : backend for the local database
4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
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.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include <stdint.h> /* intmax_t */
32 #include <limits.h> /* PATH_MAX */
36 #include "alpm_list.h"
44 #define LAZY_LOAD(info, errret) \
46 if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
47 _alpm_local_db_read(pkg->origin_data.db, pkg, info); \
52 /* Cache-specific accessor functions. These implementations allow for lazy
53 * loading by the files backend when a data member is actually needed
54 * rather than loading all pieces of information when the package is first
58 static const char *_cache_get_filename(pmpkg_t
*pkg
)
60 LAZY_LOAD(INFRQ_DESC
, NULL
);
64 static const char *_cache_get_desc(pmpkg_t
*pkg
)
66 LAZY_LOAD(INFRQ_DESC
, NULL
);
70 static const char *_cache_get_url(pmpkg_t
*pkg
)
72 LAZY_LOAD(INFRQ_DESC
, NULL
);
76 static time_t _cache_get_builddate(pmpkg_t
*pkg
)
78 LAZY_LOAD(INFRQ_DESC
, 0);
79 return pkg
->builddate
;
82 static time_t _cache_get_installdate(pmpkg_t
*pkg
)
84 LAZY_LOAD(INFRQ_DESC
, 0);
85 return pkg
->installdate
;
88 static const char *_cache_get_packager(pmpkg_t
*pkg
)
90 LAZY_LOAD(INFRQ_DESC
, NULL
);
94 static const char *_cache_get_md5sum(pmpkg_t
*pkg
)
96 LAZY_LOAD(INFRQ_DESC
, NULL
);
100 static const char *_cache_get_arch(pmpkg_t
*pkg
)
102 LAZY_LOAD(INFRQ_DESC
, NULL
);
106 static off_t
_cache_get_size(pmpkg_t
*pkg
)
108 LAZY_LOAD(INFRQ_DESC
, -1);
112 static off_t
_cache_get_isize(pmpkg_t
*pkg
)
114 LAZY_LOAD(INFRQ_DESC
, -1);
118 static pmpkgreason_t
_cache_get_reason(pmpkg_t
*pkg
)
120 LAZY_LOAD(INFRQ_DESC
, -1);
124 static alpm_list_t
*_cache_get_licenses(pmpkg_t
*pkg
)
126 LAZY_LOAD(INFRQ_DESC
, NULL
);
127 return pkg
->licenses
;
130 static alpm_list_t
*_cache_get_groups(pmpkg_t
*pkg
)
132 LAZY_LOAD(INFRQ_DESC
, NULL
);
136 static int _cache_has_scriptlet(pmpkg_t
*pkg
)
138 if(!(pkg
->infolevel
& INFRQ_SCRIPTLET
)) {
139 _alpm_local_db_read(pkg
->origin_data
.db
, pkg
, INFRQ_SCRIPTLET
);
141 return pkg
->scriptlet
;
144 static alpm_list_t
*_cache_get_depends(pmpkg_t
*pkg
)
146 LAZY_LOAD(INFRQ_DESC
, NULL
);
150 static alpm_list_t
*_cache_get_optdepends(pmpkg_t
*pkg
)
152 LAZY_LOAD(INFRQ_DESC
, NULL
);
153 return pkg
->optdepends
;
156 static alpm_list_t
*_cache_get_conflicts(pmpkg_t
*pkg
)
158 LAZY_LOAD(INFRQ_DESC
, NULL
);
159 return pkg
->conflicts
;
162 static alpm_list_t
*_cache_get_provides(pmpkg_t
*pkg
)
164 LAZY_LOAD(INFRQ_DESC
, NULL
);
165 return pkg
->provides
;
168 static alpm_list_t
*_cache_get_replaces(pmpkg_t
*pkg
)
170 LAZY_LOAD(INFRQ_DESC
, NULL
);
171 return pkg
->replaces
;
174 /* local packages can not have deltas */
175 static alpm_list_t
*_cache_get_deltas(pmpkg_t UNUSED
*pkg
)
180 static alpm_list_t
*_cache_get_files(pmpkg_t
*pkg
)
182 if(pkg
->origin
== PKG_FROM_LOCALDB
183 && !(pkg
->infolevel
& INFRQ_FILES
)) {
184 _alpm_local_db_read(pkg
->origin_data
.db
, pkg
, INFRQ_FILES
);
189 static alpm_list_t
*_cache_get_backup(pmpkg_t
*pkg
)
191 if(pkg
->origin
== PKG_FROM_LOCALDB
192 && !(pkg
->infolevel
& INFRQ_FILES
)) {
193 _alpm_local_db_read(pkg
->origin_data
.db
, pkg
, INFRQ_FILES
);
199 * Open a package changelog for reading. Similar to fopen in functionality,
200 * except that the returned 'file stream' is from the database.
201 * @param pkg the package (from db) to read the changelog
202 * @return a 'file stream' to the package changelog
204 static void *_cache_changelog_open(pmpkg_t
*pkg
)
206 char clfile
[PATH_MAX
];
207 snprintf(clfile
, PATH_MAX
, "%s/%s/%s-%s/changelog",
208 alpm_option_get_dbpath(pkg
->handle
),
209 alpm_db_get_name(alpm_pkg_get_db(pkg
)),
210 alpm_pkg_get_name(pkg
),
211 alpm_pkg_get_version(pkg
));
212 return fopen(clfile
, "r");
216 * Read data from an open changelog 'file stream'. Similar to fread in
217 * functionality, this function takes a buffer and amount of data to read.
218 * @param ptr a buffer to fill with raw changelog data
219 * @param size the size of the buffer
220 * @param pkg the package that the changelog is being read from
221 * @param fp a 'file stream' to the package changelog
222 * @return the number of characters read, or 0 if there is no more data
224 static size_t _cache_changelog_read(void *ptr
, size_t size
,
225 const pmpkg_t UNUSED
*pkg
, const void *fp
)
227 return fread(ptr
, 1, size
, (FILE *)fp
);
231 * Close a package changelog for reading. Similar to fclose in functionality,
232 * except that the 'file stream' is from the database.
233 * @param pkg the package that the changelog was read from
234 * @param fp a 'file stream' to the package changelog
235 * @return whether closing the package changelog stream was successful
237 static int _cache_changelog_close(const pmpkg_t UNUSED
*pkg
, void *fp
)
239 return fclose((FILE *)fp
);
243 /** The local database operations struct. Get package fields through
244 * lazy accessor methods that handle any backend loading and caching
247 static struct pkg_operations local_pkg_ops
= {
248 .get_filename
= _cache_get_filename
,
249 .get_desc
= _cache_get_desc
,
250 .get_url
= _cache_get_url
,
251 .get_builddate
= _cache_get_builddate
,
252 .get_installdate
= _cache_get_installdate
,
253 .get_packager
= _cache_get_packager
,
254 .get_md5sum
= _cache_get_md5sum
,
255 .get_arch
= _cache_get_arch
,
256 .get_size
= _cache_get_size
,
257 .get_isize
= _cache_get_isize
,
258 .get_reason
= _cache_get_reason
,
259 .has_scriptlet
= _cache_has_scriptlet
,
260 .get_licenses
= _cache_get_licenses
,
261 .get_groups
= _cache_get_groups
,
262 .get_depends
= _cache_get_depends
,
263 .get_optdepends
= _cache_get_optdepends
,
264 .get_conflicts
= _cache_get_conflicts
,
265 .get_provides
= _cache_get_provides
,
266 .get_replaces
= _cache_get_replaces
,
267 .get_deltas
= _cache_get_deltas
,
268 .get_files
= _cache_get_files
,
269 .get_backup
= _cache_get_backup
,
271 .changelog_open
= _cache_changelog_open
,
272 .changelog_read
= _cache_changelog_read
,
273 .changelog_close
= _cache_changelog_close
,
276 static int checkdbdir(pmdb_t
*db
)
279 const char *path
= _alpm_db_path(db
);
281 if(stat(path
, &buf
) != 0) {
282 _alpm_log(db
->handle
, PM_LOG_DEBUG
, "database dir '%s' does not exist, creating it\n",
284 if(_alpm_makepath(path
) != 0) {
285 RET_ERR(db
->handle
, PM_ERR_SYSTEM
, -1);
287 } else if(!S_ISDIR(buf
.st_mode
)) {
288 _alpm_log(db
->handle
, PM_LOG_WARNING
, _("removing invalid database: %s\n"), path
);
289 if(unlink(path
) != 0 || _alpm_makepath(path
) != 0) {
290 RET_ERR(db
->handle
, PM_ERR_SYSTEM
, -1);
296 static int is_dir(const char *path
, struct dirent
*entry
)
298 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
299 if(entry
->d_type
!= DT_UNKNOWN
) {
300 return (entry
->d_type
== DT_DIR
);
304 char buffer
[PATH_MAX
];
307 snprintf(buffer
, PATH_MAX
, "%s/%s", path
, entry
->d_name
);
309 if(!stat(buffer
, &sbuf
)) {
310 return S_ISDIR(sbuf
.st_mode
);
317 static int local_db_validate(pmdb_t
*db
)
319 struct dirent
*ent
= NULL
;
324 dbpath
= _alpm_db_path(db
);
326 RET_ERR(db
->handle
, PM_ERR_DB_OPEN
, -1);
328 dbdir
= opendir(dbpath
);
330 if(errno
== ENOENT
) {
331 /* database dir doesn't exist yet */
334 RET_ERR(db
->handle
, PM_ERR_DB_OPEN
, -1);
338 while((ent
= readdir(dbdir
)) != NULL
) {
339 const char *name
= ent
->d_name
;
342 if(strcmp(name
, ".") == 0 || strcmp(name
, "..") == 0) {
345 if(!is_dir(dbpath
, ent
)) {
349 snprintf(path
, PATH_MAX
, "%s%s/depends", dbpath
, name
);
350 if(access(path
, F_OK
) == 0) {
351 /* we found a depends file- bail */
352 db
->handle
->pm_errno
= PM_ERR_DB_VERSION
;
356 /* we found no depends file after full scan */
367 static int local_db_populate(pmdb_t
*db
)
372 struct dirent
*ent
= NULL
;
376 dbpath
= _alpm_db_path(db
);
378 /* pm_errno set in _alpm_db_path() */
382 dbdir
= opendir(dbpath
);
384 if(errno
== ENOENT
) {
385 /* no database existing yet is not an error */
388 RET_ERR(db
->handle
, PM_ERR_DB_OPEN
, -1);
390 if(fstat(dirfd(dbdir
), &buf
) != 0) {
391 RET_ERR(db
->handle
, PM_ERR_DB_OPEN
, -1);
393 if(buf
.st_nlink
>= 2) {
394 est_count
= buf
.st_nlink
;
396 /* Some filesystems don't subscribe to the two-implicit links school of
397 * thought, e.g. BTRFS, HFS+. See
398 * http://kerneltrap.org/mailarchive/linux-btrfs/2010/1/23/6723483/thread
401 while(readdir(dbdir
) != NULL
) {
407 /* subtract the two extra pointers to get # of children */
411 /* initialize hash at 50% full */
412 db
->pkgcache
= _alpm_pkghash_create(est_count
* 2);
413 if(db
->pkgcache
== NULL
){
415 RET_ERR(db
->handle
, PM_ERR_MEMORY
, -1);
418 while((ent
= readdir(dbdir
)) != NULL
) {
419 const char *name
= ent
->d_name
;
423 if(strcmp(name
, ".") == 0 || strcmp(name
, "..") == 0) {
426 if(!is_dir(dbpath
, ent
)) {
430 pkg
= _alpm_pkg_new();
433 RET_ERR(db
->handle
, PM_ERR_MEMORY
, -1);
435 /* split the db entry name */
436 if(_alpm_splitname(name
, pkg
) != 0) {
437 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("invalid name for database entry '%s'\n"),
443 /* duplicated database entries are not allowed */
444 if(_alpm_pkghash_find(db
->pkgcache
, pkg
->name
)) {
445 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("duplicated database entry '%s'\n"), pkg
->name
);
450 pkg
->origin
= PKG_FROM_LOCALDB
;
451 pkg
->origin_data
.db
= db
;
452 pkg
->ops
= &local_pkg_ops
;
453 pkg
->handle
= db
->handle
;
455 /* explicitly read with only 'BASE' data, accessors will handle the rest */
456 if(_alpm_local_db_read(db
, pkg
, INFRQ_BASE
) == -1) {
457 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("corrupted database entry '%s'\n"), name
);
462 /* add to the collection */
463 _alpm_log(db
->handle
, PM_LOG_FUNCTION
, "adding '%s' to package cache for db '%s'\n",
464 pkg
->name
, db
->treename
);
465 db
->pkgcache
= _alpm_pkghash_add(db
->pkgcache
, pkg
);
471 db
->pkgcache
->list
= alpm_list_msort(db
->pkgcache
->list
, (size_t)count
, _alpm_pkg_cmp
);
473 _alpm_log(db
->handle
, PM_LOG_DEBUG
, "added %d packages to package cache for db '%s'\n",
474 count
, db
->treename
);
479 /* Note: the return value must be freed by the caller */
480 static char *get_pkgpath(pmdb_t
*db
, pmpkg_t
*info
)
486 dbpath
= _alpm_db_path(db
);
487 len
= strlen(dbpath
) + strlen(info
->name
) + strlen(info
->version
) + 3;
488 MALLOC(pkgpath
, len
, RET_ERR(db
->handle
, PM_ERR_MEMORY
, NULL
));
489 sprintf(pkgpath
, "%s%s-%s/", dbpath
, info
->name
, info
->version
);
494 int _alpm_local_db_read(pmdb_t
*db
, pmpkg_t
*info
, pmdbinfrq_t inforeq
)
499 char *pkgpath
= NULL
;
501 if(info
== NULL
|| info
->name
== NULL
|| info
->version
== NULL
) {
502 _alpm_log(db
->handle
, PM_LOG_DEBUG
,
503 "invalid package entry provided to _alpm_local_db_read, skipping\n");
507 if(info
->origin
!= PKG_FROM_LOCALDB
) {
508 _alpm_log(db
->handle
, PM_LOG_DEBUG
,
509 "request to read info for a non-local package '%s', skipping...\n",
514 /* bitmask logic here:
515 * infolevel: 00001111
518 * == to inforeq? nope, we need to load more info. */
519 if((info
->infolevel
& inforeq
) == inforeq
) {
520 /* already loaded all of this info, do nothing */
523 _alpm_log(db
->handle
, PM_LOG_FUNCTION
, "loading package data for %s : level=0x%x\n",
524 info
->name
, inforeq
);
526 /* clear out 'line', to be certain - and to make valgrind happy */
527 memset(line
, 0, sizeof(line
));
529 pkgpath
= get_pkgpath(db
, info
);
531 if(access(pkgpath
, F_OK
)) {
532 /* directory doesn't exist or can't be opened */
533 _alpm_log(db
->handle
, PM_LOG_DEBUG
, "cannot find '%s-%s' in db '%s'\n",
534 info
->name
, info
->version
, db
->treename
);
539 if(inforeq
& INFRQ_DESC
&& !(info
->infolevel
& INFRQ_DESC
)) {
540 snprintf(path
, PATH_MAX
, "%sdesc", pkgpath
);
541 if((fp
= fopen(path
, "r")) == NULL
) {
542 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("could not open file %s: %s\n"), path
, strerror(errno
));
546 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
550 if(strcmp(line
, "%NAME%") == 0) {
551 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
554 if(strcmp(_alpm_strtrim(line
), info
->name
) != 0) {
555 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("%s database is inconsistent: name "
556 "mismatch on package %s\n"), db
->treename
, info
->name
);
558 } else if(strcmp(line
, "%VERSION%") == 0) {
559 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
562 if(strcmp(_alpm_strtrim(line
), info
->version
) != 0) {
563 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("%s database is inconsistent: version "
564 "mismatch on package %s\n"), db
->treename
, info
->name
);
566 } else if(strcmp(line
, "%DESC%") == 0) {
567 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
570 STRDUP(info
->desc
, _alpm_strtrim(line
), goto error
);
571 } else if(strcmp(line
, "%GROUPS%") == 0) {
572 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
574 STRDUP(linedup
, line
, goto error
);
575 info
->groups
= alpm_list_add(info
->groups
, linedup
);
577 } else if(strcmp(line
, "%URL%") == 0) {
578 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
581 STRDUP(info
->url
, _alpm_strtrim(line
), goto error
);
582 } else if(strcmp(line
, "%LICENSE%") == 0) {
583 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
585 STRDUP(linedup
, line
, goto error
);
586 info
->licenses
= alpm_list_add(info
->licenses
, linedup
);
588 } else if(strcmp(line
, "%ARCH%") == 0) {
589 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
592 STRDUP(info
->arch
, _alpm_strtrim(line
), goto error
);
593 } else if(strcmp(line
, "%BUILDDATE%") == 0) {
594 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
598 info
->builddate
= _alpm_parsedate(line
);
599 } else if(strcmp(line
, "%INSTALLDATE%") == 0) {
600 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
604 info
->installdate
= _alpm_parsedate(line
);
605 } else if(strcmp(line
, "%PACKAGER%") == 0) {
606 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
609 STRDUP(info
->packager
, _alpm_strtrim(line
), goto error
);
610 } else if(strcmp(line
, "%REASON%") == 0) {
611 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
614 info
->reason
= (pmpkgreason_t
)atol(_alpm_strtrim(line
));
615 } else if(strcmp(line
, "%SIZE%") == 0) {
616 /* NOTE: the CSIZE and SIZE fields both share the "size" field
617 * in the pkginfo_t struct. This can be done b/c CSIZE
618 * is currently only used in sync databases, and SIZE is
619 * only used in local databases.
621 if(fgets(line
, sizeof(line
), fp
) == NULL
) {
624 info
->size
= atol(_alpm_strtrim(line
));
625 /* also store this value to isize */
626 info
->isize
= info
->size
;
627 } else if(strcmp(line
, "%REPLACES%") == 0) {
628 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
630 STRDUP(linedup
, line
, goto error
);
631 info
->replaces
= alpm_list_add(info
->replaces
, linedup
);
633 } else if(strcmp(line
, "%DEPENDS%") == 0) {
634 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
635 pmdepend_t
*dep
= _alpm_splitdep(line
);
636 info
->depends
= alpm_list_add(info
->depends
, dep
);
638 } else if(strcmp(line
, "%OPTDEPENDS%") == 0) {
639 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
641 STRDUP(linedup
, line
, goto error
);
642 info
->optdepends
= alpm_list_add(info
->optdepends
, linedup
);
644 } else if(strcmp(line
, "%CONFLICTS%") == 0) {
645 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
647 STRDUP(linedup
, line
, goto error
);
648 info
->conflicts
= alpm_list_add(info
->conflicts
, linedup
);
650 } else if(strcmp(line
, "%PROVIDES%") == 0) {
651 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
653 STRDUP(linedup
, line
, goto error
);
654 info
->provides
= alpm_list_add(info
->provides
, linedup
);
663 if(inforeq
& INFRQ_FILES
&& !(info
->infolevel
& INFRQ_FILES
)) {
664 snprintf(path
, PATH_MAX
, "%sfiles", pkgpath
);
665 if((fp
= fopen(path
, "r")) == NULL
) {
666 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("could not open file %s: %s\n"), path
, strerror(errno
));
669 while(fgets(line
, sizeof(line
), fp
)) {
671 if(strcmp(line
, "%FILES%") == 0) {
672 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
674 STRDUP(linedup
, line
, goto error
);
675 info
->files
= alpm_list_add(info
->files
, linedup
);
677 } else if(strcmp(line
, "%BACKUP%") == 0) {
678 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
680 CALLOC(backup
, 1, sizeof(pmbackup_t
), goto error
);
681 if(_alpm_split_backup(line
, &backup
)) {
684 info
->backup
= alpm_list_add(info
->backup
, backup
);
693 if(inforeq
& INFRQ_SCRIPTLET
&& !(info
->infolevel
& INFRQ_SCRIPTLET
)) {
694 snprintf(path
, PATH_MAX
, "%sinstall", pkgpath
);
695 if(access(path
, F_OK
) == 0) {
701 info
->infolevel
|= inforeq
;
714 int _alpm_local_db_prepare(pmdb_t
*db
, pmpkg_t
*info
)
718 char *pkgpath
= NULL
;
720 if(checkdbdir(db
) != 0) {
724 oldmask
= umask(0000);
725 pkgpath
= get_pkgpath(db
, info
);
727 if((retval
= mkdir(pkgpath
, 0755)) != 0) {
728 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("could not create directory %s: %s\n"),
729 pkgpath
, strerror(errno
));
738 int _alpm_local_db_write(pmdb_t
*db
, pmpkg_t
*info
, pmdbinfrq_t inforeq
)
743 alpm_list_t
*lp
= NULL
;
745 char *pkgpath
= NULL
;
747 if(db
== NULL
|| info
== NULL
) {
751 pkgpath
= get_pkgpath(db
, info
);
753 /* make sure we have a sane umask */
754 oldmask
= umask(0022);
756 if(strcmp(db
->treename
, "local") != 0) {
761 if(inforeq
& INFRQ_DESC
) {
762 _alpm_log(db
->handle
, PM_LOG_DEBUG
, "writing %s-%s DESC information back to db\n",
763 info
->name
, info
->version
);
764 snprintf(path
, PATH_MAX
, "%sdesc", pkgpath
);
765 if((fp
= fopen(path
, "w")) == NULL
) {
766 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("could not open file %s: %s\n"),
767 path
, strerror(errno
));
771 fprintf(fp
, "%%NAME%%\n%s\n\n"
772 "%%VERSION%%\n%s\n\n", info
->name
, info
->version
);
774 fprintf(fp
, "%%DESC%%\n"
775 "%s\n\n", info
->desc
);
778 fputs("%GROUPS%\n", fp
);
779 for(lp
= info
->groups
; lp
; lp
= lp
->next
) {
780 fprintf(fp
, "%s\n", (char *)lp
->data
);
785 fputs("%REPLACES%\n", fp
);
786 for(lp
= info
->replaces
; lp
; lp
= lp
->next
) {
787 fprintf(fp
, "%s\n", (char *)lp
->data
);
792 fprintf(fp
, "%%URL%%\n"
793 "%s\n\n", info
->url
);
796 fputs("%LICENSE%\n", fp
);
797 for(lp
= info
->licenses
; lp
; lp
= lp
->next
) {
798 fprintf(fp
, "%s\n", (char *)lp
->data
);
803 fprintf(fp
, "%%ARCH%%\n"
804 "%s\n\n", info
->arch
);
806 if(info
->builddate
) {
807 fprintf(fp
, "%%BUILDDATE%%\n"
808 "%ld\n\n", info
->builddate
);
810 if(info
->installdate
) {
811 fprintf(fp
, "%%INSTALLDATE%%\n"
812 "%ld\n\n", info
->installdate
);
815 fprintf(fp
, "%%PACKAGER%%\n"
816 "%s\n\n", info
->packager
);
819 /* only write installed size, csize is irrelevant once installed */
820 fprintf(fp
, "%%SIZE%%\n"
821 "%jd\n\n", (intmax_t)info
->isize
);
824 fprintf(fp
, "%%REASON%%\n"
825 "%u\n\n", info
->reason
);
828 fputs("%DEPENDS%\n", fp
);
829 for(lp
= info
->depends
; lp
; lp
= lp
->next
) {
830 char *depstring
= alpm_dep_compute_string(lp
->data
);
831 fprintf(fp
, "%s\n", depstring
);
836 if(info
->optdepends
) {
837 fputs("%OPTDEPENDS%\n", fp
);
838 for(lp
= info
->optdepends
; lp
; lp
= lp
->next
) {
839 fprintf(fp
, "%s\n", (char *)lp
->data
);
843 if(info
->conflicts
) {
844 fputs("%CONFLICTS%\n", fp
);
845 for(lp
= info
->conflicts
; lp
; lp
= lp
->next
) {
846 fprintf(fp
, "%s\n", (char *)lp
->data
);
851 fputs("%PROVIDES%\n", fp
);
852 for(lp
= info
->provides
; lp
; lp
= lp
->next
) {
853 fprintf(fp
, "%s\n", (char *)lp
->data
);
863 if(inforeq
& INFRQ_FILES
) {
864 _alpm_log(db
->handle
, PM_LOG_DEBUG
, "writing %s-%s FILES information back to db\n",
865 info
->name
, info
->version
);
866 snprintf(path
, PATH_MAX
, "%sfiles", pkgpath
);
867 if((fp
= fopen(path
, "w")) == NULL
) {
868 _alpm_log(db
->handle
, PM_LOG_ERROR
, _("could not open file %s: %s\n"),
869 path
, strerror(errno
));
874 fprintf(fp
, "%%FILES%%\n");
875 for(lp
= info
->files
; lp
; lp
= lp
->next
) {
876 fprintf(fp
, "%s\n", (char *)lp
->data
);
881 fprintf(fp
, "%%BACKUP%%\n");
882 for(lp
= info
->backup
; lp
; lp
= lp
->next
) {
883 pmbackup_t
*backup
= lp
->data
;
884 fprintf(fp
, "%s\t%s\n", backup
->name
, backup
->hash
);
893 /* nothing needed here (script is automatically extracted) */
906 int _alpm_local_db_remove(pmdb_t
*db
, pmpkg_t
*info
)
909 char *pkgpath
= NULL
;
911 pkgpath
= get_pkgpath(db
, info
);
913 ret
= _alpm_rmrf(pkgpath
);
921 struct db_operations local_db_ops
= {
922 .populate
= local_db_populate
,
923 .unregister
= _alpm_db_unregister
,
926 pmdb_t
*_alpm_db_register_local(pmhandle_t
*handle
)
930 _alpm_log(handle
, PM_LOG_DEBUG
, "registering local database\n");
932 db
= _alpm_db_new("local", 1);
934 handle
->pm_errno
= PM_ERR_DB_CREATE
;
937 db
->ops
= &local_db_ops
;
940 if(local_db_validate(db
)) {
941 /* pm_errno set in local_db_validate() */
946 handle
->db_local
= db
;
950 /* vim: set ts=2 sw=2 noet: */