Skip to content

Commit

Permalink
builtins.fetchurl: Fix segfault on s3:// URLs
Browse files Browse the repository at this point in the history
Also, add an activity to show that we're downloading an s3:// file.
  • Loading branch information
edolstra committed Oct 11, 2024
1 parent dbcd4cd commit 62b5da7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,17 @@ struct curlFileTransfer : public FileTransfer

S3Helper s3Helper(profile, region, scheme, endpoint);

Activity act(*logger, lvlTalkative, actFileTransfer,
fmt("downloading '%s'", request.uri),
{request.uri}, request.parentAct);

// FIXME: implement ETag
auto s3Res = s3Helper.getObject(bucketName, key);
FileTransferResult res;
if (!s3Res.data)
throw FileTransferError(NotFound, "S3 object '%s' does not exist", request.uri);
res.data = std::move(*s3Res.data);
res.urls.push_back(request.uri);
callback(std::move(res));
#else
throw nix::Error("cannot download '%s' because Nix is not built with S3 support", request.uri);
Expand Down
3 changes: 3 additions & 0 deletions tests/nixos/s3-binary-cache-store.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ in {
server.succeed("${env} nix copy --to '${storeUrl}' ${pkgA}")
# Test fetchurl on s3:// URLs while we're at it.
client.succeed("${env} nix eval --impure --expr 'builtins.fetchurl { name = \"foo\"; url = \"s3://my-cache/nix-cache-info?endpoint=http://server:9000&region=eu-west-1\"; }'")
# Copy a package from the binary cache.
client.fail("nix path-info ${pkgA}")
Expand Down

0 comments on commit 62b5da7

Please sign in to comment.