]> git.ipfire.org Git - people/ms/pakfire.git/blame - src/libpakfire/db.c
libpakfire: Remove LMDB
[people/ms/pakfire.git] / src / libpakfire / db.c
CommitLineData
33d55ab4
MT
1/*#############################################################################
2# #
3# Pakfire - The IPFire package management system #
4# Copyright (C) 2021 Pakfire development team #
5# #
6# This program is free software: you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation, either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# This program is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with this program. If not, see <http://www.gnu.org/licenses/>. #
18# #
19#############################################################################*/
20
21#include <errno.h>
22#include <stdlib.h>
23
33d55ab4
MT
24#include <pakfire/db.h>
25#include <pakfire/pakfire.h>
26#include <pakfire/logging.h>
27#include <pakfire/types.h>
28#include <pakfire/util.h>
29
0cb487ff
MT
30#define DATABASE_PATH PAKFIRE_PRIVATE_DIR "/packages.db"
31
33d55ab4
MT
32struct pakfire_db {
33 Pakfire pakfire;
34 int nrefs;
35};
36
33d55ab4
MT
37int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire) {
38 struct pakfire_db* o = pakfire_calloc(1, sizeof(*o));
39 if (!o)
40 return -ENOMEM;
41
42 DEBUG(pakfire, "Allocated database at %p\n", o);
43
44 o->pakfire = pakfire_ref(pakfire);
45 o->nrefs = 1;
46
47 *db = o;
48
49 return 0;
50}
51
52struct pakfire_db* pakfire_db_ref(struct pakfire_db* db) {
53 db->nrefs++;
54
55 return db;
56}
57
58static void pakfire_db_free(struct pakfire_db* db) {
59 DEBUG(db->pakfire, "Releasing database at %p\n", db);
60
61 pakfire_unref(db->pakfire);
62
63 pakfire_free(db);
64}
65
66struct pakfire_db* pakfire_db_unref(struct pakfire_db* db) {
67 if (--db->nrefs > 0)
68 return db;
69
70 pakfire_db_free(db);
71
72 return NULL;
73}
eafbe2ce
MT
74
75int pakfire_db_add_package(struct pakfire_db* db, PakfirePackage pkg) {
76 return 0; // TODO
77}
78
79int pakfire_db_remove_package(struct pakfire_db* db, PakfirePackage pkg) {
80 return 0; // TODO
81}