Re: [PATCH 3/3] Teach "git branch" about --new-workdir
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jul 23, 2007, 10:32 UTC
- Message-ID
- <Pine.LNX.4.64.0707231129010.14781@racer.site>
- In-Reply-To
- <7v1wezohi4.fsf@assigned-by-dhcp.cox.net>
Hi,
On Sun, 22 Jul 2007, Junio C Hamano wrote:
Show 15 quoted lines
> @@ -28,6 +28,17 @@ static void remove_lock_file_on_signal(int signo)
> 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;
> + }I wonder if we should not make this a while loop:
struct stat st; int i = 0;
while (i++ < 10 && !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)
die("Cannot readlink %s", path);
else
path = target;
}
if (i == 10)
die ("Too deep symlink depth: %s", path);(As you see, I would not warn, but die if readlink fails.)
Ciao, Dscho