From 938c5c45b976387ceea5792b0ce9717dd97667eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luc=C3=ADa=20Andrea=20Illanes=20Albornoz?= Date: Mon, 27 Mar 2023 08:04:23 +0200 Subject: Generalise subr.pkg/*.subr code. --- subr.rtl/rtl_filepath.subr | 59 +++++++++++++++++++++++++++++++++++++++++++++- subr.rtl/rtl_platform.subr | 1 + 2 files changed, 59 insertions(+), 1 deletion(-) (limited to 'subr.rtl') diff --git a/subr.rtl/rtl_filepath.subr b/subr.rtl/rtl_filepath.subr index 3e24057f..a2f0f5c4 100644 --- a/subr.rtl/rtl_filepath.subr +++ b/subr.rtl/rtl_filepath.subr @@ -213,7 +213,7 @@ rtl_is_newer() { }; # -# rtl_patch_files() - +# rtl_patch_files() - patch files # @_patch_cwd: patch(1) -d directory # @_strip_count: patch(1) strip count # @_fn: name of function that produces patch filenames and takes the arguments @_rpatch_fname @_patch_idx @... @@ -246,4 +246,61 @@ rtl_patch_files() { return 0; }; +# +# rtl_set_perms_treeV() - set mode bits of directories and files +# @_mode_dir: mode bits for directories +# @_mode_file_exec: mode bits for executable files +# @_mode_file_nonexec: mode bits for non-executable files +# @...: list of base directory pathnames as positional parameters; empty strings are ignored +# +# Returns: zero (0) on success, non-zero (>0) on failure +# +rtl_set_perms_treeV() { + local _rspt_mode_dir="${1}" _rspt_mode_file_exec="${2}" _rspt_mode_file_nonexec="${3}" \ + _rspt_destdir="" _rspt_fname="" \ + IFS IFS0="${IFS}"; + shift 3; + + for _rspt_destdir in "${@}"; do + if [ -e "${_rspt_destdir}" ]; then + rtl_set_IFS_nl; + + for _rspt_fname in $(find "${_rspt_destdir}" -type d); do + if ! rtl_fileop chmod "${_rspt_mode_dir}" \ + "${_rspt_fname}"; + then + return 1; + fi; + done; + + for _rspt_fname in $(find \ + "${_rspt_destdir}" \ + \( -not -perm /0111 \) \ + -type f); + do + if ! rtl_fileop chmod "${_rspt_mode_file_nonexec}" \ + "${_rspt_fname}"; + then + return 1; + fi; + done; + + for _rspt_fname in $(find \ + "${_rspt_destdir}" \ + -perm /0111 \ + -type f); + do + if ! rtl_fileop chmod "${_rspt_mode_file_exec}" \ + "${_rspt_fname}"; + then + return 1; + fi; + done; + + IFS="${IFS0}"; + fi; + done; + return 0; +}; + # vim:filetype=sh textwidth=0 diff --git a/subr.rtl/rtl_platform.subr b/subr.rtl/rtl_platform.subr index 9fc7b013..d3ba8f56 100644 --- a/subr.rtl/rtl_platform.subr +++ b/subr.rtl/rtl_platform.subr @@ -237,6 +237,7 @@ rtl_set_var() { # N.B.: This function is *unsafe* and impossible to implement otherwise w/o filtering @_vname # and implicitly allows for code execution and other undefined behaviour via @_vname. # Do *not* pass untrusted input through @_vname. +# rtl_set_var_unsafe() { local _rsvu_vname="" _rsvu_vval=""; if [ "x${1}" = "x-u" ]; then -- cgit v1.2.3