[Midnightbsd-cvs] src [9835] stable/0.9: Update mport package manager.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri May 11 18:22:46 EDT 2018
Revision: 9835
http://svnweb.midnightbsd.org/src/?rev=9835
Author: laffer1
Date: 2018-05-11 18:22:45 -0400 (Fri, 11 May 2018)
Log Message:
-----------
Update mport package manager.
Add enhanced .sample file handling
Introduce basic which command that can tell you what package a file belongs to.
e.g. mport which /usr/local/bin/python
Modified Paths:
--------------
stable/0.9/UPDATING
stable/0.9/lib/libmport/Makefile
stable/0.9/lib/libmport/bundle_read_update_pkg.c
stable/0.9/lib/libmport/mport.h
stable/0.9/lib/libmport/mport_private.h
stable/0.9/lib/libmport/pkgmeta.c
stable/0.9/lib/libmport/verify.c
stable/0.9/usr.sbin/mport/mport.c
Added Paths:
-----------
stable/0.9/lib/libmport/asset.c
Modified: stable/0.9/UPDATING
===================================================================
--- stable/0.9/UPDATING 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/UPDATING 2018-05-11 22:22:45 UTC (rev 9835)
@@ -1,5 +1,13 @@
Updating Information for MidnightBSD users.
+20180511:
+ Update mport package manager.
+
+ Add enhanced .sample file handling
+
+ Introduce basic which command that can tell you what package a file belongs to.
+ e.g. mport which /usr/local/bin/python
+
20171004:
Perl 5.26.0
Modified: stable/0.9/lib/libmport/Makefile
===================================================================
--- stable/0.9/lib/libmport/Makefile 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/lib/libmport/Makefile 2018-05-11 22:22:45 UTC (rev 9835)
@@ -1,7 +1,7 @@
# $MidnightBSD$
LIB= mport
-SRCS= bundle_write.c bundle_read.c plist.c create_primative.c db.c \
+SRCS= asset.c bundle_write.c bundle_read.c plist.c create_primative.c db.c \
dispatch.c util.c error.c \
info.c install_primative.c instance.c \
version_cmp.c check_preconditions.c delete_primative.c \
Added: stable/0.9/lib/libmport/asset.c
===================================================================
--- stable/0.9/lib/libmport/asset.c (rev 0)
+++ stable/0.9/lib/libmport/asset.c 2018-05-11 22:22:45 UTC (rev 9835)
@@ -0,0 +1,179 @@
+/*-
+ * Copyright (c) 2018 Lucas Holt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <sys/cdefs.h>
+__MBSDID("$MidnightBSD$");
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include <sqlite3.h>
+#include <stdlib.h>
+#include "mport.h"
+#include "mport_private.h"
+
+MPORT_PUBLIC_API int
+mport_asset_get_package_from_file_path(mportInstance *mport, const char *filePath, mportPackageMeta **pack)
+{
+ __block sqlite3_stmt *stmt = NULL;
+ __block int result = MPORT_OK;
+ __block char *err;
+
+ if (mport_db_prepare(mport->db, &stmt, "SELECT pkg FROM assets WHERE data=%Q", filePath) != MPORT_OK) {
+ sqlite3_finalize(stmt);
+ RETURN_CURRENT_ERROR;
+ }
+
+ if (stmt == NULL) {
+ RETURN_ERROR(MPORT_ERR_FATAL, "Statement was null");
+ }
+
+ while (1) {
+ int ret = sqlite3_step(stmt);
+
+ if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
+ sleep(1);
+ ret = sqlite3_step(stmt);
+ }
+
+ if (ret == SQLITE_DONE)
+ break;
+
+ if (ret != SQLITE_ROW) {
+ err = (char *) sqlite3_errmsg(mport->db);
+ result = MPORT_ERR_FATAL;
+ pack = NULL;
+ break; // we finalize below
+ }
+
+ const unsigned char *pkgName = sqlite3_column_text(stmt, 0);
+ if (pkgName != NULL) {
+ mportPackageMeta **packs;
+ if (mport_pkgmeta_search_master(mport, &packs, "pkg=%Q", pkgName) != MPORT_OK || packs[0] == NULL) {
+ err = "Package does not exist despite having assets";
+ result = MPORT_ERR_FATAL;
+ pack = NULL;
+ break; // we finalize below
+ } else {
+ if (packs[0]->name == NULL || packs[0]->origin == NULL) {
+ pack = NULL;
+ } else {
+ *pack = packs[0];
+ }
+ result = MPORT_OK;
+ break;
+ }
+ }
+ }
+
+ sqlite3_finalize(stmt);
+
+ if (result == MPORT_ERR_FATAL)
+ SET_ERRORX(result, "Error reading assets %s", err);
+ return result;
+}
+
+MPORT_PUBLIC_API int
+mport_asset_get_assetlist(mportInstance *mport, mportPackageMeta *pack, mportAssetList **alist_p)
+{
+ __block mportAssetList *alist;
+ __block sqlite3_stmt *stmt = NULL;
+ __block int result = MPORT_OK;
+ __block char *err;
+
+ if ((alist = mport_assetlist_new()) == NULL)
+ RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+
+ *alist_p = alist;
+
+ // pkg text NOT NULL, type int NOT NULL, data text, checksum text, owner text, grp text, mode text)
+
+ if (mport_db_prepare(mport->db, &stmt, "SELECT type,data,checksum,owner,grp,mode FROM assets WHERE pkg=%Q", pack->name) != MPORT_OK) {
+ sqlite3_finalize(stmt);
+ RETURN_CURRENT_ERROR;
+ }
+
+ if (stmt == NULL) {
+ RETURN_ERROR(MPORT_ERR_FATAL, "Statement was null");
+ }
+
+ dispatch_sync(mportSQLSerial, ^{
+ while (1) {
+ mportAssetListEntry *e;
+
+ int ret = sqlite3_step(stmt);
+
+ if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
+ sleep(1);
+ ret = sqlite3_step(stmt);
+ }
+
+ if (ret == SQLITE_DONE)
+ break;
+
+ if (ret != SQLITE_ROW) {
+ err = (char *) sqlite3_errmsg(mport->db);
+ result = MPORT_ERR_FATAL;
+ break; // we finalize below
+ }
+
+ e = (mportAssetListEntry *) calloc(1, sizeof(mportAssetListEntry));
+
+ if (e == NULL) {
+ err = "Out of memory";
+ result = MPORT_ERR_FATAL;
+ break; // we finalize below
+ }
+
+ e->type = (mportAssetListEntryType) sqlite3_column_int(stmt, 0);
+ const unsigned char *data = sqlite3_column_text(stmt, 1);
+ const unsigned char *checksum = sqlite3_column_text(stmt, 2);
+ const unsigned char *owner = sqlite3_column_text(stmt, 3);
+ const unsigned char *group = sqlite3_column_text(stmt, 4);
+ const unsigned char *mode = sqlite3_column_text(stmt, 5);
+
+ e->data = data == NULL ? NULL : strdup((char *) data);
+ if (checksum != NULL)
+ e->checksum = strdup((char *) checksum);
+ if (owner != NULL)
+ e->owner = strdup((char *) owner);
+ if (group != NULL)
+ e->group = strdup((char *) group);
+ if (mode != NULL)
+ e->mode = strdup((char *) mode);
+
+ STAILQ_INSERT_TAIL(alist, e, next);
+ }
+
+ sqlite3_finalize(stmt);
+ });
+
+ if (result == MPORT_ERR_FATAL)
+ SET_ERRORX(result, "Error reading assets %s", err);
+ return result;
+}
Property changes on: stable/0.9/lib/libmport/asset.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: stable/0.9/lib/libmport/bundle_read_update_pkg.c
===================================================================
--- stable/0.9/lib/libmport/bundle_read_update_pkg.c 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/lib/libmport/bundle_read_update_pkg.c 2018-05-11 22:22:45 UTC (rev 9835)
@@ -80,7 +80,7 @@
mportCreateExtras *extra;
int ret;
- if (mport_pkgmeta_get_assetlist(mport, pkg, &alist) != MPORT_OK)
+ if (mport_asset_get_assetlist(mport, pkg, &alist) != MPORT_OK)
RETURN_CURRENT_ERROR;
if (build_create_extras(mport, pkg, tempfile, &extra) != MPORT_OK)
Modified: stable/0.9/lib/libmport/mport.h
===================================================================
--- stable/0.9/lib/libmport/mport.h 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/lib/libmport/mport.h 2018-05-11 22:22:45 UTC (rev 9835)
@@ -123,8 +123,10 @@
char *os_release;
char *cpe;
int locked;
-} mportPackageMeta;
+} mportPackageMeta;
+int mport_asset_get_assetlist(mportInstance *, mportPackageMeta *, mportAssetList **);
+int mport_asset_get_package_from_file_path(mportInstance *, const char *, mportPackageMeta **);
mportPackageMeta * mport_pkgmeta_new(void);
void mport_pkgmeta_free(mportPackageMeta *);
Modified: stable/0.9/lib/libmport/mport_private.h
===================================================================
--- stable/0.9/lib/libmport/mport_private.h 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/lib/libmport/mport_private.h 2018-05-11 22:22:45 UTC (rev 9835)
@@ -77,7 +77,6 @@
/* pkgmeta */
int mport_pkgmeta_read_stub(mportInstance *, mportPackageMeta ***);
-int mport_pkgmeta_get_assetlist(mportInstance *, mportPackageMeta *, mportAssetList **);
int mport_pkgmeta_logevent(mportInstance *, mportPackageMeta *, const char *);
/* Utils */
@@ -173,8 +172,8 @@
#error "Unable to detect arch!"
#endif
-#if __MidnightBSD_version >= 10000
-#define MPORT_OSVERSION "0.10"
+#if __MidnightBSD_version >= 100000
+#define MPORT_OSVERSION "1.0"
#elif __MidnightBSD_version >= 9000
#define MPORT_OSVERSION "0.9"
#elif __MidnightBSD_version >= 8000
Modified: stable/0.9/lib/libmport/pkgmeta.c
===================================================================
--- stable/0.9/lib/libmport/pkgmeta.c 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/lib/libmport/pkgmeta.c 2018-05-11 22:22:45 UTC (rev 9835)
@@ -346,83 +346,6 @@
sqlite3_finalize(stmt);
return ret;
-}
-
-
-int
-mport_pkgmeta_get_assetlist(mportInstance *mport, mportPackageMeta *pkg, mportAssetList **alist_p)
-{
- mportAssetList *alist;
- sqlite3_stmt *stmt;
- int ret;
- mportAssetListEntry *e;
-
- if ((alist = mport_assetlist_new()) == NULL)
- RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
-
- *alist_p = alist;
-
- if (mport_db_prepare(mport->db, &stmt, "SELECT type, data, owner, grp, mode FROM assets WHERE pkg=%Q", pkg->name) != MPORT_OK) {
- sqlite3_finalize(stmt);
- RETURN_CURRENT_ERROR;
- }
-
- if (stmt == NULL)
- RETURN_CURRENT_ERROR;
-
- while (1) {
- ret = sqlite3_step(stmt);
-
- if (ret == SQLITE_DONE)
- break;
-
- if (ret != SQLITE_ROW) {
- sqlite3_finalize(stmt);
- RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
- }
-
- e = (mportAssetListEntry *)calloc(1, sizeof(mportAssetListEntry));
-
- if (e == NULL) {
- sqlite3_finalize(stmt);
- RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
- }
-
- const unsigned char *data;
- const unsigned char *owner;
- const unsigned char *group;
- const unsigned char *mode;
-
- e->type = sqlite3_column_int(stmt, 0);
- data = sqlite3_column_text(stmt, 1);
- owner = sqlite3_column_text(stmt, 2);
- group = sqlite3_column_text(stmt, 3);
- mode = sqlite3_column_text(stmt, 4);
-
- if (data == NULL) {
- sqlite3_finalize(stmt);
- RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
- }
-
- e->data = strdup(data);
- if (owner != NULL)
- e->owner = strdup(owner);
- if (group != NULL)
- e->group = strdup(group);
- if (mode != NULL)
- e->mode = strdup(mode);
-
- if (e->data == NULL) {
- sqlite3_finalize(stmt);
- RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
- }
-
- STAILQ_INSERT_TAIL(alist, e, next);
- }
-
- sqlite3_finalize(stmt);
-
- return MPORT_OK;
}
@@ -467,8 +390,10 @@
*vec = mport_pkgmeta_new();
if (*vec == NULL)
RETURN_ERROR(MPORT_ERR_FATAL, "Couldn't allocate meta.");
- if (populate_meta_from_stmt(*vec, db, stmt) != MPORT_OK)
+ if (populate_meta_from_stmt(*vec, db, stmt) != MPORT_OK) {
+ *vec = NULL;
RETURN_CURRENT_ERROR;
+ }
vec++;
break;
case SQLITE_DONE:
Modified: stable/0.9/lib/libmport/verify.c
===================================================================
--- stable/0.9/lib/libmport/verify.c 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/lib/libmport/verify.c 2018-05-11 22:22:45 UTC (rev 9835)
@@ -53,64 +53,67 @@
sqlite3_finalize(stmt);
RETURN_CURRENT_ERROR;
}
-
+
while (1) {
- ret = sqlite3_step(stmt);
+ ret = sqlite3_step(stmt);
- if (ret == SQLITE_DONE)
- break;
+ if (ret == SQLITE_DONE)
+ break;
- if (ret != SQLITE_ROW) {
- /* some error occured */
- SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
- sqlite3_finalize(stmt);
- RETURN_CURRENT_ERROR;
- }
+ if (ret != SQLITE_ROW) {
+ /* some error occured */
+ SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
+ sqlite3_finalize(stmt);
+ RETURN_CURRENT_ERROR;
+ }
- type = (mportAssetListEntryType) sqlite3_column_int(stmt, 0);
- data = sqlite3_column_text(stmt, 1);
- checksum = sqlite3_column_text(stmt, 2);
+ type = (mportAssetListEntryType) sqlite3_column_int(stmt, 0);
+ data = sqlite3_column_text(stmt, 1);
+ checksum = sqlite3_column_text(stmt, 2);
- char file[FILENAME_MAX];
- /* XXX TMP */
- if (data == NULL) {
- /* XXX data is null when ASSET_CHMOD (mode) or similar commands are in plist */
- snprintf(file, sizeof(file), "%s", mport->root);
- } else if (*data == '/') {
- /* we don't use mport->root because it's an absolute path like /var */
- snprintf(file, sizeof(file), "%s", data);
- } else {
- snprintf(file, sizeof(file), "%s%s/%s", mport->root, pack->prefix, data);
- }
+ char file[FILENAME_MAX];
+ /* XXX TMP */
+ if (data == NULL) {
+ /* XXX data is null when ASSET_CHMOD (mode) or similar commands are in plist */
+ snprintf(file, sizeof(file), "%s", mport->root);
+ } else if (*data == '/') {
+ /* we don't use mport->root because it's an absolute path like /var */
+ snprintf(file, sizeof(file), "%s", data);
+ } else {
+ snprintf(file, sizeof(file), "%s%s/%s", mport->root, pack->prefix, data);
+ }
- switch (type) {
- case ASSET_FILE_OWNER_MODE:
- /* FALLS THROUGH */
- case ASSET_FILE:
- /* FALLS THROUGH */
- case ASSET_SAMPLE:
- if (lstat(file, &st) != 0) {
- mport_call_msg_cb(mport, "Can't stat %s: %s", file, strerror(errno));
- break; /* next asset */
- }
+ switch (type) {
+ case ASSET_FILE_OWNER_MODE:
+ /* FALLS THROUGH */
+ case ASSET_FILE:
+ /* FALLS THROUGH */
+ case ASSET_SAMPLE:
+ if (lstat(file, &st) != 0) {
+ mport_call_msg_cb(mport, "Can't stat %s: %s", file, strerror(errno));
+ break; /* next asset */
+ }
- if (S_ISREG(st.st_mode)) {
- if (MD5File(file, md5) == NULL)
- mport_call_msg_cb(mport, "Can't md5 %s: %s", file, strerror(errno));
+ if (S_ISREG(st.st_mode)) {
+ if (MD5File(file, md5) == NULL)
+ mport_call_msg_cb(mport, "Can't md5 %s: %s", file, strerror(errno));
- if (md5 == NULL)
- mport_call_msg_cb(mport, "Destination checksum could not be computed %s", file);
- else if (checksum == NULL)
- mport_call_msg_cb(mport, "Source checksum missing %s", file);
- else if (strcmp(md5, checksum) != 0)
- mport_call_msg_cb(mport, "Checksum mismatch: %s %s %s", file, md5, checksum);
- }
+ if (md5 == NULL)
+ mport_call_msg_cb(mport,
+ "Destination checksum could not be computed %s",
+ file);
+ else if (checksum == NULL)
+ mport_call_msg_cb(mport, "Source checksum missing %s", file);
+ else if (strcmp(md5, checksum) != 0)
+ mport_call_msg_cb(mport, "Checksum mismatch: %s %s %s", file, md5,
+ checksum);
+ }
- break;
- default:
- /* do nothing */
- break;
- }
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
}
sqlite3_finalize(stmt);
Modified: stable/0.9/usr.sbin/mport/mport.c
===================================================================
--- stable/0.9/usr.sbin/mport/mport.c 2018-05-11 22:20:52 UTC (rev 9834)
+++ stable/0.9/usr.sbin/mport/mport.c 2018-05-11 22:22:45 UTC (rev 9835)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2010-2016 Lucas Holt
+ * Copyright (c) 2010-2018 Lucas Holt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -60,6 +60,7 @@
static int verify(mportInstance *);
static int lock(mportInstance *, const char *);
static int unlock(mportInstance *, const char *);
+static int which(mportInstance *mport, const char *filePath);
int
main(int argc, char *argv[]) {
@@ -220,6 +221,14 @@
dispatch_group_async(grp, q, ^{
resultCode = verify(mport);
});
+ } else if (!strcmp(argv[1], "which")) {
+ dispatch_group_async(grp, q, ^{
+ if (argc > 2) {
+ which(mport, argv[2]);
+ } else {
+ usage();
+ }
+ });
} else {
mport_instance_free(mport);
usage();
@@ -259,6 +268,7 @@
" mport update [package name]\n"
" mport upgrade\n"
" mport verify\n"
+ " mport which [file path]\n"
);
exit(1);
}
@@ -398,6 +408,29 @@
return (0);
}
+int
+which(mportInstance *mport, const char *filePath) {
+
+ mportPackageMeta *pack = NULL;
+
+ if (filePath == NULL) {
+ warnx("%s", "Specify file path");
+ return (1);
+ }
+
+ if (mport_asset_get_package_from_file_path(mport, filePath, &pack) != MPORT_OK) {
+ warnx("%s", mport_err_string());
+ return (1);
+ }
+
+ if (pack != NULL && pack->origin != NULL) {
+ printf("%s was installed by package %s\n",
+ filePath, pack->origin);
+ }
+
+ return (0);
+}
+
/* recursive function */
int
install_depends(mportInstance *mport, const char *packageName, const char *version) {
More information about the Midnightbsd-cvs
mailing list