From 644d3bb8b82ecab7a0c34f36b4745b9c9b433b73 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 4 Aug 2017 14:21:32 +0000 Subject: [PATCH] Rename fwrite to fappend Because that is what the function is actually doing. Signed-off-by: Michael Tremer --- src/functions/functions.bonding | 8 ++++---- src/functions/functions.device | 2 +- src/functions/functions.dhclient | 4 ++-- src/functions/functions.stp | 2 +- src/functions/functions.sysctl | 4 ++-- src/functions/functions.util | 13 +++++++++++++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/functions/functions.bonding b/src/functions/functions.bonding index d9861e58..7939c962 100644 --- a/src/functions/functions.bonding +++ b/src/functions/functions.bonding @@ -69,7 +69,7 @@ bonding_create() { bonding_init # Create the bonding device. - fwrite "${BONDING_MASTERS}" "+${device}" + fappend "${BONDING_MASTERS}" "+${device}" local ret=$? if [ ${ret} -eq ${EXIT_OK} ]; then @@ -101,7 +101,7 @@ bonding_remove() { device_set_down ${device} # Remove the device. - fwrite "${BONDING_MASTERS}" "-${device}" + fappend "${BONDING_MASTERS}" "-${device}" local ret=$? if [ ${ret} -eq ${EXIT_OK} ]; then @@ -129,7 +129,7 @@ bonding_set_mode() { local device="${1}" local mode="${2}" - if fwrite "${SYS_CLASS_NET}/${device}/bonding/mode" "${mode}"; then + if fappend "${SYS_CLASS_NET}/${device}/bonding/mode" "${mode}"; then log DEBUG "Set mode of bond '${device}' to '${mode}'" else log ERROR "Could not set mode of bond '${device}' to '${mode}'" @@ -157,7 +157,7 @@ bonding_enslave_device() { fi # Add it. - fwrite "${SYS_CLASS_NET}/${device}/bonding/slaves" "+${slave}" + fappend "${SYS_CLASS_NET}/${device}/bonding/slaves" "+${slave}" local ret=$? if [ ${ret} -eq ${EXIT_OK} ]; then diff --git a/src/functions/functions.device b/src/functions/functions.device index be3fe954..6f79a7f6 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -823,7 +823,7 @@ __device_set_file() { local file="${2}" local value="${3}" - fwrite "${SYS_CLASS_NET}/${device}/${file}" "${value}" + fappend "${SYS_CLASS_NET}/${device}/${file}" "${value}" } device_get_rx_bytes() { diff --git a/src/functions/functions.dhclient b/src/functions/functions.dhclient index 9409b0b7..57724744 100644 --- a/src/functions/functions.dhclient +++ b/src/functions/functions.dhclient @@ -127,8 +127,8 @@ dhclient_write_config() { > "${config_file}" # Global options. - fwrite "${config_file}" "send vendor-class-identifier \"${vendor}\";" - fwrite "${config_file}" # empty line + fappend "${config_file}" "send vendor-class-identifier \"${vendor}\";" + fappend "${config_file}" # empty line # Interface options. ( diff --git a/src/functions/functions.stp b/src/functions/functions.stp index 7155c0f3..7b08742a 100644 --- a/src/functions/functions.stp +++ b/src/functions/functions.stp @@ -88,7 +88,7 @@ stp_bridge_set_forward_delay() { # Set the new value. log DEBUG "Setting forward delay on bridge '${bridge}' from '${current_fdelay}' to '${fdelay}'" - fwrite "${SYS_CLASS_NET}/${bridge}/bridge/forward_delay" "$(( ${fdelay} * 100 ))" + fappend "${SYS_CLASS_NET}/${bridge}/bridge/forward_delay" "$(( ${fdelay} * 100 ))" return ${EXIT_OK} } diff --git a/src/functions/functions.sysctl b/src/functions/functions.sysctl index 5d77b8e9..ce8f43a9 100644 --- a/src/functions/functions.sysctl +++ b/src/functions/functions.sysctl @@ -54,7 +54,7 @@ sysctl_set() { local value="${2}" - fwrite "$(sysctl_key_to_path "${key}")" "${value}" || return $? + fappend "$(sysctl_key_to_path "${key}")" "${value}" || return $? return ${EXIT_OK} } @@ -87,7 +87,7 @@ sysctl_set_recursively() { for path in $(find "${basepath}" -type f); do [[ ${path} =~ ${subpath}$ ]] || continue - fwrite "${path}" "${value}" + fappend "${path}" "${value}" done return ${EXIT_OK} diff --git a/src/functions/functions.util b/src/functions/functions.util index e083f6a7..91601de6 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -190,6 +190,19 @@ fwrite() { assert isset file shift + if ! print "%s" "$@" > ${file} 2>/dev/null; then + error "Could not write to file: ${file}" + return ${EXIT_ERROR} + fi + + return ${EXIT_OK} +} + +fappend() { + local file=${1} + assert isset file + shift + if [ -e "${file}" ] && [ ! -w "${file}" ]; then log ERROR "${file}: No such file" return ${EXIT_ERROR} -- 2.39.2