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 static int local_db_read(alpm_pkg_t
*info
, alpm_dbinfrq_t inforeq
);
46 #define LAZY_LOAD(info, errret) \
48 if(!(pkg->infolevel & info)) { \
49 local_db_read(pkg, info); \
54 /* Cache-specific accessor functions. These implementations allow for lazy
55 * loading by the files backend when a data member is actually needed
56 * rather than loading all pieces of information when the package is first
60 static const char *_cache_get_filename(alpm_pkg_t
*pkg
)
62 LAZY_LOAD(INFRQ_DESC
, NULL
);
66 static const char *_cache_get_desc(alpm_pkg_t
*pkg
)
68 LAZY_LOAD(INFRQ_DESC
, NULL
);
72 static const char *_cache_get_url(alpm_pkg_t
*pkg
)
74 LAZY_LOAD(INFRQ_DESC
, NULL
);
78 static time_t _cache_get_builddate(alpm_pkg_t
*pkg
)
80 LAZY_LOAD(INFRQ_DESC
, 0);
81 return pkg
->builddate
;
84 static time_t _cache_get_installdate(alpm_pkg_t
*pkg
)
86 LAZY_LOAD(INFRQ_DESC
, 0);
87 return pkg
->installdate
;
90 static const char *_cache_get_packager(alpm_pkg_t
*pkg
)
92 LAZY_LOAD(INFRQ_DESC
, NULL
);
96 static const char *_cache_get_md5sum(alpm_pkg_t
*pkg
)
98 LAZY_LOAD(INFRQ_DESC
, NULL
);
102 static const char *_cache_get_arch(alpm_pkg_t
*pkg
)
104 LAZY_LOAD(INFRQ_DESC
, NULL
);
108 static off_t
_cache_get_size(alpm_pkg_t
*pkg
)
110 LAZY_LOAD(INFRQ_DESC
, -1);
114 static off_t
_cache_get_isize(alpm_pkg_t
*pkg
)
116 LAZY_LOAD(INFRQ_DESC
, -1);
120 static alpm_pkgreason_t
_cache_get_reason(alpm_pkg_t
*pkg
)
122 LAZY_LOAD(INFRQ_DESC
, -1);
126 static alpm_list_t
*_cache_get_licenses(alpm_pkg_t
*pkg
)
128 LAZY_LOAD(INFRQ_DESC
, NULL
);
129 return pkg
->licenses
;
132 static alpm_list_t
*_cache_get_groups(alpm_pkg_t
*pkg
)
134 LAZY_LOAD(INFRQ_DESC
, NULL
);
138 static int _cache_has_scriptlet(alpm_pkg_t
*pkg
)
140 LAZY_LOAD(INFRQ_SCRIPTLET
, NULL
);
141 return pkg
->scriptlet
;
144 static alpm_list_t
*_cache_get_depends(alpm_pkg_t
*pkg
)
146 LAZY_LOAD(INFRQ_DESC
, NULL
);
150 static alpm_list_t
*_cache_get_optdepends(alpm_pkg_t
*pkg
)
152 LAZY_LOAD(INFRQ_DESC
, NULL
);
153 return pkg
->optdepends
;
156 static alpm_list_t
*_cache_get_conflicts(alpm_pkg_t
*pkg
)
158 LAZY_LOAD(INFRQ_DESC
, NULL
);
159 return pkg
->conflicts
;
162 static alpm_list_t
*_cache_get_provides(alpm_pkg_t
*pkg
)
164 LAZY_LOAD(INFRQ_DESC
, NULL
);
165 return pkg
->provides
;
168 static alpm_list_t
*_cache_get_replaces(alpm_pkg_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(alpm_pkg_t UNUSED
*pkg
)
180 static alpm_list_t
*_cache_get_files(alpm_pkg_t
*pkg
)
182 LAZY_LOAD(INFRQ_FILES
, NULL
);
186 static alpm_list_t
*_cache_get_backup(alpm_pkg_t
*pkg
)
188 LAZY_LOAD(INFRQ_FILES
, NULL
);
193 * Open a package changelog for reading. Similar to fopen in functionality,
194 * except that the returned 'file stream' is from the database.
195 * @param pkg the package (from db) to read the changelog
196 * @return a 'file stream' to the package changelog
198 static void *_cache_changelog_open(alpm_pkg_t
*pkg
)
200 char clfile
[PATH_MAX
];
201 snprintf(clfile
, PATH_MAX
, "%s/%s/%s-%s/changelog",
202 alpm_option_get_dbpath(pkg
->handle
),
203 alpm_db_get_name(alpm_pkg_get_db(pkg
)),
204 alpm_pkg_get_name(pkg
),
205 alpm_pkg_get_version(pkg
));
206 return fopen(clfile
, "r");
210 * Read data from an open changelog 'file stream'. Similar to fread in
211 * functionality, this function takes a buffer and amount of data to read.
212 * @param ptr a buffer to fill with raw changelog data
213 * @param size the size of the buffer
214 * @param pkg the package that the changelog is being read from
215 * @param fp a 'file stream' to the package changelog
216 * @return the number of characters read, or 0 if there is no more data
218 static size_t _cache_changelog_read(void *ptr
, size_t size
,
219 const alpm_pkg_t UNUSED
*pkg
, const void *fp
)
221 return fread(ptr
, 1, size
, (FILE *)fp
);
225 * Close a package changelog for reading. Similar to fclose in functionality,
226 * except that the 'file stream' is from the database.
227 * @param pkg the package that the changelog was read from
228 * @param fp a 'file stream' to the package changelog
229 * @return whether closing the package changelog stream was successful
231 static int _cache_changelog_close(const alpm_pkg_t UNUSED
*pkg
, void *fp
)
233 return fclose((FILE *)fp
);
236 static int _cache_force_load(alpm_pkg_t
*pkg
)
238 return local_db_read(pkg
, INFRQ_ALL
);
242 /** The local database operations struct. Get package fields through
243 * lazy accessor methods that handle any backend loading and caching
246 static struct pkg_operations local_pkg_ops
= {
247 .get_filename
= _cache_get_filename
,
248 .get_desc
= _cache_get_desc
,
249 .get_url
= _cache_get_url
,
250 .get_builddate
= _cache_get_builddate
,
251 .get_installdate
= _cache_get_installdate
,
252 .get_packager
= _cache_get_packager
,
253 .get_md5sum
= _cache_get_md5sum
,
254 .get_arch
= _cache_get_arch
,
255 .get_size
= _cache_get_size
,
256 .get_isize
= _cache_get_isize
,
257 .get_reason
= _cache_get_reason
,
258 .has_scriptlet
= _cache_has_scriptlet
,
259 .get_licenses
= _cache_get_licenses
,
260 .get_groups
= _cache_get_groups
,
261 .get_depends
= _cache_get_depends
,
262 .get_optdepends
= _cache_get_optdepends
,
263 .get_conflicts
= _cache_get_conflicts
,
264 .get_provides
= _cache_get_provides
,
265 .get_replaces
= _cache_get_replaces
,
266 .get_deltas
= _cache_get_deltas
,
267 .get_files
= _cache_get_files
,
268 .get_backup
= _cache_get_backup
,
270 .changelog_open
= _cache_changelog_open
,
271 .changelog_read
= _cache_changelog_read
,
272 .changelog_close
= _cache_changelog_close
,
274 .force_load
= _cache_force_load
,
277 static int checkdbdir(alpm_db_t
*db
)
280 const char *path
= _alpm_db_path(db
);
282 if(stat(path
, &buf
) != 0) {
283 _alpm_log(db
->handle
, ALPM_LOG_DEBUG
, "database dir '%s' does not exist, creating it\n",
285 if(_alpm_makepath(path
) != 0) {
286 RET_ERR(db
->handle
, ALPM_ERR_SYSTEM
, -1);
288 } else if(!S_ISDIR(buf
.st_mode
)) {
289 _alpm_log(db
->handle
, ALPM_LOG_WARNING
, _("removing invalid database: %s\n"), path
);
290 if(unlink(path
) != 0 || _alpm_makepath(path
) != 0) {
291 RET_ERR(db
->handle
, ALPM_ERR_SYSTEM
, -1);
297 static int is_dir(const char *path
, struct dirent
*entry
)
299 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
300 if(entry
->d_type
!= DT_UNKNOWN
) {
301 return (entry
->d_type
== DT_DIR
);
305 char buffer
[PATH_MAX
];
308 snprintf(buffer
, PATH_MAX
, "%s/%s", path
, entry
->d_name
);
310 if(!stat(buffer
, &sbuf
)) {
311 return S_ISDIR(sbuf
.st_mode
);
318 static int local_db_validate(alpm_db_t
*db
)
320 struct dirent
*ent
= NULL
;
325 if(db
->status
& DB_STATUS_VALID
) {
329 dbpath
= _alpm_db_path(db
);
331 RET_ERR(db
->handle
, ALPM_ERR_DB_OPEN
, -1);
333 dbdir
= opendir(dbpath
);
335 if(errno
== ENOENT
) {
336 /* database dir doesn't exist yet */
337 db
->status
|= DB_STATUS_VALID
;
340 RET_ERR(db
->handle
, ALPM_ERR_DB_OPEN
, -1);
344 while((ent
= readdir(dbdir
)) != NULL
) {
345 const char *name
= ent
->d_name
;
348 if(strcmp(name
, ".") == 0 || strcmp(name
, "..") == 0) {
351 if(!is_dir(dbpath
, ent
)) {
355 snprintf(path
, PATH_MAX
, "%s%s/depends", dbpath
, name
);
356 if(access(path
, F_OK
) == 0) {
357 /* we found a depends file- bail */
358 db
->handle
->pm_errno
= ALPM_ERR_DB_VERSION
;
362 /* we found no depends file after full scan */
363 db
->status
|= DB_STATUS_VALID
;
374 static int local_db_populate(alpm_db_t
*db
)
379 struct dirent
*ent
= NULL
;
383 dbpath
= _alpm_db_path(db
);
385 /* pm_errno set in _alpm_db_path() */
389 dbdir
= opendir(dbpath
);
391 if(errno
== ENOENT
) {
392 /* no database existing yet is not an error */
395 RET_ERR(db
->handle
, ALPM_ERR_DB_OPEN
, -1);
397 if(fstat(dirfd(dbdir
), &buf
) != 0) {
398 RET_ERR(db
->handle
, ALPM_ERR_DB_OPEN
, -1);
400 if(buf
.st_nlink
>= 2) {
401 est_count
= buf
.st_nlink
;
403 /* Some filesystems don't subscribe to the two-implicit links school of
404 * thought, e.g. BTRFS, HFS+. See
405 * http://kerneltrap.org/mailarchive/linux-btrfs/2010/1/23/6723483/thread
408 while(readdir(dbdir
) != NULL
) {
414 /* subtract the two extra pointers to get # of children */
418 /* initialize hash at 50% full */
419 db
->pkgcache
= _alpm_pkghash_create(est_count
* 2);
420 if(db
->pkgcache
== NULL
){
422 RET_ERR(db
->handle
, ALPM_ERR_MEMORY
, -1);
425 while((ent
= readdir(dbdir
)) != NULL
) {
426 const char *name
= ent
->d_name
;
430 if(strcmp(name
, ".") == 0 || strcmp(name
, "..") == 0) {
433 if(!is_dir(dbpath
, ent
)) {
437 pkg
= _alpm_pkg_new();
440 RET_ERR(db
->handle
, ALPM_ERR_MEMORY
, -1);
442 /* split the db entry name */
443 if(_alpm_splitname(name
, &(pkg
->name
), &(pkg
->version
),
444 &(pkg
->name_hash
)) != 0) {
445 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("invalid name for database entry '%s'\n"),
451 /* duplicated database entries are not allowed */
452 if(_alpm_pkghash_find(db
->pkgcache
, pkg
->name
)) {
453 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("duplicated database entry '%s'\n"), pkg
->name
);
458 pkg
->origin
= PKG_FROM_LOCALDB
;
459 pkg
->origin_data
.db
= db
;
460 pkg
->ops
= &local_pkg_ops
;
461 pkg
->handle
= db
->handle
;
463 /* explicitly read with only 'BASE' data, accessors will handle the rest */
464 if(local_db_read(pkg
, INFRQ_BASE
) == -1) {
465 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("corrupted database entry '%s'\n"), name
);
470 /* add to the collection */
471 _alpm_log(db
->handle
, ALPM_LOG_FUNCTION
, "adding '%s' to package cache for db '%s'\n",
472 pkg
->name
, db
->treename
);
473 db
->pkgcache
= _alpm_pkghash_add(db
->pkgcache
, pkg
);
479 db
->pkgcache
->list
= alpm_list_msort(db
->pkgcache
->list
, (size_t)count
, _alpm_pkg_cmp
);
481 _alpm_log(db
->handle
, ALPM_LOG_DEBUG
, "added %d packages to package cache for db '%s'\n",
482 count
, db
->treename
);
487 /* Note: the return value must be freed by the caller */
488 static char *get_pkgpath(alpm_db_t
*db
, alpm_pkg_t
*info
)
494 dbpath
= _alpm_db_path(db
);
495 len
= strlen(dbpath
) + strlen(info
->name
) + strlen(info
->version
) + 3;
496 MALLOC(pkgpath
, len
, RET_ERR(db
->handle
, ALPM_ERR_MEMORY
, NULL
));
497 sprintf(pkgpath
, "%s%s-%s/", dbpath
, info
->name
, info
->version
);
501 #define READ_NEXT() do { \
502 if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error; \
503 _alpm_strtrim(line); \
506 #define READ_AND_STORE(f) do { \
508 STRDUP(f, line, goto error); \
511 #define READ_AND_STORE_ALL(f) do { \
514 if(strlen(line) == 0) break; \
515 STRDUP(linedup, line, goto error); \
516 f = alpm_list_add(f, linedup); \
517 } while(1) /* note the while(1) and not (0) */
519 static int local_db_read(alpm_pkg_t
*info
, alpm_dbinfrq_t inforeq
)
524 char *pkgpath
= NULL
;
525 alpm_db_t
*db
= info
->origin_data
.db
;
527 /* bitmask logic here:
528 * infolevel: 00001111
531 * == to inforeq? nope, we need to load more info. */
532 if((info
->infolevel
& inforeq
) == inforeq
) {
533 /* already loaded all of this info, do nothing */
536 _alpm_log(db
->handle
, ALPM_LOG_FUNCTION
, "loading package data for %s : level=0x%x\n",
537 info
->name
, inforeq
);
539 /* clear out 'line', to be certain - and to make valgrind happy */
540 memset(line
, 0, sizeof(line
));
542 pkgpath
= get_pkgpath(db
, info
);
544 if(access(pkgpath
, F_OK
)) {
545 /* directory doesn't exist or can't be opened */
546 _alpm_log(db
->handle
, ALPM_LOG_DEBUG
, "cannot find '%s-%s' in db '%s'\n",
547 info
->name
, info
->version
, db
->treename
);
552 if(inforeq
& INFRQ_DESC
&& !(info
->infolevel
& INFRQ_DESC
)) {
553 snprintf(path
, PATH_MAX
, "%sdesc", pkgpath
);
554 if((fp
= fopen(path
, "r")) == NULL
) {
555 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("could not open file %s: %s\n"), path
, strerror(errno
));
560 if(strcmp(line
, "%NAME%") == 0) {
562 if(strcmp(line
, info
->name
) != 0) {
563 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("%s database is inconsistent: name "
564 "mismatch on package %s\n"), db
->treename
, info
->name
);
566 } else if(strcmp(line
, "%VERSION%") == 0) {
568 if(strcmp(line
, info
->version
) != 0) {
569 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("%s database is inconsistent: version "
570 "mismatch on package %s\n"), db
->treename
, info
->name
);
572 } else if(strcmp(line
, "%DESC%") == 0) {
573 READ_AND_STORE(info
->desc
);
574 } else if(strcmp(line
, "%GROUPS%") == 0) {
575 READ_AND_STORE_ALL(info
->groups
);
576 } else if(strcmp(line
, "%URL%") == 0) {
577 READ_AND_STORE(info
->url
);
578 } else if(strcmp(line
, "%LICENSE%") == 0) {
579 READ_AND_STORE_ALL(info
->licenses
);
580 } else if(strcmp(line
, "%ARCH%") == 0) {
581 READ_AND_STORE(info
->arch
);
582 } else if(strcmp(line
, "%BUILDDATE%") == 0) {
584 info
->builddate
= _alpm_parsedate(line
);
585 } else if(strcmp(line
, "%INSTALLDATE%") == 0) {
587 info
->installdate
= _alpm_parsedate(line
);
588 } else if(strcmp(line
, "%PACKAGER%") == 0) {
589 READ_AND_STORE(info
->packager
);
590 } else if(strcmp(line
, "%REASON%") == 0) {
592 info
->reason
= (alpm_pkgreason_t
)atol(line
);
593 } else if(strcmp(line
, "%SIZE%") == 0) {
594 /* NOTE: the CSIZE and SIZE fields both share the "size" field
595 * in the pkginfo_t struct. This can be done b/c CSIZE
596 * is currently only used in sync databases, and SIZE is
597 * only used in local databases.
600 info
->size
= atol(line
);
601 /* also store this value to isize */
602 info
->isize
= info
->size
;
603 } else if(strcmp(line
, "%REPLACES%") == 0) {
604 READ_AND_STORE_ALL(info
->replaces
);
605 } else if(strcmp(line
, "%DEPENDS%") == 0) {
606 /* Different than the rest because of the _alpm_splitdep call. */
609 if(strlen(line
) == 0) break;
610 info
->depends
= alpm_list_add(info
->depends
, _alpm_splitdep(line
));
612 } else if(strcmp(line
, "%OPTDEPENDS%") == 0) {
613 READ_AND_STORE_ALL(info
->optdepends
);
614 } else if(strcmp(line
, "%CONFLICTS%") == 0) {
615 READ_AND_STORE_ALL(info
->conflicts
);
616 } else if(strcmp(line
, "%PROVIDES%") == 0) {
617 READ_AND_STORE_ALL(info
->provides
);
625 if(inforeq
& INFRQ_FILES
&& !(info
->infolevel
& INFRQ_FILES
)) {
626 snprintf(path
, PATH_MAX
, "%sfiles", pkgpath
);
627 if((fp
= fopen(path
, "r")) == NULL
) {
628 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("could not open file %s: %s\n"), path
, strerror(errno
));
631 while(fgets(line
, sizeof(line
), fp
)) {
633 if(strcmp(line
, "%FILES%") == 0) {
634 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
636 CALLOC(file
, 1, sizeof(alpm_file_t
), goto error
);
637 STRDUP(file
->name
, line
, goto error
);
638 /* TODO: lstat file, get mode/size */
639 info
->files
= alpm_list_add(info
->files
, file
);
641 } else if(strcmp(line
, "%BACKUP%") == 0) {
642 while(fgets(line
, sizeof(line
), fp
) && strlen(_alpm_strtrim(line
))) {
643 alpm_backup_t
*backup
;
644 CALLOC(backup
, 1, sizeof(alpm_backup_t
), goto error
);
645 if(_alpm_split_backup(line
, &backup
)) {
648 info
->backup
= alpm_list_add(info
->backup
, backup
);
657 if(inforeq
& INFRQ_SCRIPTLET
&& !(info
->infolevel
& INFRQ_SCRIPTLET
)) {
658 snprintf(path
, PATH_MAX
, "%sinstall", pkgpath
);
659 if(access(path
, F_OK
) == 0) {
665 info
->infolevel
|= inforeq
;
678 int _alpm_local_db_prepare(alpm_db_t
*db
, alpm_pkg_t
*info
)
682 char *pkgpath
= NULL
;
684 if(checkdbdir(db
) != 0) {
688 oldmask
= umask(0000);
689 pkgpath
= get_pkgpath(db
, info
);
691 if((retval
= mkdir(pkgpath
, 0755)) != 0) {
692 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("could not create directory %s: %s\n"),
693 pkgpath
, strerror(errno
));
702 int _alpm_local_db_write(alpm_db_t
*db
, alpm_pkg_t
*info
, alpm_dbinfrq_t inforeq
)
707 alpm_list_t
*lp
= NULL
;
709 char *pkgpath
= NULL
;
711 if(db
== NULL
|| info
== NULL
) {
715 pkgpath
= get_pkgpath(db
, info
);
717 /* make sure we have a sane umask */
718 oldmask
= umask(0022);
720 if(strcmp(db
->treename
, "local") != 0) {
725 if(inforeq
& INFRQ_DESC
) {
726 _alpm_log(db
->handle
, ALPM_LOG_DEBUG
, "writing %s-%s DESC information back to db\n",
727 info
->name
, info
->version
);
728 snprintf(path
, PATH_MAX
, "%sdesc", pkgpath
);
729 if((fp
= fopen(path
, "w")) == NULL
) {
730 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("could not open file %s: %s\n"),
731 path
, strerror(errno
));
735 fprintf(fp
, "%%NAME%%\n%s\n\n"
736 "%%VERSION%%\n%s\n\n", info
->name
, info
->version
);
738 fprintf(fp
, "%%DESC%%\n"
739 "%s\n\n", info
->desc
);
742 fputs("%GROUPS%\n", fp
);
743 for(lp
= info
->groups
; lp
; lp
= lp
->next
) {
744 fprintf(fp
, "%s\n", (char *)lp
->data
);
749 fputs("%REPLACES%\n", fp
);
750 for(lp
= info
->replaces
; lp
; lp
= lp
->next
) {
751 fprintf(fp
, "%s\n", (char *)lp
->data
);
756 fprintf(fp
, "%%URL%%\n"
757 "%s\n\n", info
->url
);
760 fputs("%LICENSE%\n", fp
);
761 for(lp
= info
->licenses
; lp
; lp
= lp
->next
) {
762 fprintf(fp
, "%s\n", (char *)lp
->data
);
767 fprintf(fp
, "%%ARCH%%\n"
768 "%s\n\n", info
->arch
);
770 if(info
->builddate
) {
771 fprintf(fp
, "%%BUILDDATE%%\n"
772 "%ld\n\n", info
->builddate
);
774 if(info
->installdate
) {
775 fprintf(fp
, "%%INSTALLDATE%%\n"
776 "%ld\n\n", info
->installdate
);
779 fprintf(fp
, "%%PACKAGER%%\n"
780 "%s\n\n", info
->packager
);
783 /* only write installed size, csize is irrelevant once installed */
784 fprintf(fp
, "%%SIZE%%\n"
785 "%jd\n\n", (intmax_t)info
->isize
);
788 fprintf(fp
, "%%REASON%%\n"
789 "%u\n\n", info
->reason
);
792 fputs("%DEPENDS%\n", fp
);
793 for(lp
= info
->depends
; lp
; lp
= lp
->next
) {
794 char *depstring
= alpm_dep_compute_string(lp
->data
);
795 fprintf(fp
, "%s\n", depstring
);
800 if(info
->optdepends
) {
801 fputs("%OPTDEPENDS%\n", fp
);
802 for(lp
= info
->optdepends
; lp
; lp
= lp
->next
) {
803 fprintf(fp
, "%s\n", (char *)lp
->data
);
807 if(info
->conflicts
) {
808 fputs("%CONFLICTS%\n", fp
);
809 for(lp
= info
->conflicts
; lp
; lp
= lp
->next
) {
810 fprintf(fp
, "%s\n", (char *)lp
->data
);
815 fputs("%PROVIDES%\n", fp
);
816 for(lp
= info
->provides
; lp
; lp
= lp
->next
) {
817 fprintf(fp
, "%s\n", (char *)lp
->data
);
827 if(inforeq
& INFRQ_FILES
) {
828 _alpm_log(db
->handle
, ALPM_LOG_DEBUG
, "writing %s-%s FILES information back to db\n",
829 info
->name
, info
->version
);
830 snprintf(path
, PATH_MAX
, "%sfiles", pkgpath
);
831 if((fp
= fopen(path
, "w")) == NULL
) {
832 _alpm_log(db
->handle
, ALPM_LOG_ERROR
, _("could not open file %s: %s\n"),
833 path
, strerror(errno
));
838 fprintf(fp
, "%%FILES%%\n");
839 for(lp
= info
->files
; lp
; lp
= lp
->next
) {
840 const alpm_file_t
*file
= lp
->data
;
841 fprintf(fp
, "%s\n", file
->name
);
846 fprintf(fp
, "%%BACKUP%%\n");
847 for(lp
= info
->backup
; lp
; lp
= lp
->next
) {
848 const alpm_backup_t
*backup
= lp
->data
;
849 fprintf(fp
, "%s\t%s\n", backup
->name
, backup
->hash
);
858 /* nothing needed here (script is automatically extracted) */
871 int _alpm_local_db_remove(alpm_db_t
*db
, alpm_pkg_t
*info
)
874 char *pkgpath
= NULL
;
876 pkgpath
= get_pkgpath(db
, info
);
878 ret
= _alpm_rmrf(pkgpath
);
886 struct db_operations local_db_ops
= {
887 .validate
= local_db_validate
,
888 .populate
= local_db_populate
,
889 .unregister
= _alpm_db_unregister
,
892 alpm_db_t
*_alpm_db_register_local(alpm_handle_t
*handle
)
896 _alpm_log(handle
, ALPM_LOG_DEBUG
, "registering local database\n");
898 db
= _alpm_db_new("local", 1);
900 handle
->pm_errno
= ALPM_ERR_DB_CREATE
;
903 db
->ops
= &local_db_ops
;
906 if(local_db_validate(db
)) {
907 /* pm_errno set in local_db_validate() */
912 handle
->db_local
= db
;
916 /* vim: set ts=2 sw=2 noet: */