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
This commit is contained in:
Panu Matilainen 2013-11-13 17:10:35 +02:00
parent 77423af798
commit 4ab11d140b
3 changed files with 125 additions and 0 deletions

View File

@ -46,6 +46,7 @@ struct rpmfi_s {
int j; /*!< Current directory index. */ int j; /*!< Current directory index. */
iterfunc next; /*!< Iterator function. */ iterfunc next; /*!< Iterator function. */
char * fn; /*!< File name buffer. */ char * fn; /*!< File name buffer. */
char * ofn; /*!< Original file name buffer. */
rpmfiles files; /*!< File info set */ rpmfiles files; /*!< File info set */
rpmcpio_t archive; /*!< Archive with payload */ rpmcpio_t archive; /*!< Archive with payload */
@ -334,31 +335,61 @@ int rpmfilesDI(rpmfiles fi, int dx)
return (fi != NULL) ? rpmfnDI(&fi->fndata, dx) : -1; 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) rpmsid rpmfilesBNId(rpmfiles fi, int ix)
{ {
return (fi != NULL) ? rpmfnBNId(&fi->fndata, ix) : 0; 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) rpmsid rpmfilesDNId(rpmfiles fi, int jx)
{ {
return (fi != NULL) ? rpmfnDNId(&fi->fndata, jx) : 0; 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) const char * rpmfilesBN(rpmfiles fi, int ix)
{ {
return (fi != NULL) ? rpmfnBN(fi->pool, &fi->fndata, ix) : NULL; 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) const char * rpmfilesDN(rpmfiles fi, int jx)
{ {
return (fi != NULL) ? rpmfnDN(fi->pool, &fi->fndata, jx) : NULL; 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) char * rpmfilesFN(rpmfiles fi, int ix)
{ {
return (fi != NULL) ? rpmfnFN(fi->pool, &fi->fndata, ix) : NULL; 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) static int cmpPoolFn(rpmstrPool pool, rpmfn files, int ix, const char * fn)
{ {
rpmsid dnid = rpmfnDNId(files, rpmfnDI(files, ix)); 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; 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 rpmfiFindFN(rpmfi fi, const char * fn)
{ {
int ix = -1; int ix = -1;
@ -418,6 +454,16 @@ int rpmfiFindFN(rpmfi fi, const char * fn)
return ix; 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 rpmfilesFFlags(rpmfiles fi, int ix)
{ {
rpmfileAttrs FFlags = 0; rpmfileAttrs FFlags = 0;
@ -1422,6 +1468,7 @@ rpmfi rpmfiFree(rpmfi fi)
fi->files = rpmfilesFree(fi->files); fi->files = rpmfilesFree(fi->files);
fi->fn = _free(fi->fn); fi->fn = _free(fi->fn);
fi->ofn = _free(fi->ofn);
fi->apath = _free(fi->apath); fi->apath = _free(fi->apath);
free(fi); free(fi);
@ -1861,6 +1908,18 @@ const char * rpmfiFN(rpmfi fi)
return fn; 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) const unsigned char * rpmfiFDigest(rpmfi fi, int *algo, size_t *len)
{ {
return rpmfilesFDigest(fi->files, fi ? fi->i : -1, algo, len); return rpmfilesFDigest(fi->files, fi ? fi->i : -1, algo, len);

View File

@ -178,6 +178,36 @@ const char * rpmfiFN(rpmfi fi);
*/ */
int rpmfiFindFN(rpmfi fi, const char * fn); 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 /** \ingroup rpmfi
* Return current file flags from file info set. * Return current file flags from file info set.
* @param fi file info set * @param fi file info set

View File

@ -60,6 +60,40 @@ const char * rpmfilesDN(rpmfiles fi, int jx);
RPM_GNUC_INTERNAL RPM_GNUC_INTERNAL
char * rpmfilesFN(rpmfiles fi, int ix); 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 RPM_GNUC_INTERNAL
rpmVerifyAttrs rpmfilesVFlags(rpmfiles fi, int ix); rpmVerifyAttrs rpmfilesVFlags(rpmfiles fi, int ix);
@ -154,6 +188,8 @@ rpm_count_t rpmfilesDC(rpmfiles fi);
int rpmfilesFindFN(rpmfiles files, const char * fn); int rpmfilesFindFN(rpmfiles files, const char * fn);
int rpmfilesFindOFN(rpmfiles files, const char * fn);
rpmfi rpmfilesIter(rpmfiles files, int itype); rpmfi rpmfilesIter(rpmfiles files, int itype);
int rpmfilesDigestAlgo(rpmfiles fi); int rpmfilesDigestAlgo(rpmfiles fi);