1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-24 11:19:35 +01:00

libstore/filetransfer: Use ref instead of std::shared_ptr

Those can never be nullptr, so we should use the type system
to ensure this invariant.
This commit is contained in:
Sergei Zimmerman 2025-11-21 23:52:00 +03:00
parent eb654acdd1
commit 3f8474a62f
No known key found for this signature in database

View file

@ -624,7 +624,7 @@ struct curlFileTransfer : public FileTransfer
errorSink.reset(); errorSink.reset();
embargo = std::chrono::steady_clock::now() + std::chrono::milliseconds(ms); embargo = std::chrono::steady_clock::now() + std::chrono::milliseconds(ms);
try { try {
fileTransfer.enqueueItem(shared_from_this()); fileTransfer.enqueueItem(ref{shared_from_this()});
} catch (const nix::Error & e) { } catch (const nix::Error & e) {
// If enqueue fails (e.g., during shutdown), fail the transfer properly // If enqueue fails (e.g., during shutdown), fail the transfer properly
// instead of letting the exception propagate, which would leave done=false // instead of letting the exception propagate, which would leave done=false
@ -641,15 +641,13 @@ struct curlFileTransfer : public FileTransfer
{ {
struct EmbargoComparator struct EmbargoComparator
{ {
bool operator()(const std::shared_ptr<TransferItem> & i1, const std::shared_ptr<TransferItem> & i2) bool operator()(const ref<TransferItem> & i1, const ref<TransferItem> & i2)
{ {
return i1->embargo > i2->embargo; return i1->embargo > i2->embargo;
} }
}; };
std:: std::priority_queue<ref<TransferItem>, std::vector<ref<TransferItem>>, EmbargoComparator> incoming;
priority_queue<std::shared_ptr<TransferItem>, std::vector<std::shared_ptr<TransferItem>>, EmbargoComparator>
incoming;
private: private:
bool quitting = false; bool quitting = false;
public: public:
@ -851,7 +849,7 @@ struct curlFileTransfer : public FileTransfer
} }
} }
void enqueueItem(std::shared_ptr<TransferItem> item) void enqueueItem(ref<TransferItem> item)
{ {
if (item->request.data && item->request.uri.scheme() != "http" && item->request.uri.scheme() != "https" if (item->request.data && item->request.uri.scheme() != "http" && item->request.uri.scheme() != "https"
&& item->request.uri.scheme() != "s3") && item->request.uri.scheme() != "s3")
@ -874,11 +872,11 @@ struct curlFileTransfer : public FileTransfer
if (request.uri.scheme() == "s3") { if (request.uri.scheme() == "s3") {
auto modifiedRequest = request; auto modifiedRequest = request;
modifiedRequest.setupForS3(); modifiedRequest.setupForS3();
enqueueItem(std::make_shared<TransferItem>(*this, std::move(modifiedRequest), std::move(callback))); enqueueItem(make_ref<TransferItem>(*this, std::move(modifiedRequest), std::move(callback)));
return; return;
} }
enqueueItem(std::make_shared<TransferItem>(*this, request, std::move(callback))); enqueueItem(make_ref<TransferItem>(*this, request, std::move(callback)));
} }
}; };