Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Aug 2021 17:29:00 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 48ac2697742e - stable/13 - pkg: allow multiple add arguments again
Message-ID:  <202108261729.17QHT0Jr011027@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=48ac2697742ed4e0beed3f074af41b7a9e21b662

commit 48ac2697742ed4e0beed3f074af41b7a9e21b662
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2021-02-18 03:41:53 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-08-26 17:28:38 +0000

    pkg: allow multiple add arguments again
    
    While pkg(7) add only handles a single 'add' argument, pkg-add(8) fully
    handles multiple arguments.
    
    Stop rejecting it, just turn off local-bootstrap mode and proceed to
    remote bootstrap if we need it.
    
    While we're here, check if the first argument to pkg add is even a pkg
    package. If it's not, also do remote bootstrap instead. Future work
    could improve this altogether by picking out a pkg package out of many
    and local bootstrap then pass the rest through to the newly installed
    pkg.
    
    (cherry picked from commit 40b9f924b189ce8fa871db600b4abc99b03c6a65)
---
 usr.sbin/pkg/pkg.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 50 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c
index 8193dc79a430..1196c78e5cc9 100644
--- a/usr.sbin/pkg/pkg.c
+++ b/usr.sbin/pkg/pkg.c
@@ -1056,6 +1056,40 @@ cleanup:
 	return (ret);
 }
 
+#define	PKG_NAME	"pkg"
+#define	PKG_DEVEL_NAME	PKG_NAME "-devel"
+#define	PKG_PKG		PKG_NAME "."
+
+static bool
+pkg_is_pkg_pkg(const char *pkg)
+{
+	char *vstart;
+	size_t namelen;
+
+	/*
+	 * Chop off the final "-" (version delimiter) and check the name that
+	 * precedes it.  If we didn't have a version delimiter, it must be the
+	 * pkg.$archive short form but we'll check it anyways.  pkg-devel short
+	 * form will look like a pkg archive with 'devel' version, but that's
+	 * OK.  We otherwise assumed that non-pkg packages will always have a
+	 * version component.
+	 */
+	vstart = strrchr(pkg, '-');
+	if (vstart == NULL) {
+		return (strlen(pkg) > sizeof(PKG_PKG) - 1 &&
+		    strncmp(pkg, PKG_PKG, sizeof(PKG_PKG) - 1) == 0);
+	}
+
+	namelen = vstart - pkg;
+	if (namelen == sizeof(PKG_NAME) - 1 &&
+	    strncmp(pkg, PKG_NAME, sizeof(PKG_NAME) - 1) == 0)
+		return (true);
+	if (namelen == sizeof(PKG_DEVEL_NAME) - 1 &&
+	    strncmp(pkg, PKG_DEVEL_NAME, sizeof(PKG_DEVEL_NAME) - 1) == 0)
+		return (true);
+	return (false);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -1159,13 +1193,25 @@ main(int argc, char *argv[])
 				fprintf(stderr, args_bootstrap_message);
 				exit(EXIT_FAILURE);
 			}
-			// For add, we accept exactly one further argument
 			else if (add_pkg && pkgarg != NULL) {
-				fprintf(stderr, args_add_message);
-				exit(EXIT_FAILURE);
+				/*
+				 * Additional arguments also means it's not a
+				 * local bootstrap request.
+				 */
+				add_pkg = false;
 			}
 			else if (add_pkg) {
-				pkgarg = argv[optind-1];
+				/*
+				 * If it's not a request for pkg or pkg-devel,
+				 * then we must assume they were trying to
+				 * install some other local package and we
+				 * should try to bootstrap from the repo.
+				 */
+				if (!pkg_is_pkg_pkg(argv[optind-1])) {
+					add_pkg = false;
+				} else {
+					pkgarg = argv[optind-1];
+				}
 			}
 			break;
 		default:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108261729.17QHT0Jr011027>