When locking in a symlinked repository, try to lock the original.
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>
Junio C Hamano committed
Jul 25, 2007 at 16:22 UTC
d58e8d34b019d435b424811c6f972910dfac6f55
1 file changed
+13
lockfile.c
+13
@@ -28,6 +28,19 @@ static void remove_lock_file_on_signal(int signo)
28
static int lock_file(struct lock_file *lk, const char *path)
29
{
30
int fd;
31
+ struct stat st;
32
+
33
+ if ((!lstat(path, &st)) && S_ISLNK(st.st_mode)) {
34
+ ssize_t sz;
35
+ static char target[PATH_MAX];
36
+ sz = readlink(path, target, sizeof(target));
37
+ if (sz < 0)
38
+ warning("Cannot readlink %s", path);
39
+ else if (target[0] != '/')
40
+ warning("Cannot lock target of relative symlink %s", path);
41
+ else
42
+ path = target;
43
+ }
44
sprintf(lk->filename, "%s.lock", path);
45
fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
46
if (0 <= fd) {