Issue
I am trying to create a new header and insert some tags with the RPM Header API using the href="http://rpm.org/api/4.12.0.1/group__header.html#ga9a7cc53243734db48200933aecaea57c" rel="nofollow noreferrer">headerPut* functions, but in this simple example my attempted insertions fail with the exception of headerPutString
and I am at a loss as to why:
Header s = NULL;
unsigned char md5[16] = {0};
uint32_t size = 42;
s = headerNew();
if (headerPutString(s, RPMSIGTAG_SHA1, "foo") != 1)
fprintf(stderr, "headerPutString error\n");
if (headerPutUint32(s, RPMSIGTAG_SIZE, &size, 1) != 1)
fprintf(stderr, "headerPutUint32 error\n");
if (headerPutBin(s, RPMSIGTAG_MD5, md5, 16) != 1)
fprintf(stderr, "headerPutBin error\n");
Running this outputs:
headerPutUint32 error
headerPutBin error
and when I then call headerWrite
and examine the resulting file contents with the hexdump
tool, I can see that the header only contains the string-type tag.
Why can't I insert the other two?
Solution
Well, after some gdb
debugging and looking through the RPM source files, I see where the problem is.
In the signature, RPMSIGTAG_SIZE
(1000) is of type INT32
and RPMSIGTAG_MD5
(1004) is of type BIN
. The problem is that these symbolic values also correspond to RPM header tags, where the type differs: RPMTAG_NAME
is 1000 and is a STRING
, RPMTAG_SUMMARY
is 1004 and is an I18NSTRING
. The RPM source files have no way to distinguish between the two and assume they are header tags, not signature tags.
Fortunately, the API also contains the headerPut
function. This is actually what gets called by the type-specific functions after the sanity checks (including type checking), headerPut
itself doesn't attempt any tag-type match, it just goes ahead and tries to add/append it, and is therefore a good solution for these situations.
Answered By - MC93 Answer Checked By - Marie Seifert (WPSolving Admin)