示例#1
0
文件: triglib.c 项目: guillemj/dpkg
void
trig_file_interests_ensure(void)
{
	FILE *f;
	char linebuf[1024], *space;
	struct pkginfo *pkg;
	struct pkgbin *pkgbin;

	if (filetriggers_edited >= 0)
		return;

	f = fopen(triggersfilefile, "r");
	if (!f) {
		if (errno == ENOENT)
			goto ok;
		ohshite(_("unable to read file triggers file '%.250s'"),
		        triggersfilefile);
	}

	push_cleanup(cu_closestream, ~0, 1, f);
	while (fgets_checked(linebuf, sizeof(linebuf), f, triggersfilefile) >= 0) {
		struct dpkg_error err;
		char *slash;
		enum trig_options trig_opts = TRIG_AWAIT;
		space = strchr(linebuf, ' ');
		if (!space || linebuf[0] != '/')
			ohshit(_("syntax error in file triggers file '%.250s'"),
			       triggersfilefile);
		*space++ = '\0';

		slash = strchr(space, '/');
		if (slash && strcmp("/noawait", slash) == 0) {
			trig_opts = TRIG_NOAWAIT;
			*slash = '\0';
		}
		if (slash && strcmp("/await", slash) == 0) {
			trig_opts = TRIG_AWAIT;
			*slash = '\0';
		}

		pkg = pkg_spec_parse_pkg(space, &err);
		if (pkg == NULL)
			ohshit(_("file triggers record mentions illegal "
			         "package name '%.250s' (for interest in file "
			         "'%.250s'): %.250s"), space, linebuf, err.str);
		pkgbin = &pkg->installed;

		trk_file_interest_change(linebuf, pkg, pkgbin, +2, trig_opts);
	}
	pop_cleanup(ehflag_normaltidy);
ok:
	filetriggers_edited = 0;
}
示例#2
0
void
trig_file_interests_ensure(void)
{
	FILE *f;
	char linebuf[1024], *space;
	struct pkginfo *pkg;
	const char *emsg;

	if (filetriggers_edited >= 0)
		return;

	f = fopen(triggersfilefile, "r");
	if (!f) {
		if (errno == ENOENT)
			goto ok;
		ohshite(_("unable to read file triggers file `%.250s'"),
		        triggersfilefile);
	}

	push_cleanup(cu_closestream, ~0, NULL, 0, 1, f);
	while (fgets_checked(linebuf, sizeof(linebuf), f, triggersfilefile) >= 0) {
		char *slash;
		enum trig_options trig_opts = trig_await;
		space = strchr(linebuf, ' ');
		if (!space || linebuf[0] != '/')
			ohshit(_("syntax error in file triggers file `%.250s'"),
			       triggersfilefile);
		*space++ = '\0';

		slash = strchr(space, '/');
		if (slash && strcmp("/noawait", slash) == 0) {
			trig_opts = trig_noawait;
			*slash = '\0';
		}
		emsg = pkg_name_is_illegal(space, NULL);
		if (emsg)
			ohshit(_("file triggers record mentions illegal "
			         "package name `%.250s' (for interest in file "
				 "`%.250s'): %.250s"), space, linebuf, emsg);
		pkg = pkg_db_find(space);
		trk_file_interest_change(linebuf, pkg, +2, trig_opts);
	}
	pop_cleanup(ehflag_normaltidy);
ok:
	filetriggers_edited = 0;
}