Skip to content

Commit a60272b

Browse files
torvaldsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b11b7e1 commit a60272b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

read-cache.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,21 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
9999
static int ce_compare_link(struct cache_entry *ce, size_t expected_size)
100100
{
101101
int match = -1;
102-
char *target;
103102
void *buffer;
104103
unsigned long size;
105104
enum object_type type;
106-
int len;
105+
struct strbuf sb = STRBUF_INIT;
107106

108-
target = xmalloc(expected_size);
109-
len = readlink(ce->name, target, expected_size);
110-
if (len != expected_size) {
111-
free(target);
107+
if (strbuf_readlink(&sb, ce->name, expected_size))
112108
return -1;
113-
}
109+
114110
buffer = read_sha1_file(ce->sha1, &type, &size);
115-
if (!buffer) {
116-
free(target);
117-
return -1;
111+
if (buffer) {
112+
if (size == sb.len)
113+
match = memcmp(buffer, sb.buf, size);
114+
free(buffer);
118115
}
119-
if (size == expected_size)
120-
match = memcmp(buffer, target, size);
121-
free(buffer);
122-
free(target);
116+
strbuf_release(&sb);
123117
return match;
124118
}
125119

0 commit comments

Comments
 (0)