From 4ab11d140b73145fb0edddaba8b5d863f76ea62e Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 13 Nov 2013 17:10:35 +0200 Subject: [PATCH] Add a bit of API for accessing the original paths - Especially rpmfiOFN() and its underlying buffer is more than a bit dubious, but can't really help it as people are going to expect it behaving identically to rpmfiFN(). And they can't share the same buffer as somebody is going to be tempted to do eg if (strcmp(rpmfiFN(fi), rpmfiOFN(fi))) /* file has been relocated */ - Based on ffesti's original work on the subject --- lib/rpmfi.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ lib/rpmfi.h | 30 ++++++++++++++++++++++ lib/rpmfi_internal.h | 36 +++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) diff --git a/lib/rpmfi.c b/lib/rpmfi.c index 6c49c541b..424e5a715 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -46,6 +46,7 @@ struct rpmfi_s { int j; /*!< Current directory index. */ iterfunc next; /*!< Iterator function. */ char * fn; /*!< File name buffer. */ + char * ofn; /*!< Original file name buffer. */ rpmfiles files; /*!< File info set */ rpmcpio_t archive; /*!< Archive with payload */ @@ -334,31 +335,61 @@ int rpmfilesDI(rpmfiles fi, int dx) return (fi != NULL) ? rpmfnDI(&fi->fndata, dx) : -1; } +int rpmfilesODI(rpmfiles fi, int dx) +{ + return (fi != NULL) ? rpmfnDI(fi->ofndata, dx) : -1; +} + rpmsid rpmfilesBNId(rpmfiles fi, int ix) { return (fi != NULL) ? rpmfnBNId(&fi->fndata, ix) : 0; } +rpmsid rpmfilesOBNId(rpmfiles fi, int ix) +{ + return (fi != NULL) ? rpmfnBNId(fi->ofndata, ix) : 0; +} + rpmsid rpmfilesDNId(rpmfiles fi, int jx) { return (fi != NULL) ? rpmfnDNId(&fi->fndata, jx) : 0; } +rpmsid rpmfilesODNId(rpmfiles fi, int jx) +{ + return (fi != NULL) ? rpmfnDNId(fi->ofndata, jx) : 0; +} + const char * rpmfilesBN(rpmfiles fi, int ix) { return (fi != NULL) ? rpmfnBN(fi->pool, &fi->fndata, ix) : NULL; } +const char * rpmfilesOBN(rpmfiles fi, int ix) +{ + return (fi != NULL) ? rpmstrPoolStr(fi->pool, rpmfilesOBNId(fi, ix)) : NULL; +} + const char * rpmfilesDN(rpmfiles fi, int jx) { return (fi != NULL) ? rpmfnDN(fi->pool, &fi->fndata, jx) : NULL; } +const char * rpmfilesODN(rpmfiles fi, int jx) +{ + return (fi != NULL) ? rpmstrPoolStr(fi->pool, rpmfilesODNId(fi, jx)) : NULL; +} + char * rpmfilesFN(rpmfiles fi, int ix) { return (fi != NULL) ? rpmfnFN(fi->pool, &fi->fndata, ix) : NULL; } +char * rpmfilesOFN(rpmfiles fi, int ix) +{ + return (fi != NULL) ? rpmfnFN(fi->pool, fi->ofndata, ix) : NULL; +} + static int cmpPoolFn(rpmstrPool pool, rpmfn files, int ix, const char * fn) { rpmsid dnid = rpmfnDNId(files, rpmfnDI(files, ix)); @@ -408,6 +439,11 @@ int rpmfilesFindFN(rpmfiles files, const char * fn) return (files && fn) ? rpmfnFindFN(files->pool, &files->fndata, fn) : -1; } +int rpmfilesFindOFN(rpmfiles files, const char * fn) +{ + return (files && fn) ? rpmfnFindFN(files->pool, files->ofndata, fn) : -1; +} + int rpmfiFindFN(rpmfi fi, const char * fn) { int ix = -1; @@ -418,6 +454,16 @@ int rpmfiFindFN(rpmfi fi, const char * fn) return ix; } +int rpmfiFindOFN(rpmfi fi, const char * fn) +{ + int ix = -1; + + if (fi != NULL) { + ix = rpmfilesFindOFN(fi->files, fn); + } + return ix; +} + rpmfileAttrs rpmfilesFFlags(rpmfiles fi, int ix) { rpmfileAttrs FFlags = 0; @@ -1422,6 +1468,7 @@ rpmfi rpmfiFree(rpmfi fi) fi->files = rpmfilesFree(fi->files); fi->fn = _free(fi->fn); + fi->ofn = _free(fi->ofn); fi->apath = _free(fi->apath); free(fi); @@ -1861,6 +1908,18 @@ const char * rpmfiFN(rpmfi fi) return fn; } +const char * rpmfiOFN(rpmfi fi) +{ + const char *fn = ""; /* preserve behavior on errors */ + if (fi != NULL) { + free(fi->ofn); + fi->ofn = rpmfilesOFN(fi->files, fi->i); + if (fi->ofn != NULL) + fn = fi->ofn; + } + return fn; +} + const unsigned char * rpmfiFDigest(rpmfi fi, int *algo, size_t *len) { return rpmfilesFDigest(fi->files, fi ? fi->i : -1, algo, len); diff --git a/lib/rpmfi.h b/lib/rpmfi.h index 121a7d9af..c4ec6b091 100644 --- a/lib/rpmfi.h +++ b/lib/rpmfi.h @@ -178,6 +178,36 @@ const char * rpmfiFN(rpmfi fi); */ int rpmfiFindFN(rpmfi fi, const char * fn); +/** \ingroup rpmfi + * Return current original base name from file info set. + * @param fi file info set + * @return current base name, NULL on invalid + */ +const char * rpmfiOBN(rpmfi fi); + +/** \ingroup rpmfi + * Return current original directory name from file info set. + * @param fi file info set + * @return current directory, NULL on invalid + */ +const char * rpmfiODN(rpmfi fi); + +/** \ingroup rpmfi + * Return current original file name from file info set. + * @param fi file info set + * @return current file name + */ +const char * rpmfiOFN(rpmfi fi); + +/** \ingroup rpmfi + * Return file index of the given original file name or -1 if file is not + * in the rpmfi. The file name may have "." prefixed but is then interpreted + * as a global path without the prefixing "." + * @param fi file info set + * @return file index or -1 + */ +int rpmfiFindOFN(rpmfi fi, const char * fn); + /** \ingroup rpmfi * Return current file flags from file info set. * @param fi file info set diff --git a/lib/rpmfi_internal.h b/lib/rpmfi_internal.h index 041b6f5b6..d00829874 100644 --- a/lib/rpmfi_internal.h +++ b/lib/rpmfi_internal.h @@ -60,6 +60,40 @@ const char * rpmfilesDN(rpmfiles fi, int jx); RPM_GNUC_INTERNAL char * rpmfilesFN(rpmfiles fi, int ix); +/** \ingroup rpmfi + * Return current original base name pool id from file info set. + * @param fi file info set + * @return current base name id, 0 on invalid + */ +RPM_GNUC_INTERNAL +rpmsid rpmfiOBNId(rpmfi fi); + +/** \ingroup rpmfi + * Return current original directory name pool id from file info set. + * @param fi file info set + * @return current base name id, 0 on invalid + */ +RPM_GNUC_INTERNAL +rpmsid rpmfiODNId(rpmfi fi); + +RPM_GNUC_INTERNAL +int rpmfilesODI(rpmfiles fi, int dx); + +RPM_GNUC_INTERNAL +rpmsid rpmfilesOBNId(rpmfiles fi, int ix); + +RPM_GNUC_INTERNAL +rpmsid rpmfilesODNId(rpmfiles fi, int jx); + +RPM_GNUC_INTERNAL +const char * rpmfilesOBN(rpmfiles fi, int ix); + +RPM_GNUC_INTERNAL +const char * rpmfilesODN(rpmfiles fi, int jx); + +RPM_GNUC_INTERNAL +char * rpmfilesOFN(rpmfiles fi, int ix); + RPM_GNUC_INTERNAL rpmVerifyAttrs rpmfilesVFlags(rpmfiles fi, int ix); @@ -154,6 +188,8 @@ rpm_count_t rpmfilesDC(rpmfiles fi); int rpmfilesFindFN(rpmfiles files, const char * fn); +int rpmfilesFindOFN(rpmfiles files, const char * fn); + rpmfi rpmfilesIter(rpmfiles files, int itype); int rpmfilesDigestAlgo(rpmfiles fi);