diff options
| author | Derrick Stolee <derrickstolee@github.com> | 2022-11-07 18:35:43 +0000 |
|---|---|---|
| committer | Taylor Blau <me@ttaylorr.com> | 2022-11-07 13:53:52 -0500 |
| commit | a17ad58dfc28442816321c22d150f0944bc75584 (patch) | |
| tree | c129fd2ed00fde488783f99e436b0b07194a324a | |
| parent | c25606aea1c233e4914acc8d73111b4aeb63661e (diff) | |
| download | git-a17ad58dfc28442816321c22d150f0944bc75584.tar.gz | |
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>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
| -rw-r--r-- | chunk-format.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/chunk-format.c b/chunk-format.c index 0275b74a89..f1b2c8a8b3 100644 --- a/chunk-format.c +++ b/chunk-format.c @@ -13,6 +13,7 @@ struct chunk_info { chunk_write_fn write_fn; const void *start; + off_t offset; }; struct chunkfile { @@ -78,16 +79,16 @@ int write_chunkfile(struct chunkfile *cf, void *data) hashwrite_be64(cf->f, cur_offset); for (i = 0; i < cf->chunks_nr; i++) { - off_t start_offset = hashfile_total(cf->f); + cf->chunks[i].offset = hashfile_total(cf->f); result = cf->chunks[i].write_fn(cf->f, data); if (result) goto cleanup; - if (hashfile_total(cf->f) - start_offset != cf->chunks[i].size) + if (hashfile_total(cf->f) - cf->chunks[i].offset != cf->chunks[i].size) BUG("expected to write %"PRId64" bytes to chunk %"PRIx32", but wrote %"PRId64" instead", cf->chunks[i].size, cf->chunks[i].id, - hashfile_total(cf->f) - start_offset); + hashfile_total(cf->f) - cf->chunks[i].offset); } cleanup: |
