Skip to content

Commit

Permalink
Make 'ce_compare_link()' use the new 'strbuf_readlink()'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Dec 17, 2008
1 parent b11b7e1 commit a60272b
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
int match = -1;
char *target;
void *buffer;
unsigned long size;
enum object_type type;
int len;
struct strbuf sb = STRBUF_INIT;

target = xmalloc(expected_size);
len = readlink(ce->name, target, expected_size);
if (len != expected_size) {
free(target);
if (strbuf_readlink(&sb, ce->name, expected_size))
return -1;
}

buffer = read_sha1_file(ce->sha1, &type, &size);
if (!buffer) {
free(target);
return -1;
if (buffer) {
if (size == sb.len)
match = memcmp(buffer, sb.buf, size);
free(buffer);
}
if (size == expected_size)
match = memcmp(buffer, target, size);
free(buffer);
free(target);
strbuf_release(&sb);
return match;
}

Expand Down

0 comments on commit a60272b

Please sign in to comment.