sw-collector: strip arch suffix from package names

This commit is contained in:
Andreas Steffen 2017-07-13 12:03:27 +02:00
parent 5b1dbc3a8d
commit cab4cc3a10
5 changed files with 22 additions and 34 deletions

View File

@ -518,7 +518,7 @@ static int migrate(sw_collector_info_t *info, sw_collector_db_t *db)
sw_collector_dpkg_t *dpkg;
char *package, *arch, *version;
char package_arch[BUF_LEN];
char package_filter[BUF_LEN];
int res, count = 0;
int status = EXIT_SUCCESS;
enumerator_t *enumerator;
@ -532,15 +532,11 @@ static int migrate(sw_collector_info_t *info, sw_collector_db_t *db)
enumerator = dpkg->create_sw_enumerator(dpkg);
while (enumerator->enumerate(enumerator, &package, &arch, &version))
{
if (streq(arch, "all"))
{
continue;
}
/* Concatenate package and architecture strings */
snprintf(package_arch, BUF_LEN, "%s:%s", package, arch);
/* Look for package names with architecture suffix */
snprintf(package_filter, BUF_LEN, "%s:%%", package);
res = db->update_package(db, package, package_arch);
res = db->update_package(db, package_filter, package);
if (res < 0)
{
status = EXIT_FAILURE;
@ -549,7 +545,7 @@ static int migrate(sw_collector_info_t *info, sw_collector_db_t *db)
else if (res > 0)
{
count += res;
DBG2(DBG_IMC, "replaced '%s' by '%s'", package, package_arch);
DBG2(DBG_IMC, "%s: removed arch suffix %d times", package, res);
}
}
enumerator->destroy(enumerator);

View File

@ -231,13 +231,13 @@ METHOD(sw_collector_db_t, update_sw_id, bool,
}
METHOD(sw_collector_db_t, update_package, int,
private_sw_collector_db_t *this, char *package, char *package_new)
private_sw_collector_db_t *this, char *package_filter, char *package)
{
int count;
count = this->db->execute(this->db, NULL,
"UPDATE sw_identifiers SET package = ? "
"WHERE package = ?", DB_TEXT, package_new, DB_TEXT, package);
"UPDATE sw_identifiers SET package = ? WHERE package LIKE ?",
DB_TEXT, package, DB_TEXT, package_filter);
if (count < 0)
{
DBG1(DBG_IMC, "unable to update package name in database");

View File

@ -120,12 +120,12 @@ struct sw_collector_db_t {
/**
* Update the package name
*
* @param package Package name to be changed
* @param package_new New package name
* @return TRUE if update successful
* @param package_filter Package name[s] to be changed
* @param package New package name
* @return TRUE if update successful
*/
int (*update_package)(sw_collector_db_t *this, char *package,
char *package_new);
int (*update_package)(sw_collector_db_t *this, char *package_filter,
char *package);
/**
* Enumerate over all collected [installed] software identities

View File

@ -110,7 +110,7 @@ static void free_package(package_t *this)
static package_t* extract_package(chunk_t item, sw_collector_info_t *info,
sw_collector_history_op_t op)
{
chunk_t package, version, old_version;
chunk_t package, package_stripped, version, old_version;
package_t *p;
/* extract package name */
@ -121,6 +121,12 @@ static package_t* extract_package(chunk_t item, sw_collector_info_t *info,
}
item = chunk_skip(item, 1);
/* strip architecture suffix if present */
if (extract_token(&package_stripped, ':', &package))
{
package = package_stripped;
}
/* extract versions */
version = old_version = chunk_empty;
@ -371,7 +377,6 @@ METHOD(sw_collector_history_t, merge_installed_packages, bool,
private_sw_collector_history_t *this)
{
uint32_t sw_id, count = 0;
char package_arch[BUF_LEN];
char *package, *arch, *version, *v1, *name, *n1;
bool installed, success = FALSE;
sw_collector_dpkg_t *dpkg;
@ -439,13 +444,6 @@ METHOD(sw_collector_history_t, merge_installed_packages, bool,
if (!sw_id)
{
/* Package name is stored with appended architecture */
if (!streq(arch, "all"))
{
snprintf(package_arch, BUF_LEN, "%s:%s", package, arch);
package = package_arch;
}
/* new sw identifier - create with state 'installed' */
sw_id = this->db->set_sw_id(this->db, name, package, version,
this->source, TRUE);

View File

@ -93,15 +93,9 @@ METHOD(sw_collector_info_t, get_os, char*,
METHOD(sw_collector_info_t, create_sw_id, char*,
private_sw_collector_info_t *this, char *package, char *version)
{
char *pos, *sw_id;
size_t len;
char *sw_id;
/* Remove architecture from package name */
pos = strchr(package, ':');
len = pos ? (pos - package) : strlen(package);
/* Build software identifier */
if (asprintf(&sw_id, "%s__%s-%.*s%s%s", this->tag_creator, this->os, len,
if (asprintf(&sw_id, "%s__%s-%s%s%s", this->tag_creator, this->os,
package, strlen(version) ? "-" : "", version) == -1)
{
return NULL;