[Midnightbsd-cvs] src [9834] stable/0.8: Update mport package manager.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri May 11 18:20:53 EDT 2018
Revision: 9834
http://svnweb.midnightbsd.org/src/?rev=9834
Author: laffer1
Date: 2018-05-11 18:20:52 -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.8/UPDATING
stable/0.8/lib/libmport/Makefile
stable/0.8/lib/libmport/bundle_read_install_pkg.c
stable/0.8/lib/libmport/bundle_read_update_pkg.c
stable/0.8/lib/libmport/create_primative.c
stable/0.8/lib/libmport/mport.h
stable/0.8/lib/libmport/mport_private.h
stable/0.8/lib/libmport/pkgmeta.c
stable/0.8/lib/libmport/verify.c
stable/0.8/usr.sbin/mport/mport.c
Added Paths:
-----------
stable/0.8/lib/libmport/asset.c
Modified: stable/0.8/UPDATING
===================================================================
--- stable/0.8/UPDATING 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/UPDATING 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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
+
20180404:
Fix a security issue in ipsec which could result in a crash or denial of service.
Modified: stable/0.8/lib/libmport/Makefile
===================================================================
--- stable/0.8/lib/libmport/Makefile 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/Makefile 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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.8/lib/libmport/asset.c
===================================================================
--- stable/0.8/lib/libmport/asset.c (rev 0)
+++ stable/0.8/lib/libmport/asset.c 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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.8/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.8/lib/libmport/bundle_read_install_pkg.c
===================================================================
--- stable/0.8/lib/libmport/bundle_read_install_pkg.c 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/bundle_read_install_pkg.c 2018-05-11 22:20:52 UTC (rev 9834)
@@ -55,7 +55,8 @@
static int create_package_row(mportInstance *, mportPackageMeta *);
static int create_categories(mportInstance *mport, mportPackageMeta *pkg);
static int create_depends(mportInstance *mport, mportPackageMeta *pkg);
-static int create_sample_file(const char *file);
+static int create_sample_file(mportInstance *mport, char *cwd, const char *file);
+static char** parse_sample(char *input);
static int mark_complete(mportInstance *, mportPackageMeta *);
static int mport_bundle_read_get_assetlist(mportInstance *mport, mportPackageMeta *pkg, mportAssetList **alist_p, enum phase);
@@ -210,20 +211,59 @@
return MPORT_OK;
}
+static char**
+parse_sample(char *input)
+{
+ char **ap, **argv;
+ argv = calloc(3, sizeof(char *));
+
+ if (argv == NULL)
+ return NULL;
+
+ for (ap = argv; (*ap = strsep(&input, " \t")) != NULL;) {
+ if (**ap != '\0') {
+ if (++ap >= &argv[3])
+ break;
+ }
+ }
+
+ return argv;
+}
+
static int
-create_sample_file(const char *file)
+create_sample_file(mportInstance *mport, char *cwd, const char *file)
{
- char nonSample[FILENAME_MAX];
- strlcpy(nonSample, file, FILENAME_MAX);
- char *sptr = strcasestr(nonSample, ".sample");
- if (sptr != NULL) {
- sptr[0] = '\0'; /* hack off .sample */
- if (!mport_file_exists(nonSample)) {
- if (mport_copy_file(file, nonSample) != MPORT_OK)
+ char nonSample[FILENAME_MAX * 2];
+ char secondFile[FILENAME_MAX];
+
+ strlcpy(nonSample, file, FILENAME_MAX * 2);
+ (void) snprintf(nonSample, FILENAME_MAX, "%s%s/%s", mport->root, cwd, file);
+ char** fileargv = parse_sample(nonSample);
+
+ if (fileargv[1] != '\0') {
+ if (fileargv[1][0] == '/')
+ strlcpy(secondFile, fileargv[1], FILENAME_MAX);
+ else
+ (void) snprintf(secondFile, FILENAME_MAX, "%s%s/%s", mport->root, cwd, fileargv[1]);
+
+ if (!mport_file_exists(secondFile)) {
+ if (mport_copy_file(fileargv[0], secondFile) != MPORT_OK)
RETURN_CURRENT_ERROR;
}
+ } else {
+ /* single file */
+ char *sptr = strcasestr(nonSample, ".sample");
+ if (sptr != NULL) {
+ sptr[0] = '\0'; /* hack off .sample */
+ if (!mport_file_exists(nonSample)) {
+ if (mport_copy_file(file, nonSample) != MPORT_OK)
+ RETURN_CURRENT_ERROR;
+ }
+ }
}
+ free(fileargv);
+
return MPORT_OK;
}
@@ -458,6 +498,17 @@
goto ERROR;
(void) snprintf(file, FILENAME_MAX, "%s%s/%s", mport->root, cwd, e->data);
+
+ if (e->type == ASSET_SAMPLE)
+ for (int ch = 0; ch < FILENAME_MAX; ch++) {
+ if (file[ch] == '\0')
+ break;
+ if (file[ch] == ' ' || file[ch] == '\t') {
+ file[ch] = '\0';
+ break;
+ }
+ }
+
if (entry == NULL) {
SET_ERROR(MPORT_ERR_FATAL, "Unexpected EOF with archive file");
goto ERROR;
@@ -549,7 +600,7 @@
}
/* for sample files, if we don't have an existing file, make a new one */
- if (e->type == ASSET_SAMPLE && create_sample_file(file) != MPORT_OK) {
+ if (e->type == ASSET_SAMPLE && create_sample_file(mport, cwd, e->data) != MPORT_OK) {
SET_ERRORX(MPORT_ERR_FATAL, "Unable to create sample file from %s",
file);
goto ERROR;
Modified: stable/0.8/lib/libmport/bundle_read_update_pkg.c
===================================================================
--- stable/0.8/lib/libmport/bundle_read_update_pkg.c 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/bundle_read_update_pkg.c 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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.8/lib/libmport/create_primative.c
===================================================================
--- stable/0.8/lib/libmport/create_primative.c 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/create_primative.c 2018-05-11 22:20:52 UTC (rev 9834)
@@ -176,6 +176,15 @@
(void)snprintf(file, FILENAME_MAX, "%s/%s", cwd, e->data);
}
+ if (e->type == ASSET_SAMPLE) {
+ for (int ch = 0; ch < FILENAME_MAX; ch++) {
+ if (file[ch] == '\0')
+ break;
+ if (file[ch] == ' ' || file[ch] == '\t')
+ file[ch] = '\0';
+ }
+ }
+
if (lstat(file, &st) != 0) {
sqlite3_finalize(stmnt);
RETURN_ERRORX(MPORT_ERR_FATAL, "Could not stat %s: %s", file, strerror(errno));
@@ -558,6 +567,18 @@
(void) snprintf(filename, FILENAME_MAX, "%s/%s/%s", extra->sourcedir, cwd, e->data);
}
+ if (e->type == ASSET_SAMPLE) {
+ // eat the second filename if it exists.
+ for (int ch = 0; ch < FILENAME_MAX; ch++) {
+ if (filename[ch] == '\0')
+ break;
+ if (filename[ch] == ' ' || filename[ch] == '\t') {
+ filename[ch] = '\0';
+ break;
+ }
+ }
+ }
+
if (mport_bundle_write_add_file(bundle, filename, e->data) != MPORT_OK)
RETURN_CURRENT_ERROR;
}
Modified: stable/0.8/lib/libmport/mport.h
===================================================================
--- stable/0.8/lib/libmport/mport.h 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/mport.h 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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.8/lib/libmport/mport_private.h
===================================================================
--- stable/0.8/lib/libmport/mport_private.h 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/mport_private.h 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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,14 +172,14 @@
#error "Unable to detect arch!"
#endif
-#if __MidnightBSD_version >= 9000
+#if __MidnightBSD_version >= 100000
+#define MPORT_OSVERSION "1.0"
+#elif __MidnightBSD_version >= 9000
#define MPORT_OSVERSION "0.9"
#elif __MidnightBSD_version >= 8000
#define MPORT_OSVERSION "0.8"
-#elif __MidnightBSD_version >= 7000
-#define MPORT_OSVERSION "0.7"
#else
-#error "libmport only supports MidnightBSD versions 0.7 and greater."
+#error "libmport only supports MidnightBSD versions 0.8 and greater."
#endif
/* fetch stuff */
Modified: stable/0.8/lib/libmport/pkgmeta.c
===================================================================
--- stable/0.8/lib/libmport/pkgmeta.c 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/pkgmeta.c 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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.8/lib/libmport/verify.c
===================================================================
--- stable/0.8/lib/libmport/verify.c 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/lib/libmport/verify.c 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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.8/usr.sbin/mport/mport.c
===================================================================
--- stable/0.8/usr.sbin/mport/mport.c 2018-05-11 22:18:50 UTC (rev 9833)
+++ stable/0.8/usr.sbin/mport/mport.c 2018-05-11 22:20:52 UTC (rev 9834)
@@ -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) {
@@ -430,11 +463,11 @@
warnx("%s", mport_err_string());
return mport_err_code();
}
- //mport_index_depends_free_vec(depends);
+ mport_index_depends_free_vec(depends);
} else {
/* already installed */
mport_pkgmeta_vec_free(packs);
- //mport_index_depends_free_vec(depends);
+ mport_index_depends_free_vec(depends);
}
return (0);
More information about the Midnightbsd-cvs
mailing list