summaryrefslogtreecommitdiffhomepage
path: root/subr.rtl/rtl_fileop.subr
diff options
context:
space:
mode:
Diffstat (limited to 'subr.rtl/rtl_fileop.subr')
-rw-r--r--subr.rtl/rtl_fileop.subr36
1 files changed, 17 insertions, 19 deletions
diff --git a/subr.rtl/rtl_fileop.subr b/subr.rtl/rtl_fileop.subr
index d69cead7..4addffcd 100644
--- a/subr.rtl/rtl_fileop.subr
+++ b/subr.rtl/rtl_fileop.subr
@@ -3,10 +3,8 @@
#
#
-# Private globals and subroutines
+# Private subroutines
#
-RTLP_FILEOP_LOG=0;
-rtl_fileop_set_log() { RTLP_FILEOP_LOG="${1}"; };
rtlp_fileop_check() {
local _prefix="${1}" _pname="" _rname=""; shift;
@@ -16,38 +14,38 @@ rtlp_fileop_check() {
};
rtlp_fileop_log() {
- local _msg="${1}";
- if [ "${RTLP_FILEOP_LOG:-0}" -eq 1 ]; then
- rtl_log_msg notice "${_msg}";
- fi;
+ rtl_log_msg "fileop" "${1}";
};
+#
+# Public subroutines
+#
rtl_fileop() {
local _op="${1}" _dst="" _group="" _install_args="" _mode="" _owner="" _rc=0 _src=""; shift;
case "${_op}" in
cd) if [ \( -z "${1}" \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then
- rtl_log_msg fatalexit "Invalid or non-existent directory \`%s'." "${1}";
+ rtl_log_msg "fatalexit" "Error: Invalid or non-existent directory \`%s'." "${1}";
elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then
rtlp_fileop_log "Changing working directory to \`${1}'.";
cd -- "${1}"; _rc="${?}";
fi; ;;
chmod) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: chmod %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: chmod %s.)" "${*}";
elif _mode="${1}" && shift\
&& rtlp_fileop_check "${PREFIX:-}" "${*}"; then
rtlp_fileop_log "Changing file mode bits of \`${*}' to \`${_mode}'.";
chmod -- "${_mode}" "${@}"; _rc="${?}";
fi; ;;
chgrp) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: chgrp %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: chgrp %s.)" "${*}";
elif _group="${1}" && shift\
&& rtlp_fileop_check "${PREFIX:-}" "${*}"; then
rtlp_fileop_log "Changing file group of \`${*}' to \`${_group}'.";
chgrp -- "${_group}" "${@}"; _rc="${?}";
fi; ;;
chown) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: chown %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: chown %s.)" "${*}";
elif _owner="${1}" && shift\
&& rtlp_fileop_check "${PREFIX:-}" "${*}"; then
rtlp_fileop_log "Changing file owner of \`${*}' to \`${_owner}'.";
@@ -55,7 +53,7 @@ rtl_fileop() {
fi; ;;
cp_follow)
if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: cp_follow %s}.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: cp_follow %s}.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then
_src="${*}"; _src="${_src% *}";
_dst="${*}"; _dst="${_dst##* }";
@@ -63,7 +61,7 @@ rtl_fileop() {
cp -pLR -- "${@}"; _rc="${?}";
fi; ;;
cp) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: cp %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: cp %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then
_src="${*}"; _src="${_src% *}";
_dst="${*}"; _dst="${_dst##* }";
@@ -72,7 +70,7 @@ rtl_fileop() {
fi; ;;
install)
if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: install %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: install %s.)" "${*}";
else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${2}")";
_install_args="$(while [ ""${#}"" -gt 2 ]; do printf "%s" "${1}"; shift; done)";
_src="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${1}")";
@@ -83,7 +81,7 @@ rtl_fileop() {
fi; ;;
ln_symbolic)
if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then
- rtl_log_msg fatalexit "Missing parameters (in: ln_symbolic %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: ln_symbolic %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${2}"; then
if rtl_fileop test "${2}"; then
rtl_fileop rm "${2}";
@@ -94,13 +92,13 @@ rtl_fileop() {
fi;
fi; ;;
mv) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then
- rtl_log_msg fatalexit "Missing parameters (in: mv %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: mv %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${1}" "${2}"; then
rtlp_fileop_log "Moving \`${1}' to \`${2}' w/ -fs";
mv -f -- "${1}" "${2}"; _rc="${?}";
fi; ;;
touch) if [ -z "${1}" ]; then
- rtl_log_msg fatalexit "Missing parameters (in: touch %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: touch %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then
rtlp_fileop_log "Touching file \`${1}'${2:+ w/ timestamp \`${2}\'}.";
touch ${2:+-t "${2}"} -- "${1}"; _rc="${?}";
@@ -108,7 +106,7 @@ rtl_fileop() {
mkdir|mkfifo|rm|source|source_opt|test)
while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do
if [ -z "${1}" ]; then
- rtl_log_msg fatalexit "Missing parameters (in: %s %s.)" "${_op}" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: %s %s.)" "${_op}" "${*}";
elif [ "${_op}" = mkdir ]\
&& [ ! -d "${1}" ]\
&& rtlp_fileop_check "${PREFIX:-}" "${1}"; then
@@ -145,7 +143,7 @@ rtl_fileop() {
return 1;
fi; shift;
done; ;;
- *) rtl_log_msg fatalexit "Error: rtl_fileop() called w/ invalid parameter(s): %s" "${*}"; ;;
+ *) rtl_log_msg "fatalexit" "Error: rtl_fileop() called w/ invalid parameter(s): %s" "${*}"; ;;
esac; return "${_rc}";
};