Handle tag separators

This commit is contained in:
Andreas Steffen
2014-04-15 09:28:38 +02:00
parent edd2ed860f
commit fa6c5f3506
2 changed files with 16 additions and 13 deletions
+15 -12
View File
@@ -63,10 +63,11 @@ static status_t generate_tags(private_swid_inventory_t *this, char *generator,
status_t status = SUCCESS; status_t status = SUCCESS;
/* Assemble the SWID generator command */ /* Assemble the SWID generator command */
snprintf(command, sizeof(command), "%s %s%s%s\n", generator, snprintf(command, sizeof(command), "%s %s%s%s%s\n", generator,
(this->full_tags) ? "swid" : "software-id", (this->full_tags) ? "swid" : "software-id",
(this->full_tags && pretty) ? " --pretty" : "", (this->full_tags && pretty) ? " --pretty" : "",
(this->full_tags && full) ? " --full" : ""); (this->full_tags && !pretty) ? " --doc-separator $'\n\n'" : "",
(this->full_tags && full) ? " --full" : "");
/* Open a pipe stream for reading the output of the dpkg-query commmand */ /* Open a pipe stream for reading the output of the dpkg-query commmand */
file = popen(command, "r"); file = popen(command, "r");
@@ -108,16 +109,18 @@ static status_t generate_tags(private_swid_inventory_t *this, char *generator,
tag_encoding = writer->get_buf(writer); tag_encoding = writer->get_buf(writer);
/* remove trailing newline if present */ if (tag_encoding.len > 1)
if (tag_encoding.len > 0 &&
tag_encoding.ptr[tag_encoding.len - 1] == '\n')
{ {
tag_encoding.len--; /* remove trailing newline if present */
} if (tag_encoding.ptr[tag_encoding.len - 1] == '\n')
DBG2(DBG_IMC, " %.*s", tag_encoding.len, tag_encoding.ptr); {
tag_encoding.len--;
}
DBG2(DBG_IMC, " %.*s", tag_encoding.len, tag_encoding.ptr);
tag = swid_tag_create(tag_encoding, tag_file_path); tag = swid_tag_create(tag_encoding, tag_file_path);
this->list->insert_last(this->list, tag); this->list->insert_last(this->list, tag);
}
writer->destroy(writer); writer->destroy(writer);
} }
} }
@@ -24,7 +24,7 @@ libimcv {
push_info = no push_info = no
} }
imc-swid { imc-swid {
swid_pretty = yes swid_pretty = no
} }
} }
} }