From 00e397d5646df33e2823d73e2388013d461ed5e9 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Sun, 6 Mar 2022 16:07:42 +0200 Subject: db: honor APK_OPENF_NO_STATE again Do not call apk_db_read_layer() or try to process the layer if APK_OPENF_NO_STATE is specified. It might fail because of non-existing database directory. Based on patch by Daniel. fixes commit 9e4dd29f "db: prepare database reading for layers" Fixes #10821 Reported-and-analyzed-by: Daniel Kolesa --- src/database.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/database.c b/src/database.c index bf970b1..28f3cba 100644 --- a/src/database.c +++ b/src/database.c @@ -1730,16 +1730,18 @@ int apk_db_open(struct apk_database *db, struct apk_ctx *ac) apk_db_read_overlay(db, apk_istream_from_fd(STDIN_FILENO)); } - for (i = 0; i < APK_DB_LAYER_NUM; i++) { - r = apk_db_read_layer(db, i); - if (r) { - if (i != APK_DB_LAYER_ROOT) continue; - if (!(r == -ENOENT && (ac->open_flags & APK_OPENF_CREATE))) { - msg = "Unable to read database"; - goto ret_r; + if ((db->ctx->flags & APK_OPENF_NO_STATE) != APK_OPENF_NO_STATE) { + for (i = 0; i < APK_DB_LAYER_NUM; i++) { + r = apk_db_read_layer(db, i); + if (r) { + if (i != APK_DB_LAYER_ROOT) continue; + if (!(r == -ENOENT && (ac->open_flags & APK_OPENF_CREATE))) { + msg = "Unable to read database"; + goto ret_r; + } } + db->active_layers |= BIT(i); } - db->active_layers |= BIT(i); } if (!(ac->open_flags & APK_OPENF_NO_INSTALLED_REPO)) { -- cgit v1.2.3-70-g09d2