00001
00005 #include "system.h"
00006
00007 #include <rpmio.h>
00008 #include <rpmcb.h>
00009 #include <rpmmacro.h>
00010
00011 #define _RPMTAG_INTERNAL
00012 #include <rpmtag.h>
00013 #include <rpmlib.h>
00014
00015 #define _RPMEVR_INTERNAL
00016 #include <rpmds.h>
00017 #include <rpmfi.h>
00018
00019 #include "legacy.h"
00020 #include "manifest.h"
00021 #include "argv.h"
00022 #include "fs.h"
00023
00024 #include "debug.h"
00025
00026
00027
00034 static int fsnamesTag( Header h, HE_t he)
00035
00036
00037 {
00038 const char ** list;
00039
00040 if (rpmGetFilesystemList(&list, &he->c))
00041 return 1;
00042
00043 he->t = RPM_STRING_ARRAY_TYPE;
00044 he->p.argv = list;
00045 he->freeData = 0;
00046
00047 return 0;
00048 }
00049
00056 static int fssizesTag(Header h, HE_t he)
00057
00058
00059
00060
00061 {
00062 rpmTagData fnames = { .ptr = NULL };
00063 rpmTagData fsizes = { .ptr = NULL };
00064 rpmTagData p;
00065 uint64_t *usages;
00066 int numFiles;
00067 int rc = 1;
00068 int xx, yy;
00069
00070 p.ptr = he->p.ptr;
00071 he->tag = RPMTAG_FILESIZES;
00072 xx = headerGet(h, he, 0);
00073 fsizes.ptr = he->p.ptr;
00074 he->tag = RPMTAG_FILEPATHS;
00075 yy = headerGet(h, he, 0);
00076 fnames.ptr = he->p.ptr;
00077 numFiles = he->c;
00078 he->p.ptr = p.ptr;
00079 if (!xx || !yy) {
00080 numFiles = 0;
00081 fsizes.ui32p = _free(fsizes.ui32p);
00082 fnames.argv = _free(fnames.argv);
00083 }
00084
00085 if (rpmGetFilesystemList(NULL, &he->c))
00086 goto exit;
00087
00088 he->t = RPM_UINT64_TYPE;
00089 he->freeData = 1;
00090
00091 if (fnames.ptr == NULL)
00092 usages = xcalloc(he->c, sizeof(*usages));
00093 else
00094 if (rpmGetFilesystemUsage(fnames.argv, fsizes.ui32p, numFiles, &usages, 0))
00095 goto exit;
00096
00097 he->p.ui64p = usages;
00098 rc = 0;
00099
00100 exit:
00101 fnames.ptr = _free(fnames.ptr);
00102 fsizes.ptr = _free(fsizes.ptr);
00103
00104 return rc;
00105 }
00106
00113 static int fileclassTag(Header h, HE_t he)
00114
00115
00116
00117 {
00118 he->t = RPM_STRING_ARRAY_TYPE;
00119 rpmfiBuildFClasses(h, &he->p.argv, &he->c);
00120 he->freeData = 1;
00121 return 0;
00122 }
00123
00130 static int filecontextsTag(Header h, HE_t he)
00131
00132
00133
00134 {
00135 he->t = RPM_STRING_ARRAY_TYPE;
00136 rpmfiBuildFContexts(h, &he->p.argv, &he->c);
00137 he->freeData = 1;
00138 return 0;
00139 }
00140
00147 static int fscontextsTag(Header h, HE_t he)
00148
00149
00150
00151 {
00152 he->t = RPM_STRING_ARRAY_TYPE;
00153 rpmfiBuildFSContexts(h, &he->p.argv, &he->c);
00154 he->freeData = 1;
00155 return 0;
00156 }
00157
00164 static int recontextsTag(Header h, HE_t he)
00165
00166
00167
00168 {
00169 he->t = RPM_STRING_ARRAY_TYPE;
00170 rpmfiBuildREContexts(h, &he->p.argv, &he->c);
00171 he->freeData = 1;
00172 return 0;
00173 }
00174
00181 static int fileprovideTag(Header h, HE_t he)
00182
00183
00184
00185 {
00186 he->t = RPM_STRING_ARRAY_TYPE;
00187 rpmfiBuildFDeps(h, RPMTAG_PROVIDENAME, &he->p.argv, &he->c);
00188 he->freeData = 1;
00189 return 0;
00190 }
00191
00198 static int filerequireTag(Header h, HE_t he)
00199
00200
00201
00202 {
00203 he->t = RPM_STRING_ARRAY_TYPE;
00204 rpmfiBuildFDeps(h, RPMTAG_REQUIRENAME, &he->p.argv, &he->c);
00205 he->freeData = 1;
00206 return 0;
00207 }
00208
00215 static int missingokTag(Header h, HE_t he)
00216
00217
00218
00219 {
00220 rpmds ds = rpmdsNew(h, RPMTAG_REQUIRENAME, 0);
00221 ARGV_t av = NULL;
00222 ARGV_t argv;
00223 int argc = 0;
00224 char * t;
00225 size_t nb = 0;
00226 int i;
00227
00228 assert(ds != NULL);
00229
00230 ds = rpmdsInit(ds);
00231 if (ds != NULL)
00232 while (rpmdsNext(ds) >= 0) {
00233 int Flags = rpmdsFlags(ds);
00234 const char * DNEVR;
00235 if (!(Flags & RPMSENSE_MISSINGOK))
00236 continue;
00237 DNEVR = rpmdsDNEVR(ds);
00238 if (DNEVR == NULL)
00239 continue;
00240 nb += sizeof(*argv) + strlen(DNEVR+2) + 1;
00241 (void) argvAdd(&av, DNEVR+2);
00242 argc++;
00243 }
00244 nb += sizeof(*argv);
00245
00246
00247 argv = (ARGV_t) xcalloc(nb, 1);
00248 t = (char *)(argv + argc);
00249 for (i = 0; i < argc; i++) {
00250 argv[i] = t;
00251 t = stpcpy(t, av[i]);
00252 *t++ = '\0';
00253 }
00254 av = argvFree(av);
00255 ds = rpmdsFree(ds);
00256
00257
00258
00259 he->t = RPM_STRING_ARRAY_TYPE;
00260 he->p.argv = argv;
00261 he->c = argc;
00262 he->freeData = 1;
00263 return 0;
00264 }
00265
00266
00267 static struct headerSprintfExtension_s _rpmHeaderFormats[] = {
00268 { HEADER_EXT_TAG, "RPMTAG_ENHANCES",
00269 { .tagFunction = missingokTag } },
00270 { HEADER_EXT_TAG, "RPMTAG_FILECLASS",
00271 { .tagFunction = fileclassTag } },
00272 { HEADER_EXT_TAG, "RPMTAG_FILECONTEXTS",
00273 { .tagFunction = filecontextsTag } },
00274 { HEADER_EXT_TAG, "RPMTAG_FILEPROVIDE",
00275 { .tagFunction = fileprovideTag } },
00276 { HEADER_EXT_TAG, "RPMTAG_FILEREQUIRE",
00277 { .tagFunction = filerequireTag } },
00278 { HEADER_EXT_TAG, "RPMTAG_FSCONTEXTS",
00279 { .tagFunction = fscontextsTag } },
00280 { HEADER_EXT_TAG, "RPMTAG_FSNAMES",
00281 { .tagFunction = fsnamesTag } },
00282 { HEADER_EXT_TAG, "RPMTAG_FSSIZES",
00283 { .tagFunction = fssizesTag } },
00284 { HEADER_EXT_TAG, "RPMTAG_RECONTEXTS",
00285 { .tagFunction = recontextsTag } },
00286 { HEADER_EXT_TAG, "RPMTAG_SUGGESTS",
00287 { .tagFunction = missingokTag } },
00288 { HEADER_EXT_MORE, NULL, { (void *) &headerCompoundFormats } }
00289 } ;
00290
00291
00292 headerSprintfExtension rpmHeaderFormats = &_rpmHeaderFormats[0];