Skip to content

Commit

Permalink
Merge commit '87447c7ded6ad4a99419e3bb8bd1d1a8334e13d5'
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Dec 5, 2023
2 parents af86d3b + 87447c7 commit 803a916
Show file tree
Hide file tree
Showing 32 changed files with 795 additions and 482 deletions.
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.check-fake/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.check-fake

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 6

MK_MAN= no
Expand Down
4 changes: 2 additions & 2 deletions contrib/mport/libexec/mport.check-fake/mport.check-fake.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;

DIAG("assetlist = %s; destdir = %s; prefix = %s; skip = %s", assetlistfile, destdir, prefix, skip)

if (!prefix || !destdir || !assetlistfile)
usage();

DIAG("assetlist = %s; destdir = %s; prefix = %s; skip = %s", assetlistfile, destdir, prefix, skip)

if (chroot_path != NULL) {
if (chroot(chroot_path) == -1) {
err(EXIT_FAILURE, "chroot failed");
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.check-for-older/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.check-for-older

CFLAGS+= -I ../../libmport/
CFLAGS+= -I ../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.create/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.create

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 6

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.delete/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.delete

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
1 change: 1 addition & 0 deletions contrib/mport/libexec/mport.delete/mport.delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ int main(int argc, char *argv[]) {
}

while (*packs != NULL) {
(*packs)->action = MPORT_ACTION_DELETE;
if (mport_delete_primative(mport, *packs, force) != MPORT_OK) {
warnx("%s", mport_err_string());
mport_instance_free(mport);
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.fetch/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.fetch

CFLAGS= -I${.CURDIR}/../../libmport/
CFLAGS= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.info/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.info

CFLAGS+=-I${.CURDIR}/../../libmport/
CFLAGS+=-I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.init/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.init

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.install/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.install

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 6

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.list/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.list

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.list/mport.list.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ main(int argc, char *argv[])
}

iestart = indexEntries;
while (*indexEntries != NULL) {
while (indexEntries != NULL && *indexEntries != NULL) {
if (((*indexEntries)->version != NULL && mport_version_cmp((*packs)->version, (*indexEntries)->version) < 0)
|| ((*packs)->version != NULL && mport_version_cmp((*packs)->os_release, os_release) < 0)) {

Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.merge/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.merge

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.query/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.query

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.update/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.update

CFLAGS+= -I${.CURDIR}/../../libmport/ -fblocks
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.updepends/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.updepends

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libexec/mport.version_cmp/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROG= mport.version_cmp

CFLAGS+= -I${.CURDIR}/../../libmport/
CFLAGS+= -I${.CURDIR}/../../libmport/ -I/usr/include/private/ucl
WARNS?= 4

MK_MAN= no
Expand Down
2 changes: 1 addition & 1 deletion contrib/mport/libmport/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SRCS= asset.c bundle_write.c bundle_read.c plist.c create_primative.c db.c \
update_primative.c bundle_read_update_pkg.c pkgmeta.c \
fetch.c index.c index_depends.c install.c clean.c setting.c \
stats.c update.c upgrade.c verify.c lock.c mkdir.c import_export.c \
autoremove.c audit.c ping.c
autoremove.c audit.c ping.c message.c
INCS= mport.h

CFLAGS+= -I${.CURDIR} -I/usr/include/private/ucl
Expand Down
1 change: 1 addition & 0 deletions contrib/mport/libmport/autoremove.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ mport_autoremove(mportInstance *mport) {
depends = depends_start;
while ((*depends) != NULL) {
mport_call_msg_cb(mport, "Auto-removing %s", (*depends)->name);
(*depends)->action = MPORT_ACTION_DELETE;
if (mport_delete_primative(mport, *depends, true) != MPORT_OK) {
mport_call_msg_cb(mport, "Unable to autoremove %s: %s", (*depends)->name, mport_err_string());
continue;
Expand Down
155 changes: 2 additions & 153 deletions contrib/mport/libmport/bundle_read_install_pkg.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2013-2015, 2021 Lucas Holt
* Copyright (c) 2013-2015, 2021, 2023 Lucas Holt
* Copyright (c) 2007-2009 Chris Reinhardt
* All rights reserved.
*
Expand Down Expand Up @@ -59,8 +59,6 @@ static int run_pkg_install(mportInstance *, mportBundleRead *, mportPackageMeta

static int run_mtree(mportInstance *, mportBundleRead *, mportPackageMeta *);

static int display_pkg_msg(mportInstance *, mportBundleRead *, mportPackageMeta *);

static int get_file_count(mportInstance *, char *, int *);

static int create_package_row(mportInstance *, mportPackageMeta *);
Expand All @@ -77,10 +75,6 @@ static int mark_complete(mportInstance *, mportPackageMeta *);

static int mport_bundle_read_get_assetlist(mportInstance *mport, mportPackageMeta *pkg, mportAssetList **alist_p, enum phase);

static int load_pkg_msg(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg, mportPackageMessage *packageMessage);

static mportPackageMessage * pkg_message_from_ucl(mportInstance *mport, const ucl_object_t *obj, mportPackageMessage *msg);

static int copy_metafile(mportInstance *, mportBundleRead *, mportPackageMeta *, char *);

/**
Expand Down Expand Up @@ -854,7 +848,7 @@ do_post_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta
if (run_postexec(mport, pkg) != MPORT_OK)
RETURN_CURRENT_ERROR;

if (display_pkg_msg(mport, bundle, pkg) != MPORT_OK)
if (mport_pkg_message_display(mport, pkg) != MPORT_OK)
RETURN_CURRENT_ERROR;

if (run_pkg_install(mport, bundle, pkg, "POST-INSTALL") != MPORT_OK)
Expand Down Expand Up @@ -996,148 +990,3 @@ run_pkg_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta

return MPORT_OK;
}


static int
display_pkg_msg(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg)
{
mportPackageMessage packageMessage;
pkg_message_t expectedType;

packageMessage.minimum_version = NULL;
packageMessage.maximum_version = NULL;
packageMessage.str = NULL;
packageMessage.prev = NULL;
packageMessage.next = NULL;
packageMessage.type = PKG_MESSAGE_ALWAYS; // default type

if (load_pkg_msg(mport, bundle, pkg, &packageMessage) != MPORT_OK) {
RETURN_CURRENT_ERROR;
}

switch (pkg->action) {
case MPORT_ACTION_INSTALL:
expectedType = PKG_MESSAGE_INSTALL;
break;
case MPORT_ACTION_UPDATE:
case MPORT_ACTION_UPGRADE:
expectedType = PKG_MESSAGE_UPGRADE;
break;
case MPORT_ACTION_DELETE:
expectedType = PKG_MESSAGE_REMOVE;
break;
default:
expectedType = PKG_MESSAGE_INSTALL;
}

if (packageMessage.type == expectedType || packageMessage.type == PKG_MESSAGE_ALWAYS) {
if (packageMessage.str != NULL && packageMessage.str[0] != '\0')
mport_call_msg_cb(mport, "%s", packageMessage.str);
}

free(packageMessage.str);

return MPORT_OK;
}


static int
load_pkg_msg(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg, mportPackageMessage *packageMessage)
{
char filename[FILENAME_MAX];
char *buf;
struct stat st;
FILE *file;
struct ucl_parser *parser;
ucl_object_t *obj;

(void) snprintf(filename, FILENAME_MAX, "%s/%s/%s-%s/%s", bundle->tmpdir, MPORT_STUB_INFRA_DIR, pkg->name,
pkg->version, MPORT_MESSAGE_FILE);

if (stat(filename, &st) == -1) {
/* if we couldn't stat the file, we assume there isn't a pkg-msg */
return MPORT_OK;
}

if ((file = fopen(filename, "re")) == NULL)
RETURN_ERRORX(MPORT_ERR_FATAL, "Couldn't open %s: %s", filename, strerror(errno));

if ((buf = (char *) calloc((size_t)(st.st_size + 1), sizeof(char))) == NULL)
RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");

if (fread(buf, sizeof(char), (size_t) st.st_size, file) != (size_t) st.st_size) {
free(buf);
RETURN_ERRORX(MPORT_ERR_FATAL, "Read error: %s", strerror(errno));
}

buf[st.st_size] = '\0';

if (buf[0] == '[') {
parser = ucl_parser_new(0);
// remove leading/trailing array entries
buf[0] = ' ';
buf[st.st_size-1] = '\0';

if (ucl_parser_add_chunk(parser, (const unsigned char*)buf, st.st_size)) {
obj = ucl_parser_get_object(parser);
ucl_parser_free(parser);
free(buf);

packageMessage = pkg_message_from_ucl(mport, obj, packageMessage);
ucl_object_unref(obj);

return packageMessage == NULL ? MPORT_ERR_FATAL : MPORT_OK;
}

ucl_parser_free (parser);
} else {
/*obj = ucl_object_fromlstring(buf, st.st_size);
packageMessage = pkg_message_from_ucl(mport, obj, packageMessage);
ucl_object_unref(obj); */
packageMessage->str = strdup(buf);
packageMessage->type = PKG_MESSAGE_ALWAYS;
free(buf);
}

return MPORT_OK;
}

static mportPackageMessage *
pkg_message_from_ucl(mportInstance *mport, const ucl_object_t *obj, mportPackageMessage *msg)
{
const ucl_object_t *enhanced;

if (ucl_object_type(obj) == UCL_STRING) {
msg->str = strdup(ucl_object_tostring(obj));
} else if (ucl_object_type(obj) == UCL_OBJECT) {
/* New format of pkg message */
enhanced = ucl_object_find_key(obj, "message");
if (enhanced == NULL || ucl_object_type(enhanced) != UCL_STRING) {
return NULL;
}
msg->str = strdup(ucl_object_tostring(enhanced));

enhanced = ucl_object_find_key(obj, "minimum_version");
if (enhanced != NULL && ucl_object_type(enhanced) == UCL_STRING) {
msg->minimum_version = strdup(ucl_object_tostring(enhanced));
}

enhanced = ucl_object_find_key(obj, "type");
if (enhanced != NULL && ucl_object_type(enhanced) == UCL_STRING) {
const char *type = ucl_object_tostring(enhanced);
if (type != NULL) {
if (strcmp(type, "install") == 0) {
msg->type = PKG_MESSAGE_INSTALL;
} else if (strcmp(type, "upgrade") == 0) {
msg->type = PKG_MESSAGE_UPGRADE;
} else if (strcmp(type, "remove") == 0) {
msg->type = PKG_MESSAGE_REMOVE;
} else {
msg->type = PKG_MESSAGE_ALWAYS;
}
}
}
}

return msg;
}
3 changes: 3 additions & 0 deletions contrib/mport/libmport/delete_primative.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)
if (mport_db_do(mport->db, "DELETE FROM categories WHERE pkg=%Q", pack->name) != MPORT_OK)
RETURN_CURRENT_ERROR;

if (mport_pkg_message_display(mport, pack) != MPORT_OK)
RETURN_CURRENT_ERROR;

if (delete_pkg_infra(mport, pack) != MPORT_OK)
RETURN_CURRENT_ERROR;

Expand Down
Loading

0 comments on commit 803a916

Please sign in to comment.