Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cram seek ability to do range queries via SEEK_CUR. #1878

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 1 addition & 18 deletions cram/cram_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -5440,28 +5440,11 @@ cram_fd *cram_dopen(hFILE *fp, const char *filename, const char *mode) {
* -1 on failure
*/
int cram_seek(cram_fd *fd, off_t offset, int whence) {
char buf[65536];

fd->ooc = 0;

cram_drain_rqueue(fd);

if (hseek(fd->fp, offset, whence) >= 0) {
return 0;
}

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;
return hseek(fd->fp, offset, whence) >= 0 ? 0 : -1;
}

/*
Expand Down