Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #62 from neicnordic/fix/coordinate-bug
Browse files Browse the repository at this point in the history
fix coordinate to reader translation bug
  • Loading branch information
teemukataja authored Nov 2, 2021
2 parents f986b63 + 0aa5af3 commit ee79d0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions api/sda/sda.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,22 @@ func Download(w http.ResponseWriter, r *http.Request) {
http.Error(w, "endCoordinate must be an integer", 400)
return
}
if end < start {
log.Errorf("endCoordinate=%d must be greater than startCoordinate=%d", end, start)
http.Error(w, "endCoordinate must be greater than startCoordinate", 400)
return
}
// API query params take a coordinate range to read "start...end"
// But Crypt4GHReader takes a start byte and number of bytes to read "start...(end-start)"
bytesToRead := end - start
coordinates.NumberLengths = 2
coordinates.Lengths = []uint64{start, end}
coordinates.Lengths = []uint64{start, bytesToRead}
} else {
coordinates = nil
}

// Get file stream
fileStream, err := files.StreamFile(fileDetails.Header, file, coordinates)
log.Debugf("HELLO %v", err)
if err != nil {
log.Errorf("could not prepare file for streaming, %s", err)
http.Error(w, "file stream error", 500)
Expand Down
3 changes: 2 additions & 1 deletion internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ func (dbs *SQLdb) getFiles(datasetID string) ([]*FileInfo, error) {
"decrypted_file_size, decrypted_file_checksum, decrypted_file_checksum_type, file_status from " +
"local_ega_ebi.file a, local_ega_ebi.file_dataset b WHERE dataset_id = $1 AND a.file_id=b.file_id;"

// nolint:rowserrcheck
rows, err := db.Query(query, datasetID)
if rows.Err() != nil || err != nil {
if err != nil {
log.Error(err)
return nil, err
}
Expand Down

0 comments on commit ee79d0a

Please sign in to comment.