@matheusbsbs / matheus-bagliano / commits / a60272b38e
Fork 0

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>

Linus Torvalds committed Dec 17, 2008 at 09:47 UTC a60272b38e548f46c5e1d7127cf18a469fefa237
1 file changed +8 -14
read-cache.c
+8 -14
@@ -99,27 +99,21 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
99 static int ce_compare_link(struct cache_entry *ce, size_t expected_size)
100 {
101 int match = -1;
102 - char *target;
102 void *buffer;
103 unsigned long size;
104 enum object_type type;
106 - int len;
105 + struct strbuf sb = STRBUF_INIT;
106
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))
108 return -1;
113 - }
109 +
110 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);
115 }
119 - if (size == expected_size)
120 - match = memcmp(buffer, target, size);
121 - free(buffer);
122 - free(target);
116 + strbuf_release(&sb);
117 return match;
118 }
119