Skip to content

Commit 1f338eb

Browse files
committed
Remove cram seek ability to do range queries via SEEK_CUR.
This was a feature that came all the way from the initial index support added to io_lib, but I think it's a misfeature. The consequence of it is on failing with a SEEK_SET (eg network error, or file corruption) it falls back to doing a read-and-discard loop to simulate the seek via SEEK_CUR. This may perhaps be of use when querying stdin, but it's highly unlikely for us to be doing that while also having an index on disk and it's not something we support with other formats. Fixes #1877
1 parent 7b65da3 commit 1f338eb

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

cram/cram_index.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,7 @@ int cram_seek_to_refpos(cram_fd *fd, cram_range *r) {
580580
// Ideally use an index, so see if we have one.
581581
if ((e = cram_index_query(fd, r->refid, r->start, NULL))) {
582582
if (0 != cram_seek(fd, e->offset, SEEK_SET)) {
583-
if (0 != cram_seek(fd, e->offset - fd->first_container, SEEK_CUR)) {
584-
ret = -1; goto err;
585-
}
583+
ret = -1; goto err;
586584
}
587585
} else {
588586
// Absent from index, but this most likely means it simply has no data.

cram/cram_io.c

+1-18
Original file line numberDiff line numberDiff line change
@@ -5440,28 +5440,11 @@ cram_fd *cram_dopen(hFILE *fp, const char *filename, const char *mode) {
54405440
* -1 on failure
54415441
*/
54425442
int cram_seek(cram_fd *fd, off_t offset, int whence) {
5443-
char buf[65536];
5444-
54455443
fd->ooc = 0;
54465444

54475445
cram_drain_rqueue(fd);
54485446

5449-
if (hseek(fd->fp, offset, whence) >= 0) {
5450-
return 0;
5451-
}
5452-
5453-
if (!(whence == SEEK_CUR && offset >= 0))
5454-
return -1;
5455-
5456-
/* Couldn't fseek, but we're in SEEK_CUR mode so read instead */
5457-
while (offset > 0) {
5458-
int len = MIN(65536, offset);
5459-
if (len != hread(fd->fp, buf, len))
5460-
return -1;
5461-
offset -= len;
5462-
}
5463-
5464-
return 0;
5447+
return hseek(fd->fp, offset, whence) >= 0 ? 0 : -1;
54655448
}
54665449

54675450
/*

0 commit comments

Comments
 (0)