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 <daniel@octaforge.org>
cute-signatures
Timo Teräs 2022-03-06 16:07:42 +02:00
parent 62bc43d2a4
commit 00e397d564
1 changed files with 10 additions and 8 deletions

View File

@ -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)) {