Add tag extension to calculate hardlink count for files
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Feb 2012 13:40:02 +0000 (15:40 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Feb 2012 13:40:02 +0000 (15:40 +0200)
lib/rpmtag.h
lib/tagexts.c
tests/rpmgeneral.at

index 767e17c..e8e9dee 100644 (file)
@@ -306,6 +306,7 @@ typedef enum rpmTag_e {
     RPMTAG_PROVIDENEVRS                = 5042, /* s[] extension */
     RPMTAG_OBSOLETENEVRS       = 5043, /* s[] extension */
     RPMTAG_CONFLICTNEVRS       = 5044, /* s[] extension */
+    RPMTAG_FILENLINKS          = 5045, /* i[] extension */
 
     RPMTAG_FIRSTFREE_TAG       /*!< internal */
 } rpmTag;
index bc12d2b..77d2024 100644 (file)
@@ -767,6 +767,27 @@ static int conflictnevrsTag(Header h, rpmtd td, headerGetFlags hgflags)
     return depnevrsTag(h, td, hgflags, RPMTAG_CONFLICTNAME);
 }
 
+static int filenlinksTag(Header h, rpmtd td, headerGetFlags hgflags)
+{
+    rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, RPMFI_NOHEADER);
+    rpm_count_t fc = rpmfiFC(fi);
+
+    if (fc > 0) {
+       uint32_t *nlinks = xmalloc(fc * sizeof(*nlinks));
+       int ix;
+       while ((ix = rpmfiNext(fi)) >= 0) {
+           nlinks[ix] = rpmfiFNlink(fi);
+       }
+       td->data = nlinks;
+       td->type = RPM_INT32_TYPE;
+       td->count = fc;
+       td->flags = RPMTD_ALLOCED;
+    }
+
+    rpmfiFree(fi);
+    return (fc > 0);
+}
+
 static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
     { RPMTAG_GROUP,            groupTag },
     { RPMTAG_DESCRIPTION,      descriptionTag },
@@ -796,6 +817,7 @@ static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
     { RPMTAG_PROVIDENEVRS,     providenevrsTag },
     { RPMTAG_OBSOLETENEVRS,    obsoletenevrsTag },
     { RPMTAG_CONFLICTNEVRS,    conflictnevrsTag },
+    { RPMTAG_FILENLINKS,       filenlinksTag },
     { 0,                       NULL }
 };
 
index 04857ab..13131e2 100644 (file)
@@ -104,6 +104,7 @@ FILEMD5S
 FILEMODES
 FILEMTIMES
 FILENAMES
+FILENLINKS
 FILEPROVIDE
 FILERDEVS
 FILEREQUIRE