Commit aa51f4a4acac901a4f1bf4062664644ce95d3e8c

Stefan Sperling 2021-06-18T13:57:59

handle fseek in got_deltify() instead of in stretchblk(); simplifies the code

diff --git a/lib/deltify.c b/lib/deltify.c
index e27b25b..330dc41 100644
--- a/lib/deltify.c
+++ b/lib/deltify.c
@@ -315,8 +315,6 @@ stretchblk(FILE *basefile, struct got_delta_block *block, FILE *f,
 {
 	uint8_t basebuf[GOT_DELTIFY_MAXCHUNK], buf[GOT_DELTIFY_MAXCHUNK];
 	size_t base_r, r, i;
-	off_t orig_blocklen = *blocklen;
-	off_t pos = ftello(f);
 	int buf_equal = 1;
 
 	if (fseeko(basefile, block->offset, SEEK_SET) == -1)
@@ -344,9 +342,6 @@ stretchblk(FILE *basefile, struct got_delta_block *block, FILE *f,
 		}
 	}
 
-	if (fseeko(f, pos + *blocklen - orig_blocklen, SEEK_SET) == -1)
-		return got_error_from_errno("fseeko");
-
 	return NULL;
 }
 
@@ -403,6 +398,9 @@ got_deltify(struct got_delta_instruction **deltas, int *ndeltas,
 			    blocklen);
 		}
 		fileoffset += blocklen;
+		if (fseeko(f, fileoffset, SEEK_SET) == -1)
+			return got_error_from_errno("fseeko");
+
 	}
 
 	if (err) {