setup: translate symlinks in filename when using absolute paths

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>
maint
Carlo Marcelo Arenas Belon 2010-12-27 02:54:37 -08:00 committed by Junio C Hamano
parent 0ed7481347
commit 18e051a398
1 changed files with 7 additions and 4 deletions

11
setup.c
View File

@ -7,10 +7,13 @@ static int inside_work_tree = -1;
const char *prefix_path(const char *prefix, int len, const char *path) const char *prefix_path(const char *prefix, int len, const char *path)
{ {
const char *orig = path; const char *orig = path;
char *sanitized = xmalloc(len + strlen(path) + 1); char *sanitized;
if (is_absolute_path(orig)) if (is_absolute_path(orig)) {
strcpy(sanitized, path); const char *temp = make_absolute_path(path);
else { sanitized = xmalloc(len + strlen(temp) + 1);
strcpy(sanitized, temp);
} else {
sanitized = xmalloc(len + strlen(path) + 1);
if (len) if (len)
memcpy(sanitized, prefix, len); memcpy(sanitized, prefix, len);
strcpy(sanitized + len, path); strcpy(sanitized + len, path);