handle existing symlink but wrong source

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2014-03-11 20:48:47 +01:00
parent 0a98abbffa
commit 75c203a1f0
2 changed files with 12 additions and 7 deletions

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # 2012-2014 Steven Armstrong (steven-cdist at armstrong.cc)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -34,8 +34,12 @@ case "$type" in
symbolic) symbolic)
cd "$destination_dir" cd "$destination_dir"
source_is=$(ls -l "$destination" | sed 's/.*-> //g') source_is=$(ls -l "$destination" | sed 's/.*-> //g')
if [ -h "$destination" -a "$source_is" = "$source" ]; then if [ -h "$destination" ]; then
if [ "$source_is" = "$source" ]; then
echo present echo present
else
echo wrongsource
fi
else else
echo absent echo absent
fi fi

View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Steven Armstrong (steven-cdist at armstrong.cc) # 2013-2014 Steven Armstrong (steven-cdist at armstrong.cc)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -18,9 +18,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
#
# Mostly a wrapper for ln
#
destination="/$__object_id" destination="/$__object_id"
@ -55,6 +52,10 @@ rm -rf "$destination"
DONE DONE
fi fi
if [ "$state_is" = "wrongsource" ]; then
printf 'rm -f "%s"\n' "$destination"
fi
# create our link # create our link
cat << DONE cat << DONE
ln ${lnopt} -f "$source" "$destination" ln ${lnopt} -f "$source" "$destination"