* This function verifies if index_state has the correct sha1 of the * index file. Don't die if we have any other failure, just return 0. */
| 2693 | * index file. Don't die if we have any other failure, just return 0. |
| 2694 | */ |
| 2695 | static int verify_index_from(const struct index_state *istate, const char *path) |
| 2696 | { |
| 2697 | int fd; |
| 2698 | ssize_t n; |
| 2699 | struct stat st; |
| 2700 | unsigned char hash[GIT_MAX_RAWSZ]; |
| 2701 | |
| 2702 | if (!istate->initialized) |
| 2703 | return 0; |
| 2704 | |
| 2705 | fd = open(path, O_RDONLY); |
| 2706 | if (fd < 0) |
| 2707 | return 0; |
| 2708 | |
| 2709 | if (fstat(fd, &st)) |
| 2710 | goto out; |
| 2711 | |
| 2712 | if (st.st_size < sizeof(struct cache_header) + the_hash_algo->rawsz) |
| 2713 | goto out; |
| 2714 | |
| 2715 | n = pread_in_full(fd, hash, the_hash_algo->rawsz, st.st_size - the_hash_algo->rawsz); |
| 2716 | if (n != the_hash_algo->rawsz) |
| 2717 | goto out; |
| 2718 | |
| 2719 | if (!hasheq(istate->oid.hash, hash, the_repository->hash_algo)) |
| 2720 | goto out; |
| 2721 | |
| 2722 | close(fd); |
| 2723 | return 1; |
| 2724 | |
| 2725 | out: |
| 2726 | close(fd); |
| 2727 | return 0; |
| 2728 | } |
| 2729 | |
| 2730 | static int repo_verify_index(struct repository *repo) |
| 2731 | { |
no test coverage detected