properly handle existing links

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
remotes/origin/feature_files_export
Steven Armstrong 13 years ago
parent 63ba527bd8
commit 9d25dfdfa9
  1. 62
      conf/type/__link/explorer/state
  2. 7
      conf/type/__link/gencode-remote

@ -0,0 +1,62 @@
#!/bin/sh
#
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
type="$(cat "$__object/parameter/type")"
source="$(cat "$__object/parameter/source")"
# no destination? -> state is absent
if [ ! -e "$destination" ]; then
echo absent
exit 0
fi
destination_dir="${destination%/*}"
case "$type" in
symbolic)
cd "$destination_dir"
source_is=$(ls -l "$destination" | sed 's/.*-> //g')
if [ -h "$destination" -a "$source_is" = "$source" ]; then
echo present
else
echo absent
fi
;;
hard)
cd "$destination_dir"
# check source relative to destination_dir
if [ ! -e "$source" ]; then
echo sourcemissing
exit 0
fi
destination_inode=$(ls -i "$destination" | awk '{print $1}')
source_inode=$(ls -i "$source" | awk '{print $1}')
if [ "$destination_inode" -eq "$source_inode" ]; then
echo present
else
echo absent
fi
;;
*)
echo "Unknown type: $type" >&2
exit 1
;;
esac

@ -39,7 +39,14 @@ case "$type" in
;;
esac
state_is="$(cat "$__object/explorer/state")"
state_should="$(cat "$__object/parameter/state")"
if [ "$state_should" = "$state_is" ]; then
# nothing to do
exit 0
fi
case "$state_should" in
present)
echo ln ${lnopt} -f \"$source\" \"$destination\"

Loading…
Cancel
Save