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;
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;
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);
}
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");
/**
* 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
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 */
}
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;
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;
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);
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;