Exemplo n.º 1
0
Arquivo: pkg-spec.c Projeto: smcv/dpkg
void
pkg_spec_iter_init(struct pkg_spec *ps)
{
	if (ps->name_is_pattern)
		ps->pkg_iter = pkg_db_iter_new();
	else
		ps->pkg_next = &pkg_db_find_set(ps->name)->pkg;
}
Exemplo n.º 2
0
const char *
pkg_spec_is_illegal(struct pkg_spec *ps)
{
	static char msg[1024];
	const char *emsg;

	if (!ps->name_is_pattern &&
	    (emsg = pkg_name_is_illegal(ps->name))) {
		const char *arch_sep;

		/* Only check for DPKG_ARCH_NONE, because for everything else
		 * we want to see the passed package specification, even if
		 * the architecture is empty. */
		if (ps->arch->type == DPKG_ARCH_NONE)
			arch_sep = "";
		else
			arch_sep = ":";

		snprintf(msg, sizeof(msg),
		         _("illegal package name in specifier '%s%s%s': %s"),
		         ps->name, arch_sep, ps->arch->name, emsg);
		return msg;
	}

	if ((!ps->arch_is_pattern && ps->arch->type == DPKG_ARCH_ILLEGAL) ||
	    ps->arch->type == DPKG_ARCH_EMPTY) {
		emsg = dpkg_arch_name_is_illegal(ps->arch->name);
		snprintf(msg, sizeof(msg),
		         _("illegal architecture name in specifier '%s:%s': %s"),
		         ps->name, ps->arch->name, emsg);
		return msg;
	}

	/* If we have been requested a single instance, check that the
	 * package does not contain other instances. */
	if (!ps->arch_is_pattern && ps->flags & PKG_SPEC_ARCH_SINGLE) {
		struct pkgset *set;

		set = pkg_db_find_set(ps->name);

		/* Single instancing only applies with no architecture. */
		if (ps->arch->type == DPKG_ARCH_NONE &&
		    pkgset_installed_instances(set) > 1) {
			snprintf(msg, sizeof(msg),
			         _("ambiguous package name '%s' with more "
			           "than one installed instance"), ps->name);
			return msg;
		}
	}

	return NULL;
}
Exemplo n.º 3
0
Arquivo: pkg-spec.c Projeto: smcv/dpkg
const char *
pkg_spec_is_illegal(struct pkg_spec *ps)
{
	static char msg[1024];
	const char *emsg;

	if (!ps->name_is_pattern &&
	    (emsg = pkg_name_is_illegal(ps->name))) {
		snprintf(msg, sizeof(msg),
		         _("illegal package name in specifier '%s%s%s': %s"),
		         ps->name,
		         (ps->arch->type != DPKG_ARCH_NONE) ? ":" : "",
		         ps->arch->name, emsg);
		return msg;
	}

	if ((!ps->arch_is_pattern && ps->arch->type == DPKG_ARCH_ILLEGAL) ||
	    ps->arch->type == DPKG_ARCH_EMPTY) {
		emsg = dpkg_arch_name_is_illegal(ps->arch->name);
		snprintf(msg, sizeof(msg),
		         _("illegal architecture name in specifier '%s:%s': %s"),
		         ps->name, ps->arch->name, emsg);
		return msg;
	}

	/* If we have been requested a single instance, check that the
	 * package does not contain other instances. */
	if (!ps->arch_is_pattern && ps->flags & PKG_SPEC_ARCH_SINGLE) {
		struct pkgset *set;

		set = pkg_db_find_set(ps->name);

		/* Single instancing only applies with no architecture. */
		if (ps->arch->type == DPKG_ARCH_NONE &&
		    pkgset_installed_instances(set) > 1) {
			snprintf(msg, sizeof(msg),
			         _("ambiguous package name '%s' with more "
			           "than one installed instance"), ps->name);
			return msg;
		}
	}

	return NULL;
}
Exemplo n.º 4
0
void
ensure_diversions(void)
{
	struct stat stab1, stab2;
	char linebuf[MAXDIVERTFILENAME];
	FILE *file;
	struct diversion *ov, *oicontest, *oialtname;

	if (diversionsname != NULL)
		free(diversionsname);
	diversionsname = dpkg_db_get_path(DIVERSIONSFILE);

	onerr_abort++;

	file = fopen(diversionsname, "r");
	if (!file) {
		if (errno != ENOENT)
			ohshite(_("failed to open diversions file"));
		if (!diversionsfile) {
			onerr_abort--;
			return;
		}
	} else if (diversionsfile) {
		if (fstat(fileno(diversionsfile), &stab1))
			ohshite(_("failed to fstat previous diversions file"));
		if (fstat(fileno(file), &stab2))
			ohshite(_("failed to fstat diversions file"));
		if (stab1.st_dev == stab2.st_dev &&
		    stab1.st_ino == stab2.st_ino) {
			fclose(file);
			onerr_abort--;
			return;
		}
	}
	if (diversionsfile)
		fclose(diversionsfile);
	diversionsfile = file;
	setcloexec(fileno(diversionsfile), diversionsname);

	for (ov = diversions; ov; ov = ov->next) {
		ov->useinstead->divert->camefrom->divert = NULL;
		ov->useinstead->divert = NULL;
	}
	diversions = NULL;
	if (!file) {
		onerr_abort--;
		return;
	}

	while (fgets_checked(linebuf, sizeof(linebuf), file, diversionsname) >= 0) {
		oicontest = nfmalloc(sizeof(struct diversion));
		oialtname = nfmalloc(sizeof(struct diversion));

		oialtname->camefrom = findnamenode(linebuf, 0);
		oialtname->useinstead = NULL;

		fgets_must(linebuf, sizeof(linebuf), file, diversionsname);
		oicontest->useinstead = findnamenode(linebuf, 0);
		oicontest->camefrom = NULL;

		fgets_must(linebuf, sizeof(linebuf), file, diversionsname);
		oicontest->pkgset = strcmp(linebuf, ":") ?
		                    pkg_db_find_set(linebuf) : NULL;
		oialtname->pkgset = oicontest->pkgset;

		if (oialtname->camefrom->divert ||
		    oicontest->useinstead->divert)
			ohshit(_("conflicting diversions involving `%.250s' or `%.250s'"),
			       oialtname->camefrom->name, oicontest->useinstead->name);

		oialtname->camefrom->divert = oicontest;
		oicontest->useinstead->divert = oialtname;

		oicontest->next = diversions;
		diversions = oicontest;
	}

	onerr_abort--;
}