if [[ -L $dest_file ]]; then
if [[ $(readlink $dest_file) == "$target" ]]; then
# Leave the link in place, but make sure it's
- # ownership is right.
- # already exists. links all get 777 perms, so
- # we dun have to mess with that.
- if [[ $(stat -L -c%a "$dest_dir") == 2* ]]; then
- grp=$(stat -L -c%g "$dest_dir")
+ # owner & group is as if we created it.
+ # links all get 777 perms, so
+ # we already know that is right.
+
+ # test for setgid.
+ if [[ $(stat -L -c%a "$dest_dir") == 2??? ]]; then
+ grp=$(stat -L -c%g "$dest_dir") || return $?
else
- grp=$(id -g)
+ grp=$(id -g) || return $?
fi
if [[ $EUID == 0 && $(stat -c%u "$dest_file") != 0 ]]; then
- chown 0:$grp "$dest_file"
+ chown -h 0:$grp "$dest_file" || return $?
elif [[ $(stat -c%g "$dest_file") != "$grp" ]]; then
- chgrp $grp "$dest_file"
+ chgrp -h $grp "$dest_file" || return $?
fi
- return 1
+ do_exit=true
+ return 0
fi
to_remove+=("$dest_file")
elif [[ -e $dest_file ]]; then
"
- local temp
+ local temp nodir
local verbose=false
local dry_run=false
- local nodir
+ local do_exit=false
temp=$(getopt -l help,dry-run,verbose hnTv "$@") || usage 1
eval set -- "$temp"
while true; do
if [[ $nodir ]]; then
dest_file="$2"
dest_dir="$(dirname "$dest_file")"
- _lnf_existing_link "$1" "$dest_file" "$dest_dir" || return 0
+ _lnf_existing_link "$1" "$dest_file" "$dest_dir" || return $?
+ if $do_exit; then return 0; fi
if [[ ! -d $dest_dir ]]; then
mkdir=true
if [[ -e $dest_dir || -L $dest_dir ]]; then
to_link+=("$dest_dir")
elif [[ $# -eq 1 ]]; then
dest_file="${1##*/}"
- _lnf_existing_link "$1" "$dest_file" . || return 0
+ _lnf_existing_link "$1" "$dest_file" . || return $?
+ if $do_exit; then return 0; fi
fi
if (( ${#to_remove[@]} >= 1 )); then
if type -P trash-put >/dev/null; then
# so revert to rm -rf in that case
if [[ $ret == 72 ]]; then
echo "lnf: using rm -rf to overcome cross filesystem trash-put limitation"
- rm -rf -- "${to_remove[@]}"
+ rm -rf -- "${to_remove[@]}" || return $?
elif [[ $ret == 74 ]]; then
echo "lnf: using rm -rf to overcome empty file & hardlink trash-put limitation"
rm -rf -- "${to_remove[@]}"