git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH] cogito --- don't overwrite metadata files in place (breaks CoW use)

From
CWChris Wedgwood <cw@f00f.org>
Date
Jul 13, 2005, 18:53 UTC
Message-ID
<20050713185339.GA9260@taniwha.stupidest.org>
In-Reply-To
<pan.2005.07.13.07.03.26.398212@smurf.noris.de>
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)
Previous: Matthias UrlichsNext: Linus Torvalds
Message 5 of 15 in “cogito --- don't overwrite metadata files in place (breaks CoW use)”
  1. cogito --- don't overwrite metadata files in place (breaks CoW use)Chris Wedgwood, Jul 12, 2005
  2. Junio C HamanoJul 12, 2005
  3. Chris WedgwoodJul 13, 2005
  4. Matthias UrlichsJul 13, 2005
  5. Chris WedgwoodJul 13, 2005
  6. Linus TorvaldsJul 13, 2005
  7. Chris WedgwoodJul 13, 2005
  8. Linus TorvaldsJul 13, 2005
  9. Chris WedgwoodJul 13, 2005
  10. Linus TorvaldsJul 13, 2005
  11. Chris WedgwoodJul 13, 2005
  12. Matthias UrlichsJul 13, 2005
  13. Chris WedgwoodJul 13, 2005
  14. Linus TorvaldsJul 13, 2005
  15. Chris WedgwoodJul 13, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.