From cef48161fbf809b7ed2ba06af8b31d0e38e4e2fb Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 15 Apr 2017 08:17:10 +0300 Subject: swap_files: not necessarily regular --- %HOME%/.bash_utils/file.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to '%HOME%') diff --git a/%HOME%/.bash_utils/file.sh b/%HOME%/.bash_utils/file.sh index 33f9994..6034713 100644 --- a/%HOME%/.bash_utils/file.sh +++ b/%HOME%/.bash_utils/file.sh @@ -16,18 +16,21 @@ swap_files() ( local path1="$1" local path2="$2" - if [ ! -f "$path1" ]; then + if [ ! -r "$path1" ] || [ ! -w "$path1" ]; then echo "${FUNCNAME[0]}: must be a regular file: $path1" >&2 return 1 fi - if [ ! -f "$path2" ]; then + if [ ! -r "$path2" ] || [ ! -w "$path2" ]; then echo "${FUNCNAME[0]}: must be a regular file: $path2" >&2 return 1 fi + local path1_dir + path1_dir="$( dirname -- "$path1" )" + local tmp_path - tmp_path="$( mktemp -- "$( dirname -- "$path1" )/XXX" )" + tmp_path="$( mktemp -- "$path1_dir/XXX" )" mv -- "$path1" "$tmp_path" mv -- "$path2" "$path1" -- cgit v1.2.3