Move database handling utility functions
[pacman-ng.git] / lib / libalpm / db.h
blobf4559fe9fa04d4adeacb5a1505e4f1d7bccc2986
1 /*
2 * db.h
4 * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef _ALPM_DB_H
23 #define _ALPM_DB_H
25 #include "alpm.h"
26 #include <limits.h>
27 #include <time.h>
29 /* Database entries */
30 typedef enum _pmdbinfrq_t {
31 INFRQ_BASE = 1,
32 INFRQ_DESC = (1 << 1),
33 INFRQ_DEPENDS = (1 << 2),
34 INFRQ_FILES = (1 << 3),
35 INFRQ_SCRIPTLET = (1 << 4),
36 INFRQ_DELTAS = (1 << 5),
37 INFRQ_DSIZE = (1 << 6),
38 /* ALL should be info stored in the package or database */
39 INFRQ_ALL = 0x3F
40 } pmdbinfrq_t;
42 struct db_operations {
43 int (*populate) (pmdb_t *);
44 void (*unregister) (pmdb_t *);
47 /* Database */
48 struct __pmdb_t {
49 char *treename;
50 /* do not access directly, use _alpm_db_path(db) for lazy access */
51 char *_path;
52 int pkgcache_loaded;
53 int grpcache_loaded;
54 /* also indicates whether we are RO or RW */
55 int is_local;
56 alpm_list_t *pkgcache;
57 alpm_list_t *grpcache;
58 alpm_list_t *servers;
60 struct db_operations *ops;
63 extern struct db_operations default_db_ops;
65 /* db.c, database general calls */
66 void _alpm_db_free(pmdb_t *db);
67 const char *_alpm_db_path(pmdb_t *db);
68 int _alpm_db_cmp(const void *d1, const void *d2);
69 alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
70 pmdb_t *_alpm_db_register_local(void);
71 pmdb_t *_alpm_db_register_sync(const char *treename);
72 void _alpm_db_unregister(pmdb_t *db);
74 /* be.c, backend specific calls */
75 int _alpm_db_populate(pmdb_t *db);
76 int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
77 int _alpm_db_prepare(pmdb_t *db, pmpkg_t *info);
78 int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
79 int _alpm_db_remove(pmdb_t *db, pmpkg_t *info);
81 /* cache bullshit */
82 /* packages */
83 int _alpm_db_load_pkgcache(pmdb_t *db);
84 void _alpm_db_free_pkgcache(pmdb_t *db);
85 int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg);
86 int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg);
87 alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db);
88 int _alpm_db_ensure_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel);
89 pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target);
90 /* groups */
91 int _alpm_db_load_grpcache(pmdb_t *db);
92 void _alpm_db_free_grpcache(pmdb_t *db);
93 alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db);
94 pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target);
96 int splitname(const char *target, pmpkg_t *pkg);
97 int checkdbdir(pmdb_t *db);
98 char *get_pkgpath(pmdb_t *db, pmpkg_t *info);
100 #endif /* _ALPM_DB_H */
102 /* vim: set ts=2 sw=2 noet: */