Add rpmtdSetTag() method for setting (or changing) container tag + type

- permit change on non-empty container to compatible type to allow things like
    headerGet(h, RPMTAG_FILENAMES, td, HEADERGET_EXT);
    rpmtdSetTag(td, RPMTAG_OLDFILENAMES);
    headerPut(h, td, HEADERPUT_DEFAULT);
- empty container can be set to any valid type
This commit is contained in:
Panu Matilainen 2008-05-23 10:31:45 +03:00
parent 3249b289e8
commit 9979407567
2 changed files with 38 additions and 0 deletions

View File

@ -191,6 +191,34 @@ char *rpmtdFormat(rpmtd td, rpmtdFormats fmt, const char *errmsg)
return str;
}
int rpmtdSetTag(rpmtd td, rpmTag tag)
{
assert(td != NULL);
rpmTagType newtype = rpmTagGetType(tag);
int rc = 0;
/*
* Sanity checks:
* - is the new tag valid at all
* - if changing tag of non-empty container, require matching type
*/
if (newtype == RPM_NULL_TYPE)
goto exit;
if (td->data || td->count > 0) {
if (rpmTagGetType(td->tag) != rpmTagGetType(tag)) {
goto exit;
}
}
td->tag = tag;
td->type = newtype & RPM_MASK_TYPE;
rc = 1;
exit:
return rc;
}
int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv)
{
int count = argvCount(argv);

View File

@ -171,6 +171,16 @@ typedef enum rpmtdFormats_e {
*/
char *rpmtdFormat(rpmtd td, rpmtdFormats fmt, const char *errmsg);
/** \ingroup rpmtd
* Set container tag and type.
* For empty container, any valid tag can be set. If the container has
* data, changing is only permitted to tag of same type.
* @param td Tag data container
* @param tag New tag
* @return 1 on success, 0 on error
*/
int rpmtdSetTag(rpmtd td, rpmTag tag);
/** \ingroup rpmtd
* Construct tag container from ARGV_t array.
* Tag type is checked to be of string array type and array is checked