csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
/** \ingroup rpmbuild
2ff057
 * \file build/parseFiles.c
2ff057
 *  Parse %files section from spec file.
2ff057
 */
2ff057
2ff057
#include "system.h"
2ff057
2ff057
#include <rpm/rpmlog.h>
2ff057
#include <rpm/rpmfileutil.h>
2ff057
#include "build/rpmbuild_internal.h"
2ff057
#include "debug.h"
2ff057
2ff057
int parseFiles(rpmSpec spec)
2ff057
{
2ff057
    int nextPart, res = PART_ERROR;
2ff057
    Package pkg;
2ff057
    int rc, argc;
2ff057
    int arg;
2ff057
    const char ** argv = NULL;
2ff057
    const char *name = NULL;
2ff057
    int flag = PART_SUBNAME;
2ff057
    poptContext optCon = NULL;
2ff057
    struct poptOption optionsTable[] = {
2ff057
	{ NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
2ff057
	{ NULL, 'f', POPT_ARG_STRING, NULL, 'f', NULL, NULL},
2ff057
	{ 0, 0, 0, 0, 0, NULL, NULL}
2ff057
    };
2ff057
2ff057
    /* XXX unmask %license while parsing %files */
2ff057
    rpmPushMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC);
2ff057
2ff057
    if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
2ff057
	rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"),
2ff057
		 spec->lineNum, poptStrerror(rc));
2ff057
	goto exit;
2ff057
    }
2ff057
2ff057
    optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
2ff057
    while ((arg = poptGetNextOpt(optCon)) > 0) {
2ff057
	if (arg == 'n') {
2ff057
	    flag = PART_NAME;
2ff057
	}
2ff057
    }
2ff057
2ff057
    if (arg < -1) {
2ff057
	rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
2ff057
		 spec->lineNum,
2ff057
		 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
2ff057
		 spec->line);
2ff057
	goto exit;
2ff057
    }
2ff057
2ff057
    if (poptPeekArg(optCon)) {
2ff057
	if (name == NULL)
2ff057
	    name = poptGetArg(optCon);
2ff057
	if (poptPeekArg(optCon)) {
2ff057
	    rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
2ff057
		     spec->lineNum,
2ff057
		     spec->line);
2ff057
	    goto exit;
2ff057
	}
2ff057
    }
2ff057
2ff057
    if (lookupPackage(spec, name, flag, &pkg))
2ff057
	goto exit;
2ff057
2ff057
    /*
2ff057
     * This should be an error, but its surprisingly commonly abused for the
2ff057
     * effect of multiple -f arguments in versions that dont support it.
2ff057
     * Warn but preserve behavior, except for leaking memory.
2ff057
     */
2ff057
    if (pkg->fileList != NULL) {
2ff057
	rpmlog(RPMLOG_WARNING, _("line %d: multiple %%files for package '%s'\n"),
2ff057
	       spec->lineNum, rpmstrPoolStr(pkg->pool, pkg->name));
2ff057
	pkg->fileList = argvFree(pkg->fileList);
2ff057
    }
2ff057
2ff057
    for (arg=1; arg
2ff057
	if (rstreq(argv[arg], "-f") && argv[arg+1]) {
2ff057
	    char *file = rpmGetPath(argv[arg+1], NULL);
2ff057
	    argvAdd(&(pkg->fileFile), file);
2ff057
	    free(file);
2ff057
	}
2ff057
    }
2ff057
2ff057
    pkg->fileList = argvNew();
2ff057
2ff057
    if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
2ff057
	nextPart = PART_NONE;
2ff057
    } else if (rc < 0) {
2ff057
	goto exit;
2ff057
    } else {
2ff057
	while (! (nextPart = isPart(spec->line))) {
2ff057
	    argvAdd(&(pkg->fileList), spec->line);
2ff057
	    if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
2ff057
		nextPart = PART_NONE;
2ff057
		break;
2ff057
	    } else if (rc < 0) {
2ff057
		goto exit;
2ff057
	    }
2ff057
	}
2ff057
    }
2ff057
    res = nextPart;
2ff057
2ff057
exit:
2ff057
    rpmPopMacro(NULL, "license");
2ff057
    free(argv);
2ff057
    poptFreeContext(optCon);
2ff057
	
2ff057
    return res;
2ff057
}