[Midnightbsd-cvs] src [9830] trunk/usr.sbin/mport/mport.c: add basic which command
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri May 11 17:58:21 EDT 2018
Revision: 9830
http://svnweb.midnightbsd.org/src/?rev=9830
Author: laffer1
Date: 2018-05-11 17:58:20 -0400 (Fri, 11 May 2018)
Log Message:
-----------
add basic which command
Modified Paths:
--------------
trunk/usr.sbin/mport/mport.c
Modified: trunk/usr.sbin/mport/mport.c
===================================================================
--- trunk/usr.sbin/mport/mport.c 2018-05-11 19:23:49 UTC (rev 9829)
+++ trunk/usr.sbin/mport/mport.c 2018-05-11 21:58:20 UTC (rev 9830)
@@ -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,31 @@
return (0);
}
+int
+which(mportInstance *mport, const char *filePath) {
+
+ mportPackageMeta *pack;
+
+ 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) {
+ printf("%s was installed by package %s\n",
+ filePath, pack->origin);
+ } else {
+ puts("null?");
+ }
+
+ return (0);
+}
+
/* recursive function */
int
install_depends(mportInstance *mport, const char *packageName, const char *version) {
More information about the Midnightbsd-cvs
mailing list