Skip to content

Commit ff176b5

Browse files
committed
chunk-format: store chunk offset during write
As a preparatory step to allowing trailing table of contents, store the offsets of each chunk as we write them. This replaces an existing use of a local variable, but the stored value will be used in the next change. Signed-off-by: Derrick Stolee <derrickstolee@github.com>
1 parent a7bf8cb commit ff176b5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

chunk-format.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct chunk_info {
1313
chunk_write_fn write_fn;
1414

1515
const void *start;
16+
off_t offset;
1617
};
1718

1819
struct chunkfile {
@@ -78,16 +79,16 @@ int write_chunkfile(struct chunkfile *cf, void *data)
7879
hashwrite_be64(cf->f, cur_offset);
7980

8081
for (i = 0; i < cf->chunks_nr; i++) {
81-
off_t start_offset = hashfile_total(cf->f);
82+
cf->chunks[i].offset = hashfile_total(cf->f);
8283
result = cf->chunks[i].write_fn(cf->f, data);
8384

8485
if (result)
8586
goto cleanup;
8687

87-
if (hashfile_total(cf->f) - start_offset != cf->chunks[i].size)
88+
if (hashfile_total(cf->f) - cf->chunks[i].offset != cf->chunks[i].size)
8889
BUG("expected to write %"PRId64" bytes to chunk %"PRIx32", but wrote %"PRId64" instead",
8990
cf->chunks[i].size, cf->chunks[i].id,
90-
hashfile_total(cf->f) - start_offset);
91+
hashfile_total(cf->f) - cf->chunks[i].offset);
9192
}
9293

9394
cleanup:

0 commit comments

Comments
 (0)