Skip to content

Conversation

@whitwham
Copy link
Contributor

@whitwham whitwham commented Oct 1, 2025

Add code to read from S3 sources in the same style as the current writing code. Merge the s3_write.c code into hfile_s3.c to put all the S3 code in the same file.

This should simplify the S3 code and give us a little more flexibility in how we use it.

Still need to remove the old writing code (file removal and other modifications).

hfile_s3.c Outdated


if (ret) {
fprintf(stderr, "Unable to open file.\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to do something like hfile_libcul's easy_errno() here.

Add code to read from S3 sources in the same style as the current writing code.
Merge the s3_write.c code into hfile_s3.c to put all the S3 code in the same
file.

This should simplify the S3 code and give us a little more flexibility in how
we use it.
@whitwham whitwham marked this pull request as ready for review November 6, 2025 14:47
Comment on lines +1307 to +1334
struct curl_slist *headers = NULL;

// add the scheme marker
ksprintf(&final_url, "s3w+%s", url.s);
if (auth->l)
if ((headers = curl_slist_append(headers, auth->s)) == NULL)
goto error;

if(final_url.l == 0) goto error;
if ((headers = curl_slist_append(headers, date->s)) == NULL)
goto error;

fp = hopen(final_url.s, mode, "va_list", argsp,
"s3_auth_callback", write_authorisation_callback,
"s3_auth_callback_data", ad,
"redirect_callback", redirect_endpoint_callback,
"set_region_callback", set_region,
NULL);
free(final_url.s);
if (content->l)
if ((headers = curl_slist_append(headers, content->s)) == NULL)
goto error;

if (fp == NULL) goto error;
if (range) {
if ((headers = curl_slist_append(headers, range->s)) == NULL)
goto error;
}

free(url.s);

return fp;
if (token->l) {
if ((headers = curl_slist_append(headers, token->s)) == NULL)
goto error;
}

error:
curl_easy_setopt(fp->curl, CURLOPT_HTTPHEADER, headers);

if (fp) hclose_abruptly(fp);
free(url.s);
free_auth_data(ad);
error:

return NULL;
return headers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a risk of leaking headers here because curl_slist_append() can return NULL. In fact, gievn the number of times it's called, I'd be tempted to wrap it in a function that takes a struct curl_slist **, and returns a non-zero value on error so the dance needed to prevent loss of the pointer doesn't have to be repeated.

Comment on lines +1111 to +1112
static int set_region(void *adv, kstring_t *region) {
s3_auth_data *ad = (s3_auth_data *) adv;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting from a void * is no longer needed here.

Suggested change
static int set_region(void *adv, kstring_t *region) {
s3_auth_data *ad = (s3_auth_data *) adv;
static int set_region(s3_auth_data *ad, kstring_t *region) {

return -1;
}

ret = set_region((void *)fp->au, &region);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast can be removed.

#ifdef ENABLE_PLUGINS
// Embed version string for examination via strings(1) or what(1)
static const char id[] =
"@(#)hfile_s3 test plugin (htslib)\t" HTS_VERSION_TEXT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a test any more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants