From owner-dev-commits-src-all@freebsd.org Fri Aug 6 19:28:17 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0E21865DB39; Fri, 6 Aug 2021 19:28:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GhFrJ6Swqz3JLD; Fri, 6 Aug 2021 19:28:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C1FBC13712; Fri, 6 Aug 2021 19:28:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 176JSGGi043353; Fri, 6 Aug 2021 19:28:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 176JSG42043352; Fri, 6 Aug 2021 19:28:16 GMT (envelope-from git) Date: Fri, 6 Aug 2021 19:28:16 GMT Message-Id: <202108061928.176JSG42043352@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 40b9f924b189 - main - pkg: allow multiple add arguments again MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 40b9f924b189ce8fa871db600b4abc99b03c6a65 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Aug 2021 19:28:17 -0000 The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=40b9f924b189ce8fa871db600b4abc99b03c6a65 commit 40b9f924b189ce8fa871db600b4abc99b03c6a65 Author: Kyle Evans AuthorDate: 2021-02-18 03:41:53 +0000 Commit: Kyle Evans CommitDate: 2021-08-06 19:25:07 +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. Reviewed by: bapt, manu (earlier version) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D28766 --- 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: