From 37fbafcd928c466c82c892a7868d686d710e5d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Mon, 3 Jun 2019 09:27:33 +0300 Subject: [PATCH] add: make virtual packages upgradeable (ref #9957) Originally the virtual packages could have dependencies added to it. However, commit b06e3b99 broke this behaviour to fix error reporting. The root cause however was that the virtual depedency package was not properly versioned. This fixes to use current date/time as the package version, and constructs the "faked" package hash from it. This effectively makes "add -t virtpkg deps.." replace the dependencies which should be the desired behaviour for "abuild deps". 'world' dependency to the generated virtual package is also now versioned to make sure it get's upgraded. --- src/add.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/add.c b/src/add.c index 946dc55..7df8197 100644 --- a/src/add.c +++ b/src/add.c @@ -93,6 +93,9 @@ static int add_main(void *ctx, struct apk_database *db, struct apk_string_array if (actx->virtpkg) { apk_blob_t b = APK_BLOB_STR(actx->virtpkg); + struct tm tm; + time_t now; + char ver[32]; apk_blob_pull_dep(&b, db, &virtdep); if (APK_BLOB_IS_NULL(b) || virtdep.conflict || @@ -105,17 +108,23 @@ static int add_main(void *ctx, struct apk_database *db, struct apk_string_array if (virtdep.name->name[0] != '.' && non_repository_check(db)) return -1; + time(&now); + localtime_r(&now, &tm); + strftime(ver, sizeof ver, "%Y%m%d.%H%M%S", &tm); + virtpkg = apk_pkg_new(); if (virtpkg == NULL) { apk_error("Failed to allocate virtual meta package"); return -1; } virtpkg->name = virtdep.name; - apk_blob_checksum(APK_BLOB_STR(virtpkg->name->name), - apk_checksum_default(), &virtpkg->csum); - virtpkg->version = apk_blob_atomize(APK_BLOB_STR("0")); + apk_blob_checksum(APK_BLOB_STR(ver), apk_checksum_default(), &virtpkg->csum); + virtpkg->version = apk_blob_atomize(APK_BLOB_STR(ver)); virtpkg->description = strdup("virtual meta package"); virtpkg->arch = apk_blob_atomize(APK_BLOB_STR("noarch")); + + virtdep.result_mask = APK_VERSION_EQUAL; + virtdep.version = virtpkg->version; } foreach_array_item(parg, args) {