]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: db: Add flags to decide whether we need write access
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Jan 2021 21:39:32 +0000 (21:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Jan 2021 21:39:32 +0000 (21:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/db.c
src/libpakfire/include/pakfire/db.h
src/libpakfire/transaction.c

index 0086404a8bcee38b7e6531cd8d3ee1dcd2d23f6f..d40fb212d24a65483411762aab8bcbd1a913d6db 100644 (file)
 struct pakfire_db {
        Pakfire pakfire;
        int nrefs;
+
+       int mode;
 };
 
-PAKFIRE_EXPORT int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire) {
+PAKFIRE_EXPORT int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire, int flags) {
        struct pakfire_db* o = pakfire_calloc(1, sizeof(*o));
        if (!o)
                return -ENOMEM;
@@ -45,6 +47,12 @@ PAKFIRE_EXPORT int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire) {
        o->pakfire = pakfire_ref(pakfire);
        o->nrefs = 1;
 
+       // Store mode
+       if (flags & PAKFIRE_DB_READWRITE)
+               o->mode = PAKFIRE_DB_READWRITE;
+       else
+               o->mode = PAKFIRE_DB_READONLY;
+
        *db = o;
 
        return 0;
index c4eb363faaee62f74fd03857e4fc7a3bef86e92f..bc0f890dfd359e5c2d901308835ab994d0f77893 100644 (file)
 
 struct pakfire_db;
 
-int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire);
+enum {
+       PAKFIRE_DB_READONLY  = 0,
+       PAKFIRE_DB_READWRITE = (1 << 0),
+};
+
+int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire, int flags);
 
 struct pakfire_db* pakfire_db_ref(struct pakfire_db* db);
 struct pakfire_db* pakfire_db_unref(struct pakfire_db* db);
index 208d7256657246411197e4349ffa176aa7fcdfec..77355e92cc7a657907272e3f65ed29ce84c05532 100644 (file)
@@ -340,7 +340,7 @@ PAKFIRE_EXPORT int pakfire_transaction_run(PakfireTransaction transaction) {
        DEBUG(transaction->pakfire, "Running Transaction %p\n", transaction);
 
        // Open the database
-       r = pakfire_db_open(&db, transaction->pakfire);
+       r = pakfire_db_open(&db, transaction->pakfire, PAKFIRE_DB_READWRITE);
        if (r) {
                ERROR(transaction->pakfire, "Could not open the database\n");
                return r;