Skip to content

Add support for Triggers #97

Description

@laffer1

FreeBSD's pkg has a concept called triggers.

There are a few types and they tend to be stored in a few places.

A port can include triggers.mk extension

In that scenario, a file is written to ${LOCALBASE}/share/pkg/triggers/$t.ucl from a lua script.

From the mports side

TRIGGERS?=      ${PORTNAME}
.for t in ${TRIGGERS}
SUB_FILES+=     ${t}.ucl
PLIST_FILES+=   ${LOCALBASE}/share/pkg/triggers/$t.ucl
.endfor

_USES_install+= 601:trigger-post-install
trigger-post-install:
        ${MKDIR} ${FAKE_DESTDIR}${LOCALBASE}/share/pkg/triggers
.for t in ${TRIGGERS}
        ${INSTALL_DATA} ${WRKDIR}/$t.ucl ${FAKE_DESTDIR}${LOCALBASE}/share/pkg/triggers/
.endfor

For example, desktop-file-utils could have files/desktop-file-utils.ucl.in

it would get installed in localbase/share/pkg/triggers

First type might contain

path: "%%PREFIX%%/%%MIMEDIRS%%"
cleanup: {
	type: lua
	script: <<EOS
local mimedir = "%%PREFIX%%/%%MIMEDIRS%%/"
local cache = mimedir .. "mimeinfo.cache"
local st = pkg.stat(cache)
if st then
	os.remove(cache)
end
local res = pkg.readdir(mimedir)
if #res == 0 then
	os.remove(mimedir)
end
EOS
}
trigger: {
	type: lua
	sandbox: false
	script: <<EOS
print("Building cache database of MIME types")
pkg.exec({"%%PREFIX%%/bin/update-desktop-database","-q"})
EOS
}

Seems to support these methods within the lua interpreter

			{ "print_msg", lua_print_msg },
			{ "filecmp", lua_pkg_filecmp },
			{ "copy", lua_pkg_copy },
			{ "stat", lua_stat },
			{ "readdir", lua_readdir },
			{ "exec", lua_exec },
			{ "symlink", lua_pkg_symlink },

With a trigger struct


struct trigger {
	char *name;
	ucl_object_t *path;
	ucl_object_t *path_glob;
	ucl_object_t *path_regex;
	struct {
		char *script;
		int type;
		bool sandbox;
	} script;
	struct {
		char *script;
		int type;
		bool sandbox;
	} cleanup;
	pkghash *matched;
};
typedef tll(struct trigger *) trigger_t;

struct triggers {
	ucl_object_t *schema;
	int dfd;
	trigger_t *cleanup;
	trigger_t *post_transaction;
	trigger_t *post_install;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions