midx: use real paths in lookup_multi_pack_index()
This helper looks for a parsed multi-pack-index whose object directory matches the given object_dir. Before going into the loop over the parsed multi-pack-indexes, it calls find_odb() to ensure that the given object_dir is actually a known object directory. However, find_odb() uses real-path manipulations to compare the input to the alternate directories. This same real-path comparison is not used in the loop, leading to potential issues with the strcmp(). Update the method to use the real-path values instead. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Apr 25, 2022 at 18:27 UTC
eafcc6de5296f6afc67fdc98101ae51959203ad8
1 file changed
+13
-4
midx.c
+13
-4
@@ -1113,17 +1113,26 @@ cleanup:
1113
static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
1114
const char *object_dir)
1115
{
1116
+ struct multi_pack_index *result = NULL;
1117
struct multi_pack_index *cur;
1118
+ char *obj_dir_real = real_pathdup(object_dir, 1);
1119
+ struct strbuf cur_path_real = STRBUF_INIT;
1120
1121
/* Ensure the given object_dir is local, or a known alternate. */
1119
- find_odb(r, object_dir);
1122
+ find_odb(r, obj_dir_real);
1123
1124
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
1122
- if (!strcmp(object_dir, cur->object_dir))
1123
- return cur;
1125
+ strbuf_realpath(&cur_path_real, cur->object_dir, 1);
1126
+ if (!strcmp(obj_dir_real, cur_path_real.buf)) {
1127
+ result = cur;
1128
+ goto cleanup;
1129
+ }
1130
}
1131
1126
- return NULL;
1132
+cleanup:
1133
+ free(obj_dir_real);
1134
+ strbuf_release(&cur_path_real);
1135
+ return result;
1136
}
1137
1138
static int write_midx_internal(const char *object_dir,