aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-04-15 08:17:10 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-04-15 08:17:10 +0300
commitcef48161fbf809b7ed2ba06af8b31d0e38e4e2fb (patch)
tree7bb2546429f03b6ebd54c7a472601387e96f0b62 /%HOME%
parentcode style (diff)
downloadlinux-home-cef48161fbf809b7ed2ba06af8b31d0e38e4e2fb.tar.gz
linux-home-cef48161fbf809b7ed2ba06af8b31d0e38e4e2fb.zip
swap_files: not necessarily regular
Diffstat (limited to '%HOME%')
-rw-r--r--%HOME%/.bash_utils/file.sh9
1 files changed, 6 insertions, 3 deletions
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"