Code

setup: translate symlinks in filename when using absolute paths
authorCarlo Marcelo Arenas Belon <carenas@sajinet.com.pe>
Mon, 27 Dec 2010 10:54:37 +0000 (02:54 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Jan 2011 21:44:41 +0000 (13:44 -0800)
otherwise, comparison to validate against work tree will fail when
the path includes a symlink and the name passed is not canonical.

Signed-off-by: Carlo Marcelo Arenas Belon <carenas@sajinet.com.pe>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c

diff --git a/setup.c b/setup.c
index be550af42a12a29d3e10a2d6cbfcc3287d46cbbc..8031f99e978a27d394b04c998623388d2ab762b6 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -7,10 +7,13 @@ static int inside_work_tree = -1;
 const char *prefix_path(const char *prefix, int len, const char *path)
 {
        const char *orig = path;
-       char *sanitized = xmalloc(len + strlen(path) + 1);
-       if (is_absolute_path(orig))
-               strcpy(sanitized, path);
-       else {
+       char *sanitized;
+       if (is_absolute_path(orig)) {
+               const char *temp = make_absolute_path(path);
+               sanitized = xmalloc(len + strlen(temp) + 1);
+               strcpy(sanitized, temp);
+       } else {
+               sanitized = xmalloc(len + strlen(path) + 1);
                if (len)
                        memcpy(sanitized, prefix, len);
                strcpy(sanitized + len, path);