From 77423af7986902cde3459a304f839fa675d5beea Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 13 Nov 2013 17:03:58 +0200 Subject: [PATCH] Store original path data in rpmfi for relocated packages - Relocation is relatively rare, so instead of storing the data within rpmfiles, we allocate it separately if needed. This also allows nicely handling the normal case where ORIG paths are the same as actual paths, ie we simply point it to the same data (and take care not to free twice...) --- lib/rpmfi.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/rpmfi.c b/lib/rpmfi.c index 827d12608..6c49c541b 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -72,6 +72,7 @@ struct rpmfiles_s { rpmstrPool pool; /*!< String pool of this file info set */ struct rpmfn_s fndata; /*!< File name data */ + struct rpmfn_s *ofndata; /*!< Original file name data */ rpmsid * flinks; /*!< Index to file link(s) (pool) */ @@ -1357,6 +1358,10 @@ rpmfiles rpmfilesFree(rpmfiles fi) return rpmfilesUnlink(fi); if (rpmfilesFC(fi) > 0) { + if (fi->ofndata != &fi->fndata) { + rpmfnClear(fi->ofndata); + free(fi->ofndata); + } rpmfnClear(&fi->fndata); fi->flinks = _free(fi->flinks); @@ -1685,8 +1690,22 @@ rpmfiles rpmfilesNew(rpmstrPool pool, Header h, rpmTagVal tagN, rpmfiFlags flags goto err; /* populate the rest of the stuff if we have files */ - if (fc > 0) + if (fc > 0) { + if (headerIsEntry(h, RPMTAG_ORIGBASENAMES)) { + /* For relocated packages, grab the original paths too */ + int ofc; + fi->ofndata = xmalloc(sizeof(*fi->ofndata)); + ofc = rpmfnInit(fi->ofndata, RPMTAG_ORIGBASENAMES, h, fi->pool); + + if (ofc != 0 && ofc != fc) + goto err; + } else { + /* In the normal case, orig is the same as actual path data */ + fi->ofndata = &fi->fndata; + } + rpmfilesPopulate(fi, h, flags); + } /* freeze the pool to save memory, but only if private pool */ if (fi->pool != pool)