Make 'ce_compare_link()' use the new 'strbuf_readlink()'

This simplifies the code, and also makes ce_compare_link now able to
handle filesystems with odd 'st_size' return values for symlinks.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Linus Torvalds 2008-12-17 09:47:27 -08:00 committed by Junio C Hamano
parent b11b7e13f4
commit a60272b38e

View File

@ -99,27 +99,21 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
static int ce_compare_link(struct cache_entry *ce, size_t expected_size) static int ce_compare_link(struct cache_entry *ce, size_t expected_size)
{ {
int match = -1; int match = -1;
char *target;
void *buffer; void *buffer;
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
int len; struct strbuf sb = STRBUF_INIT;
target = xmalloc(expected_size); if (strbuf_readlink(&sb, ce->name, expected_size))
len = readlink(ce->name, target, expected_size);
if (len != expected_size) {
free(target);
return -1; return -1;
}
buffer = read_sha1_file(ce->sha1, &type, &size); buffer = read_sha1_file(ce->sha1, &type, &size);
if (!buffer) { if (buffer) {
free(target); if (size == sb.len)
return -1; match = memcmp(buffer, sb.buf, size);
free(buffer);
} }
if (size == expected_size) strbuf_release(&sb);
match = memcmp(buffer, target, size);
free(buffer);
free(target);
return match; return match;
} }