diff --git a/lib/rpmtd.c b/lib/rpmtd.c index daac14542..911405944 100644 --- a/lib/rpmtd.c +++ b/lib/rpmtd.c @@ -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); diff --git a/lib/rpmtd.h b/lib/rpmtd.h index 30d28c0c8..bc368fa25 100644 --- a/lib/rpmtd.h +++ b/lib/rpmtd.h @@ -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