+_lnf_existing_link() {
+ local target dest_file dest_dir
+ target="$1"
+ dest_file="$2"
+ dest_dir="$3"
+ 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")
+ else
+ grp=$(id -g)
+ fi
+ if [[ $EUID == 0 && $(stat -c%u "$dest_file") != 0 ]]; then
+ chown 0:$grp "$dest_file"
+ elif [[ $(stat -c%g "$dest_file") != "$grp" ]]; then
+ chgrp $grp "$dest_file"
+ fi
+ return 1
+ fi
+ to_remove+=("$dest_file")
+ elif [[ -e $dest_file ]]; then
+ to_remove+=("$dest_file")
+ fi
+ to_link+=("$target")
+}