diff options
author | Daniel Kolesa <daniel@octaforge.org> | 2022-03-06 19:08:06 +0100 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2022-03-07 08:26:07 +0000 |
commit | c5d9aaa1ee02c81de4319fcb0f4fb83310aab351 (patch) | |
tree | 598da181ef4e4cf47e646528af9816213a55345d /src | |
parent | fa913aba4bbca9c672c581171c6845140010e80d (diff) | |
download | apk-tools-c5d9aaa1ee02c81de4319fcb0f4fb83310aab351.tar.gz apk-tools-c5d9aaa1ee02c81de4319fcb0f4fb83310aab351.tar.bz2 apk-tools-c5d9aaa1ee02c81de4319fcb0f4fb83310aab351.tar.xz apk-tools-c5d9aaa1ee02c81de4319fcb0f4fb83310aab351.zip |
adb: fix handling of conflicts
Ensure not to mask away previously set APK_VERSION_CONFLICT when
serializing.
When deserializing, make sure to actually write out the conflict
flag when no version part is set.
When creating apk_dependency, ensure to set the conflict bit
correctly and mask it off result_mask.
Fixes https://gitlab.alpinelinux.org/alpine/apk-tools/-/issues/10824
Diffstat (limited to 'src')
-rw-r--r-- | src/apk_adb.c | 15 | ||||
-rw-r--r-- | src/apk_version.h | 1 | ||||
-rw-r--r-- | src/package.c | 4 |
3 files changed, 14 insertions, 6 deletions
diff --git a/src/apk_adb.c b/src/apk_adb.c index ea27a4d..25508c1 100644 --- a/src/apk_adb.c +++ b/src/apk_adb.c @@ -4,8 +4,6 @@ #include "apk_print.h" #include "apk_version.h" -#define APK_VERSION_CONFLICT 16 - /* Few helpers to map old database to new one */ int apk_dep_split(apk_blob_t *b, apk_blob_t *bdep) @@ -259,10 +257,17 @@ static apk_blob_t dependency_tostring(struct adb_obj *obj, char *buf, size_t buf name = adb_ro_blob(obj, ADBI_DEP_NAME); ver = adb_ro_blob(obj, ADBI_DEP_VERSION); + mask = adb_ro_int(obj, ADBI_DEP_MATCH) ?: APK_VERSION_EQUAL; + if (APK_BLOB_IS_NULL(name)) return APK_BLOB_NULL; - if (APK_BLOB_IS_NULL(ver)) return name; + if (APK_BLOB_IS_NULL(ver)) { + if (mask & APK_VERSION_CONFLICT) + return APK_BLOB_PTR_LEN(buf, + snprintf(buf, bufsz, "!"BLOB_FMT, + BLOB_PRINTF(name))); + return name; + } - mask = adb_ro_int(obj, ADBI_DEP_MATCH) ?: APK_VERSION_EQUAL; return APK_BLOB_PTR_LEN(buf, snprintf(buf, bufsz, "%s"BLOB_FMT"%s"BLOB_FMT, (mask & APK_VERSION_CONFLICT) ? "!" : "", @@ -295,7 +300,7 @@ static int dependency_fromstring(struct adb_obj *obj, apk_blob_t bdep) if (!apk_blob_spn(bop, apk_spn_dependency_comparer, &bop, &bver)) goto fail; - mask = 0; + mask &= APK_VERSION_CONFLICT; for (i = 0; i < bop.len; i++) { switch (bop.ptr[i]) { case '<': diff --git a/src/apk_version.h b/src/apk_version.h index 0996207..59a7e57 100644 --- a/src/apk_version.h +++ b/src/apk_version.h @@ -17,6 +17,7 @@ #define APK_VERSION_LESS 2 #define APK_VERSION_GREATER 4 #define APK_VERSION_FUZZY 8 +#define APK_VERSION_CONFLICT 16 #define APK_DEPMASK_ANY (APK_VERSION_EQUAL|APK_VERSION_LESS|\ APK_VERSION_GREATER|APK_VERSION_FUZZY) diff --git a/src/package.c b/src/package.c index 001f7d5..0b2c7d8 100644 --- a/src/package.c +++ b/src/package.c @@ -457,10 +457,12 @@ int apk_deps_write(struct apk_database *db, struct apk_dependency_array *deps, s void apk_dep_from_adb(struct apk_dependency *dep, struct apk_database *db, struct adb_obj *d) { + int mask = adb_ro_int(d, ADBI_DEP_MATCH); *dep = (struct apk_dependency) { .name = apk_db_get_name(db, adb_ro_blob(d, ADBI_DEP_NAME)), .version = apk_atomize_dup(&db->atoms, adb_ro_blob(d, ADBI_DEP_VERSION)), - .result_mask = adb_ro_int(d, ADBI_DEP_MATCH) ?: APK_VERSION_EQUAL, + .conflict = !!(mask & APK_VERSION_CONFLICT), + .result_mask = (mask & ~APK_VERSION_CONFLICT) ?: APK_VERSION_EQUAL, }; } |