Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg add: really execute once and only once the trigger
Baptiste Daroussin committed 4 years ago
commit 721ad15ca091cd8670c47b78c848d58ce32622a9
parent 0106f22
6 files changed +46 -8
modified libpkg/libpkg.ver
@@ -4,6 +4,7 @@ global:
	pkg_add;
	pkg_add_from_remote;
	pkg_add_port;
+
	pkg_add_triggers;
	pkg_adddep;
	pkg_addluascript_fileat;
	pkg_addrdep;
modified libpkg/pkg.h.in
@@ -1662,6 +1662,7 @@ int pkg_create_staged(const char *, pkg_formats, const char *, const char *, cha
int pkg_create_installed(const char *, pkg_formats, struct pkg *) __attribute__((deprecated));
int pkgdb_register_ports(struct pkgdb *db, struct pkg *pkg) __attribute__((deprecated));;
int pkg_execute_deferred_triggers(void);
+
int pkg_add_triggers(void);

#ifdef __cplusplus
}
modified libpkg/pkg_add.c
@@ -1059,6 +1059,12 @@ pkg_rollback_cb(void *data)
	pkg_rollback_pkg((struct pkg *)data);
}

+
int
+
pkg_add_triggers(void)
+
{
+
	return (triggers_execute(NULL));
+
}
+

static int
pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
    struct pkg_manifest_key *keys, const char *reloc, struct pkg *remote,
@@ -1278,12 +1284,6 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
		pkg_emit_message(message->buf);
		xstring_free(message);
	}
-
	/*
-
	 * Command pkg add has been invoked, note that in this case
-
	 * it is impossible to get cleanup triggers to execute
-
	 */
-
	if (remote == NULL)
-
		triggers_execute(NULL);

cleanup:
	if (a != NULL) {
modified libpkg/triggers.c
@@ -488,8 +488,9 @@ trigger_check_match(struct trigger *t, char *dir)
		}
	}

-
	if (match_ucl_lists(dir, t->path_glob, t->path_regex))
+
	if (match_ucl_lists(dir, t->path_glob, t->path_regex)) {
		pkghash_safe_add(t->matched, dir, dir, NULL);
+
	}
}

/*
modified src/add.c
@@ -199,6 +199,7 @@ exec_add(int argc, char **argv)
	}
	xstring_free(failedpkgs);

+
	pkg_add_triggers();
	if (messages != NULL) {
		fflush(messages->fp);
		printf("%s", messages->buf);
modified tests/frontend/triggers.sh
@@ -9,7 +9,8 @@ tests_init \
	regex_trigger \
	path_trigger \
	pkg_exec_sandbox \
-
	pkg_exec_no_sandbox
+
	pkg_exec_no_sandbox \
+
	pkg_add

cleanup_lua_body() {
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "/"
@@ -166,3 +167,36 @@ EOF
	unset PKG_TRIGGERS_DIR
	atf_check -o inline:"plop\n" pkg -o REPOS_DIR=/dev/null -o PKG_TRIGGERS_DIR="${TMPDIR}/trigger_dir" install -qfy ${TMPDIR}/test-1.pkg
}
+

+
pkg_add_body() {
+
	atf_check -s exit:0 ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "/"
+
	mkdir trigger_dir/
+
	cat << EOF >> trigger_dir/trigger.ucl
+
path_glob: [ "/*" ]
+
trigger: {
+
	type: lua
+
	sandbox: false
+
	script: <<EOS
+
print("plop")
+
EOS
+
}
+
EOF
+
	echo "${TMPDIR}"/trigger_dir/trigger.ucl > plist
+
	atf_check pkg create -M test.ucl -p plist
+

+
	atf_check -s exit:0 ${RESOURCEDIR}/test_subr.sh new_pkg "meh" "meh" "1" "/"
+
	cat << EOF >> meh.ucl
+
deps: { test: { version: "1", origin: "dontcare" } }
+
EOF
+
	echo "@dir ${TMPDIR}"/trigger_dir/ > plist
+
	mkdir target
+
	unset PKG_TRIGGERS_DIR
+
	atf_check pkg create -M meh.ucl -p plist
+
OUTPUT="Installing meh-1...
+
\`-- Installing test-1...
+
\`-- Extracting test-1:  done
+
Extracting meh-1:  done
+
plop
+
"
+
	atf_check -o inline:"${OUTPUT}" pkg -o PKG_TRIGGERS_DIR="${TMPDIR}/trigger_dir" add meh-1.pkg
+
}