change: decompress the hashed section too
Dependencies
- [2]
KDJUAAALchange: prefix function names with change_ - [3]
Q7TKZCJPAdd initial support for reading the offsets from a (fixed) change - [4]
QEFCNNVCchange: display offsets for given change file - [5]
AEMTSEJXchange: simplify readout of offsets - [6]
RIWSVVASchange: decompress the 'contents' with zstd_seekable
Change contents
- edit in change.c at line 12
voiddump_buf(const char *name, uint8_t *buf, size_t len){int i; - edit in change.c at line 18
if (len == 0) {printf("%s = []\n", name);return;}printf("%s = [%02x", name, buf[0]);for (i = 1; i < len; i++)printf(", %02x", buf[i]);printf("]\n");} - edit in change.c at line 59
}voiddump_buf(const char *name, uint8_t *buf, size_t len){int i;if (len == 0) {printf("%s = []\n", name);return;}printf("%s = [%u", name, buf[0]);for (i = 1; i < len; i++)printf(", %u", buf[i]);printf("]\n"); - replacement in change.c at line 62
* Read the contents section of the open change file, decompress it and return* the raw bytes.** Returns a malloc()'ed byte buffer that the caller is responsible for* deallocating. Returns NULL if the full contents could not be read, or the* decompression failed, or some other error occurred.* Read in an expected amount of bytes (or die failing), and decompress with* zstd-seekable. Return a malloc()'ed byte buffer that the caller is in charge* of free()'ing. - replacement in change.c at line 66
uint8_t *change_read_contents(int fd, struct offsets *off)static uint8_t *decompress_segment(int fd,size_t compressed_len,uint64_t expected_len) - edit in change.c at line 73
/*** Allocate two buffers: one for compressed data, and one for* decompressed data. The decompressed data buffer is the return value.*/ - edit in change.c at line 75
size_t compressed_to_read; - replacement in change.c at line 79
compressed_to_read = off->total - off->contents_off;printf("expecting to read %lu bytes (compressed)\n", compressed_to_read);compressed = calloc(sizeof(uint8_t), compressed_to_read);printf("expecting to read %lu bytes (compressed)\n", compressed_len);compressed = calloc(sizeof(uint8_t), compressed_len); - replacement in change.c at line 85
buf = calloc(sizeof(uint8_t), off->contents_len);buf = calloc(sizeof(uint8_t), expected_len); - replacement in change.c at line 92
compressed_read = read(fd, compressed, compressed_to_read);if (compressed_read != compressed_to_read) {compressed_read = read(fd, compressed, compressed_len);if (compressed_read != compressed_len) { - replacement in change.c at line 95
compressed_to_read, compressed_read);compressed_len, compressed_read); - replacement in change.c at line 106
result = ZSTD_seekable_initBuff(zs, compressed, compressed_to_read);result = ZSTD_seekable_initBuff(zs, compressed, compressed_len); - replacement in change.c at line 113
result = ZSTD_seekable_decompress(zs, buf, off->contents_len, 0);result = ZSTD_seekable_decompress(zs, buf, expected_len, 0); - replacement in change.c at line 120
if (result != off->contents_len) {fprintf(stderr, "decoded %lu bytes, wanted %lu\n", result, off->contents_len);if (result != expected_len) {fprintf(stderr, "decoded %lu bytes, wanted %lu\n", result, expected_len); - edit in change.c at line 136
}/****/intchange_decode_hashed(int fd, size_t comp_hashed_len, size_t hashed_len){uint8_t *buf; - edit in change.c at line 146
buf = decompress_segment(fd, comp_hashed_len, hashed_len);if (buf == NULL) {fprintf(stderr, "error: failed to decompress hashed segment\n");return 1;}dump_buf("hashed", buf, hashed_len);free(buf);return 0;}/*** Read the contents section of the open change file, decompress it and return* the raw bytes.** Returns a malloc()'ed byte buffer that the caller is responsible for* deallocating. Returns NULL if the full contents could not be read, or the* decompression failed, or some other error occurred.*/uint8_t *change_read_contents(int fd, struct offsets *off){return decompress_segment(fd, off->total - off->contents_off, off->contents_len); - edit in change.c at line 205
goto out;}err = change_decode_hashed(fd, off.unhashed_off - OFFSETS_SIZE, off.hashed_len);if (err != 0) {printf("error: failed to decode hashed\n"); - edit in change.c at line 217
** seek to off.contents_off - OFFSETS_SIZE