From nobody Thu Nov 03 02:43:09 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N2p314wNSz4gdDX; Thu, 3 Nov 2022 02:43:09 +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 4N2p314Q52z3fh2; Thu, 3 Nov 2022 02:43:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667443389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8nDT+35t2icSuJecXouN/j/SNiwzLKpLd6tSpZgLoxw=; b=g5j8z/SNKsWC5eOyxGxeSUte1ckYCTONutUsp2+Ai4dWYWYBLXJfOCfXz9wM+stT1uZWzE rSckSFgqRis5rqVvdZ30oO01xxlptqnblx+RaEFvfJkokogH51xyXONsPF1AHkbpX7jcX2 GCCVLZNYop0OgCiB0tFHvJfGcE3KS5F7I15HCcYpo1EAx7PFfBNSgednglaOyj5IPF3nFO /wWXQtLQBxkZoA/GjQkxk79I5FZo4Bx0XZHpKQd0RrHw2xghVkVTDmMQ8FwCdWpgNZPAkf yxdrspiCJCxaNdBIXFPqZTesmBG5w2pqp9MnEnwnnfGkC6IYoOSlmMGU5n5G5w== 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 4N2p313SJVzL5g; Thu, 3 Nov 2022 02:43:09 +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 2A32h9EO084216; Thu, 3 Nov 2022 02:43:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A32h9TI084215; Thu, 3 Nov 2022 02:43:09 GMT (envelope-from git) Date: Thu, 3 Nov 2022 02:43:09 GMT Message-Id: <202211030243.2A32h9TI084215@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: a6346c02f646 - main - mktemp: don't double up on trailing slashes for -t paths List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: a6346c02f646c6b74f007c64a9b546deb06182ae Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667443389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8nDT+35t2icSuJecXouN/j/SNiwzLKpLd6tSpZgLoxw=; b=GWuU+SWTsuTdWHpvF3WroZp4mcReTxq/yOSvXg8vuRaJ0DzRjQMcesDaZA6gQQgTfhJ19p mB8168RIdOSIEDAEU3WuhR8wCJx8dGNl//bG8CpJi1jfWImjzxkNdKN+RMLLNco+CvTb1c ZKqCaXKcApeEBPfd8LuQDGBRoaJmmrF84UwajUw8ovqneOhC9fC9k4PvoI2kJF0xAilTOc jBys6hxeYQGF1l7bynWRt/nKK8uZgEy72anf+B6vfMUTM1nl34EcABfSgg4B5BxbuBHmVz pxD/ASrYRz6Z6FRw1gts1BuU9Ap2CgPaVlEvuLl4wpnfUFIAu3A+mOyMJA8DQQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667443389; a=rsa-sha256; cv=none; b=Vwvb1J3AK7ioaKkCJb/Pf3eScE2gZ9Zx6PTEFTomC1BfGhemq1PAB2gsWSpzCqSmxQWsbV iN6wWKe4Dw8wA+ZWDBmpRaf+S1XmPVH3WYbH2acnG+jSibkqmkXnmtB0Qwd9O/7Ocpts04 Ycfd/bKQISyvb48Sj/nb0zClFGaBNVQsdE6otYES3g4m+fIw3XFmw3YjCuW5qpdnd7jHSB 0dj9vcF5IEivAY3FWuFHAJjVbw7vwcYBMurOwurlTBz+6fV93KgXgSAgBMfgcVf/9eCeG9 zKU+YhjYALsfbBG0SXN5YhSLUh+mlEn/tB8wKPy01ppc82ziwkiOzfPgMuWNHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=a6346c02f646c6b74f007c64a9b546deb06182ae commit a6346c02f646c6b74f007c64a9b546deb06182ae Author: Kyle Evans AuthorDate: 2022-11-02 20:29:16 +0000 Commit: Kyle Evans CommitDate: 2022-11-03 02:42:57 +0000 mktemp: don't double up on trailing slashes for -t paths This is a minor cosmetic change; re-organize slightly to set tmpdir to _PATH_TMP if we didn't otherwise have a tmpdir candidate, then check the trailing char before appending another slash. While we're here, remove some bogus whitespace and add a test case for this change. Obtained from: https://github.com/apple-oss-distributions/shell_cmds Sponsored by: Klara, Inc. --- usr.bin/mktemp/mktemp.c | 8 ++++++-- usr.bin/mktemp/tests/mktemp_test.sh | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/usr.bin/mktemp/mktemp.c b/usr.bin/mktemp/mktemp.c index a15e0d776c40..6f5b21ce70d5 100644 --- a/usr.bin/mktemp/mktemp.c +++ b/usr.bin/mktemp/mktemp.c @@ -120,6 +120,7 @@ main(int argc, char **argv) if (tflag) { const char *envtmp; + size_t len; envtmp = NULL; @@ -131,7 +132,10 @@ main(int argc, char **argv) if (envtmp != NULL) tmpdir = envtmp; if (tmpdir == NULL) - asprintf(&name, "%s%s.XXXXXXXXXX", _PATH_TMP, prefix); + tmpdir = _PATH_TMP; + len = strlen(tmpdir); + if (len > 0 && tmpdir[len - 1] == '/') + asprintf(&name, "%s%s.XXXXXXXXXX", tmpdir, prefix); else asprintf(&name, "%s/%s.XXXXXXXXXX", tmpdir, prefix); /* if this fails, the program is in big trouble already */ @@ -142,7 +146,7 @@ main(int argc, char **argv) errx(1, "cannot generate template"); } } - + /* generate all requested files */ while (name != NULL || argc > 0) { if (name == NULL) { diff --git a/usr.bin/mktemp/tests/mktemp_test.sh b/usr.bin/mktemp/tests/mktemp_test.sh index 1138c46ec1d0..60555f1b561b 100755 --- a/usr.bin/mktemp/tests/mktemp_test.sh +++ b/usr.bin/mktemp/tests/mktemp_test.sh @@ -109,10 +109,24 @@ tmpdir_pflag_noarg_body() atf_check -o match:"^$tmpdir/foo\..+$" cat tmpname } +atf_test_case tmpdir_tflag_oneslash +tmpdir_tflag_oneslash_body() +{ + + tmpdir="$PWD" + + # Provided a trailing slash, we shouldn't end up with two trailing + # slashes. + atf_check -o save:tmpname \ + env TMPDIR="$tmpdir/" mktemp -t foo + atf_check -o match:"^$tmpdir/foo\..+$" cat tmpname +} + atf_init_test_cases() { atf_add_test_case tmpdir_env atf_add_test_case tmpdir_pflag atf_add_test_case tmpdir_pflag_dir atf_add_test_case tmpdir_pflag_noarg + atf_add_test_case tmpdir_tflag_oneslash }