Subject: Re: [PATCH 3/3] Teach "git branch" about --new-workdir

From: "Shawn O. Pearce" <[email-masked]>
Date: Mon, 23 Jul 2007 01:22:24 -0400

"Shawn O. Pearce" <[email-masked]> wrote:
> Junio C Hamano <[email-masked]> wrote:
> >  static int lock_file(struct lock_file *lk, const char *path)
> >  {
> >  	int fd;
> > +	struct stat st;
> > +
> > +	if ((!lstat(path, &st)) && S_ISLNK(st.st_mode)) {
> > +		ssize_t sz;
> > +		static char target[PATH_MAX];
> > +		sz = readlink(path, target, sizeof(target));
> > +		if (sz < 0)
> > +			warning("Cannot readlink %s", path);
> > +		else
> > +			path = target;
> > +	}
> >  	sprintf(lk->filename, "%s.lock", path);
> >  	fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
> >  	if (0 <= fd) {
> 
> Right.  But don't you have to resolve target relative to path?
> If the symlink is an absolute path its fine as-is, but if it was
> relative its relative to path, not pwd.

It might just be OK to refuse to lock a symlink that isn't absolute.
git-new-workdir already uses absolute paths to setup the symlinks.

-- 
Shawn.