From 9979407567cb42df9873f83a4dca779073759296 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 23 May 2008 10:31:45 +0300 Subject: [PATCH] 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 --- lib/rpmtd.c | 28 ++++++++++++++++++++++++++++ lib/rpmtd.h | 10 ++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/rpmtd.c b/lib/rpmtd.c index daac145..9114059 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 30d28c0..bc368fa 100644 --- a/lib/rpmtd.h +++ b/lib/rpmtd.h @@ -172,6 +172,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 * to be non-empty. -- 2.7.4