éviter les opérations inutiles

This commit is contained in:
Jephte CLAIN 2014-12-21 13:03:04 +04:00
parent 9431d64e97
commit 0c1f26a438
1 changed files with 7 additions and 2 deletions

View File

@ -824,7 +824,9 @@ function update_link() {
# c'est un lien relatif, faire un lien relatif # c'est un lien relatif, faire un lien relatif
dest="$(relpath "$1" "$linkdir")" dest="$(relpath "$1" "$linkdir")"
fi fi
if [ -d "$link" ]; then if [ "$dest" == "$ldest" ]; then
: # pas besoin de mettre à jour
elif [ -d "$link" ]; then
rm -f "$link" && ln -s "$dest" "$link" rm -f "$link" && ln -s "$dest" "$link"
else else
ln -sf "$dest" "$link" ln -sf "$dest" "$link"
@ -837,14 +839,17 @@ function move_link() {
[ -n "$1" -a -n "$2" ] || return 1 [ -n "$1" -a -n "$2" ] || return 1
local link="$1" dest="$2" local link="$1" dest="$2"
[ -d "$dest" ] && dest="$dest/$(basename -- "$link")" [ -d "$dest" ] && dest="$dest/$(basename -- "$link")"
dest="$(abspath "$dest")"
if [ -L "$link" ]; then if [ -L "$link" ]; then
link="$(abspath "$link")" link="$(abspath "$link")"
linkdir="$(dirname -- "$link")" linkdir="$(dirname -- "$link")"
ldest="$(readlink "$link")" ldest="$(readlink "$link")"
ldest="$(abspath "$ldest" "$linkdir")" ldest="$(abspath "$ldest" "$linkdir")"
[ "$dest" == "$link" ] && return 1
mv "$link" "$dest" || return 1 mv "$link" "$dest" || return 1
update_link "$ldest" "$dest" update_link "$ldest" "$dest"
else else
[ "$dest" == "$link" ] && return 1
mv "$link" "$dest" mv "$link" "$dest"
fi fi
} }
@ -889,7 +894,7 @@ function move_file() {
local src="$1" dest="$2" link local src="$1" dest="$2" link
shift; shift shift; shift
[ -d "$dest" ] && dest="$dest/$(basename -- "$src")" [ -d "$dest" ] && dest="$dest/$(basename -- "$src")"
move_link "$src" "$dest" || return move_link "$src" "$dest" || return 1
for link in "$@"; do for link in "$@"; do
update_link "$dest" "$link" update_link "$dest" "$link"
done done