]> git.ipfire.org Git - thirdparty/git.git/commitdiff
When locking in a symlinked repository, try to lock the original.
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Jul 2007 23:22:55 +0000 (16:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Jul 2007 23:22:55 +0000 (16:22 -0700)
In a working tree prepared in new-workdir (in contrib/), some files in .git/
directory are symbolic links to the original repository.  The usual sequence of
lock-write-rename would break the symbolic link.

Ideally we should resolve relative symbolic link with maxdepth, but I do not
want to risk too elaborate patch before 1.5.3 release, so this is a minimum
and trivially obvious fix.  new-workdir creates its symbolic links absolute,
and does not link from a symlinked workdir, so this fix should suffice for now.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
lockfile.c

index fb8f13bbb95eea8c66dadf409b40193ec2df8738..920247249823b8f69524b845d6bdb0cb0b1b802b 100644 (file)
@@ -28,6 +28,19 @@ 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 if (target[0] != '/')
+                       warning("Cannot lock target of relative symlink %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) {