From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 186AE159C9B for ; Fri, 2 Aug 2024 23:14:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4AF08E2A1D; Fri, 2 Aug 2024 23:14:14 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (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) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 27E90E2A1D for ; Fri, 2 Aug 2024 23:14:14 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (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) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 32B9234300A for ; Fri, 2 Aug 2024 23:14:13 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 943021E6C for ; Fri, 2 Aug 2024 23:14:11 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1720416272.4e09cd6073e9f7906081231af7511bc74cd1d1bb.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: functions/, / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh functions/rc.sh X-VCS-Directories: functions/ / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 4e09cd6073e9f7906081231af7511bc74cd1d1bb X-VCS-Branch: master Date: Fri, 2 Aug 2024 23:14:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 21652c40-7880-4d4c-961a-11e8209b95ea X-Archives-Hash: 3a7123316dc37f60197ef77b25d23168 commit: 4e09cd6073e9f7906081231af7511bc74cd1d1bb Author: Kerin Millar plushkava net> AuthorDate: Mon Jul 8 05:24:32 2024 +0000 Commit: Sam James gentoo org> CommitDate: Mon Jul 8 05:24:32 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=4e09cd60 Add the _find0() helper function The function is a simple wrapper around GNU find(1) which presumes the intent to use the -files0-from option to read NUL-delimited path names from the standard input. The benefit in having it is twofold. Firstly, the _select_by_mtime() and is_older_than() functions are thereby made a little easier to read. Secondly, the genfun_bin_find variable is now initialised lazily. Signed-off-by: Kerin Millar plushkava.net> functions.sh | 33 ++++++++++++++++++++++++++++----- functions/rc.sh | 2 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/functions.sh b/functions.sh index 82f59a3..dd4eef8 100644 --- a/functions.sh +++ b/functions.sh @@ -652,6 +652,33 @@ whenceforth() #------------------------------------------------------------------------------# +# +# See the definitions of _select_by_mtime() and is_older_than(). +# +_find0() +{ + # Store the name of the GNU find binary, which may be "gfind". + hash gfind 2>/dev/null && genfun_bin_find=gfind || genfun_bin_find=find + + _find0() + { + local opt + + case $1 in + -[HL]) + opt=$1 + shift + set -- "${opt}" -files0-from - "$@" + ;; + *) + set -- -files0-from - "$@" + esac + "${genfun_bin_find}" "$@" + } + + _find0 "$@" +} + # # Determines whether the terminal is a dumb one. # @@ -660,7 +687,6 @@ _has_dumb_terminal() ! case ${TERM} in *dumb*) false ;; esac } -# # # See the definitions of oldest() and newest(). # @@ -674,7 +700,7 @@ _select_by_mtime() { else cat fi \ - | "${genfun_bin_find}" -files0-from - -maxdepth 0 ! -path "*${genfun_newline}*" -printf '%T+ %p\n' \ + | _find0 -maxdepth 0 ! -path "*${genfun_newline}*" -printf '%T+ %p\n' \ | sort "${sort_opt}" \ | { IFS= read -r line && printf '%s\n' "${line#* }"; } } @@ -841,9 +867,6 @@ if [ ! "${genfun_basedir+set}" ]; then genfun_basedir=${genfun_prefix}/lib/gentoo fi -# Store the name of the GNU find binary. Some platforms may have it as "gfind". -hash gfind 2>/dev/null && genfun_bin_find=gfind || genfun_bin_find=find - # Assign the LF ('\n') character for later expansion. POSIX Issue 8 permits # $'\n' but it may take years for it to be commonly implemented. genfun_newline=' diff --git a/functions/rc.sh b/functions/rc.sh index 2f2dc52..9129b32 100644 --- a/functions/rc.sh +++ b/functions/rc.sh @@ -213,7 +213,7 @@ is_older_than() fi shift { test "$#" -gt 0 && printf '%s\0' "$@"; } \ - | "${genfun_bin_find}" -L -files0-from - ${ref:+-newermm} ${ref:+"${ref}"} -printf '\n' -quit \ + | _find0 -L ${ref:+-newermm} ${ref:+"${ref}"} -printf '\n' -quit \ | read -r _ }