* Open and mmap the index file at path, perform a couple of * consistency checks, then record its information to p. Return 0 on * success. */
| 158 | * success. |
| 159 | */ |
| 160 | static int check_packed_git_idx(const char *path, struct packed_git *p) |
| 161 | { |
| 162 | void *idx_map; |
| 163 | size_t idx_size; |
| 164 | int fd = git_open(path), ret; |
| 165 | struct stat st; |
| 166 | const unsigned int hashsz = p->repo->hash_algo->rawsz; |
| 167 | |
| 168 | if (fd < 0) |
| 169 | return -1; |
| 170 | if (fstat(fd, &st)) { |
| 171 | close(fd); |
| 172 | return -1; |
| 173 | } |
| 174 | idx_size = xsize_t(st.st_size); |
| 175 | if (idx_size < 4 * 256 + hashsz + hashsz) { |
| 176 | close(fd); |
| 177 | return error("index file %s is too small", path); |
| 178 | } |
| 179 | idx_map = xmmap(NULL, idx_size, PROT_READ, MAP_PRIVATE, fd, 0); |
| 180 | close(fd); |
| 181 | |
| 182 | ret = load_idx(path, hashsz, idx_map, idx_size, p); |
| 183 | |
| 184 | if (ret) |
| 185 | munmap(idx_map, idx_size); |
| 186 | |
| 187 | return ret; |
| 188 | } |
| 189 | |
| 190 | int load_idx(const char *path, const unsigned int hashsz, void *idx_map, |
| 191 | size_t idx_size, struct packed_git *p) |
no test coverage detected