When locking in a symlinked repository, try to lock the original.
[git/git.git] / lockfile.c
index fb8f13b..9202472 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) {