00001
00005 #include "system.h"
00006
00007 #include <rpmio.h>
00008 #include <rpmiotypes.h>
00009 #include <rpmmacro.h>
00010
00011 #define _RPMTAG_INTERNAL
00012 #include <rpmtag.h>
00013 #include <rpmtypes.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 rpmuint64_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 if (ds == NULL)
00229 return 1;
00230
00231
00232 ds = rpmdsInit(ds);
00233 if (ds != NULL)
00234 while (rpmdsNext(ds) >= 0) {
00235 int Flags = rpmdsFlags(ds);
00236 const char * DNEVR;
00237 if (!(Flags & RPMSENSE_MISSINGOK))
00238 continue;
00239 DNEVR = rpmdsDNEVR(ds);
00240 if (DNEVR == NULL)
00241 continue;
00242 nb += sizeof(*argv) + strlen(DNEVR+2) + 1;
00243 (void) argvAdd(&av, DNEVR+2);
00244 argc++;
00245 }
00246 nb += sizeof(*argv);
00247
00248
00249 argv = (ARGV_t) xcalloc(nb, 1);
00250 t = (char *)(argv + argc);
00251 for (i = 0; i < argc; i++) {
00252 argv[i] = t;
00253 t = stpcpy(t, av[i]);
00254 *t++ = '\0';
00255 }
00256 av = argvFree(av);
00257 (void)rpmdsFree(ds);
00258 ds = NULL;
00259
00260 he->t = RPM_STRING_ARRAY_TYPE;
00261 he->p.argv = argv;
00262 he->c = argc;
00263 he->freeData = 1;
00264 return 0;
00265 }
00266
00267
00268 static struct headerSprintfExtension_s _rpmHeaderFormats[] = {
00269 { HEADER_EXT_TAG, "RPMTAG_ENHANCES",
00270 { .tagFunction = missingokTag } },
00271 { HEADER_EXT_TAG, "RPMTAG_FILECLASS",
00272 { .tagFunction = fileclassTag } },
00273 { HEADER_EXT_TAG, "RPMTAG_FILECONTEXTS",
00274 { .tagFunction = filecontextsTag } },
00275 { HEADER_EXT_TAG, "RPMTAG_FILEPROVIDE",
00276 { .tagFunction = fileprovideTag } },
00277 { HEADER_EXT_TAG, "RPMTAG_FILEREQUIRE",
00278 { .tagFunction = filerequireTag } },
00279 { HEADER_EXT_TAG, "RPMTAG_FSCONTEXTS",
00280 { .tagFunction = fscontextsTag } },
00281 { HEADER_EXT_TAG, "RPMTAG_FSNAMES",
00282 { .tagFunction = fsnamesTag } },
00283 { HEADER_EXT_TAG, "RPMTAG_FSSIZES",
00284 { .tagFunction = fssizesTag } },
00285 { HEADER_EXT_TAG, "RPMTAG_RECONTEXTS",
00286 { .tagFunction = recontextsTag } },
00287 { HEADER_EXT_TAG, "RPMTAG_SUGGESTS",
00288 { .tagFunction = missingokTag } },
00289 { HEADER_EXT_MORE, NULL, { (void *) &headerCompoundFormats } }
00290 } ;
00291
00292
00293 headerSprintfExtension rpmHeaderFormats = &_rpmHeaderFormats[0];