On Wed, Jul 13, 2005 at 09:03:26AM +0200, Matthias Urlichs wrote:
> You are ;-) the tree itsels is no symlinked, but HEAD points to
> refs/heads/<branch> by default.
Thanks for pointing that out. I honestly never noticed that.
How about the following?
echo_to_file() {
local DEST="$2"
local count=1
local RET
# follow symlinks until we run out or end up with something
# dangling
while [ -L "$DEST" ] ; do
local NLINK=`readlink "$DEST"`
if [ ! -e "$NLINK" ] ; then
# dangling link, just poke as-is
echo "$1" > "$DEST"
return $?
fi
# follow link
if [ -L "$NLINK" ] ; then
count=$(("$count" + 1))
if [ "$count" -gt 5 ] ; then
echo "Too many symlinks when resolving $2" 1>&2
return 1
fi
DEST="$NLINK"
fi
done
# end up with a regular file
local TMPFILE=`mktemp "$DEST.tmp-XXXXXXX"`
echo "$1" > "$TMPFILE"
RET="$?"
mv -f "$TMPFILE" "$DEST"
return "$RET"
}
Obvious changes from last time are:
- mark things local
- follow links, bailing out if it takes too long
- if the link is dangling, just use as-is
- when doing the 'replace' at the end use -f because it's quite
possible someone will have done cp -Rl ~otheruser/tree here and mv
*might* bitch if the UID is different?
- return (some) errors (just because, it's not like cogito checks
for these)
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html