This functions now: - return an error when the destination is a directory - creates the destination if the destination not exist
Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/functions/functions.util | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/functions/functions.util b/src/functions/functions.util index 381208c..3bcd00f 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -179,12 +179,26 @@ fwrite() { assert isset file shift
- if [ ! -w "${file}" ]; then - log ERROR "${file}: No such file" + if [ -d "${file}" ]; then + log ERROR "${file} is a directory" return ${EXIT_ERROR} fi
- print "%s" "$@" >> ${file} 2>/dev/null + if [ -f "${file}" ]; then + if [ -w "${file}" ]; then + print "%s" "$@" >> ${file} 2>/dev/null + else + log ERROR "${file} is not writeable" + return ${EXIT_ERROR} + fi + else + if ! touch "${file}"; then + log ERROR "Could not touch ${file}" + return ${EXIT_ERROR} + fi + + print "%s" "$@" >> ${file} 2>/dev/null + fi }
make_parent_dir() {