summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-07-08 06:24:32 +0100
committerKerin Millar <kfm@plushkava.net>2024-07-08 06:24:32 +0100
commit4e09cd6073e9f7906081231af7511bc74cd1d1bb (patch)
tree04ddb59ba619eaf6e2bf70de4aa690f400ba7934 /functions.sh
parentRender _contains_all() compatible with mawk (diff)
downloadgentoo-functions-4e09cd6073e9f7906081231af7511bc74cd1d1bb.tar.gz
gentoo-functions-4e09cd6073e9f7906081231af7511bc74cd1d1bb.tar.bz2
gentoo-functions-4e09cd6073e9f7906081231af7511bc74cd1d1bb.zip
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 <kfm@plushkava.net>
Diffstat (limited to 'functions.sh')
-rw-r--r--functions.sh33
1 files changed, 28 insertions, 5 deletions
diff --git a/functions.sh b/functions.sh
index 82f59a3..dd4eef8 100644
--- a/functions.sh
+++ b/functions.sh
@@ -653,6 +653,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.
#
_has_dumb_terminal()
@@ -661,7 +688,6 @@ _has_dumb_terminal()
}
#
-#
# See the definitions of oldest() and newest().
#
_select_by_mtime() {
@@ -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='