Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
groups: register installed groups in /var/db/pkg/groups
Baptiste Daroussin committed 1 year ago
commit 7c89c8518c3805ada93e3ddfa3058ca43b288778
parent 0f00f1e
3 files changed +48 -1
modified libpkg/pkg_add.c
@@ -1487,6 +1487,48 @@ pkg_add_upgrade(struct pkgdb *db, const char *path, unsigned flags,
	return pkg_add_common(db, path, flags, location, rp, lp, t);
}

+
static int
+
pkg_group_dump(int fd, struct pkg *pkg)
+
{
+
	ucl_object_t *o, *seq;
+
	struct pkg_dep	*dep = NULL;
+

+
	if (pkg->type != PKG_GROUP_REMOTE)
+
		return (EPKG_FATAL);
+
	o = ucl_object_typed_new(UCL_OBJECT);
+
	ucl_object_insert_key(o, ucl_object_fromstring(pkg->name), "name", 0, false);
+
	ucl_object_insert_key(o, ucl_object_fromstring(pkg->comment), "comment", 0, false);
+
	seq = ucl_object_typed_new(UCL_ARRAY);
+
	while (pkg_deps(pkg, &dep) == EPKG_OK)
+
		ucl_array_append(seq, ucl_object_fromstring(dep->name));
+
	ucl_object_insert_key(o, seq, "depends", 0, false);
+
	ucl_object_emit_fd(o, UCL_EMIT_CONFIG, fd);
+
	return (EPKG_OK);
+
}
+

+
int
+
pkg_add_group(struct pkg *pkg)
+
{
+
	char temp[MAXPATHLEN];
+
	int dfd = pkg_get_dbdirfd();
+
	mkdirat(dfd, "groups", 0755);
+
	int gfd = openat(dfd, "groups", O_DIRECTORY|O_EXEC);
+
	hidden_tempfile(temp, MAXPATHLEN, pkg->name);
+
	int fd = openat(gfd, temp, O_CREAT|O_EXCL|O_WRONLY, 0644);
+
	if (fd == -1) {
+
		pkg_emit_errno("impossible to create group file %s", pkg->name);
+
		return (EPKG_FATAL);
+
	}
+
	pkg_group_dump(fd, pkg);
+
	close(fd);
+
	if (renameat(gfd, temp, gfd, pkg->name) == -1) {
+
		unlinkat(gfd, temp, 0);
+
		pkg_emit_errno("impossible to create group file %s", pkg->name);
+
		return (EPKG_FATAL);
+
	}
+
	return (EPKG_OK);
+
}
+

int
pkg_add_fromdir(struct pkg *pkg, const char *src)
{
modified libpkg/pkg_jobs.c
@@ -2075,6 +2075,7 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j)
	int flags = 0;
	int retcode = EPKG_FATAL;

+
	dbg(2, "begin %s", __func__);
	/*
	 * For a split upgrade, pass along the old package even though it's
	 * already deleted, since we need it in order to merge configuration
@@ -2121,11 +2122,14 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j)
	if (new->automatic || (j->flags & PKG_FLAG_AUTOMATIC) == PKG_FLAG_AUTOMATIC)
		flags |= PKG_ADD_AUTOMATIC;

-
	if (old != NULL)
+
	if (new->type == PKG_GROUP_REMOTE)
+
		retcode = pkg_add_group(new);
+
	else if (old != NULL)
		retcode = pkg_add_upgrade(j->db, target, flags, NULL, new, old, &j->triggers);
	else
		retcode = pkg_add_from_remote(j->db, target, flags, NULL, new, &j->triggers);

+
	dbg(2, "end %s:", __func__);
	return (retcode);
}

modified libpkg/private/pkg.h
@@ -787,6 +787,7 @@ char *pkg_checksum_generate_file(const char *path, pkg_checksum_type_t type);
char *pkg_checksum_generate_fileat(int fd, const char *path,
    pkg_checksum_type_t type);

+
int pkg_add_group(struct pkg *pkg);
int pkg_add_upgrade(struct pkgdb *db, const char *path, unsigned flags,
    const char *location, struct pkg *rp, struct pkg *lp, struct triggers *);
int pkg_add_from_remote(struct pkgdb *db, const char *path, unsigned flags,