Skip to content

Commit

Permalink
Remove cram seek ability to do range queries via SEEK_CUR.
Browse files Browse the repository at this point in the history
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 samtools#1877
  • Loading branch information
jkbonfield committed Jan 23, 2025
1 parent 7b65da3 commit e4bdae1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
4 changes: 1 addition & 3 deletions cram/cram_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,7 @@ int cram_seek_to_refpos(cram_fd *fd, cram_range *r) {
// Ideally use an index, so see if we have one.
if ((e = cram_index_query(fd, r->refid, r->start, NULL))) {
if (0 != cram_seek(fd, e->offset, SEEK_SET)) {
if (0 != cram_seek(fd, e->offset - fd->first_container, SEEK_CUR)) {
ret = -1; goto err;
}
ret = -1; goto err;
}
} else {
// Absent from index, but this most likely means it simply has no data.
Expand Down
8 changes: 0 additions & 8 deletions cram/cram_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -5453,14 +5453,6 @@ int cram_seek(cram_fd *fd, off_t offset, int whence) {
if (!(whence == SEEK_CUR && offset >= 0))
return -1;

/* Couldn't fseek, but we're in SEEK_CUR mode so read instead */
while (offset > 0) {
int len = MIN(65536, offset);
if (len != hread(fd->fp, buf, len))
return -1;
offset -= len;
}

return 0;
}

Expand Down

0 comments on commit e4bdae1

Please sign in to comment.